blob: 3a024364dae675cbb5a0c4128e0847999394a34a [file] [log] [blame]
kenton@google.comd2fcbba2010-01-04 19:47:18 +00001#!/bin/sh
2#
3# Protocol Buffers - Google's data interchange format
4# Copyright 2009 Google Inc. All rights reserved.
5# http://code.google.com/p/protobuf/
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10#
11# * Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# * Redistributions in binary form must reproduce the above
14# copyright notice, this list of conditions and the following disclaimer
15# in the documentation and/or other materials provided with the
16# distribution.
17# * Neither the name of Google Inc. nor the names of its
18# contributors may be used to endorse or promote products derived from
19# this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33# Author: kenton@google.com (Kenton Varda)
34#
35# Test protoc's zip output mode.
36
kenton@google.com38fcd392010-01-08 04:48:19 +000037fail() {
kenton@google.comd2fcbba2010-01-04 19:47:18 +000038 echo "$@" >&2
39 exit 1
40}
41
liujisi@google.com33165fe2010-11-02 13:14:58 +000042TEST_TMPDIR=.
43PROTOC=./protoc
44
kenton@google.comd2fcbba2010-01-04 19:47:18 +000045echo '
liujisi@google.com33165fe2010-11-02 13:14:58 +000046 syntax = "proto2";
kenton@google.comd2fcbba2010-01-04 19:47:18 +000047 option java_multiple_files = true;
48 option java_package = "test.jar";
49 option java_outer_classname = "Outer";
50 message Foo {}
51 message Bar {}
liujisi@google.com33165fe2010-11-02 13:14:58 +000052' > $TEST_TMPDIR/testzip.proto
kenton@google.comd2fcbba2010-01-04 19:47:18 +000053
liujisi@google.com33165fe2010-11-02 13:14:58 +000054$PROTOC \
55 --cpp_out=$TEST_TMPDIR/testzip.zip --python_out=$TEST_TMPDIR/testzip.zip \
56 --java_out=$TEST_TMPDIR/testzip.jar -I$TEST_TMPDIR testzip.proto \
57 || fail 'protoc failed.'
kenton@google.comd2fcbba2010-01-04 19:47:18 +000058
59echo "Testing output to zip..."
60if unzip -h > /dev/null; then
liujisi@google.com33165fe2010-11-02 13:14:58 +000061 unzip -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list || fail 'unzip failed.'
kenton@google.comd2fcbba2010-01-04 19:47:18 +000062
liujisi@google.com33165fe2010-11-02 13:14:58 +000063 grep 'testing: testzip\.pb\.cc *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000064 || fail 'testzip.pb.cc not found in output zip.'
liujisi@google.com33165fe2010-11-02 13:14:58 +000065 grep 'testing: testzip\.pb\.h *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000066 || fail 'testzip.pb.h not found in output zip.'
liujisi@google.com33165fe2010-11-02 13:14:58 +000067 grep 'testing: testzip_pb2\.py *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000068 || fail 'testzip_pb2.py not found in output zip.'
liujisi@google.com33165fe2010-11-02 13:14:58 +000069 grep -i 'manifest' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000070 && fail 'Zip file contained manifest.'
71else
72 echo "Warning: 'unzip' command not available. Skipping test."
73fi
74
75echo "Testing output to jar..."
liujisi@google.com33165fe2010-11-02 13:14:58 +000076if jar c $TEST_TMPDIR/testzip.proto > /dev/null; then
77 jar tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list || fail 'jar failed.'
kenton@google.comd2fcbba2010-01-04 19:47:18 +000078
liujisi@google.com33165fe2010-11-02 13:14:58 +000079 grep '^test/jar/Foo\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000080 || fail 'Foo.java not found in output jar.'
liujisi@google.com33165fe2010-11-02 13:14:58 +000081 grep '^test/jar/Bar\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000082 || fail 'Bar.java not found in output jar.'
liujisi@google.com33165fe2010-11-02 13:14:58 +000083 grep '^test/jar/Outer\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
kenton@google.comd2fcbba2010-01-04 19:47:18 +000084 || fail 'Outer.java not found in output jar.'
liujisi@google.com33165fe2010-11-02 13:14:58 +000085 grep '^META-INF/MANIFEST\.MF$' $TEST_TMPDIR/testzip.list > /dev/null \
86 || fail 'Manifest not found in output jar.'
kenton@google.comd2fcbba2010-01-04 19:47:18 +000087else
88 echo "Warning: 'jar' command not available. Skipping test."
89fi
90
91echo PASS