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

Side by Side Diff: third_party/protobuf/src/google/protobuf/arenastring_unittest.cc

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 3 years, 12 months 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 static string WrapString(const char* value) { 53 static string WrapString(const char* value) {
54 return value; 54 return value;
55 } 55 }
56 56
57 // Test ArenaStringPtr with arena == NULL. 57 // Test ArenaStringPtr with arena == NULL.
58 TEST(ArenaStringPtrTest, ArenaStringPtrOnHeap) { 58 TEST(ArenaStringPtrTest, ArenaStringPtrOnHeap) {
59 ArenaStringPtr field; 59 ArenaStringPtr field;
60 ::std::string default_value = "default"; 60 ::std::string default_value = "default";
61 field.UnsafeSetDefault(&default_value); 61 field.UnsafeSetDefault(&default_value);
62 EXPECT_EQ(string("default"), field.Get()); 62 EXPECT_EQ(string("default"), field.Get(&default_value));
63 field.Set(&default_value, WrapString("Test short"), NULL); 63 field.Set(&default_value, WrapString("Test short"), NULL);
64 EXPECT_EQ(string("Test short"), field.Get()); 64 EXPECT_EQ(string("Test short"), field.Get(&default_value));
65 field.Set(&default_value, WrapString("Test long long long long value"), NULL); 65 field.Set(&default_value, WrapString("Test long long long long value"), NULL);
66 EXPECT_EQ(string("Test long long long long value"), field.Get()); 66 EXPECT_EQ(string("Test long long long long value"), field.Get(&default_value)) ;
67 field.Set(&default_value, string(""), NULL); 67 field.Set(&default_value, string(""), NULL);
68 field.Destroy(&default_value, NULL); 68 field.Destroy(&default_value, NULL);
69 69
70 ArenaStringPtr field2; 70 ArenaStringPtr field2;
71 field2.UnsafeSetDefault(&default_value); 71 field2.UnsafeSetDefault(&default_value);
72 ::std::string* mut = field2.Mutable(&default_value, NULL); 72 ::std::string* mut = field2.Mutable(&default_value, NULL);
73 EXPECT_EQ(mut, field2.Mutable(&default_value, NULL)); 73 EXPECT_EQ(mut, field2.Mutable(&default_value, NULL));
74 EXPECT_EQ(mut, &field2.Get()); 74 EXPECT_EQ(mut, &field2.Get(&default_value));
75 EXPECT_NE(&default_value, mut); 75 EXPECT_NE(&default_value, mut);
76 EXPECT_EQ(string("default"), *mut); 76 EXPECT_EQ(string("default"), *mut);
77 *mut = "Test long long long long value"; // ensure string allocates storage 77 *mut = "Test long long long long value"; // ensure string allocates storage
78 EXPECT_EQ(string("Test long long long long value"), field2.Get()); 78 EXPECT_EQ(string("Test long long long long value"), field2.Get(&default_value) );
79 field2.Destroy(&default_value, NULL); 79 field2.Destroy(&default_value, NULL);
80 } 80 }
81 81
82 TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) { 82 TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) {
83 google::protobuf::Arena arena; 83 google::protobuf::Arena arena;
84 ArenaStringPtr field; 84 ArenaStringPtr field;
85 ::std::string default_value = "default"; 85 ::std::string default_value = "default";
86 field.UnsafeSetDefault(&default_value); 86 field.UnsafeSetDefault(&default_value);
87 EXPECT_EQ(string("default"), field.Get()); 87 EXPECT_EQ(string("default"), field.Get(&default_value));
88 field.Set(&default_value, WrapString("Test short"), &arena); 88 field.Set(&default_value, WrapString("Test short"), &arena);
89 EXPECT_EQ(string("Test short"), field.Get()); 89 EXPECT_EQ(string("Test short"), field.Get(&default_value));
90 field.Set(&default_value, WrapString("Test long long long long value"), &arena ); 90 field.Set(&default_value, WrapString("Test long long long long value"), &arena );
91 EXPECT_EQ(string("Test long long long long value"), field.Get()); 91 EXPECT_EQ(string("Test long long long long value"),
92 field.Get(&default_value));
92 field.Set(&default_value, string(""), &arena); 93 field.Set(&default_value, string(""), &arena);
93 field.Destroy(&default_value, &arena); 94 field.Destroy(&default_value, &arena);
94 95
95 ArenaStringPtr field2; 96 ArenaStringPtr field2;
96 field2.UnsafeSetDefault(&default_value); 97 field2.UnsafeSetDefault(&default_value);
97 ::std::string* mut = field2.Mutable(&default_value, &arena); 98 ::std::string* mut = field2.Mutable(&default_value, &arena);
98 EXPECT_EQ(mut, field2.Mutable(&default_value, &arena)); 99 EXPECT_EQ(mut, field2.Mutable(&default_value, &arena));
99 EXPECT_EQ(mut, &field2.Get()); 100 EXPECT_EQ(mut, &field2.Get(&default_value));
100 EXPECT_NE(&default_value, mut); 101 EXPECT_NE(&default_value, mut);
101 EXPECT_EQ(string("default"), *mut); 102 EXPECT_EQ(string("default"), *mut);
102 *mut = "Test long long long long value"; // ensure string allocates storage 103 *mut = "Test long long long long value"; // ensure string allocates storage
103 EXPECT_EQ(string("Test long long long long value"), field2.Get()); 104 EXPECT_EQ(string("Test long long long long value"),
105 field2.Get(&default_value));
104 field2.Destroy(&default_value, &arena); 106 field2.Destroy(&default_value, &arena);
105 } 107 }
106 108
107 } // namespace protobuf 109 } // namespace protobuf
108 } // namespace google 110 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698