1#!/bin/sh
2#
3# Protocol Buffers - Google's data interchange format
4# Copyright 2009 Google Inc.  All rights reserved.
5# https://developers.google.com/protocol-buffers/
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
37fail() {
38  echo "$@" >&2
39  exit 1
40}
41
42TEST_TMPDIR=.
43PROTOC=./protoc
44
45echo '
46  syntax = "proto2";
47  option java_multiple_files = true;
48  option java_package = "test.jar";
49  option java_outer_classname = "Outer";
50  message Foo {}
51  message Bar {}
52' > $TEST_TMPDIR/testzip.proto
53
54$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.'
58
59echo "Testing output to zip..."
60if unzip -h > /dev/null; then
61  unzip -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list || fail 'unzip failed.'
62
63  grep 'testing: testzip\.pb\.cc *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
64    || fail 'testzip.pb.cc not found in output zip.'
65  grep 'testing: testzip\.pb\.h *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
66    || fail 'testzip.pb.h not found in output zip.'
67  grep 'testing: testzip_pb2\.py *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
68    || fail 'testzip_pb2.py not found in output zip.'
69  grep -i 'manifest' $TEST_TMPDIR/testzip.list > /dev/null \
70    && fail 'Zip file contained manifest.'
71else
72  echo "Warning:  'unzip' command not available.  Skipping test."
73fi
74
75echo "Testing output to jar..."
76if jar c $TEST_TMPDIR/testzip.proto > /dev/null; then
77  jar tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list || fail 'jar failed.'
78
79  grep '^test/jar/Foo\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
80    || fail 'Foo.java not found in output jar.'
81  grep '^test/jar/Bar\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
82    || fail 'Bar.java not found in output jar.'
83  grep '^test/jar/Outer\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
84    || fail 'Outer.java not found in output jar.'
85  grep '^META-INF/MANIFEST\.MF$' $TEST_TMPDIR/testzip.list > /dev/null \
86    || fail 'Manifest not found in output jar.'
87else
88  echo "Warning:  'jar' command not available.  Skipping test."
89fi
90
91echo PASS
92