zip_output_unittest.sh 3.8 KB

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