Tamir Duberstein | 9d9d0b7 | 2015-04-11 20:23:45 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 2 | # |
| 3 | # Protocol Buffers - Google's data interchange format |
| 4 | # Copyright 2008 Google Inc. All rights reserved. |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 5 | # https://developers.google.com/protocol-buffers/ |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 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 | """Tests for google.protobuf.descriptor_database.""" |
| 34 | |
| 35 | __author__ = 'matthewtoia@google.com (Matt Toia)' |
| 36 | |
Dan O'Reilly | 2621c8a | 2015-08-14 22:54:53 -0400 | [diff] [blame] | 37 | try: |
| 38 | import unittest2 as unittest |
| 39 | except ImportError: |
| 40 | import unittest |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 41 | from google.protobuf import descriptor_pb2 |
| 42 | from google.protobuf.internal import factory_test2_pb2 |
| 43 | from google.protobuf import descriptor_database |
| 44 | |
| 45 | |
Tres Seaver | 7ee2583 | 2015-01-13 14:47:32 -0500 | [diff] [blame] | 46 | class DescriptorDatabaseTest(unittest.TestCase): |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 47 | |
| 48 | def testAdd(self): |
| 49 | db = descriptor_database.DescriptorDatabase() |
| 50 | file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString( |
| 51 | factory_test2_pb2.DESCRIPTOR.serialized_pb) |
| 52 | db.Add(file_desc_proto) |
| 53 | |
Tres Seaver | a2abc94 | 2015-01-13 15:47:55 -0500 | [diff] [blame] | 54 | self.assertEqual(file_desc_proto, db.FindFileByName( |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 55 | 'google/protobuf/internal/factory_test2.proto')) |
Tres Seaver | a2abc94 | 2015-01-13 15:47:55 -0500 | [diff] [blame] | 56 | self.assertEqual(file_desc_proto, db.FindFileContainingSymbol( |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 57 | 'google.protobuf.python.internal.Factory2Message')) |
Tres Seaver | a2abc94 | 2015-01-13 15:47:55 -0500 | [diff] [blame] | 58 | self.assertEqual(file_desc_proto, db.FindFileContainingSymbol( |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 59 | 'google.protobuf.python.internal.Factory2Message.NestedFactory2Message')) |
Tres Seaver | a2abc94 | 2015-01-13 15:47:55 -0500 | [diff] [blame] | 60 | self.assertEqual(file_desc_proto, db.FindFileContainingSymbol( |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 61 | 'google.protobuf.python.internal.Factory2Enum')) |
Tres Seaver | a2abc94 | 2015-01-13 15:47:55 -0500 | [diff] [blame] | 62 | self.assertEqual(file_desc_proto, db.FindFileContainingSymbol( |
jieluo@google.com | bde4a32 | 2014-08-12 21:10:30 +0000 | [diff] [blame] | 63 | 'google.protobuf.python.internal.Factory2Message.NestedFactory2Enum')) |
Tres Seaver | a2abc94 | 2015-01-13 15:47:55 -0500 | [diff] [blame] | 64 | self.assertEqual(file_desc_proto, db.FindFileContainingSymbol( |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 65 | 'google.protobuf.python.internal.MessageWithNestedEnumOnly.NestedEnum')) |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 66 | |
| 67 | if __name__ == '__main__': |
Tres Seaver | 7ee2583 | 2015-01-13 14:47:32 -0500 | [diff] [blame] | 68 | unittest.main() |