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 44JAR=jar 45UNZIP=unzip 46 47echo ' 48 syntax = "proto2"; 49 option java_multiple_files = true; 50 option java_package = "test.jar"; 51 option java_outer_classname = "Outer"; 52 message Foo {} 53 message Bar {} 54' > $TEST_TMPDIR/testzip.proto 55 56$PROTOC \ 57 --cpp_out=$TEST_TMPDIR/testzip.zip --python_out=$TEST_TMPDIR/testzip.zip \ 58 --java_out=$TEST_TMPDIR/testzip.jar -I$TEST_TMPDIR testzip.proto \ 59 || fail 'protoc failed.' 60 61echo "Testing output to zip..." 62if $UNZIP -h > /dev/null; then 63 $UNZIP -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list \ 64 || fail 'unzip failed.' 65 66 grep 'testing: testzip\.pb\.cc *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ 67 || fail 'testzip.pb.cc not found in output zip.' 68 grep 'testing: testzip\.pb\.h *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ 69 || fail 'testzip.pb.h not found in output zip.' 70 grep 'testing: testzip_pb2\.py *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ 71 || fail 'testzip_pb2.py not found in output zip.' 72 grep -i 'manifest' $TEST_TMPDIR/testzip.list > /dev/null \ 73 && fail 'Zip file contained manifest.' 74else 75 echo "Warning: 'unzip' command not available. Skipping test." 76fi 77 78echo "Testing output to jar..." 79if $JAR c $TEST_TMPDIR/testzip.proto > /dev/null; then 80 $JAR tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list \ 81 || fail 'jar failed.' 82 83 # Check that -interface.jar timestamps are normalized: 84 if [[ "$(TZ=UTC $JAR tvf $TEST_TMPDIR/testzip.jar)" != *'Tue Jan 01 00:00:00 UTC 1980'* ]]; then 85 fail 'Zip did not contain normalized timestamps' 86 fi 87 88 grep '^test/jar/Foo\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ 89 || fail 'Foo.java not found in output jar.' 90 grep '^test/jar/Bar\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ 91 || fail 'Bar.java not found in output jar.' 92 grep '^test/jar/Outer\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ 93 || fail 'Outer.java not found in output jar.' 94 grep '^META-INF/MANIFEST\.MF$' $TEST_TMPDIR/testzip.list > /dev/null \ 95 || fail 'Manifest not found in output jar.' 96else 97 echo "Warning: 'jar' command not available. Skipping test." 98fi 99 100echo PASS 101