Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // visual studio to compile (report internal errors). 60 // visual studio to compile (report internal errors).
61 #include <google/protobuf/unittest_enormous_descriptor.pb.h> 61 #include <google/protobuf/unittest_enormous_descriptor.pb.h>
62 #endif 62 #endif
63 #include <google/protobuf/unittest_no_generic_services.pb.h> 63 #include <google/protobuf/unittest_no_generic_services.pb.h>
64 #include <google/protobuf/test_util.h> 64 #include <google/protobuf/test_util.h>
65 #include <google/protobuf/compiler/cpp/cpp_helpers.h> 65 #include <google/protobuf/compiler/cpp/cpp_helpers.h>
66 #include <google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h> 66 #include <google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h>
67 #include <google/protobuf/compiler/importer.h> 67 #include <google/protobuf/compiler/importer.h>
68 #include <google/protobuf/io/coded_stream.h> 68 #include <google/protobuf/io/coded_stream.h>
69 #include <google/protobuf/io/zero_copy_stream_impl.h> 69 #include <google/protobuf/io/zero_copy_stream_impl.h>
70 #include <google/protobuf/arena.h>
71 #include <google/protobuf/descriptor.h> 70 #include <google/protobuf/descriptor.h>
72 #include <google/protobuf/descriptor.pb.h> 71 #include <google/protobuf/descriptor.pb.h>
73 #include <google/protobuf/dynamic_message.h> 72 #include <google/protobuf/dynamic_message.h>
74 73
75 #include <google/protobuf/stubs/callback.h> 74 #include <google/protobuf/stubs/callback.h>
76 #include <google/protobuf/stubs/common.h> 75 #include <google/protobuf/stubs/common.h>
77 #include <google/protobuf/stubs/logging.h> 76 #include <google/protobuf/stubs/logging.h>
78 #include <google/protobuf/stubs/strutil.h> 77 #include <google/protobuf/stubs/strutil.h>
79 #include <google/protobuf/stubs/substitute.h> 78 #include <google/protobuf/stubs/substitute.h>
80 #include <google/protobuf/testing/googletest.h> 79 #include <google/protobuf/testing/googletest.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 Importer importer(&source_tree, &error_collector); 122 Importer importer(&source_tree, &error_collector);
124 123
125 // Import (parse) unittest.proto. 124 // Import (parse) unittest.proto.
126 const FileDescriptor* parsed_descriptor = 125 const FileDescriptor* parsed_descriptor =
127 importer.Import("google/protobuf/unittest.proto"); 126 importer.Import("google/protobuf/unittest.proto");
128 EXPECT_EQ("", error_collector.text_); 127 EXPECT_EQ("", error_collector.text_);
129 ASSERT_TRUE(parsed_descriptor != NULL); 128 ASSERT_TRUE(parsed_descriptor != NULL);
130 129
131 // Test that descriptors are generated correctly by converting them to 130 // Test that descriptors are generated correctly by converting them to
132 // FileDescriptorProtos and comparing. 131 // FileDescriptorProtos and comparing.
133 FileDescriptorProto generated_descriptor_proto, parsed_descriptor_proto; 132 FileDescriptorProto generated_decsriptor_proto, parsed_descriptor_proto;
134 generated_descriptor->CopyTo(&generated_descriptor_proto); 133 generated_descriptor->CopyTo(&generated_decsriptor_proto);
135 parsed_descriptor->CopyTo(&parsed_descriptor_proto); 134 parsed_descriptor->CopyTo(&parsed_descriptor_proto);
136 135
137 EXPECT_EQ(parsed_descriptor_proto.DebugString(), 136 EXPECT_EQ(parsed_descriptor_proto.DebugString(),
138 generated_descriptor_proto.DebugString()); 137 generated_decsriptor_proto.DebugString());
139 } 138 }
140 139
141 #if !defined(GOOGLE_PROTOBUF_CMAKE_BUILD) && !defined(_MSC_VER) 140 #if !defined(GOOGLE_PROTOBUF_CMAKE_BUILD) && !defined(_MSC_VER)
142 // Test that generated code has proper descriptors: 141 // Test that generated code has proper descriptors:
143 // Touch a descriptor generated from an enormous message to validate special 142 // Touch a descriptor generated from an enormous message to validate special
144 // handling for descriptors exceeding the C++ standard's recommended minimum 143 // handling for descriptors exceeding the C++ standard's recommended minimum
145 // limit for string literal size 144 // limit for string literal size
146 TEST(GeneratedDescriptorTest, EnormousDescriptor) { 145 TEST(GeneratedDescriptorTest, EnormousDescriptor) {
147 const Descriptor* generated_descriptor = 146 const Descriptor* generated_descriptor =
148 TestEnormousDescriptor::descriptor(); 147 TestEnormousDescriptor::descriptor();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const unittest::TestExtremeDefaultValues& extreme_default = 192 const unittest::TestExtremeDefaultValues& extreme_default =
194 unittest::TestExtremeDefaultValues::default_instance(); 193 unittest::TestExtremeDefaultValues::default_instance();
195 194
196 EXPECT_EQ(0.0f, extreme_default.zero_float()); 195 EXPECT_EQ(0.0f, extreme_default.zero_float());
197 EXPECT_EQ(1.0f, extreme_default.one_float()); 196 EXPECT_EQ(1.0f, extreme_default.one_float());
198 EXPECT_EQ(1.5f, extreme_default.small_float()); 197 EXPECT_EQ(1.5f, extreme_default.small_float());
199 EXPECT_EQ(-1.0f, extreme_default.negative_one_float()); 198 EXPECT_EQ(-1.0f, extreme_default.negative_one_float());
200 EXPECT_EQ(-1.5f, extreme_default.negative_float()); 199 EXPECT_EQ(-1.5f, extreme_default.negative_float());
201 EXPECT_EQ(2.0e8f, extreme_default.large_float()); 200 EXPECT_EQ(2.0e8f, extreme_default.large_float());
202 EXPECT_EQ(-8e-28f, extreme_default.small_negative_float()); 201 EXPECT_EQ(-8e-28f, extreme_default.small_negative_float());
203 EXPECT_EQ(std::numeric_limits<double>::infinity(), 202 EXPECT_EQ(numeric_limits<double>::infinity(),
204 extreme_default.inf_double()); 203 extreme_default.inf_double());
205 EXPECT_EQ(-std::numeric_limits<double>::infinity(), 204 EXPECT_EQ(-numeric_limits<double>::infinity(),
206 extreme_default.neg_inf_double()); 205 extreme_default.neg_inf_double());
207 EXPECT_TRUE(extreme_default.nan_double() != extreme_default.nan_double()); 206 EXPECT_TRUE(extreme_default.nan_double() != extreme_default.nan_double());
208 EXPECT_EQ(std::numeric_limits<float>::infinity(), 207 EXPECT_EQ(numeric_limits<float>::infinity(),
209 extreme_default.inf_float()); 208 extreme_default.inf_float());
210 EXPECT_EQ(-std::numeric_limits<float>::infinity(), 209 EXPECT_EQ(-numeric_limits<float>::infinity(),
211 extreme_default.neg_inf_float()); 210 extreme_default.neg_inf_float());
212 EXPECT_TRUE(extreme_default.nan_float() != extreme_default.nan_float()); 211 EXPECT_TRUE(extreme_default.nan_float() != extreme_default.nan_float());
213 } 212 }
214 213
215 TEST(GeneratedMessageTest, Trigraph) { 214 TEST(GeneratedMessageTest, Trigraph) {
216 const unittest::TestExtremeDefaultValues& extreme_default = 215 const unittest::TestExtremeDefaultValues& extreme_default =
217 unittest::TestExtremeDefaultValues::default_instance(); 216 unittest::TestExtremeDefaultValues::default_instance();
218 217
219 EXPECT_EQ("? ? ?? ?? ??? ?\?/ ?\?-", extreme_default.cpp_trigraph()); 218 EXPECT_EQ("? ? ?? ?? ??? ?\?/ ?\?-", extreme_default.cpp_trigraph());
220 } 219 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 511 }
513 512
514 TEST(GeneratedMessageTest, CopyConstructor) { 513 TEST(GeneratedMessageTest, CopyConstructor) {
515 unittest::TestAllTypes message1; 514 unittest::TestAllTypes message1;
516 TestUtil::SetAllFields(&message1); 515 TestUtil::SetAllFields(&message1);
517 516
518 unittest::TestAllTypes message2(message1); 517 unittest::TestAllTypes message2(message1);
519 TestUtil::ExpectAllFieldsSet(message2); 518 TestUtil::ExpectAllFieldsSet(message2);
520 } 519 }
521 520
522 TEST(GeneratedMessageTest, CopyConstructorWithArenas) {
523 Arena arena;
524 unittest::TestAllTypes* message1 =
525 Arena::CreateMessage<unittest::TestAllTypes>(&arena);
526 TestUtil::SetAllFields(message1);
527
528 unittest::TestAllTypes message2_stack(*message1);
529 TestUtil::ExpectAllFieldsSet(message2_stack);
530
531 google::protobuf::scoped_ptr<unittest::TestAllTypes> message2_heap(
532 new unittest::TestAllTypes(*message1));
533 TestUtil::ExpectAllFieldsSet(*message2_heap);
534
535 arena.Reset();
536
537 // Verify that the copies are still intact.
538 TestUtil::ExpectAllFieldsSet(message2_stack);
539 TestUtil::ExpectAllFieldsSet(*message2_heap);
540 }
541
542 TEST(GeneratedMessageTest, CopyAssignmentOperator) { 521 TEST(GeneratedMessageTest, CopyAssignmentOperator) {
543 unittest::TestAllTypes message1; 522 unittest::TestAllTypes message1;
544 TestUtil::SetAllFields(&message1); 523 TestUtil::SetAllFields(&message1);
545 524
546 unittest::TestAllTypes message2; 525 unittest::TestAllTypes message2;
547 message2 = message1; 526 message2 = message1;
548 TestUtil::ExpectAllFieldsSet(message2); 527 TestUtil::ExpectAllFieldsSet(message2);
549 528
550 // Make sure that self-assignment does something sane. 529 // Make sure that self-assignment does something sane.
551 message2.operator=(message2); 530 message2.operator=(message2);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 message1.add_repeated_int32(i); 593 message1.add_repeated_int32(i);
615 594
616 message1.MergeFrom(message2); 595 message1.MergeFrom(message2);
617 596
618 TestUtil::ExpectAllFieldsSet(message1); 597 TestUtil::ExpectAllFieldsSet(message1);
619 } 598 }
620 599
621 #if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || \ 600 #if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || \
622 !defined(GOOGLE_PROTOBUF_NO_RTTI) 601 !defined(GOOGLE_PROTOBUF_NO_RTTI)
623 #ifdef PROTOBUF_HAS_DEATH_TEST 602 #ifdef PROTOBUF_HAS_DEATH_TEST
624 #ifndef NDEBUG
625 603
626 TEST(GeneratedMessageTest, MergeFromSelf) { 604 TEST(GeneratedMessageTest, MergeFromSelf) {
627 unittest::TestAllTypes message; 605 unittest::TestAllTypes message;
628 EXPECT_DEATH(message.MergeFrom(message), "pb[.]cc.*Check failed:"); 606 EXPECT_DEATH(message.MergeFrom(message), "Check failed:.*pb[.]cc");
629 EXPECT_DEATH(message.MergeFrom(implicit_cast<const Message&>(message)), 607 EXPECT_DEATH(message.MergeFrom(implicit_cast<const Message&>(message)),
630 "pb[.]cc.*Check failed:"); 608 "Check failed:.*pb[.]cc");
631 } 609 }
632 610
633 #endif // NDEBUG
634 #endif // PROTOBUF_HAS_DEATH_TEST 611 #endif // PROTOBUF_HAS_DEATH_TEST
635 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS || !GOOGLE_PROTOBUF_NO_RTTI 612 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS || !GOOGLE_PROTOBUF_NO_RTTI
636 613
637 // Test the generated SerializeWithCachedSizesToArray(), 614 // Test the generated SerializeWithCachedSizesToArray(),
638 TEST(GeneratedMessageTest, SerializationToArray) { 615 TEST(GeneratedMessageTest, SerializationToArray) {
639 unittest::TestAllTypes message1, message2; 616 unittest::TestAllTypes message1, message2;
640 string data; 617 string data;
641 TestUtil::SetAllFields(&message1); 618 TestUtil::SetAllFields(&message1);
642 int size = message1.ByteSize(); 619 int size = message1.ByteSize();
643 data.resize(size); 620 data.resize(size);
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 void NotifyOnCancel(Closure* callback) { 1245 void NotifyOnCancel(Closure* callback) {
1269 ADD_FAILURE() << "NotifyOnCancel() not expected during this test."; 1246 ADD_FAILURE() << "NotifyOnCancel() not expected during this test.";
1270 } 1247 }
1271 }; 1248 };
1272 1249
1273 GeneratedServiceTest() 1250 GeneratedServiceTest()
1274 : descriptor_(unittest::TestService::descriptor()), 1251 : descriptor_(unittest::TestService::descriptor()),
1275 foo_(descriptor_->FindMethodByName("Foo")), 1252 foo_(descriptor_->FindMethodByName("Foo")),
1276 bar_(descriptor_->FindMethodByName("Bar")), 1253 bar_(descriptor_->FindMethodByName("Bar")),
1277 stub_(&mock_channel_), 1254 stub_(&mock_channel_),
1278 done_(NewPermanentCallback(&DoNothing)) {} 1255 done_(::google::protobuf::internal::NewPermanentCallback(&DoNothing)) {}
1279 1256
1280 virtual void SetUp() { 1257 virtual void SetUp() {
1281 ASSERT_TRUE(foo_ != NULL); 1258 ASSERT_TRUE(foo_ != NULL);
1282 ASSERT_TRUE(bar_ != NULL); 1259 ASSERT_TRUE(bar_ != NULL);
1283 } 1260 }
1284 1261
1285 const ServiceDescriptor* descriptor_; 1262 const ServiceDescriptor* descriptor_;
1286 const MethodDescriptor* foo_; 1263 const MethodDescriptor* foo_;
1287 const MethodDescriptor* bar_; 1264 const MethodDescriptor* bar_;
1288 1265
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 DescriptorPool::generated_pool()->InternalIsFileLoaded( 2130 DescriptorPool::generated_pool()->InternalIsFileLoaded(
2154 "google/protobuf/unittest.proto")); 2131 "google/protobuf/unittest.proto"));
2155 } 2132 }
2156 2133
2157 } // namespace cpp_unittest 2134 } // namespace cpp_unittest
2158 2135
2159 } // namespace cpp 2136 } // namespace cpp
2160 } // namespace compiler 2137 } // namespace compiler
2161 } // namespace protobuf 2138 } // namespace protobuf
2162 } // namespace google 2139 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698