cpp_unittest.cc revision fbaaef999ba563838ebd00874ed8a1c01fbf286d
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3// http://code.google.com/p/protobuf/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9//     * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11//     * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15//     * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// Author: kenton@google.com (Kenton Varda)
32//  Based on original Protocol Buffers design by
33//  Sanjay Ghemawat, Jeff Dean, and others.
34//
35// To test the code generator, we actually use it to generate code for
36// google/protobuf/unittest.proto, then test that.  This means that we
37// are actually testing the parser and other parts of the system at the same
38// time, and that problems in the generator may show up as compile-time errors
39// rather than unittest failures, which may be surprising.  However, testing
40// the output of the C++ generator directly would be very hard.  We can't very
41// well just check it against golden files since those files would have to be
42// updated for any small change; such a test would be very brittle and probably
43// not very helpful.  What we really want to test is that the code compiles
44// correctly and produces the interfaces we expect, which is why this test
45// is written this way.
46
47#include <vector>
48
49#include <google/protobuf/unittest.pb.h>
50#include <google/protobuf/unittest_optimize_for.pb.h>
51#include <google/protobuf/unittest_embed_optimize_for.pb.h>
52#include <google/protobuf/test_util.h>
53#include <google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h>
54#include <google/protobuf/compiler/importer.h>
55#include <google/protobuf/io/coded_stream.h>
56#include <google/protobuf/io/zero_copy_stream_impl.h>
57#include <google/protobuf/descriptor.h>
58#include <google/protobuf/descriptor.pb.h>
59#include <google/protobuf/dynamic_message.h>
60
61#include <google/protobuf/stubs/common.h>
62#include <google/protobuf/stubs/strutil.h>
63#include <google/protobuf/stubs/substitute.h>
64#include <google/protobuf/testing/googletest.h>
65#include <gtest/gtest.h>
66#include <google/protobuf/stubs/stl_util-inl.h>
67
68namespace google {
69namespace protobuf {
70namespace compiler {
71namespace cpp {
72
73// Can't use an anonymous namespace here due to brokenness of Tru64 compiler.
74namespace cpp_unittest {
75
76
77class MockErrorCollector : public MultiFileErrorCollector {
78 public:
79  MockErrorCollector() {}
80  ~MockErrorCollector() {}
81
82  string text_;
83
84  // implements ErrorCollector ---------------------------------------
85  void AddError(const string& filename, int line, int column,
86                const string& message) {
87    strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n",
88                                 filename, line, column, message);
89  }
90};
91
92#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
93
94// Test that generated code has proper descriptors:
95// Parse a descriptor directly (using google::protobuf::compiler::Importer) and
96// compare it to the one that was produced by generated code.
97TEST(GeneratedDescriptorTest, IdenticalDescriptors) {
98  const FileDescriptor* generated_descriptor =
99    unittest::TestAllTypes::descriptor()->file();
100
101  // Set up the Importer.
102  MockErrorCollector error_collector;
103  DiskSourceTree source_tree;
104  source_tree.MapPath("", TestSourceDir());
105  Importer importer(&source_tree, &error_collector);
106
107  // Import (parse) unittest.proto.
108  const FileDescriptor* parsed_descriptor =
109    importer.Import("google/protobuf/unittest.proto");
110  EXPECT_EQ("", error_collector.text_);
111  ASSERT_TRUE(parsed_descriptor != NULL);
112
113  // Test that descriptors are generated correctly by converting them to
114  // FileDescriptorProtos and comparing.
115  FileDescriptorProto generated_decsriptor_proto, parsed_descriptor_proto;
116  generated_descriptor->CopyTo(&generated_decsriptor_proto);
117  parsed_descriptor->CopyTo(&parsed_descriptor_proto);
118
119  EXPECT_EQ(parsed_descriptor_proto.DebugString(),
120            generated_decsriptor_proto.DebugString());
121}
122
123#endif  // !PROTOBUF_TEST_NO_DESCRIPTORS
124
125// ===================================================================
126
127TEST(GeneratedMessageTest, Defaults) {
128  // Check that all default values are set correctly in the initial message.
129  unittest::TestAllTypes message;
130
131  TestUtil::ExpectClear(message);
132
133  // Messages should return pointers to default instances until first use.
134  // (This is not checked by ExpectClear() since it is not actually true after
135  // the fields have been set and then cleared.)
136  EXPECT_EQ(&unittest::TestAllTypes::OptionalGroup::default_instance(),
137            &message.optionalgroup());
138  EXPECT_EQ(&unittest::TestAllTypes::NestedMessage::default_instance(),
139            &message.optional_nested_message());
140  EXPECT_EQ(&unittest::ForeignMessage::default_instance(),
141            &message.optional_foreign_message());
142  EXPECT_EQ(&unittest_import::ImportMessage::default_instance(),
143            &message.optional_import_message());
144}
145
146TEST(GeneratedMessageTest, FloatingPointDefaults) {
147  const unittest::TestExtremeDefaultValues& extreme_default =
148      unittest::TestExtremeDefaultValues::default_instance();
149
150  EXPECT_EQ(0.0f, extreme_default.zero_float());
151  EXPECT_EQ(1.0f, extreme_default.one_float());
152  EXPECT_EQ(1.5f, extreme_default.small_float());
153  EXPECT_EQ(-1.0f, extreme_default.negative_one_float());
154  EXPECT_EQ(-1.5f, extreme_default.negative_float());
155  EXPECT_EQ(2.0e8f, extreme_default.large_float());
156  EXPECT_EQ(-8e-28f, extreme_default.small_negative_float());
157}
158
159TEST(GeneratedMessageTest, Accessors) {
160  // Set every field to a unique value then go back and check all those
161  // values.
162  unittest::TestAllTypes message;
163
164  TestUtil::SetAllFields(&message);
165  TestUtil::ExpectAllFieldsSet(message);
166
167  TestUtil::ModifyRepeatedFields(&message);
168  TestUtil::ExpectRepeatedFieldsModified(message);
169}
170
171TEST(GeneratedMessageTest, MutableStringDefault) {
172  // mutable_foo() for a string should return a string initialized to its
173  // default value.
174  unittest::TestAllTypes message;
175
176  EXPECT_EQ("hello", *message.mutable_default_string());
177
178  // Note that the first time we call mutable_foo(), we get a newly-allocated
179  // string, but if we clear it and call it again, we get the same object again.
180  // We should verify that it has its default value in both cases.
181  message.set_default_string("blah");
182  message.Clear();
183
184  EXPECT_EQ("hello", *message.mutable_default_string());
185}
186
187TEST(GeneratedMessageTest, Clear) {
188  // Set every field to a unique value, clear the message, then check that
189  // it is cleared.
190  unittest::TestAllTypes message;
191
192  TestUtil::SetAllFields(&message);
193  message.Clear();
194  TestUtil::ExpectClear(message);
195
196  // Unlike with the defaults test, we do NOT expect that requesting embedded
197  // messages will return a pointer to the default instance.  Instead, they
198  // should return the objects that were created when mutable_blah() was
199  // called.
200  EXPECT_NE(&unittest::TestAllTypes::OptionalGroup::default_instance(),
201            &message.optionalgroup());
202  EXPECT_NE(&unittest::TestAllTypes::NestedMessage::default_instance(),
203            &message.optional_nested_message());
204  EXPECT_NE(&unittest::ForeignMessage::default_instance(),
205            &message.optional_foreign_message());
206  EXPECT_NE(&unittest_import::ImportMessage::default_instance(),
207            &message.optional_import_message());
208}
209
210TEST(GeneratedMessageTest, EmbeddedNullsInBytesCharStar) {
211  unittest::TestAllTypes message;
212
213  const char* value = "\0lalala\0\0";
214  message.set_optional_bytes(value, 9);
215  ASSERT_EQ(9, message.optional_bytes().size());
216  EXPECT_EQ(0, memcmp(value, message.optional_bytes().data(), 9));
217
218  message.add_repeated_bytes(value, 9);
219  ASSERT_EQ(9, message.repeated_bytes(0).size());
220  EXPECT_EQ(0, memcmp(value, message.repeated_bytes(0).data(), 9));
221}
222
223TEST(GeneratedMessageTest, ClearOneField) {
224  // Set every field to a unique value, then clear one value and insure that
225  // only that one value is cleared.
226  unittest::TestAllTypes message;
227
228  TestUtil::SetAllFields(&message);
229  int64 original_value = message.optional_int64();
230
231  // Clear the field and make sure it shows up as cleared.
232  message.clear_optional_int64();
233  EXPECT_FALSE(message.has_optional_int64());
234  EXPECT_EQ(0, message.optional_int64());
235
236  // Other adjacent fields should not be cleared.
237  EXPECT_TRUE(message.has_optional_int32());
238  EXPECT_TRUE(message.has_optional_uint32());
239
240  // Make sure if we set it again, then all fields are set.
241  message.set_optional_int64(original_value);
242  TestUtil::ExpectAllFieldsSet(message);
243}
244
245TEST(GeneratedMessageTest, StringCharStarLength) {
246  // Verify that we can use a char*,length to set one of the string fields.
247  unittest::TestAllTypes message;
248  message.set_optional_string("abcdef", 3);
249  EXPECT_EQ("abc", message.optional_string());
250
251  // Verify that we can use a char*,length to add to a repeated string field.
252  message.add_repeated_string("abcdef", 3);
253  EXPECT_EQ(1, message.repeated_string_size());
254  EXPECT_EQ("abc", message.repeated_string(0));
255
256  // Verify that we can use a char*,length to set a repeated string field.
257  message.set_repeated_string(0, "wxyz", 2);
258  EXPECT_EQ("wx", message.repeated_string(0));
259}
260
261
262TEST(GeneratedMessageTest, CopyFrom) {
263  unittest::TestAllTypes message1, message2;
264
265  TestUtil::SetAllFields(&message1);
266  message2.CopyFrom(message1);
267  TestUtil::ExpectAllFieldsSet(message2);
268
269  // Copying from self should be a no-op.
270  message2.CopyFrom(message2);
271  TestUtil::ExpectAllFieldsSet(message2);
272}
273
274TEST(GeneratedMessageTest, SwapWithEmpty) {
275  unittest::TestAllTypes message1, message2;
276  TestUtil::SetAllFields(&message1);
277
278  TestUtil::ExpectAllFieldsSet(message1);
279  TestUtil::ExpectClear(message2);
280  message1.Swap(&message2);
281  TestUtil::ExpectAllFieldsSet(message2);
282  TestUtil::ExpectClear(message1);
283}
284
285TEST(GeneratedMessageTest, SwapWithSelf) {
286  unittest::TestAllTypes message;
287  TestUtil::SetAllFields(&message);
288  TestUtil::ExpectAllFieldsSet(message);
289  message.Swap(&message);
290  TestUtil::ExpectAllFieldsSet(message);
291}
292
293TEST(GeneratedMessageTest, SwapWithOther) {
294  unittest::TestAllTypes message1, message2;
295
296  message1.set_optional_int32(123);
297  message1.set_optional_string("abc");
298  message1.mutable_optional_nested_message()->set_bb(1);
299  message1.set_optional_nested_enum(unittest::TestAllTypes::FOO);
300  message1.add_repeated_int32(1);
301  message1.add_repeated_int32(2);
302  message1.add_repeated_string("a");
303  message1.add_repeated_string("b");
304  message1.add_repeated_nested_message()->set_bb(7);
305  message1.add_repeated_nested_message()->set_bb(8);
306  message1.add_repeated_nested_enum(unittest::TestAllTypes::FOO);
307  message1.add_repeated_nested_enum(unittest::TestAllTypes::BAR);
308
309  message2.set_optional_int32(456);
310  message2.set_optional_string("def");
311  message2.mutable_optional_nested_message()->set_bb(2);
312  message2.set_optional_nested_enum(unittest::TestAllTypes::BAR);
313  message2.add_repeated_int32(3);
314  message2.add_repeated_string("c");
315  message2.add_repeated_nested_message()->set_bb(9);
316  message2.add_repeated_nested_enum(unittest::TestAllTypes::BAZ);
317
318  message1.Swap(&message2);
319
320  EXPECT_EQ(456, message1.optional_int32());
321  EXPECT_EQ("def", message1.optional_string());
322  EXPECT_EQ(2, message1.optional_nested_message().bb());
323  EXPECT_EQ(unittest::TestAllTypes::BAR, message1.optional_nested_enum());
324  ASSERT_EQ(1, message1.repeated_int32_size());
325  EXPECT_EQ(3, message1.repeated_int32(0));
326  ASSERT_EQ(1, message1.repeated_string_size());
327  EXPECT_EQ("c", message1.repeated_string(0));
328  ASSERT_EQ(1, message1.repeated_nested_message_size());
329  EXPECT_EQ(9, message1.repeated_nested_message(0).bb());
330  ASSERT_EQ(1, message1.repeated_nested_enum_size());
331  EXPECT_EQ(unittest::TestAllTypes::BAZ, message1.repeated_nested_enum(0));
332
333  EXPECT_EQ(123, message2.optional_int32());
334  EXPECT_EQ("abc", message2.optional_string());
335  EXPECT_EQ(1, message2.optional_nested_message().bb());
336  EXPECT_EQ(unittest::TestAllTypes::FOO, message2.optional_nested_enum());
337  ASSERT_EQ(2, message2.repeated_int32_size());
338  EXPECT_EQ(1, message2.repeated_int32(0));
339  EXPECT_EQ(2, message2.repeated_int32(1));
340  ASSERT_EQ(2, message2.repeated_string_size());
341  EXPECT_EQ("a", message2.repeated_string(0));
342  EXPECT_EQ("b", message2.repeated_string(1));
343  ASSERT_EQ(2, message2.repeated_nested_message_size());
344  EXPECT_EQ(7, message2.repeated_nested_message(0).bb());
345  EXPECT_EQ(8, message2.repeated_nested_message(1).bb());
346  ASSERT_EQ(2, message2.repeated_nested_enum_size());
347  EXPECT_EQ(unittest::TestAllTypes::FOO, message2.repeated_nested_enum(0));
348  EXPECT_EQ(unittest::TestAllTypes::BAR, message2.repeated_nested_enum(1));
349}
350
351TEST(GeneratedMessageTest, CopyConstructor) {
352  unittest::TestAllTypes message1;
353  TestUtil::SetAllFields(&message1);
354
355  unittest::TestAllTypes message2(message1);
356  TestUtil::ExpectAllFieldsSet(message2);
357}
358
359TEST(GeneratedMessageTest, CopyAssignmentOperator) {
360  unittest::TestAllTypes message1;
361  TestUtil::SetAllFields(&message1);
362
363  unittest::TestAllTypes message2;
364  message2 = message1;
365  TestUtil::ExpectAllFieldsSet(message2);
366
367  // Make sure that self-assignment does something sane.
368  message2 = message2;
369  TestUtil::ExpectAllFieldsSet(message2);
370}
371
372TEST(GeneratedMessageTest, UpcastCopyFrom) {
373  // Test the CopyFrom method that takes in the generic const Message&
374  // parameter.
375  unittest::TestAllTypes message1, message2;
376
377  TestUtil::SetAllFields(&message1);
378
379  const Message* source = implicit_cast<const Message*>(&message1);
380  message2.CopyFrom(*source);
381
382  TestUtil::ExpectAllFieldsSet(message2);
383}
384
385#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
386
387TEST(GeneratedMessageTest, DynamicMessageCopyFrom) {
388  // Test copying from a DynamicMessage, which must fall back to using
389  // reflection.
390  unittest::TestAllTypes message2;
391
392  // Construct a new version of the dynamic message via the factory.
393  DynamicMessageFactory factory;
394  scoped_ptr<Message> message1;
395  message1.reset(factory.GetPrototype(
396                     unittest::TestAllTypes::descriptor())->New());
397
398  TestUtil::ReflectionTester reflection_tester(
399    unittest::TestAllTypes::descriptor());
400  reflection_tester.SetAllFieldsViaReflection(message1.get());
401
402  message2.CopyFrom(*message1);
403
404  TestUtil::ExpectAllFieldsSet(message2);
405}
406
407#endif  // !PROTOBUF_TEST_NO_DESCRIPTORS
408
409TEST(GeneratedMessageTest, NonEmptyMergeFrom) {
410  // Test merging with a non-empty message. Code is a modified form
411  // of that found in google/protobuf/reflection_ops_unittest.cc.
412  unittest::TestAllTypes message1, message2;
413
414  TestUtil::SetAllFields(&message1);
415
416  // This field will test merging into an empty spot.
417  message2.set_optional_int32(message1.optional_int32());
418  message1.clear_optional_int32();
419
420  // This tests overwriting.
421  message2.set_optional_string(message1.optional_string());
422  message1.set_optional_string("something else");
423
424  // This tests concatenating.
425  message2.add_repeated_int32(message1.repeated_int32(1));
426  int32 i = message1.repeated_int32(0);
427  message1.clear_repeated_int32();
428  message1.add_repeated_int32(i);
429
430  message1.MergeFrom(message2);
431
432  TestUtil::ExpectAllFieldsSet(message1);
433}
434
435#ifdef GTEST_HAS_DEATH_TEST
436
437TEST(GeneratedMessageTest, MergeFromSelf) {
438  unittest::TestAllTypes message;
439  EXPECT_DEATH(message.MergeFrom(message), "&from");
440  EXPECT_DEATH(message.MergeFrom(implicit_cast<const Message&>(message)),
441               "&from");
442}
443
444#endif  // GTEST_HAS_DEATH_TEST
445
446// Test the generated SerializeWithCachedSizesToArray(),
447TEST(GeneratedMessageTest, SerializationToArray) {
448  unittest::TestAllTypes message1, message2;
449  string data;
450  TestUtil::SetAllFields(&message1);
451  int size = message1.ByteSize();
452  data.resize(size);
453  uint8* start = reinterpret_cast<uint8*>(string_as_array(&data));
454  uint8* end = message1.SerializeWithCachedSizesToArray(start);
455  EXPECT_EQ(size, end - start);
456  EXPECT_TRUE(message2.ParseFromString(data));
457  TestUtil::ExpectAllFieldsSet(message2);
458
459}
460
461TEST(GeneratedMessageTest, PackedFieldsSerializationToArray) {
462  unittest::TestPackedTypes packed_message1, packed_message2;
463  string packed_data;
464  TestUtil::SetPackedFields(&packed_message1);
465  int packed_size = packed_message1.ByteSize();
466  packed_data.resize(packed_size);
467  uint8* start = reinterpret_cast<uint8*>(string_as_array(&packed_data));
468  uint8* end = packed_message1.SerializeWithCachedSizesToArray(start);
469  EXPECT_EQ(packed_size, end - start);
470  EXPECT_TRUE(packed_message2.ParseFromString(packed_data));
471  TestUtil::ExpectPackedFieldsSet(packed_message2);
472}
473
474// Test the generated SerializeWithCachedSizes() by forcing the buffer to write
475// one byte at a time.
476TEST(GeneratedMessageTest, SerializationToStream) {
477  unittest::TestAllTypes message1, message2;
478  TestUtil::SetAllFields(&message1);
479  int size = message1.ByteSize();
480  string data;
481  data.resize(size);
482  {
483    // Allow the output stream to buffer only one byte at a time.
484    io::ArrayOutputStream array_stream(string_as_array(&data), size, 1);
485    io::CodedOutputStream output_stream(&array_stream);
486    message1.SerializeWithCachedSizes(&output_stream);
487    EXPECT_FALSE(output_stream.HadError());
488    EXPECT_EQ(size, output_stream.ByteCount());
489  }
490  EXPECT_TRUE(message2.ParseFromString(data));
491  TestUtil::ExpectAllFieldsSet(message2);
492
493}
494
495TEST(GeneratedMessageTest, PackedFieldsSerializationToStream) {
496  unittest::TestPackedTypes message1, message2;
497  TestUtil::SetPackedFields(&message1);
498  int size = message1.ByteSize();
499  string data;
500  data.resize(size);
501  {
502    // Allow the output stream to buffer only one byte at a time.
503    io::ArrayOutputStream array_stream(string_as_array(&data), size, 1);
504    io::CodedOutputStream output_stream(&array_stream);
505    message1.SerializeWithCachedSizes(&output_stream);
506    EXPECT_FALSE(output_stream.HadError());
507    EXPECT_EQ(size, output_stream.ByteCount());
508  }
509  EXPECT_TRUE(message2.ParseFromString(data));
510  TestUtil::ExpectPackedFieldsSet(message2);
511}
512
513
514TEST(GeneratedMessageTest, Required) {
515  // Test that IsInitialized() returns false if required fields are missing.
516  unittest::TestRequired message;
517
518  EXPECT_FALSE(message.IsInitialized());
519  message.set_a(1);
520  EXPECT_FALSE(message.IsInitialized());
521  message.set_b(2);
522  EXPECT_FALSE(message.IsInitialized());
523  message.set_c(3);
524  EXPECT_TRUE(message.IsInitialized());
525}
526
527TEST(GeneratedMessageTest, RequiredForeign) {
528  // Test that IsInitialized() returns false if required fields in nested
529  // messages are missing.
530  unittest::TestRequiredForeign message;
531
532  EXPECT_TRUE(message.IsInitialized());
533
534  message.mutable_optional_message();
535  EXPECT_FALSE(message.IsInitialized());
536
537  message.mutable_optional_message()->set_a(1);
538  message.mutable_optional_message()->set_b(2);
539  message.mutable_optional_message()->set_c(3);
540  EXPECT_TRUE(message.IsInitialized());
541
542  message.add_repeated_message();
543  EXPECT_FALSE(message.IsInitialized());
544
545  message.mutable_repeated_message(0)->set_a(1);
546  message.mutable_repeated_message(0)->set_b(2);
547  message.mutable_repeated_message(0)->set_c(3);
548  EXPECT_TRUE(message.IsInitialized());
549}
550
551TEST(GeneratedMessageTest, ForeignNested) {
552  // Test that TestAllTypes::NestedMessage can be embedded directly into
553  // another message.
554  unittest::TestForeignNested message;
555
556  // If this compiles and runs without crashing, it must work.  We have
557  // nothing more to test.
558  unittest::TestAllTypes::NestedMessage* nested =
559    message.mutable_foreign_nested();
560  nested->set_bb(1);
561}
562
563TEST(GeneratedMessageTest, ReallyLargeTagNumber) {
564  // Test that really large tag numbers don't break anything.
565  unittest::TestReallyLargeTagNumber message1, message2;
566  string data;
567
568  // For the most part, if this compiles and runs then we're probably good.
569  // (The most likely cause for failure would be if something were attempting
570  // to allocate a lookup table of some sort using tag numbers as the index.)
571  // We'll try serializing just for fun.
572  message1.set_a(1234);
573  message1.set_bb(5678);
574  message1.SerializeToString(&data);
575  EXPECT_TRUE(message2.ParseFromString(data));
576  EXPECT_EQ(1234, message2.a());
577  EXPECT_EQ(5678, message2.bb());
578}
579
580TEST(GeneratedMessageTest, MutualRecursion) {
581  // Test that mutually-recursive message types work.
582  unittest::TestMutualRecursionA message;
583  unittest::TestMutualRecursionA* nested = message.mutable_bb()->mutable_a();
584  unittest::TestMutualRecursionA* nested2 = nested->mutable_bb()->mutable_a();
585
586  // Again, if the above compiles and runs, that's all we really have to
587  // test, but just for run we'll check that the system didn't somehow come
588  // up with a pointer loop...
589  EXPECT_NE(&message, nested);
590  EXPECT_NE(&message, nested2);
591  EXPECT_NE(nested, nested2);
592}
593
594TEST(GeneratedMessageTest, CamelCaseFieldNames) {
595  // This test is mainly checking that the following compiles, which verifies
596  // that the field names were coerced to lower-case.
597  //
598  // Protocol buffers standard style is to use lowercase-with-underscores for
599  // field names.  Some old proto1 .protos unfortunately used camel-case field
600  // names.  In proto1, these names were forced to lower-case.  So, we do the
601  // same thing in proto2.
602
603  unittest::TestCamelCaseFieldNames message;
604
605  message.set_primitivefield(2);
606  message.set_stringfield("foo");
607  message.set_enumfield(unittest::FOREIGN_FOO);
608  message.mutable_messagefield()->set_c(6);
609
610  message.add_repeatedprimitivefield(8);
611  message.add_repeatedstringfield("qux");
612  message.add_repeatedenumfield(unittest::FOREIGN_BAR);
613  message.add_repeatedmessagefield()->set_c(15);
614
615  EXPECT_EQ(2, message.primitivefield());
616  EXPECT_EQ("foo", message.stringfield());
617  EXPECT_EQ(unittest::FOREIGN_FOO, message.enumfield());
618  EXPECT_EQ(6, message.messagefield().c());
619
620  EXPECT_EQ(8, message.repeatedprimitivefield(0));
621  EXPECT_EQ("qux", message.repeatedstringfield(0));
622  EXPECT_EQ(unittest::FOREIGN_BAR, message.repeatedenumfield(0));
623  EXPECT_EQ(15, message.repeatedmessagefield(0).c());
624}
625
626TEST(GeneratedMessageTest, TestConflictingSymbolNames) {
627  // test_bad_identifiers.proto successfully compiled, then it works.  The
628  // following is just a token usage to insure that the code is, in fact,
629  // being compiled and linked.
630
631  protobuf_unittest::TestConflictingSymbolNames message;
632  message.set_uint32(1);
633  EXPECT_EQ(3, message.ByteSize());
634
635  message.set_friend_(5);
636  EXPECT_EQ(5, message.friend_());
637}
638
639#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
640
641TEST(GeneratedMessageTest, TestOptimizedForSize) {
642  // We rely on the tests in reflection_ops_unittest and wire_format_unittest
643  // to really test that reflection-based methods work.  Here we are mostly
644  // just making sure that TestOptimizedForSize actually builds and seems to
645  // function.
646
647  protobuf_unittest::TestOptimizedForSize message, message2;
648  message.set_i(1);
649  message.mutable_msg()->set_c(2);
650  message2.CopyFrom(message);
651  EXPECT_EQ(1, message2.i());
652  EXPECT_EQ(2, message2.msg().c());
653}
654
655TEST(GeneratedMessageTest, TestEmbedOptimizedForSize) {
656  // Verifies that something optimized for speed can contain something optimized
657  // for size.
658
659  protobuf_unittest::TestEmbedOptimizedForSize message, message2;
660  message.mutable_optional_message()->set_i(1);
661  message.add_repeated_message()->mutable_msg()->set_c(2);
662  string data;
663  message.SerializeToString(&data);
664  ASSERT_TRUE(message2.ParseFromString(data));
665  EXPECT_EQ(1, message2.optional_message().i());
666  EXPECT_EQ(2, message2.repeated_message(0).msg().c());
667}
668
669TEST(GeneratedMessageTest, TestSpaceUsed) {
670  unittest::TestAllTypes message1;
671  // sizeof provides a lower bound on SpaceUsed().
672  EXPECT_LE(sizeof(unittest::TestAllTypes), message1.SpaceUsed());
673  const int empty_message_size = message1.SpaceUsed();
674
675  // Setting primitive types shouldn't affect the space used.
676  message1.set_optional_int32(123);
677  message1.set_optional_int64(12345);
678  message1.set_optional_uint32(123);
679  message1.set_optional_uint64(12345);
680  EXPECT_EQ(empty_message_size, message1.SpaceUsed());
681
682  // On some STL implementations, setting the string to a small value should
683  // only increase SpaceUsed() by the size of a string object, though this is
684  // not true everywhere.
685  message1.set_optional_string("abc");
686  EXPECT_LE(empty_message_size + sizeof(string), message1.SpaceUsed());
687
688  // Setting a string to a value larger than the string object itself should
689  // increase SpaceUsed(), because it cannot store the value internally.
690  message1.set_optional_string(string(sizeof(string) + 1, 'x'));
691  int min_expected_increase = message1.optional_string().capacity() +
692      sizeof(string);
693  EXPECT_LE(empty_message_size + min_expected_increase,
694            message1.SpaceUsed());
695
696  int previous_size = message1.SpaceUsed();
697  // Adding an optional message should increase the size by the size of the
698  // nested message type. NestedMessage is simple enough (1 int field) that it
699  // is equal to sizeof(NestedMessage)
700  message1.mutable_optional_nested_message();
701  ASSERT_EQ(sizeof(unittest::TestAllTypes::NestedMessage),
702            message1.optional_nested_message().SpaceUsed());
703  EXPECT_EQ(previous_size +
704            sizeof(unittest::TestAllTypes::NestedMessage),
705            message1.SpaceUsed());
706}
707
708#endif  // !PROTOBUF_TEST_NO_DESCRIPTORS
709
710TEST(GeneratedMessageTest, FieldConstantValues) {
711  unittest::TestRequired message;
712  EXPECT_EQ(unittest::TestAllTypes_NestedMessage::kBbFieldNumber, 1);
713  EXPECT_EQ(unittest::TestAllTypes::kOptionalInt32FieldNumber, 1);
714  EXPECT_EQ(unittest::TestAllTypes::kOptionalgroupFieldNumber, 16);
715  EXPECT_EQ(unittest::TestAllTypes::kOptionalNestedMessageFieldNumber, 18);
716  EXPECT_EQ(unittest::TestAllTypes::kOptionalNestedEnumFieldNumber, 21);
717  EXPECT_EQ(unittest::TestAllTypes::kRepeatedInt32FieldNumber, 31);
718  EXPECT_EQ(unittest::TestAllTypes::kRepeatedgroupFieldNumber, 46);
719  EXPECT_EQ(unittest::TestAllTypes::kRepeatedNestedMessageFieldNumber, 48);
720  EXPECT_EQ(unittest::TestAllTypes::kRepeatedNestedEnumFieldNumber, 51);
721}
722
723TEST(GeneratedMessageTest, ExtensionConstantValues) {
724  EXPECT_EQ(unittest::TestRequired::kSingleFieldNumber, 1000);
725  EXPECT_EQ(unittest::TestRequired::kMultiFieldNumber, 1001);
726  EXPECT_EQ(unittest::kOptionalInt32ExtensionFieldNumber, 1);
727  EXPECT_EQ(unittest::kOptionalgroupExtensionFieldNumber, 16);
728  EXPECT_EQ(unittest::kOptionalNestedMessageExtensionFieldNumber, 18);
729  EXPECT_EQ(unittest::kOptionalNestedEnumExtensionFieldNumber, 21);
730  EXPECT_EQ(unittest::kRepeatedInt32ExtensionFieldNumber, 31);
731  EXPECT_EQ(unittest::kRepeatedgroupExtensionFieldNumber, 46);
732  EXPECT_EQ(unittest::kRepeatedNestedMessageExtensionFieldNumber, 48);
733  EXPECT_EQ(unittest::kRepeatedNestedEnumExtensionFieldNumber, 51);
734}
735
736// ===================================================================
737
738TEST(GeneratedEnumTest, EnumValuesAsSwitchCases) {
739  // Test that our nested enum values can be used as switch cases.  This test
740  // doesn't actually do anything, the proof that it works is that it
741  // compiles.
742  int i =0;
743  unittest::TestAllTypes::NestedEnum a = unittest::TestAllTypes::BAR;
744  switch (a) {
745    case unittest::TestAllTypes::FOO:
746      i = 1;
747      break;
748    case unittest::TestAllTypes::BAR:
749      i = 2;
750      break;
751    case unittest::TestAllTypes::BAZ:
752      i = 3;
753      break;
754    // no default case:  We want to make sure the compiler recognizes that
755    //   all cases are covered.  (GCC warns if you do not cover all cases of
756    //   an enum in a switch.)
757  }
758
759  // Token check just for fun.
760  EXPECT_EQ(2, i);
761}
762
763TEST(GeneratedEnumTest, IsValidValue) {
764  // Test enum IsValidValue.
765  EXPECT_TRUE(unittest::TestAllTypes::NestedEnum_IsValid(1));
766  EXPECT_TRUE(unittest::TestAllTypes::NestedEnum_IsValid(2));
767  EXPECT_TRUE(unittest::TestAllTypes::NestedEnum_IsValid(3));
768
769  EXPECT_FALSE(unittest::TestAllTypes::NestedEnum_IsValid(0));
770  EXPECT_FALSE(unittest::TestAllTypes::NestedEnum_IsValid(4));
771
772  // Make sure it also works when there are dups.
773  EXPECT_TRUE(unittest::TestEnumWithDupValue_IsValid(1));
774  EXPECT_TRUE(unittest::TestEnumWithDupValue_IsValid(2));
775  EXPECT_TRUE(unittest::TestEnumWithDupValue_IsValid(3));
776
777  EXPECT_FALSE(unittest::TestEnumWithDupValue_IsValid(0));
778  EXPECT_FALSE(unittest::TestEnumWithDupValue_IsValid(4));
779}
780
781TEST(GeneratedEnumTest, MinAndMax) {
782  EXPECT_EQ(unittest::TestAllTypes::FOO,unittest::TestAllTypes::NestedEnum_MIN);
783  EXPECT_EQ(unittest::TestAllTypes::BAZ,unittest::TestAllTypes::NestedEnum_MAX);
784
785  EXPECT_EQ(unittest::FOREIGN_FOO, unittest::ForeignEnum_MIN);
786  EXPECT_EQ(unittest::FOREIGN_BAZ, unittest::ForeignEnum_MAX);
787
788  EXPECT_EQ(1, unittest::TestEnumWithDupValue_MIN);
789  EXPECT_EQ(3, unittest::TestEnumWithDupValue_MAX);
790
791  EXPECT_EQ(unittest::SPARSE_E, unittest::TestSparseEnum_MIN);
792  EXPECT_EQ(unittest::SPARSE_C, unittest::TestSparseEnum_MAX);
793
794  // Make sure we can use _MIN and _MAX as switch cases.
795  switch(unittest::SPARSE_A) {
796    case unittest::TestSparseEnum_MIN:
797    case unittest::TestSparseEnum_MAX:
798      break;
799    default:
800      break;
801  }
802}
803
804#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
805
806TEST(GeneratedEnumTest, Name) {
807  // "Names" in the presence of dup values are a bit arbitrary.
808  EXPECT_EQ("FOO1", unittest::TestEnumWithDupValue_Name(unittest::FOO1));
809  EXPECT_EQ("FOO1", unittest::TestEnumWithDupValue_Name(unittest::FOO2));
810
811  EXPECT_EQ("SPARSE_A", unittest::TestSparseEnum_Name(unittest::SPARSE_A));
812  EXPECT_EQ("SPARSE_B", unittest::TestSparseEnum_Name(unittest::SPARSE_B));
813  EXPECT_EQ("SPARSE_C", unittest::TestSparseEnum_Name(unittest::SPARSE_C));
814  EXPECT_EQ("SPARSE_D", unittest::TestSparseEnum_Name(unittest::SPARSE_D));
815  EXPECT_EQ("SPARSE_E", unittest::TestSparseEnum_Name(unittest::SPARSE_E));
816  EXPECT_EQ("SPARSE_F", unittest::TestSparseEnum_Name(unittest::SPARSE_F));
817  EXPECT_EQ("SPARSE_G", unittest::TestSparseEnum_Name(unittest::SPARSE_G));
818}
819
820TEST(GeneratedEnumTest, Parse) {
821  unittest::TestEnumWithDupValue dup_value = unittest::FOO1;
822  EXPECT_TRUE(unittest::TestEnumWithDupValue_Parse("FOO1", &dup_value));
823  EXPECT_EQ(unittest::FOO1, dup_value);
824  EXPECT_TRUE(unittest::TestEnumWithDupValue_Parse("FOO2", &dup_value));
825  EXPECT_EQ(unittest::FOO2, dup_value);
826  EXPECT_FALSE(unittest::TestEnumWithDupValue_Parse("FOO", &dup_value));
827}
828
829TEST(GeneratedEnumTest, GetEnumDescriptor) {
830  EXPECT_EQ(unittest::TestAllTypes::NestedEnum_descriptor(),
831            GetEnumDescriptor<unittest::TestAllTypes::NestedEnum>());
832  EXPECT_EQ(unittest::ForeignEnum_descriptor(),
833            GetEnumDescriptor<unittest::ForeignEnum>());
834  EXPECT_EQ(unittest::TestEnumWithDupValue_descriptor(),
835            GetEnumDescriptor<unittest::TestEnumWithDupValue>());
836  EXPECT_EQ(unittest::TestSparseEnum_descriptor(),
837            GetEnumDescriptor<unittest::TestSparseEnum>());
838}
839
840#endif  // PROTOBUF_TEST_NO_DESCRIPTORS
841
842// ===================================================================
843
844#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
845
846// Support code for testing services.
847class GeneratedServiceTest : public testing::Test {
848 protected:
849  class MockTestService : public unittest::TestService {
850   public:
851    MockTestService()
852      : called_(false),
853        method_(""),
854        controller_(NULL),
855        request_(NULL),
856        response_(NULL),
857        done_(NULL) {}
858
859    ~MockTestService() {}
860
861    void Reset() { called_ = false; }
862
863    // implements TestService ----------------------------------------
864
865    void Foo(RpcController* controller,
866             const unittest::FooRequest* request,
867             unittest::FooResponse* response,
868             Closure* done) {
869      ASSERT_FALSE(called_);
870      called_ = true;
871      method_ = "Foo";
872      controller_ = controller;
873      request_ = request;
874      response_ = response;
875      done_ = done;
876    }
877
878    void Bar(RpcController* controller,
879             const unittest::BarRequest* request,
880             unittest::BarResponse* response,
881             Closure* done) {
882      ASSERT_FALSE(called_);
883      called_ = true;
884      method_ = "Bar";
885      controller_ = controller;
886      request_ = request;
887      response_ = response;
888      done_ = done;
889    }
890
891    // ---------------------------------------------------------------
892
893    bool called_;
894    string method_;
895    RpcController* controller_;
896    const Message* request_;
897    Message* response_;
898    Closure* done_;
899  };
900
901  class MockRpcChannel : public RpcChannel {
902   public:
903    MockRpcChannel()
904      : called_(false),
905        method_(NULL),
906        controller_(NULL),
907        request_(NULL),
908        response_(NULL),
909        done_(NULL),
910        destroyed_(NULL) {}
911
912    ~MockRpcChannel() {
913      if (destroyed_ != NULL) *destroyed_ = true;
914    }
915
916    void Reset() { called_ = false; }
917
918    // implements TestService ----------------------------------------
919
920    void CallMethod(const MethodDescriptor* method,
921                    RpcController* controller,
922                    const Message* request,
923                    Message* response,
924                    Closure* done) {
925      ASSERT_FALSE(called_);
926      called_ = true;
927      method_ = method;
928      controller_ = controller;
929      request_ = request;
930      response_ = response;
931      done_ = done;
932    }
933
934    // ---------------------------------------------------------------
935
936    bool called_;
937    const MethodDescriptor* method_;
938    RpcController* controller_;
939    const Message* request_;
940    Message* response_;
941    Closure* done_;
942    bool* destroyed_;
943  };
944
945  class MockController : public RpcController {
946   public:
947    void Reset() {
948      ADD_FAILURE() << "Reset() not expected during this test.";
949    }
950    bool Failed() const {
951      ADD_FAILURE() << "Failed() not expected during this test.";
952      return false;
953    }
954    string ErrorText() const {
955      ADD_FAILURE() << "ErrorText() not expected during this test.";
956      return "";
957    }
958    void StartCancel() {
959      ADD_FAILURE() << "StartCancel() not expected during this test.";
960    }
961    void SetFailed(const string& reason) {
962      ADD_FAILURE() << "SetFailed() not expected during this test.";
963    }
964    bool IsCanceled() const {
965      ADD_FAILURE() << "IsCanceled() not expected during this test.";
966      return false;
967    }
968    void NotifyOnCancel(Closure* callback) {
969      ADD_FAILURE() << "NotifyOnCancel() not expected during this test.";
970    }
971  };
972
973  GeneratedServiceTest()
974    : descriptor_(unittest::TestService::descriptor()),
975      foo_(descriptor_->FindMethodByName("Foo")),
976      bar_(descriptor_->FindMethodByName("Bar")),
977      stub_(&mock_channel_),
978      done_(NewPermanentCallback(&DoNothing)) {}
979
980  virtual void SetUp() {
981    ASSERT_TRUE(foo_ != NULL);
982    ASSERT_TRUE(bar_ != NULL);
983  }
984
985  const ServiceDescriptor* descriptor_;
986  const MethodDescriptor* foo_;
987  const MethodDescriptor* bar_;
988
989  MockTestService mock_service_;
990  MockController mock_controller_;
991
992  MockRpcChannel mock_channel_;
993  unittest::TestService::Stub stub_;
994
995  // Just so we don't have to re-define these with every test.
996  unittest::FooRequest foo_request_;
997  unittest::FooResponse foo_response_;
998  unittest::BarRequest bar_request_;
999  unittest::BarResponse bar_response_;
1000  scoped_ptr<Closure> done_;
1001};
1002
1003TEST_F(GeneratedServiceTest, GetDescriptor) {
1004  // Test that GetDescriptor() works.
1005
1006  EXPECT_EQ(descriptor_, mock_service_.GetDescriptor());
1007}
1008
1009TEST_F(GeneratedServiceTest, GetChannel) {
1010  EXPECT_EQ(&mock_channel_, stub_.channel());
1011}
1012
1013TEST_F(GeneratedServiceTest, OwnsChannel) {
1014  MockRpcChannel* channel = new MockRpcChannel;
1015  bool destroyed = false;
1016  channel->destroyed_ = &destroyed;
1017
1018  {
1019    unittest::TestService::Stub owning_stub(channel,
1020                                            Service::STUB_OWNS_CHANNEL);
1021    EXPECT_FALSE(destroyed);
1022  }
1023
1024  EXPECT_TRUE(destroyed);
1025}
1026
1027TEST_F(GeneratedServiceTest, CallMethod) {
1028  // Test that CallMethod() works.
1029
1030  // Call Foo() via CallMethod().
1031  mock_service_.CallMethod(foo_, &mock_controller_,
1032                           &foo_request_, &foo_response_, done_.get());
1033
1034  ASSERT_TRUE(mock_service_.called_);
1035
1036  EXPECT_EQ("Foo"            , mock_service_.method_    );
1037  EXPECT_EQ(&mock_controller_, mock_service_.controller_);
1038  EXPECT_EQ(&foo_request_    , mock_service_.request_   );
1039  EXPECT_EQ(&foo_response_   , mock_service_.response_  );
1040  EXPECT_EQ(done_.get()      , mock_service_.done_      );
1041
1042  // Try again, but call Bar() instead.
1043  mock_service_.Reset();
1044  mock_service_.CallMethod(bar_, &mock_controller_,
1045                           &bar_request_, &bar_response_, done_.get());
1046
1047  ASSERT_TRUE(mock_service_.called_);
1048  EXPECT_EQ("Bar", mock_service_.method_);
1049}
1050
1051TEST_F(GeneratedServiceTest, CallMethodTypeFailure) {
1052  // Verify death if we call Foo() with Bar's message types.
1053
1054#ifdef GTEST_HAS_DEATH_TEST  // death tests do not work on Windows yet
1055  EXPECT_DEBUG_DEATH(
1056    mock_service_.CallMethod(foo_, &mock_controller_,
1057                             &foo_request_, &bar_response_, done_.get()),
1058    "dynamic_cast");
1059
1060  mock_service_.Reset();
1061  EXPECT_DEBUG_DEATH(
1062    mock_service_.CallMethod(foo_, &mock_controller_,
1063                             &bar_request_, &foo_response_, done_.get()),
1064    "dynamic_cast");
1065#endif  // GTEST_HAS_DEATH_TEST
1066}
1067
1068TEST_F(GeneratedServiceTest, GetPrototypes) {
1069  // Test Get{Request,Response}Prototype() methods.
1070
1071  EXPECT_EQ(&unittest::FooRequest::default_instance(),
1072            &mock_service_.GetRequestPrototype(foo_));
1073  EXPECT_EQ(&unittest::BarRequest::default_instance(),
1074            &mock_service_.GetRequestPrototype(bar_));
1075
1076  EXPECT_EQ(&unittest::FooResponse::default_instance(),
1077            &mock_service_.GetResponsePrototype(foo_));
1078  EXPECT_EQ(&unittest::BarResponse::default_instance(),
1079            &mock_service_.GetResponsePrototype(bar_));
1080}
1081
1082TEST_F(GeneratedServiceTest, Stub) {
1083  // Test that the stub class works.
1084
1085  // Call Foo() via the stub.
1086  stub_.Foo(&mock_controller_, &foo_request_, &foo_response_, done_.get());
1087
1088  ASSERT_TRUE(mock_channel_.called_);
1089
1090  EXPECT_EQ(foo_             , mock_channel_.method_    );
1091  EXPECT_EQ(&mock_controller_, mock_channel_.controller_);
1092  EXPECT_EQ(&foo_request_    , mock_channel_.request_   );
1093  EXPECT_EQ(&foo_response_   , mock_channel_.response_  );
1094  EXPECT_EQ(done_.get()      , mock_channel_.done_      );
1095
1096  // Call Bar() via the stub.
1097  mock_channel_.Reset();
1098  stub_.Bar(&mock_controller_, &bar_request_, &bar_response_, done_.get());
1099
1100  ASSERT_TRUE(mock_channel_.called_);
1101  EXPECT_EQ(bar_, mock_channel_.method_);
1102}
1103
1104TEST_F(GeneratedServiceTest, NotImplemented) {
1105  // Test that failing to implement a method of a service causes it to fail
1106  // with a "not implemented" error message.
1107
1108  // A service which doesn't implement any methods.
1109  class UnimplementedService : public unittest::TestService {
1110   public:
1111    UnimplementedService() {}
1112  };
1113
1114  UnimplementedService unimplemented_service;
1115
1116  // And a controller which expects to get a "not implemented" error.
1117  class ExpectUnimplementedController : public MockController {
1118   public:
1119    ExpectUnimplementedController() : called_(false) {}
1120
1121    void SetFailed(const string& reason) {
1122      EXPECT_FALSE(called_);
1123      called_ = true;
1124      EXPECT_EQ("Method Foo() not implemented.", reason);
1125    }
1126
1127    bool called_;
1128  };
1129
1130  ExpectUnimplementedController controller;
1131
1132  // Call Foo.
1133  unimplemented_service.Foo(&controller, &foo_request_, &foo_response_,
1134                            done_.get());
1135
1136  EXPECT_TRUE(controller.called_);
1137}
1138
1139#endif  // !PROTOBUF_TEST_NO_DESCRIPTORS
1140
1141// ===================================================================
1142
1143// This test must run last.  It verifies that descriptors were or were not
1144// initialized depending on whether PROTOBUF_TEST_NO_DESCRIPTORS was defined.
1145// When this is defined, we skip all tests which are expected to trigger
1146// descriptor initialization.  This verifies that everything else still works
1147// if descriptors are not initialized.
1148TEST(DescriptorInitializationTest, Initialized) {
1149#ifdef PROTOBUF_TEST_NO_DESCRIPTORS
1150  bool should_have_descriptors = false;
1151#else
1152  bool should_have_descriptors = true;
1153#endif
1154
1155  EXPECT_EQ(should_have_descriptors,
1156    DescriptorPool::generated_pool()->InternalIsFileLoaded(
1157      "google/protobuf/unittest.proto"));
1158}
1159
1160}  // namespace cpp_unittest
1161
1162}  // namespace cpp
1163}  // namespace compiler
1164}  // namespace protobuf
1165}  // namespace google
1166