1#!/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
37fail() {
38  echo "$@" >&2
39  exit 1
40}
41
42echo '
43  option java_multiple_files = true;
44  option java_package = "test.jar";
45  option java_outer_classname = "Outer";
46  message Foo {}
47  message Bar {}
48' > testzip.proto
49
50./protoc --cpp_out=testzip.zip --python_out=testzip.zip --java_out=testzip.jar \
51    testzip.proto || fail 'protoc failed.'
52
53echo "Testing output to zip..."
54if unzip -h > /dev/null; then
55  unzip -t testzip.zip > testzip.list || fail 'unzip failed.'
56
57  grep 'testing: testzip\.pb\.cc *OK$' testzip.list > /dev/null \
58    || fail 'testzip.pb.cc not found in output zip.'
59  grep 'testing: testzip\.pb\.h *OK$' testzip.list > /dev/null \
60    || fail 'testzip.pb.h not found in output zip.'
61  grep 'testing: testzip_pb2\.py *OK$' testzip.list > /dev/null \
62    || fail 'testzip_pb2.py not found in output zip.'
63  grep -i 'manifest' testzip.list > /dev/null \
64    && fail 'Zip file contained manifest.'
65else
66  echo "Warning:  'unzip' command not available.  Skipping test."
67fi
68
69echo "Testing output to jar..."
70if jar c testzip.proto > /dev/null; then
71  jar tf testzip.jar > testzip.list || fail 'jar failed.'
72
73  grep '^test/jar/Foo\.java$' testzip.list > /dev/null \
74    || fail 'Foo.java not found in output jar.'
75  grep '^test/jar/Bar\.java$' testzip.list > /dev/null \
76    || fail 'Bar.java not found in output jar.'
77  grep '^test/jar/Outer\.java$' testzip.list > /dev/null \
78    || fail 'Outer.java not found in output jar.'
79  grep '^META-INF/MANIFEST\.MF$' testzip.list > /dev/null \
80    || fail 'Manifest not ofund in output jar.'
81else
82  echo "Warning:  'jar' command not available.  Skipping test."
83fi
84
85echo PASS
86