protobuf/src/google/protobuf/repeated_field_unittest.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
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 // TODO(kenton): Improve this unittest to bring it up to the standards of
36 // other proto2 unittests.
37 
38 #include <google/protobuf/repeated_field.h>
39 
40 #include <algorithm>
41 #include <cstdlib>
42 #include <iterator>
43 #include <limits>
44 #include <list>
45 #include <sstream>
46 #include <type_traits>
47 #include <vector>
48 
49 #include <google/protobuf/stubs/logging.h>
50 #include <google/protobuf/stubs/common.h>
51 #include <google/protobuf/unittest.pb.h>
52 #include <google/protobuf/stubs/strutil.h>
53 #include <gmock/gmock.h>
54 #include <google/protobuf/testing/googletest.h>
55 #include <gtest/gtest.h>
56 #include <google/protobuf/stubs/stl_util.h>
57 
58 // Must be included last.
59 #include <google/protobuf/port_def.inc>
60 
61 namespace google {
62 namespace protobuf {
63 namespace {
64 
65 using ::protobuf_unittest::TestAllTypes;
67 
68 TEST(RepeatedField, ConstInit) {
69  PROTOBUF_CONSTINIT static RepeatedField<int> field{}; // NOLINT
70  EXPECT_TRUE(field.empty());
71 }
72 
73 // Test operations on a small RepeatedField.
74 TEST(RepeatedField, Small) {
76 
77  EXPECT_TRUE(field.empty());
78  EXPECT_EQ(field.size(), 0);
79 
80  field.Add(5);
81 
82  EXPECT_FALSE(field.empty());
83  EXPECT_EQ(field.size(), 1);
84  EXPECT_EQ(field.Get(0), 5);
85  EXPECT_EQ(field.at(0), 5);
86 
87  field.Add(42);
88 
89  EXPECT_FALSE(field.empty());
90  EXPECT_EQ(field.size(), 2);
91  EXPECT_EQ(field.Get(0), 5);
92  EXPECT_EQ(field.at(0), 5);
93  EXPECT_EQ(field.Get(1), 42);
94  EXPECT_EQ(field.at(1), 42);
95 
96  field.Set(1, 23);
97 
98  EXPECT_FALSE(field.empty());
99  EXPECT_EQ(field.size(), 2);
100  EXPECT_EQ(field.Get(0), 5);
101  EXPECT_EQ(field.at(0), 5);
102  EXPECT_EQ(field.Get(1), 23);
103  EXPECT_EQ(field.at(1), 23);
104 
105  field.at(1) = 25;
106 
107  EXPECT_FALSE(field.empty());
108  EXPECT_EQ(field.size(), 2);
109  EXPECT_EQ(field.Get(0), 5);
110  EXPECT_EQ(field.at(0), 5);
111  EXPECT_EQ(field.Get(1), 25);
112  EXPECT_EQ(field.at(1), 25);
113 
114  field.RemoveLast();
115 
116  EXPECT_FALSE(field.empty());
117  EXPECT_EQ(field.size(), 1);
118  EXPECT_EQ(field.Get(0), 5);
119  EXPECT_EQ(field.at(0), 5);
120 
121  field.Clear();
122 
123  EXPECT_TRUE(field.empty());
124  EXPECT_EQ(field.size(), 0);
125  // Additional bytes are for 'struct Rep' header.
126  int expected_usage = 4 * sizeof(int) + sizeof(Arena*);
127  EXPECT_GE(field.SpaceUsedExcludingSelf(), expected_usage);
128 }
129 
130 
131 // Test operations on a RepeatedField which is large enough to allocate a
132 // separate array.
135 
136  for (int i = 0; i < 16; i++) {
137  field.Add(i * i);
138  }
139 
140  EXPECT_FALSE(field.empty());
141  EXPECT_EQ(field.size(), 16);
142 
143  for (int i = 0; i < 16; i++) {
144  EXPECT_EQ(field.Get(i), i * i);
145  }
146 
147  int expected_usage = 16 * sizeof(int);
148  EXPECT_GE(field.SpaceUsedExcludingSelf(), expected_usage);
149 }
150 
151 // Test swapping between various types of RepeatedFields.
152 TEST(RepeatedField, SwapSmallSmall) {
153  RepeatedField<int> field1;
154  RepeatedField<int> field2;
155 
156  field1.Add(5);
157  field1.Add(42);
158 
159  EXPECT_FALSE(field1.empty());
160  EXPECT_EQ(field1.size(), 2);
161  EXPECT_EQ(field1.Get(0), 5);
162  EXPECT_EQ(field1.Get(1), 42);
163 
164  EXPECT_TRUE(field2.empty());
165  EXPECT_EQ(field2.size(), 0);
166 
167  field1.Swap(&field2);
168 
169  EXPECT_TRUE(field1.empty());
170  EXPECT_EQ(field1.size(), 0);
171 
172  EXPECT_FALSE(field2.empty());
173  EXPECT_EQ(field2.size(), 2);
174  EXPECT_EQ(field2.Get(0), 5);
175  EXPECT_EQ(field2.Get(1), 42);
176 }
177 
178 TEST(RepeatedField, SwapLargeSmall) {
179  RepeatedField<int> field1;
180  RepeatedField<int> field2;
181 
182  for (int i = 0; i < 16; i++) {
183  field1.Add(i * i);
184  }
185  field2.Add(5);
186  field2.Add(42);
187  field1.Swap(&field2);
188 
189  EXPECT_EQ(field1.size(), 2);
190  EXPECT_EQ(field1.Get(0), 5);
191  EXPECT_EQ(field1.Get(1), 42);
192  EXPECT_EQ(field2.size(), 16);
193  for (int i = 0; i < 16; i++) {
194  EXPECT_EQ(field2.Get(i), i * i);
195  }
196 }
197 
198 TEST(RepeatedField, SwapLargeLarge) {
199  RepeatedField<int> field1;
200  RepeatedField<int> field2;
201 
202  field1.Add(5);
203  field1.Add(42);
204  for (int i = 0; i < 16; i++) {
205  field1.Add(i);
206  field2.Add(i * i);
207  }
208  field2.Swap(&field1);
209 
210  EXPECT_EQ(field1.size(), 16);
211  for (int i = 0; i < 16; i++) {
212  EXPECT_EQ(field1.Get(i), i * i);
213  }
214  EXPECT_EQ(field2.size(), 18);
215  EXPECT_EQ(field2.Get(0), 5);
216  EXPECT_EQ(field2.Get(1), 42);
217  for (int i = 2; i < 18; i++) {
218  EXPECT_EQ(field2.Get(i), i - 2);
219  }
220 }
221 
222 // Determines how much space was reserved by the given field by adding elements
223 // to it until it re-allocates its space.
224 static int ReservedSpace(RepeatedField<int>* field) {
225  const int* ptr = field->data();
226  do {
227  field->Add(0);
228  } while (field->data() == ptr);
229 
230  return field->size() - 1;
231 }
232 
233 TEST(RepeatedField, ReserveMoreThanDouble) {
234  // Reserve more than double the previous space in the field and expect the
235  // field to reserve exactly the amount specified.
237  field.Reserve(20);
238 
239  EXPECT_LE(20, ReservedSpace(&field));
240 }
241 
242 TEST(RepeatedField, ReserveLessThanDouble) {
243  // Reserve less than double the previous space in the field and expect the
244  // field to grow by double instead.
246  field.Reserve(20);
247  int capacity = field.Capacity();
248  field.Reserve(capacity * 1.5);
249 
250  EXPECT_LE(2 * capacity, ReservedSpace(&field));
251 }
252 
253 TEST(RepeatedField, ReserveLessThanExisting) {
254  // Reserve less than the previous space in the field and expect the
255  // field to not re-allocate at all.
257  field.Reserve(20);
258  const int* previous_ptr = field.data();
259  field.Reserve(10);
260 
261  EXPECT_EQ(previous_ptr, field.data());
262  EXPECT_LE(20, ReservedSpace(&field));
263 }
264 
265 TEST(RepeatedField, Resize) {
267  field.Resize(2, 1);
268  EXPECT_EQ(2, field.size());
269  field.Resize(5, 2);
270  EXPECT_EQ(5, field.size());
271  field.Resize(4, 3);
272  ASSERT_EQ(4, field.size());
273  EXPECT_EQ(1, field.Get(0));
274  EXPECT_EQ(1, field.Get(1));
275  EXPECT_EQ(2, field.Get(2));
276  EXPECT_EQ(2, field.Get(3));
277  field.Resize(0, 4);
278  EXPECT_TRUE(field.empty());
279 }
280 
281 TEST(RepeatedField, ReserveNothing) {
283  EXPECT_EQ(0, field.Capacity());
284 
285  field.Reserve(-1);
286  EXPECT_EQ(0, field.Capacity());
287 }
288 
289 TEST(RepeatedField, ReserveLowerClamp) {
290  const int clamped_value = internal::CalculateReserveSize(0, 1);
292  EXPECT_EQ(clamped_value, internal::CalculateReserveSize(clamped_value, 2));
293 }
294 
295 TEST(RepeatedField, ReserveGrowth) {
296  // Make sure the field capacity doubles in size on repeated reservation.
297  for (int size = internal::kRepeatedFieldLowerClampLimit, i = 0; i < 4;
298  ++i, size *= 2) {
300  }
301 }
302 
303 TEST(RepeatedField, ReserveLarge) {
304  const int old_size = 10;
305  // This is a size we won't get by doubling:
306  const int new_size = old_size * 3 + 1;
307 
308  // Reserving more than 2x current capacity should grow directly to that size.
310 }
311 
312 TEST(RepeatedField, ReserveHuge) {
313  // Largest value that does not clamp to the large limit:
314  constexpr int non_clamping_limit = std::numeric_limits<int>::max() / 2;
315  ASSERT_LT(2 * non_clamping_limit, std::numeric_limits<int>::max());
316  EXPECT_LT(internal::CalculateReserveSize(non_clamping_limit,
317  non_clamping_limit + 1),
319 
320  // Smallest size that *will* clamp to the upper limit:
321  constexpr int min_clamping_size = std::numeric_limits<int>::max() / 2 + 1;
322  EXPECT_EQ(
323  internal::CalculateReserveSize(min_clamping_size, min_clamping_size + 1),
325 
326 #ifdef PROTOBUF_TEST_ALLOW_LARGE_ALLOC
327  // The rest of this test may allocate several GB of memory, so it is only
328  // built if explicitly requested.
329  RepeatedField<int> huge_field;
330 
331  // Reserve a size for huge_field that will clamp.
332  huge_field.Reserve(min_clamping_size);
333  EXPECT_GE(huge_field.Capacity(), min_clamping_size);
334  ASSERT_LT(huge_field.Capacity(), std::numeric_limits<int>::max() - 1);
335 
336 #ifndef PROTOBUF_ASAN
337  // The array containing all the fields is, in theory, up to MAXINT-1 in size.
338  // However, some compilers can't handle a struct whose size is larger
339  // than 2GB, and the protocol buffer format doesn't handle more than 2GB of
340  // data at once, either. So we limit it, but the code below accesses beyond
341  // that limit.
342 
343  // Allocation may return more memory than we requested. However, the updated
344  // size must still be clamped to a valid range.
345  huge_field.Reserve(huge_field.Capacity() + 1);
346  EXPECT_EQ(huge_field.Capacity(), std::numeric_limits<int>::max());
347 #endif // PROTOBUF_ASAN
348 #endif // PROTOBUF_TEST_ALLOW_LARGE_ALLOC
349 }
350 
352  RepeatedField<int> source, destination;
353  source.Add(4);
354  source.Add(5);
355  destination.Add(1);
356  destination.Add(2);
357  destination.Add(3);
358 
359  destination.MergeFrom(source);
360 
361  ASSERT_EQ(5, destination.size());
362  EXPECT_EQ(1, destination.Get(0));
363  EXPECT_EQ(2, destination.Get(1));
364  EXPECT_EQ(3, destination.Get(2));
365  EXPECT_EQ(4, destination.Get(3));
366  EXPECT_EQ(5, destination.Get(4));
367 }
368 
369 
371  RepeatedField<int> source, destination;
372  source.Add(4);
373  source.Add(5);
374  destination.Add(1);
375  destination.Add(2);
376  destination.Add(3);
377 
378  destination.CopyFrom(source);
379 
380  ASSERT_EQ(2, destination.size());
381  EXPECT_EQ(4, destination.Get(0));
382  EXPECT_EQ(5, destination.Get(1));
383 }
384 
385 TEST(RepeatedField, CopyFromSelf) {
387  me.Add(3);
388  me.CopyFrom(me);
389  ASSERT_EQ(1, me.size());
390  EXPECT_EQ(3, me.Get(0));
391 }
392 
393 TEST(RepeatedField, Erase) {
395  RepeatedField<int>::iterator it = me.erase(me.begin(), me.end());
396  EXPECT_TRUE(me.begin() == it);
397  EXPECT_EQ(0, me.size());
398 
399  me.Add(1);
400  me.Add(2);
401  me.Add(3);
402  it = me.erase(me.begin(), me.end());
403  EXPECT_TRUE(me.begin() == it);
404  EXPECT_EQ(0, me.size());
405 
406  me.Add(4);
407  me.Add(5);
408  me.Add(6);
409  it = me.erase(me.begin() + 2, me.end());
410  EXPECT_TRUE(me.begin() + 2 == it);
411  EXPECT_EQ(2, me.size());
412  EXPECT_EQ(4, me.Get(0));
413  EXPECT_EQ(5, me.Get(1));
414 
415  me.Add(6);
416  me.Add(7);
417  me.Add(8);
418  it = me.erase(me.begin() + 1, me.begin() + 3);
419  EXPECT_TRUE(me.begin() + 1 == it);
420  EXPECT_EQ(3, me.size());
421  EXPECT_EQ(4, me.Get(0));
422  EXPECT_EQ(7, me.Get(1));
423  EXPECT_EQ(8, me.Get(2));
424 }
425 
426 // Add contents of empty container to an empty field.
427 TEST(RepeatedField, AddRange1) {
429  std::vector<int> values;
430 
431  me.Add(values.begin(), values.end());
432  ASSERT_EQ(me.size(), 0);
433 }
434 
435 // Add contents of container with one thing to an empty field.
436 TEST(RepeatedField, AddRange2) {
438  std::vector<int> values;
439  values.push_back(-1);
440 
441  me.Add(values.begin(), values.end());
442  ASSERT_EQ(me.size(), 1);
443  ASSERT_EQ(me.Get(0), values[0]);
444 }
445 
446 // Add contents of container with more than one thing to an empty field.
447 TEST(RepeatedField, AddRange3) {
449  std::vector<int> values;
450  values.push_back(0);
451  values.push_back(1);
452 
453  me.Add(values.begin(), values.end());
454  ASSERT_EQ(me.size(), 2);
455  ASSERT_EQ(me.Get(0), values[0]);
456  ASSERT_EQ(me.Get(1), values[1]);
457 }
458 
459 // Add contents of container with more than one thing to a non-empty field.
460 TEST(RepeatedField, AddRange4) {
462  me.Add(0);
463  me.Add(1);
464 
465  std::vector<int> values;
466  values.push_back(2);
467  values.push_back(3);
468 
469  me.Add(values.begin(), values.end());
470  ASSERT_EQ(me.size(), 4);
471  ASSERT_EQ(me.Get(0), 0);
472  ASSERT_EQ(me.Get(1), 1);
473  ASSERT_EQ(me.Get(2), values[0]);
474  ASSERT_EQ(me.Get(3), values[1]);
475 }
476 
477 // Add contents of a stringstream in order to test code paths where there is
478 // an input iterator.
479 TEST(RepeatedField, AddRange5) {
481 
482  std::stringstream ss;
483  ss << 1 << ' ' << 2;
484 
485  me.Add(std::istream_iterator<int>(ss), std::istream_iterator<int>());
486  ASSERT_EQ(me.size(), 2);
487  ASSERT_EQ(me.Get(0), 1);
488  ASSERT_EQ(me.Get(1), 2);
489 }
490 
491 TEST(RepeatedField, AddAndAssignRanges) {
493 
494  int vals[] = {2, 27, 2875, 609250};
495  field.Assign(std::begin(vals), std::end(vals));
496 
497  ASSERT_EQ(field.size(), 4);
498  EXPECT_EQ(field.Get(0), 2);
499  EXPECT_EQ(field.Get(1), 27);
500  EXPECT_EQ(field.Get(2), 2875);
501  EXPECT_EQ(field.Get(3), 609250);
502 
504  ASSERT_EQ(field.size(), 8);
505  EXPECT_EQ(field.Get(0), 2);
506  EXPECT_EQ(field.Get(1), 27);
507  EXPECT_EQ(field.Get(2), 2875);
508  EXPECT_EQ(field.Get(3), 609250);
509  EXPECT_EQ(field.Get(4), 2);
510  EXPECT_EQ(field.Get(5), 27);
511  EXPECT_EQ(field.Get(6), 2875);
512  EXPECT_EQ(field.Get(7), 609250);
513 }
514 
516  RepeatedField<int> source;
517  source.Add(1);
518  source.Add(2);
519 
520  RepeatedField<int> destination(source);
521 
522  ASSERT_EQ(2, destination.size());
523  EXPECT_EQ(1, destination.Get(0));
524  EXPECT_EQ(2, destination.Get(1));
525 }
526 
527 TEST(RepeatedField, IteratorConstruct) {
528  std::vector<int> values;
529  RepeatedField<int> empty(values.begin(), values.end());
530  ASSERT_EQ(values.size(), empty.size());
531 
532  values.push_back(1);
533  values.push_back(2);
534 
535  RepeatedField<int> field(values.begin(), values.end());
536  ASSERT_EQ(values.size(), field.size());
537  EXPECT_EQ(values[0], field.Get(0));
538  EXPECT_EQ(values[1], field.Get(1));
539 
540  RepeatedField<int> other(field.begin(), field.end());
541  ASSERT_EQ(values.size(), other.size());
542  EXPECT_EQ(values[0], other.Get(0));
543  EXPECT_EQ(values[1], other.Get(1));
544 }
545 
546 TEST(RepeatedField, CopyAssign) {
547  RepeatedField<int> source, destination;
548  source.Add(4);
549  source.Add(5);
550  destination.Add(1);
551  destination.Add(2);
552  destination.Add(3);
553 
554  destination = source;
555 
556  ASSERT_EQ(2, destination.size());
557  EXPECT_EQ(4, destination.Get(0));
558  EXPECT_EQ(5, destination.Get(1));
559 }
560 
561 TEST(RepeatedField, SelfAssign) {
562  // Verify that assignment to self does not destroy data.
563  RepeatedField<int> source, *p;
564  p = &source;
565  source.Add(7);
566  source.Add(8);
567 
568  *p = source;
569 
570  ASSERT_EQ(2, source.size());
571  EXPECT_EQ(7, source.Get(0));
572  EXPECT_EQ(8, source.Get(1));
573 }
574 
575 TEST(RepeatedField, MoveConstruct) {
576  {
577  RepeatedField<int> source;
578  source.Add(1);
579  source.Add(2);
580  const int* data = source.data();
581  RepeatedField<int> destination = std::move(source);
582  EXPECT_EQ(data, destination.data());
583  EXPECT_THAT(destination, ElementsAre(1, 2));
584  // This property isn't guaranteed but it's useful to have a test that would
585  // catch changes in this area.
586  EXPECT_TRUE(source.empty());
587  }
588  {
589  Arena arena;
590  RepeatedField<int>* source =
591  Arena::CreateMessage<RepeatedField<int>>(&arena);
592  source->Add(1);
593  source->Add(2);
594  RepeatedField<int> destination = std::move(*source);
595  EXPECT_EQ(nullptr, destination.GetArena());
596  EXPECT_THAT(destination, ElementsAre(1, 2));
597  // This property isn't guaranteed but it's useful to have a test that would
598  // catch changes in this area.
599  EXPECT_THAT(*source, ElementsAre(1, 2));
600  }
601 }
602 
603 TEST(RepeatedField, MoveAssign) {
604  {
605  RepeatedField<int> source;
606  source.Add(1);
607  source.Add(2);
608  RepeatedField<int> destination;
609  destination.Add(3);
610  const int* source_data = source.data();
611  const int* destination_data = destination.data();
612  destination = std::move(source);
613  EXPECT_EQ(source_data, destination.data());
614  EXPECT_THAT(destination, ElementsAre(1, 2));
615  // This property isn't guaranteed but it's useful to have a test that would
616  // catch changes in this area.
617  EXPECT_EQ(destination_data, source.data());
618  EXPECT_THAT(source, ElementsAre(3));
619  }
620  {
621  Arena arena;
622  RepeatedField<int>* source =
623  Arena::CreateMessage<RepeatedField<int>>(&arena);
624  source->Add(1);
625  source->Add(2);
626  RepeatedField<int>* destination =
627  Arena::CreateMessage<RepeatedField<int>>(&arena);
628  destination->Add(3);
629  const int* source_data = source->data();
630  const int* destination_data = destination->data();
631  *destination = std::move(*source);
632  EXPECT_EQ(source_data, destination->data());
633  EXPECT_THAT(*destination, ElementsAre(1, 2));
634  // This property isn't guaranteed but it's useful to have a test that would
635  // catch changes in this area.
636  EXPECT_EQ(destination_data, source->data());
637  EXPECT_THAT(*source, ElementsAre(3));
638  }
639  {
640  Arena source_arena;
641  RepeatedField<int>* source =
642  Arena::CreateMessage<RepeatedField<int>>(&source_arena);
643  source->Add(1);
644  source->Add(2);
645  Arena destination_arena;
646  RepeatedField<int>* destination =
647  Arena::CreateMessage<RepeatedField<int>>(&destination_arena);
648  destination->Add(3);
649  *destination = std::move(*source);
650  EXPECT_THAT(*destination, ElementsAre(1, 2));
651  // This property isn't guaranteed but it's useful to have a test that would
652  // catch changes in this area.
653  EXPECT_THAT(*source, ElementsAre(1, 2));
654  }
655  {
656  Arena arena;
657  RepeatedField<int>* source =
658  Arena::CreateMessage<RepeatedField<int>>(&arena);
659  source->Add(1);
660  source->Add(2);
661  RepeatedField<int> destination;
662  destination.Add(3);
663  destination = std::move(*source);
664  EXPECT_THAT(destination, ElementsAre(1, 2));
665  // This property isn't guaranteed but it's useful to have a test that would
666  // catch changes in this area.
667  EXPECT_THAT(*source, ElementsAre(1, 2));
668  }
669  {
670  RepeatedField<int> source;
671  source.Add(1);
672  source.Add(2);
673  Arena arena;
674  RepeatedField<int>* destination =
675  Arena::CreateMessage<RepeatedField<int>>(&arena);
676  destination->Add(3);
677  *destination = std::move(source);
678  EXPECT_THAT(*destination, ElementsAre(1, 2));
679  // This property isn't guaranteed but it's useful to have a test that would
680  // catch changes in this area.
681  EXPECT_THAT(source, ElementsAre(1, 2));
682  }
683  {
685  // An alias to defeat -Wself-move.
686  RepeatedField<int>& alias = field;
687  field.Add(1);
688  field.Add(2);
689  const int* data = field.data();
690  field = std::move(alias);
691  EXPECT_EQ(data, field.data());
692  EXPECT_THAT(field, ElementsAre(1, 2));
693  }
694  {
695  Arena arena;
697  Arena::CreateMessage<RepeatedField<int>>(&arena);
698  field->Add(1);
699  field->Add(2);
700  const int* data = field->data();
701  *field = std::move(*field);
702  EXPECT_EQ(data, field->data());
703  EXPECT_THAT(*field, ElementsAre(1, 2));
704  }
705 }
706 
707 TEST(Movable, Works) {
708  class NonMoveConstructible {
709  public:
710  NonMoveConstructible(NonMoveConstructible&&) = delete;
711  NonMoveConstructible& operator=(NonMoveConstructible&&) { return *this; }
712  };
713  class NonMoveAssignable {
714  public:
715  NonMoveAssignable(NonMoveAssignable&&) {}
716  NonMoveAssignable& operator=(NonMoveConstructible&&) = delete;
717  };
718  class NonMovable {
719  public:
720  NonMovable(NonMovable&&) = delete;
721  NonMovable& operator=(NonMovable&&) = delete;
722  };
723 
725 
729 
733 
735 }
736 
737 TEST(RepeatedField, MoveAdd) {
738  RepeatedPtrField<TestAllTypes> field;
739  TestAllTypes test_all_types;
740  auto* optional_nested_message =
741  test_all_types.mutable_optional_nested_message();
742  optional_nested_message->set_bb(42);
743  field.Add(std::move(test_all_types));
744 
745  EXPECT_EQ(optional_nested_message,
746  field.Mutable(0)->mutable_optional_nested_message());
747 }
748 
749 TEST(RepeatedField, MutableDataIsMutable) {
751  field.Add(1);
752  EXPECT_EQ(1, field.Get(0));
753  // The fact that this line compiles would be enough, but we'll check the
754  // value anyway.
755  *field.mutable_data() = 2;
756  EXPECT_EQ(2, field.Get(0));
757 }
758 
759 TEST(RepeatedField, SubscriptOperators) {
761  field.Add(1);
762  EXPECT_EQ(1, field.Get(0));
763  EXPECT_EQ(1, field[0]);
764  EXPECT_EQ(field.Mutable(0), &field[0]);
765  const RepeatedField<int>& const_field = field;
766  EXPECT_EQ(field.data(), &const_field[0]);
767 }
768 
769 TEST(RepeatedField, Truncate) {
771 
772  field.Add(12);
773  field.Add(34);
774  field.Add(56);
775  field.Add(78);
776  EXPECT_EQ(4, field.size());
777 
778  field.Truncate(3);
779  EXPECT_EQ(3, field.size());
780 
781  field.Add(90);
782  EXPECT_EQ(4, field.size());
783  EXPECT_EQ(90, field.Get(3));
784 
785  // Truncations that don't change the size are allowed, but growing is not
786  // allowed.
787  field.Truncate(field.size());
788 #ifdef PROTOBUF_HAS_DEATH_TEST
789  EXPECT_DEBUG_DEATH(field.Truncate(field.size() + 1), "new_size");
790 #endif
791 }
792 
793 
794 TEST(RepeatedField, ExtractSubrange) {
795  // Exhaustively test every subrange in arrays of all sizes from 0 through 9.
796  for (int sz = 0; sz < 10; ++sz) {
797  for (int num = 0; num <= sz; ++num) {
798  for (int start = 0; start < sz - num; ++start) {
799  // Create RepeatedField with sz elements having values 0 through sz-1.
801  for (int i = 0; i < sz; ++i) field.Add(i);
802  EXPECT_EQ(field.size(), sz);
803 
804  // Create a catcher array and call ExtractSubrange.
805  int32 catcher[10];
806  for (int i = 0; i < 10; ++i) catcher[i] = -1;
807  field.ExtractSubrange(start, num, catcher);
808 
809  // Does the resulting array have the right size?
810  EXPECT_EQ(field.size(), sz - num);
811 
812  // Were the removed elements extracted into the catcher array?
813  for (int i = 0; i < num; ++i) EXPECT_EQ(catcher[i], start + i);
814  EXPECT_EQ(catcher[num], -1);
815 
816  // Does the resulting array contain the right values?
817  for (int i = 0; i < start; ++i) EXPECT_EQ(field.Get(i), i);
818  for (int i = start; i < field.size(); ++i)
819  EXPECT_EQ(field.Get(i), i + num);
820  }
821  }
822  }
823 }
824 
825 TEST(RepeatedField, ClearThenReserveMore) {
826  // Test that Reserve properly destroys the old internal array when it's forced
827  // to allocate a new one, even when cleared-but-not-deleted objects are
828  // present. Use a 'string' and > 16 bytes length so that the elements are
829  // non-POD and allocate -- the leak checker will catch any skipped destructor
830  // calls here.
832  for (int i = 0; i < 32; i++) {
833  field.Add(std::string("abcdefghijklmnopqrstuvwxyz0123456789"));
834  }
835  EXPECT_EQ(32, field.size());
836  field.Clear();
837  EXPECT_EQ(0, field.size());
838  EXPECT_LE(32, field.Capacity());
839 
840  field.Reserve(1024);
841  EXPECT_EQ(0, field.size());
842  EXPECT_LE(1024, field.Capacity());
843  // Finish test -- |field| should destroy the cleared-but-not-yet-destroyed
844  // strings.
845 }
846 
847 TEST(RepeatedField, TestSAddFromSelf) {
849  field.Add(0);
850  for (int i = 0; i < 1000; i++) {
851  field.Add(field[0]);
852  }
853 }
854 
855 // ===================================================================
856 // RepeatedPtrField tests. These pretty much just mirror the RepeatedField
857 // tests above.
858 
859 TEST(RepeatedPtrField, ConstInit) {
860  PROTOBUF_CONSTINIT static RepeatedPtrField<std::string> field{}; // NOLINT
861  EXPECT_TRUE(field.empty());
862 }
863 
864 // This helper overload set tests whether X::f can be called with a braced pair,
865 // X::f({a, b}) of std::string iterators (specifically, pointers: That call is
866 // ambiguous if and only if the call to ValidResolutionPointerRange is not.
867 template <typename X>
868 auto ValidResolutionPointerRange(const std::string* p)
869  -> decltype(X::f({p, p + 2}), std::true_type{});
870 template <typename X>
871 std::false_type ValidResolutionPointerRange(void*);
872 
873 TEST(RepeatedPtrField, UnambiguousConstructor) {
874  struct X {
875  static bool f(std::vector<std::string>) { return false; }
876  static bool f(google::protobuf::RepeatedPtrField<std::string>) { return true; }
877 
878  static bool g(std::vector<int>) { return false; }
879  static bool g(google::protobuf::RepeatedPtrField<std::string>) { return true; }
880  };
881 
882  // RepeatedPtrField has no initializer-list constructor, and a constructor
883  // from to const char* values is excluded by its constraints.
884  EXPECT_FALSE(X::f({"abc", "xyz"}));
885 
886  // Construction from a pair of int* is also not ambiguous.
887  int a[5] = {};
888  EXPECT_FALSE(X::g({a, a + 5}));
889 
890  // Construction from string iterators for the unique string overload "g"
891  // works.
892  // Disabling this for now, this is actually ambiguous with libstdc++.
893  // std::string b[2] = {"abc", "xyz"};
894  // EXPECT_TRUE(X::g({b, b + 2}));
895 
896  // Construction from string iterators for "f" is ambiguous, since both
897  // containers are equally good.
898  //
899  // X::f({b, b + 2}); // error => ValidResolutionPointerRange is unambiguous.
900  EXPECT_FALSE(decltype(ValidResolutionPointerRange<X>(nullptr))::value);
901 }
902 
903 TEST(RepeatedPtrField, Small) {
904  RepeatedPtrField<std::string> field;
905 
906  EXPECT_TRUE(field.empty());
907  EXPECT_EQ(field.size(), 0);
908 
909  field.Add()->assign("foo");
910 
911  EXPECT_FALSE(field.empty());
912  EXPECT_EQ(field.size(), 1);
913  EXPECT_EQ(field.Get(0), "foo");
914  EXPECT_EQ(field.at(0), "foo");
915 
916  field.Add()->assign("bar");
917 
918  EXPECT_FALSE(field.empty());
919  EXPECT_EQ(field.size(), 2);
920  EXPECT_EQ(field.Get(0), "foo");
921  EXPECT_EQ(field.at(0), "foo");
922  EXPECT_EQ(field.Get(1), "bar");
923  EXPECT_EQ(field.at(1), "bar");
924 
925  field.Mutable(1)->assign("baz");
926 
927  EXPECT_FALSE(field.empty());
928  EXPECT_EQ(field.size(), 2);
929  EXPECT_EQ(field.Get(0), "foo");
930  EXPECT_EQ(field.at(0), "foo");
931  EXPECT_EQ(field.Get(1), "baz");
932  EXPECT_EQ(field.at(1), "baz");
933 
934  field.RemoveLast();
935 
936  EXPECT_FALSE(field.empty());
937  EXPECT_EQ(field.size(), 1);
938  EXPECT_EQ(field.Get(0), "foo");
939  EXPECT_EQ(field.at(0), "foo");
940 
941  field.Clear();
942 
943  EXPECT_TRUE(field.empty());
944  EXPECT_EQ(field.size(), 0);
945 }
946 
947 TEST(RepeatedPtrField, Large) {
948  RepeatedPtrField<std::string> field;
949 
950  for (int i = 0; i < 16; i++) {
951  *field.Add() += 'a' + i;
952  }
953 
954  EXPECT_EQ(field.size(), 16);
955 
956  for (int i = 0; i < 16; i++) {
957  EXPECT_EQ(field.Get(i).size(), 1);
958  EXPECT_EQ(field.Get(i)[0], 'a' + i);
959  }
960 
961  int min_expected_usage = 16 * sizeof(std::string);
962  EXPECT_GE(field.SpaceUsedExcludingSelf(), min_expected_usage);
963 }
964 
965 TEST(RepeatedPtrField, AddAndAssignRanges) {
966  RepeatedPtrField<std::string> field;
967 
968  const char* vals[] = {"abc", "x", "yz", "xyzzy"};
969  field.Assign(std::begin(vals), std::end(vals));
970 
971  ASSERT_EQ(field.size(), 4);
972  EXPECT_EQ(field.Get(0), "abc");
973  EXPECT_EQ(field.Get(1), "x");
974  EXPECT_EQ(field.Get(2), "yz");
975  EXPECT_EQ(field.Get(3), "xyzzy");
976 
978  ASSERT_EQ(field.size(), 8);
979  EXPECT_EQ(field.Get(0), "abc");
980  EXPECT_EQ(field.Get(1), "x");
981  EXPECT_EQ(field.Get(2), "yz");
982  EXPECT_EQ(field.Get(3), "xyzzy");
983  EXPECT_EQ(field.Get(4), "abc");
984  EXPECT_EQ(field.Get(5), "x");
985  EXPECT_EQ(field.Get(6), "yz");
986  EXPECT_EQ(field.Get(7), "xyzzy");
987 }
988 
989 TEST(RepeatedPtrField, SwapSmallSmall) {
990  RepeatedPtrField<std::string> field1;
991  RepeatedPtrField<std::string> field2;
992 
993  EXPECT_TRUE(field1.empty());
994  EXPECT_EQ(field1.size(), 0);
995  EXPECT_TRUE(field2.empty());
996  EXPECT_EQ(field2.size(), 0);
997 
998  field1.Add()->assign("foo");
999  field1.Add()->assign("bar");
1000 
1001  EXPECT_FALSE(field1.empty());
1002  EXPECT_EQ(field1.size(), 2);
1003  EXPECT_EQ(field1.Get(0), "foo");
1004  EXPECT_EQ(field1.Get(1), "bar");
1005 
1006  EXPECT_TRUE(field2.empty());
1007  EXPECT_EQ(field2.size(), 0);
1008 
1009  field1.Swap(&field2);
1010 
1011  EXPECT_TRUE(field1.empty());
1012  EXPECT_EQ(field1.size(), 0);
1013 
1014  EXPECT_EQ(field2.size(), 2);
1015  EXPECT_EQ(field2.Get(0), "foo");
1016  EXPECT_EQ(field2.Get(1), "bar");
1017 }
1018 
1019 TEST(RepeatedPtrField, SwapLargeSmall) {
1020  RepeatedPtrField<std::string> field1;
1021  RepeatedPtrField<std::string> field2;
1022 
1023  field2.Add()->assign("foo");
1024  field2.Add()->assign("bar");
1025  for (int i = 0; i < 16; i++) {
1026  *field1.Add() += 'a' + i;
1027  }
1028  field1.Swap(&field2);
1029 
1030  EXPECT_EQ(field1.size(), 2);
1031  EXPECT_EQ(field1.Get(0), "foo");
1032  EXPECT_EQ(field1.Get(1), "bar");
1033  EXPECT_EQ(field2.size(), 16);
1034  for (int i = 0; i < 16; i++) {
1035  EXPECT_EQ(field2.Get(i).size(), 1);
1036  EXPECT_EQ(field2.Get(i)[0], 'a' + i);
1037  }
1038 }
1039 
1040 TEST(RepeatedPtrField, SwapLargeLarge) {
1041  RepeatedPtrField<std::string> field1;
1042  RepeatedPtrField<std::string> field2;
1043 
1044  field1.Add()->assign("foo");
1045  field1.Add()->assign("bar");
1046  for (int i = 0; i < 16; i++) {
1047  *field1.Add() += 'A' + i;
1048  *field2.Add() += 'a' + i;
1049  }
1050  field2.Swap(&field1);
1051 
1052  EXPECT_EQ(field1.size(), 16);
1053  for (int i = 0; i < 16; i++) {
1054  EXPECT_EQ(field1.Get(i).size(), 1);
1055  EXPECT_EQ(field1.Get(i)[0], 'a' + i);
1056  }
1057  EXPECT_EQ(field2.size(), 18);
1058  EXPECT_EQ(field2.Get(0), "foo");
1059  EXPECT_EQ(field2.Get(1), "bar");
1060  for (int i = 2; i < 18; i++) {
1061  EXPECT_EQ(field2.Get(i).size(), 1);
1062  EXPECT_EQ(field2.Get(i)[0], 'A' + i - 2);
1063  }
1064 }
1065 
1066 static int ReservedSpace(RepeatedPtrField<std::string>* field) {
1067  const std::string* const* ptr = field->data();
1068  do {
1069  field->Add();
1070  } while (field->data() == ptr);
1071 
1072  return field->size() - 1;
1073 }
1074 
1075 TEST(RepeatedPtrField, ReserveMoreThanDouble) {
1076  RepeatedPtrField<std::string> field;
1077  field.Reserve(20);
1078 
1079  EXPECT_LE(20, ReservedSpace(&field));
1080 }
1081 
1082 TEST(RepeatedPtrField, ReserveLessThanDouble) {
1083  RepeatedPtrField<std::string> field;
1084  field.Reserve(20);
1085 
1086  int capacity = field.Capacity();
1087  // Grow by 1.5x
1088  field.Reserve(capacity + (capacity >> 2));
1089 
1090  EXPECT_LE(2 * capacity, ReservedSpace(&field));
1091 }
1092 
1093 TEST(RepeatedPtrField, ReserveLessThanExisting) {
1094  RepeatedPtrField<std::string> field;
1095  field.Reserve(20);
1096  const std::string* const* previous_ptr = field.data();
1097  field.Reserve(10);
1098 
1099  EXPECT_EQ(previous_ptr, field.data());
1100  EXPECT_LE(20, ReservedSpace(&field));
1101 }
1102 
1103 TEST(RepeatedPtrField, ReserveDoesntLoseAllocated) {
1104  // Check that a bug is fixed: An earlier implementation of Reserve()
1105  // failed to copy pointers to allocated-but-cleared objects, possibly
1106  // leading to segfaults.
1107  RepeatedPtrField<std::string> field;
1108  std::string* first = field.Add();
1109  field.RemoveLast();
1110 
1111  field.Reserve(20);
1112  EXPECT_EQ(first, field.Add());
1113 }
1114 
1115 // Clearing elements is tricky with RepeatedPtrFields since the memory for
1116 // the elements is retained and reused.
1117 TEST(RepeatedPtrField, ClearedElements) {
1118  RepeatedPtrField<std::string> field;
1119 
1120  std::string* original = field.Add();
1121  *original = "foo";
1122 
1123  EXPECT_EQ(field.ClearedCount(), 0);
1124 
1125  field.RemoveLast();
1126  EXPECT_TRUE(original->empty());
1127  EXPECT_EQ(field.ClearedCount(), 1);
1128 
1129  EXPECT_EQ(field.Add(),
1130  original); // Should return same string for reuse.
1131  EXPECT_EQ(field.UnsafeArenaReleaseLast(), original); // We take ownership.
1132  EXPECT_EQ(field.ClearedCount(), 0);
1133 
1134  EXPECT_NE(field.Add(), original); // Should NOT return the same string.
1135  EXPECT_EQ(field.ClearedCount(), 0);
1136 
1137  field.UnsafeArenaAddAllocated(original); // Give ownership back.
1138  EXPECT_EQ(field.ClearedCount(), 0);
1139  EXPECT_EQ(field.Mutable(1), original);
1140 
1141  field.Clear();
1142  EXPECT_EQ(field.ClearedCount(), 2);
1143 #ifndef PROTOBUF_FUTURE_BREAKING_CHANGES
1144  EXPECT_EQ(field.ReleaseCleared(), original); // Take ownership again.
1145  EXPECT_EQ(field.ClearedCount(), 1);
1146  EXPECT_NE(field.Add(), original);
1147  EXPECT_EQ(field.ClearedCount(), 0);
1148  EXPECT_NE(field.Add(), original);
1149  EXPECT_EQ(field.ClearedCount(), 0);
1150 
1151  field.AddCleared(original); // Give ownership back, but as a cleared object.
1152  EXPECT_EQ(field.ClearedCount(), 1);
1153  EXPECT_EQ(field.Add(), original);
1154  EXPECT_EQ(field.ClearedCount(), 0);
1155 #endif // !PROTOBUF_FUTURE_BREAKING_CHANGES
1156 }
1157 
1158 // Test all code paths in AddAllocated().
1159 TEST(RepeatedPtrField, AddAllocated) {
1160  RepeatedPtrField<std::string> field;
1161  while (field.size() < field.Capacity()) {
1162  field.Add()->assign("filler");
1163  }
1164 
1165  int index = field.size();
1166 
1167  // First branch: Field is at capacity with no cleared objects.
1168  std::string* foo = new std::string("foo");
1169  field.AddAllocated(foo);
1170  EXPECT_EQ(index + 1, field.size());
1171  EXPECT_EQ(0, field.ClearedCount());
1172  EXPECT_EQ(foo, &field.Get(index));
1173 
1174  // Last branch: Field is not at capacity and there are no cleared objects.
1175  std::string* bar = new std::string("bar");
1176  field.AddAllocated(bar);
1177  ++index;
1178  EXPECT_EQ(index + 1, field.size());
1179  EXPECT_EQ(0, field.ClearedCount());
1180  EXPECT_EQ(bar, &field.Get(index));
1181 
1182  // Third branch: Field is not at capacity and there are no cleared objects.
1183  field.RemoveLast();
1184  std::string* baz = new std::string("baz");
1185  field.AddAllocated(baz);
1186  EXPECT_EQ(index + 1, field.size());
1187  EXPECT_EQ(1, field.ClearedCount());
1188  EXPECT_EQ(baz, &field.Get(index));
1189 
1190  // Second branch: Field is at capacity but has some cleared objects.
1191  while (field.size() < field.Capacity()) {
1192  field.Add()->assign("filler2");
1193  }
1194  field.RemoveLast();
1195  index = field.size();
1196  std::string* qux = new std::string("qux");
1197  field.AddAllocated(qux);
1198  EXPECT_EQ(index + 1, field.size());
1199  // We should have discarded the cleared object.
1200  EXPECT_EQ(0, field.ClearedCount());
1201  EXPECT_EQ(qux, &field.Get(index));
1202 }
1203 
1204 TEST(RepeatedPtrField, AddAllocatedDifferentArena) {
1205  RepeatedPtrField<TestAllTypes> field;
1206  Arena arena;
1207  auto* msg = Arena::CreateMessage<TestAllTypes>(&arena);
1208  field.AddAllocated(msg);
1209 }
1210 
1211 TEST(RepeatedPtrField, MergeFrom) {
1212  RepeatedPtrField<std::string> source, destination;
1213  source.Add()->assign("4");
1214  source.Add()->assign("5");
1215  destination.Add()->assign("1");
1216  destination.Add()->assign("2");
1217  destination.Add()->assign("3");
1218 
1219  destination.MergeFrom(source);
1220 
1221  ASSERT_EQ(5, destination.size());
1222  EXPECT_EQ("1", destination.Get(0));
1223  EXPECT_EQ("2", destination.Get(1));
1224  EXPECT_EQ("3", destination.Get(2));
1225  EXPECT_EQ("4", destination.Get(3));
1226  EXPECT_EQ("5", destination.Get(4));
1227 }
1228 
1229 
1230 TEST(RepeatedPtrField, CopyFrom) {
1231  RepeatedPtrField<std::string> source, destination;
1232  source.Add()->assign("4");
1233  source.Add()->assign("5");
1234  destination.Add()->assign("1");
1235  destination.Add()->assign("2");
1236  destination.Add()->assign("3");
1237 
1238  destination.CopyFrom(source);
1239 
1240  ASSERT_EQ(2, destination.size());
1241  EXPECT_EQ("4", destination.Get(0));
1242  EXPECT_EQ("5", destination.Get(1));
1243 }
1244 
1245 TEST(RepeatedPtrField, CopyFromSelf) {
1246  RepeatedPtrField<std::string> me;
1247  me.Add()->assign("1");
1248  me.CopyFrom(me);
1249  ASSERT_EQ(1, me.size());
1250  EXPECT_EQ("1", me.Get(0));
1251 }
1252 
1253 TEST(RepeatedPtrField, Erase) {
1254  RepeatedPtrField<std::string> me;
1255  RepeatedPtrField<std::string>::iterator it = me.erase(me.begin(), me.end());
1256  EXPECT_TRUE(me.begin() == it);
1257  EXPECT_EQ(0, me.size());
1258 
1259  *me.Add() = "1";
1260  *me.Add() = "2";
1261  *me.Add() = "3";
1262  it = me.erase(me.begin(), me.end());
1263  EXPECT_TRUE(me.begin() == it);
1264  EXPECT_EQ(0, me.size());
1265 
1266  *me.Add() = "4";
1267  *me.Add() = "5";
1268  *me.Add() = "6";
1269  it = me.erase(me.begin() + 2, me.end());
1270  EXPECT_TRUE(me.begin() + 2 == it);
1271  EXPECT_EQ(2, me.size());
1272  EXPECT_EQ("4", me.Get(0));
1273  EXPECT_EQ("5", me.Get(1));
1274 
1275  *me.Add() = "6";
1276  *me.Add() = "7";
1277  *me.Add() = "8";
1278  it = me.erase(me.begin() + 1, me.begin() + 3);
1279  EXPECT_TRUE(me.begin() + 1 == it);
1280  EXPECT_EQ(3, me.size());
1281  EXPECT_EQ("4", me.Get(0));
1282  EXPECT_EQ("7", me.Get(1));
1283  EXPECT_EQ("8", me.Get(2));
1284 }
1285 
1286 TEST(RepeatedPtrField, CopyConstruct) {
1287  RepeatedPtrField<std::string> source;
1288  source.Add()->assign("1");
1289  source.Add()->assign("2");
1290 
1291  RepeatedPtrField<std::string> destination(source);
1292 
1293  ASSERT_EQ(2, destination.size());
1294  EXPECT_EQ("1", destination.Get(0));
1295  EXPECT_EQ("2", destination.Get(1));
1296 }
1297 
1298 TEST(RepeatedPtrField, IteratorConstruct_String) {
1299  std::vector<std::string> values;
1300  values.push_back("1");
1301  values.push_back("2");
1302 
1303  RepeatedPtrField<std::string> field(values.begin(), values.end());
1304  ASSERT_EQ(values.size(), field.size());
1305  EXPECT_EQ(values[0], field.Get(0));
1306  EXPECT_EQ(values[1], field.Get(1));
1307 
1308  RepeatedPtrField<std::string> other(field.begin(), field.end());
1309  ASSERT_EQ(values.size(), other.size());
1310  EXPECT_EQ(values[0], other.Get(0));
1311  EXPECT_EQ(values[1], other.Get(1));
1312 }
1313 
1314 TEST(RepeatedPtrField, IteratorConstruct_Proto) {
1315  typedef TestAllTypes::NestedMessage Nested;
1316  std::vector<Nested> values;
1317  values.push_back(Nested());
1318  values.back().set_bb(1);
1319  values.push_back(Nested());
1320  values.back().set_bb(2);
1321 
1322  RepeatedPtrField<Nested> field(values.begin(), values.end());
1323  ASSERT_EQ(values.size(), field.size());
1324  EXPECT_EQ(values[0].bb(), field.Get(0).bb());
1325  EXPECT_EQ(values[1].bb(), field.Get(1).bb());
1326 
1327  RepeatedPtrField<Nested> other(field.begin(), field.end());
1328  ASSERT_EQ(values.size(), other.size());
1329  EXPECT_EQ(values[0].bb(), other.Get(0).bb());
1330  EXPECT_EQ(values[1].bb(), other.Get(1).bb());
1331 }
1332 
1333 TEST(RepeatedPtrField, CopyAssign) {
1334  RepeatedPtrField<std::string> source, destination;
1335  source.Add()->assign("4");
1336  source.Add()->assign("5");
1337  destination.Add()->assign("1");
1338  destination.Add()->assign("2");
1339  destination.Add()->assign("3");
1340 
1341  destination = source;
1342 
1343  ASSERT_EQ(2, destination.size());
1344  EXPECT_EQ("4", destination.Get(0));
1345  EXPECT_EQ("5", destination.Get(1));
1346 }
1347 
1348 TEST(RepeatedPtrField, SelfAssign) {
1349  // Verify that assignment to self does not destroy data.
1350  RepeatedPtrField<std::string> source, *p;
1351  p = &source;
1352  source.Add()->assign("7");
1353  source.Add()->assign("8");
1354 
1355  *p = source;
1356 
1357  ASSERT_EQ(2, source.size());
1358  EXPECT_EQ("7", source.Get(0));
1359  EXPECT_EQ("8", source.Get(1));
1360 }
1361 
1362 TEST(RepeatedPtrField, MoveConstruct) {
1363  {
1364  RepeatedPtrField<std::string> source;
1365  *source.Add() = "1";
1366  *source.Add() = "2";
1367  const std::string* const* data = source.data();
1368  RepeatedPtrField<std::string> destination = std::move(source);
1369  EXPECT_EQ(data, destination.data());
1370  EXPECT_THAT(destination, ElementsAre("1", "2"));
1371  // This property isn't guaranteed but it's useful to have a test that would
1372  // catch changes in this area.
1373  EXPECT_TRUE(source.empty());
1374  }
1375  {
1376  Arena arena;
1377  RepeatedPtrField<std::string>* source =
1378  Arena::CreateMessage<RepeatedPtrField<std::string>>(&arena);
1379  *source->Add() = "1";
1380  *source->Add() = "2";
1381  RepeatedPtrField<std::string> destination = std::move(*source);
1382  EXPECT_EQ(nullptr, destination.GetArena());
1383  EXPECT_THAT(destination, ElementsAre("1", "2"));
1384  // This property isn't guaranteed but it's useful to have a test that would
1385  // catch changes in this area.
1386  EXPECT_THAT(*source, ElementsAre("1", "2"));
1387  }
1388 }
1389 
1390 TEST(RepeatedPtrField, MoveAssign) {
1391  {
1392  RepeatedPtrField<std::string> source;
1393  *source.Add() = "1";
1394  *source.Add() = "2";
1395  RepeatedPtrField<std::string> destination;
1396  *destination.Add() = "3";
1397  const std::string* const* source_data = source.data();
1398  const std::string* const* destination_data = destination.data();
1399  destination = std::move(source);
1400  EXPECT_EQ(source_data, destination.data());
1401  EXPECT_THAT(destination, ElementsAre("1", "2"));
1402  // This property isn't guaranteed but it's useful to have a test that would
1403  // catch changes in this area.
1404  EXPECT_EQ(destination_data, source.data());
1405  EXPECT_THAT(source, ElementsAre("3"));
1406  }
1407  {
1408  Arena arena;
1409  RepeatedPtrField<std::string>* source =
1410  Arena::CreateMessage<RepeatedPtrField<std::string>>(&arena);
1411  *source->Add() = "1";
1412  *source->Add() = "2";
1413  RepeatedPtrField<std::string>* destination =
1414  Arena::CreateMessage<RepeatedPtrField<std::string>>(&arena);
1415  *destination->Add() = "3";
1416  const std::string* const* source_data = source->data();
1417  const std::string* const* destination_data = destination->data();
1418  *destination = std::move(*source);
1419  EXPECT_EQ(source_data, destination->data());
1420  EXPECT_THAT(*destination, ElementsAre("1", "2"));
1421  // This property isn't guaranteed but it's useful to have a test that would
1422  // catch changes in this area.
1423  EXPECT_EQ(destination_data, source->data());
1424  EXPECT_THAT(*source, ElementsAre("3"));
1425  }
1426  {
1427  Arena source_arena;
1428  RepeatedPtrField<std::string>* source =
1429  Arena::CreateMessage<RepeatedPtrField<std::string>>(&source_arena);
1430  *source->Add() = "1";
1431  *source->Add() = "2";
1432  Arena destination_arena;
1433  RepeatedPtrField<std::string>* destination =
1434  Arena::CreateMessage<RepeatedPtrField<std::string>>(&destination_arena);
1435  *destination->Add() = "3";
1436  *destination = std::move(*source);
1437  EXPECT_THAT(*destination, ElementsAre("1", "2"));
1438  // This property isn't guaranteed but it's useful to have a test that would
1439  // catch changes in this area.
1440  EXPECT_THAT(*source, ElementsAre("1", "2"));
1441  }
1442  {
1443  Arena arena;
1444  RepeatedPtrField<std::string>* source =
1445  Arena::CreateMessage<RepeatedPtrField<std::string>>(&arena);
1446  *source->Add() = "1";
1447  *source->Add() = "2";
1448  RepeatedPtrField<std::string> destination;
1449  *destination.Add() = "3";
1450  destination = std::move(*source);
1451  EXPECT_THAT(destination, ElementsAre("1", "2"));
1452  // This property isn't guaranteed but it's useful to have a test that would
1453  // catch changes in this area.
1454  EXPECT_THAT(*source, ElementsAre("1", "2"));
1455  }
1456  {
1457  RepeatedPtrField<std::string> source;
1458  *source.Add() = "1";
1459  *source.Add() = "2";
1460  Arena arena;
1461  RepeatedPtrField<std::string>* destination =
1462  Arena::CreateMessage<RepeatedPtrField<std::string>>(&arena);
1463  *destination->Add() = "3";
1464  *destination = std::move(source);
1465  EXPECT_THAT(*destination, ElementsAre("1", "2"));
1466  // This property isn't guaranteed but it's useful to have a test that would
1467  // catch changes in this area.
1468  EXPECT_THAT(source, ElementsAre("1", "2"));
1469  }
1470  {
1471  RepeatedPtrField<std::string> field;
1472  // An alias to defeat -Wself-move.
1473  RepeatedPtrField<std::string>& alias = field;
1474  *field.Add() = "1";
1475  *field.Add() = "2";
1476  const std::string* const* data = field.data();
1477  field = std::move(alias);
1478  EXPECT_EQ(data, field.data());
1479  EXPECT_THAT(field, ElementsAre("1", "2"));
1480  }
1481  {
1482  Arena arena;
1483  RepeatedPtrField<std::string>* field =
1484  Arena::CreateMessage<RepeatedPtrField<std::string>>(&arena);
1485  *field->Add() = "1";
1486  *field->Add() = "2";
1487  const std::string* const* data = field->data();
1488  *field = std::move(*field);
1489  EXPECT_EQ(data, field->data());
1490  EXPECT_THAT(*field, ElementsAre("1", "2"));
1491  }
1492 }
1493 
1494 TEST(RepeatedPtrField, MutableDataIsMutable) {
1495  RepeatedPtrField<std::string> field;
1496  *field.Add() = "1";
1497  EXPECT_EQ("1", field.Get(0));
1498  // The fact that this line compiles would be enough, but we'll check the
1499  // value anyway.
1500  std::string** data = field.mutable_data();
1501  **data = "2";
1502  EXPECT_EQ("2", field.Get(0));
1503 }
1504 
1505 TEST(RepeatedPtrField, SubscriptOperators) {
1506  RepeatedPtrField<std::string> field;
1507  *field.Add() = "1";
1508  EXPECT_EQ("1", field.Get(0));
1509  EXPECT_EQ("1", field[0]);
1510  EXPECT_EQ(field.Mutable(0), &field[0]);
1511  const RepeatedPtrField<std::string>& const_field = field;
1512  EXPECT_EQ(*field.data(), &const_field[0]);
1513 }
1514 
1515 TEST(RepeatedPtrField, ExtractSubrange) {
1516  // Exhaustively test every subrange in arrays of all sizes from 0 through 9
1517  // with 0 through 3 cleared elements at the end.
1518  for (int sz = 0; sz < 10; ++sz) {
1519  for (int num = 0; num <= sz; ++num) {
1520  for (int start = 0; start < sz - num; ++start) {
1521  for (int extra = 0; extra < 4; ++extra) {
1522  std::vector<std::string*> subject;
1523 
1524  // Create an array with "sz" elements and "extra" cleared elements.
1525  // Use an arena to avoid copies from debug-build stability checks.
1526  Arena arena;
1527  RepeatedPtrField<std::string> field(&arena);
1528  for (int i = 0; i < sz + extra; ++i) {
1529  subject.push_back(new std::string());
1530  field.AddAllocated(subject[i]);
1531  }
1532  EXPECT_EQ(field.size(), sz + extra);
1533  for (int i = 0; i < extra; ++i) field.RemoveLast();
1534  EXPECT_EQ(field.size(), sz);
1535  EXPECT_EQ(field.ClearedCount(), extra);
1536 
1537  // Create a catcher array and call ExtractSubrange.
1538  std::string* catcher[10];
1539  for (int i = 0; i < 10; ++i) catcher[i] = nullptr;
1540  field.ExtractSubrange(start, num, catcher);
1541 
1542  // Does the resulting array have the right size?
1543  EXPECT_EQ(field.size(), sz - num);
1544 
1545  // Were the removed elements extracted into the catcher array?
1546  for (int i = 0; i < num; ++i)
1547  EXPECT_EQ(*catcher[i], *subject[start + i]);
1548  EXPECT_EQ(nullptr, catcher[num]);
1549 
1550  // Does the resulting array contain the right values?
1551  for (int i = 0; i < start; ++i)
1552  EXPECT_EQ(field.Mutable(i), subject[i]);
1553  for (int i = start; i < field.size(); ++i)
1554  EXPECT_EQ(field.Mutable(i), subject[i + num]);
1555 
1556  // Reinstate the cleared elements.
1557  EXPECT_EQ(field.ClearedCount(), extra);
1558  for (int i = 0; i < extra; ++i) field.Add();
1559  EXPECT_EQ(field.ClearedCount(), 0);
1560  EXPECT_EQ(field.size(), sz - num + extra);
1561 
1562  // Make sure the extra elements are all there (in some order).
1563  for (int i = sz; i < sz + extra; ++i) {
1564  int count = 0;
1565  for (int j = sz; j < sz + extra; ++j) {
1566  if (field.Mutable(j - num) == subject[i]) count += 1;
1567  }
1568  EXPECT_EQ(count, 1);
1569  }
1570 
1571  // Release the caught elements.
1572  for (int i = 0; i < num; ++i) delete catcher[i];
1573  }
1574  }
1575  }
1576  }
1577 }
1578 
1579 TEST(RepeatedPtrField, DeleteSubrange) {
1580  // DeleteSubrange is a trivial extension of ExtendSubrange.
1581 }
1582 
1583 // ===================================================================
1584 
1585 // Iterator tests stolen from net/proto/proto-array_unittest.
1586 class RepeatedFieldIteratorTest : public testing::Test {
1587  protected:
1588  virtual void SetUp() {
1589  for (int i = 0; i < 3; ++i) {
1590  proto_array_.Add(i);
1591  }
1592  }
1593 
1595 };
1596 
1597 TEST_F(RepeatedFieldIteratorTest, Convertible) {
1601  EXPECT_EQ(0, value);
1602 }
1603 
1604 TEST_F(RepeatedFieldIteratorTest, MutableIteration) {
1606  EXPECT_EQ(0, *iter);
1607  ++iter;
1608  EXPECT_EQ(1, *iter++);
1609  EXPECT_EQ(2, *iter);
1610  ++iter;
1612 
1613  EXPECT_EQ(2, *(proto_array_.end() - 1));
1614 }
1615 
1616 TEST_F(RepeatedFieldIteratorTest, ConstIteration) {
1617  const RepeatedField<int>& const_proto_array = proto_array_;
1618  RepeatedField<int>::const_iterator iter = const_proto_array.begin();
1619  EXPECT_EQ(0, *iter);
1620  ++iter;
1621  EXPECT_EQ(1, *iter++);
1622  EXPECT_EQ(2, *iter);
1623  ++iter;
1625  EXPECT_EQ(2, *(proto_array_.end() - 1));
1626 }
1627 
1628 TEST_F(RepeatedFieldIteratorTest, Mutation) {
1630  *iter = 7;
1631  EXPECT_EQ(7, proto_array_.Get(0));
1632 }
1633 
1634 // -------------------------------------------------------------------
1635 
1636 class RepeatedPtrFieldIteratorTest : public testing::Test {
1637  protected:
1638  virtual void SetUp() {
1639  proto_array_.Add()->assign("foo");
1640  proto_array_.Add()->assign("bar");
1641  proto_array_.Add()->assign("baz");
1642  }
1643 
1644  RepeatedPtrField<std::string> proto_array_;
1645 };
1646 
1647 TEST_F(RepeatedPtrFieldIteratorTest, Convertible) {
1651  EXPECT_EQ("foo", value);
1652 }
1653 
1654 TEST_F(RepeatedPtrFieldIteratorTest, MutableIteration) {
1656  EXPECT_EQ("foo", *iter);
1657  ++iter;
1658  EXPECT_EQ("bar", *(iter++));
1659  EXPECT_EQ("baz", *iter);
1660  ++iter;
1662  EXPECT_EQ("baz", *(--proto_array_.end()));
1663 }
1664 
1665 TEST_F(RepeatedPtrFieldIteratorTest, ConstIteration) {
1666  const RepeatedPtrField<std::string>& const_proto_array = proto_array_;
1668  const_proto_array.begin();
1669  EXPECT_EQ("foo", *iter);
1670  ++iter;
1671  EXPECT_EQ("bar", *(iter++));
1672  EXPECT_EQ("baz", *iter);
1673  ++iter;
1674  EXPECT_TRUE(const_proto_array.end() == iter);
1675  EXPECT_EQ("baz", *(--const_proto_array.end()));
1676 }
1677 
1678 TEST_F(RepeatedPtrFieldIteratorTest, MutableReverseIteration) {
1680  EXPECT_EQ("baz", *iter);
1681  ++iter;
1682  EXPECT_EQ("bar", *(iter++));
1683  EXPECT_EQ("foo", *iter);
1684  ++iter;
1686  EXPECT_EQ("foo", *(--proto_array_.rend()));
1687 }
1688 
1689 TEST_F(RepeatedPtrFieldIteratorTest, ConstReverseIteration) {
1690  const RepeatedPtrField<std::string>& const_proto_array = proto_array_;
1692  const_proto_array.rbegin();
1693  EXPECT_EQ("baz", *iter);
1694  ++iter;
1695  EXPECT_EQ("bar", *(iter++));
1696  EXPECT_EQ("foo", *iter);
1697  ++iter;
1698  EXPECT_TRUE(const_proto_array.rend() == iter);
1699  EXPECT_EQ("foo", *(--const_proto_array.rend()));
1700 }
1701 
1702 TEST_F(RepeatedPtrFieldIteratorTest, RandomAccess) {
1705  ++iter2;
1706  ++iter2;
1707  EXPECT_TRUE(iter + 2 == iter2);
1708  EXPECT_TRUE(iter == iter2 - 2);
1709  EXPECT_EQ("baz", iter[2]);
1710  EXPECT_EQ("baz", *(iter + 2));
1712 }
1713 
1714 TEST_F(RepeatedPtrFieldIteratorTest, Comparable) {
1717  EXPECT_TRUE(iter == iter);
1718  EXPECT_TRUE(iter != iter2);
1719  EXPECT_TRUE(iter < iter2);
1720  EXPECT_TRUE(iter <= iter2);
1721  EXPECT_TRUE(iter <= iter);
1722  EXPECT_TRUE(iter2 > iter);
1723  EXPECT_TRUE(iter2 >= iter);
1724  EXPECT_TRUE(iter >= iter);
1725 }
1726 
1727 // Uninitialized iterator does not point to any of the RepeatedPtrField.
1728 TEST_F(RepeatedPtrFieldIteratorTest, UninitializedIterator) {
1731  EXPECT_TRUE(iter != proto_array_.begin() + 1);
1732  EXPECT_TRUE(iter != proto_array_.begin() + 2);
1733  EXPECT_TRUE(iter != proto_array_.begin() + 3);
1735 }
1736 
1737 TEST_F(RepeatedPtrFieldIteratorTest, STLAlgorithms_lower_bound) {
1738  proto_array_.Clear();
1739  proto_array_.Add()->assign("a");
1740  proto_array_.Add()->assign("c");
1741  proto_array_.Add()->assign("d");
1742  proto_array_.Add()->assign("n");
1743  proto_array_.Add()->assign("p");
1744  proto_array_.Add()->assign("x");
1745  proto_array_.Add()->assign("y");
1746 
1747  std::string v = "f";
1749  std::lower_bound(proto_array_.begin(), proto_array_.end(), v);
1750 
1751  EXPECT_EQ(*it, "n");
1752  EXPECT_TRUE(it == proto_array_.begin() + 3);
1753 }
1754 
1755 TEST_F(RepeatedPtrFieldIteratorTest, Mutation) {
1757  *iter = "qux";
1758  EXPECT_EQ("qux", proto_array_.Get(0));
1759 }
1760 
1761 // -------------------------------------------------------------------
1762 
1763 class RepeatedPtrFieldPtrsIteratorTest : public testing::Test {
1764  protected:
1765  virtual void SetUp() {
1766  proto_array_.Add()->assign("foo");
1767  proto_array_.Add()->assign("bar");
1768  proto_array_.Add()->assign("baz");
1770  }
1771 
1772  RepeatedPtrField<std::string> proto_array_;
1773  const RepeatedPtrField<std::string>* const_proto_array_;
1774 };
1775 
1776 TEST_F(RepeatedPtrFieldPtrsIteratorTest, ConvertiblePtr) {
1778  proto_array_.pointer_begin();
1779  static_cast<void>(iter);
1780 }
1781 
1782 TEST_F(RepeatedPtrFieldPtrsIteratorTest, ConvertibleConstPtr) {
1785  static_cast<void>(iter);
1786 }
1787 
1788 TEST_F(RepeatedPtrFieldPtrsIteratorTest, MutablePtrIteration) {
1790  proto_array_.pointer_begin();
1791  EXPECT_EQ("foo", **iter);
1792  ++iter;
1793  EXPECT_EQ("bar", **(iter++));
1794  EXPECT_EQ("baz", **iter);
1795  ++iter;
1796  EXPECT_TRUE(proto_array_.pointer_end() == iter);
1797  EXPECT_EQ("baz", **(--proto_array_.pointer_end()));
1798 }
1799 
1800 TEST_F(RepeatedPtrFieldPtrsIteratorTest, MutableConstPtrIteration) {
1803  EXPECT_EQ("foo", **iter);
1804  ++iter;
1805  EXPECT_EQ("bar", **(iter++));
1806  EXPECT_EQ("baz", **iter);
1807  ++iter;
1809  EXPECT_EQ("baz", **(--const_proto_array_->pointer_end()));
1810 }
1811 
1812 TEST_F(RepeatedPtrFieldPtrsIteratorTest, RandomPtrAccess) {
1814  proto_array_.pointer_begin();
1816  ++iter2;
1817  ++iter2;
1818  EXPECT_TRUE(iter + 2 == iter2);
1819  EXPECT_TRUE(iter == iter2 - 2);
1820  EXPECT_EQ("baz", *iter[2]);
1821  EXPECT_EQ("baz", **(iter + 2));
1823 }
1824 
1825 TEST_F(RepeatedPtrFieldPtrsIteratorTest, RandomConstPtrAccess) {
1829  ++iter2;
1830  ++iter2;
1831  EXPECT_TRUE(iter + 2 == iter2);
1832  EXPECT_TRUE(iter == iter2 - 2);
1833  EXPECT_EQ("baz", *iter[2]);
1834  EXPECT_EQ("baz", **(iter + 2));
1836 }
1837 
1838 TEST_F(RepeatedPtrFieldPtrsIteratorTest, ComparablePtr) {
1840  proto_array_.pointer_begin();
1842  EXPECT_TRUE(iter == iter);
1843  EXPECT_TRUE(iter != iter2);
1844  EXPECT_TRUE(iter < iter2);
1845  EXPECT_TRUE(iter <= iter2);
1846  EXPECT_TRUE(iter <= iter);
1847  EXPECT_TRUE(iter2 > iter);
1848  EXPECT_TRUE(iter2 >= iter);
1849  EXPECT_TRUE(iter >= iter);
1850 }
1851 
1852 TEST_F(RepeatedPtrFieldPtrsIteratorTest, ComparableConstPtr) {
1856  EXPECT_TRUE(iter == iter);
1857  EXPECT_TRUE(iter != iter2);
1858  EXPECT_TRUE(iter < iter2);
1859  EXPECT_TRUE(iter <= iter2);
1860  EXPECT_TRUE(iter <= iter);
1861  EXPECT_TRUE(iter2 > iter);
1862  EXPECT_TRUE(iter2 >= iter);
1863  EXPECT_TRUE(iter >= iter);
1864 }
1865 
1866 // Uninitialized iterator does not point to any of the RepeatedPtrOverPtrs.
1867 // Dereferencing an uninitialized iterator crashes the process.
1868 TEST_F(RepeatedPtrFieldPtrsIteratorTest, UninitializedPtrIterator) {
1870  EXPECT_TRUE(iter != proto_array_.pointer_begin());
1871  EXPECT_TRUE(iter != proto_array_.pointer_begin() + 1);
1872  EXPECT_TRUE(iter != proto_array_.pointer_begin() + 2);
1873  EXPECT_TRUE(iter != proto_array_.pointer_begin() + 3);
1874  EXPECT_TRUE(iter != proto_array_.pointer_end());
1875 }
1876 
1877 TEST_F(RepeatedPtrFieldPtrsIteratorTest, UninitializedConstPtrIterator) {
1884 }
1885 
1886 // This comparison functor is required by the tests for RepeatedPtrOverPtrs.
1887 // They operate on strings and need to compare strings as strings in
1888 // any stl algorithm, even though the iterator returns a pointer to a
1889 // string
1890 // - i.e. *iter has type std::string*.
1891 struct StringLessThan {
1892  bool operator()(const std::string* z, const std::string* y) const {
1893  return *z < *y;
1894  }
1895 };
1896 
1897 TEST_F(RepeatedPtrFieldPtrsIteratorTest, PtrSTLAlgorithms_lower_bound) {
1898  proto_array_.Clear();
1899  proto_array_.Add()->assign("a");
1900  proto_array_.Add()->assign("c");
1901  proto_array_.Add()->assign("d");
1902  proto_array_.Add()->assign("n");
1903  proto_array_.Add()->assign("p");
1904  proto_array_.Add()->assign("x");
1905  proto_array_.Add()->assign("y");
1906 
1907  {
1908  std::string v = "f";
1910  std::lower_bound(proto_array_.pointer_begin(),
1911  proto_array_.pointer_end(), &v, StringLessThan());
1912 
1913  GOOGLE_CHECK(*it != nullptr);
1914 
1915  EXPECT_EQ(**it, "n");
1916  EXPECT_TRUE(it == proto_array_.pointer_begin() + 3);
1917  }
1918  {
1919  std::string v = "f";
1922  &v, StringLessThan());
1923 
1924  GOOGLE_CHECK(*it != nullptr);
1925 
1926  EXPECT_EQ(**it, "n");
1928  }
1929 }
1930 
1931 TEST_F(RepeatedPtrFieldPtrsIteratorTest, PtrMutation) {
1933  proto_array_.pointer_begin();
1934  **iter = "qux";
1935  EXPECT_EQ("qux", proto_array_.Get(0));
1936 
1937  EXPECT_EQ("bar", proto_array_.Get(1));
1938  EXPECT_EQ("baz", proto_array_.Get(2));
1939  ++iter;
1940  delete *iter;
1941  *iter = new std::string("a");
1942  ++iter;
1943  delete *iter;
1944  *iter = new std::string("b");
1945  EXPECT_EQ("a", proto_array_.Get(1));
1946  EXPECT_EQ("b", proto_array_.Get(2));
1947 }
1948 
1949 TEST_F(RepeatedPtrFieldPtrsIteratorTest, Sort) {
1950  proto_array_.Add()->assign("c");
1951  proto_array_.Add()->assign("d");
1952  proto_array_.Add()->assign("n");
1953  proto_array_.Add()->assign("p");
1954  proto_array_.Add()->assign("a");
1955  proto_array_.Add()->assign("y");
1956  proto_array_.Add()->assign("x");
1957  EXPECT_EQ("foo", proto_array_.Get(0));
1958  EXPECT_EQ("n", proto_array_.Get(5));
1959  EXPECT_EQ("x", proto_array_.Get(9));
1960  std::sort(proto_array_.pointer_begin(), proto_array_.pointer_end(),
1961  StringLessThan());
1962  EXPECT_EQ("a", proto_array_.Get(0));
1963  EXPECT_EQ("baz", proto_array_.Get(2));
1964  EXPECT_EQ("y", proto_array_.Get(9));
1965 }
1966 
1967 // -----------------------------------------------------------------------------
1968 // Unit-tests for the insert iterators
1969 // google::protobuf::RepeatedFieldBackInserter,
1970 // google::protobuf::AllocatedRepeatedPtrFieldBackInserter
1971 // Ported from util/gtl/proto-array-iterators_unittest.
1972 
1973 class RepeatedFieldInsertionIteratorsTest : public testing::Test {
1974  protected:
1975  std::list<double> halves;
1976  std::list<int> fibonacci;
1977  std::vector<std::string> words;
1978  typedef TestAllTypes::NestedMessage Nested;
1979  Nested nesteds[2];
1980  std::vector<Nested*> nested_ptrs;
1981  TestAllTypes protobuffer;
1982 
1983  virtual void SetUp() {
1984  fibonacci.push_back(1);
1985  fibonacci.push_back(1);
1986  fibonacci.push_back(2);
1987  fibonacci.push_back(3);
1988  fibonacci.push_back(5);
1989  fibonacci.push_back(8);
1990  std::copy(fibonacci.begin(), fibonacci.end(),
1991  RepeatedFieldBackInserter(protobuffer.mutable_repeated_int32()));
1992 
1993  halves.push_back(1.0);
1994  halves.push_back(0.5);
1995  halves.push_back(0.25);
1996  halves.push_back(0.125);
1997  halves.push_back(0.0625);
1998  std::copy(halves.begin(), halves.end(),
1999  RepeatedFieldBackInserter(protobuffer.mutable_repeated_double()));
2000 
2001  words.push_back("Able");
2002  words.push_back("was");
2003  words.push_back("I");
2004  words.push_back("ere");
2005  words.push_back("I");
2006  words.push_back("saw");
2007  words.push_back("Elba");
2008  std::copy(words.begin(), words.end(),
2009  RepeatedFieldBackInserter(protobuffer.mutable_repeated_string()));
2010 
2011  nesteds[0].set_bb(17);
2012  nesteds[1].set_bb(4711);
2013  std::copy(&nesteds[0], &nesteds[2],
2015  protobuffer.mutable_repeated_nested_message()));
2016 
2017  nested_ptrs.push_back(new Nested);
2018  nested_ptrs.back()->set_bb(170);
2019  nested_ptrs.push_back(new Nested);
2020  nested_ptrs.back()->set_bb(47110);
2021  std::copy(nested_ptrs.begin(), nested_ptrs.end(),
2023  protobuffer.mutable_repeated_nested_message()));
2024  }
2025 
2026  virtual void TearDown() {
2027  for (auto ptr : nested_ptrs) {
2028  delete ptr;
2029  }
2030  }
2031 };
2032 
2033 TEST_F(RepeatedFieldInsertionIteratorsTest, Fibonacci) {
2034  EXPECT_TRUE(std::equal(fibonacci.begin(), fibonacci.end(),
2035  protobuffer.repeated_int32().begin()));
2036  EXPECT_TRUE(std::equal(protobuffer.repeated_int32().begin(),
2037  protobuffer.repeated_int32().end(),
2038  fibonacci.begin()));
2039 }
2040 
2041 TEST_F(RepeatedFieldInsertionIteratorsTest, Halves) {
2042  EXPECT_TRUE(std::equal(halves.begin(), halves.end(),
2043  protobuffer.repeated_double().begin()));
2044  EXPECT_TRUE(std::equal(protobuffer.repeated_double().begin(),
2045  protobuffer.repeated_double().end(), halves.begin()));
2046 }
2047 
2048 TEST_F(RepeatedFieldInsertionIteratorsTest, Words) {
2049  ASSERT_EQ(words.size(), protobuffer.repeated_string_size());
2050  for (int i = 0; i < words.size(); ++i)
2051  EXPECT_EQ(words.at(i), protobuffer.repeated_string(i));
2052 }
2053 
2054 TEST_F(RepeatedFieldInsertionIteratorsTest, Words2) {
2055  words.clear();
2056  words.push_back("sing");
2057  words.push_back("a");
2058  words.push_back("song");
2059  words.push_back("of");
2060  words.push_back("six");
2061  words.push_back("pence");
2062  protobuffer.mutable_repeated_string()->Clear();
2063  std::copy(
2064  words.begin(), words.end(),
2065  RepeatedPtrFieldBackInserter(protobuffer.mutable_repeated_string()));
2066  ASSERT_EQ(words.size(), protobuffer.repeated_string_size());
2067  for (int i = 0; i < words.size(); ++i)
2068  EXPECT_EQ(words.at(i), protobuffer.repeated_string(i));
2069 }
2070 
2071 TEST_F(RepeatedFieldInsertionIteratorsTest, Nesteds) {
2072  ASSERT_EQ(protobuffer.repeated_nested_message_size(), 4);
2073  EXPECT_EQ(protobuffer.repeated_nested_message(0).bb(), 17);
2074  EXPECT_EQ(protobuffer.repeated_nested_message(1).bb(), 4711);
2075  EXPECT_EQ(protobuffer.repeated_nested_message(2).bb(), 170);
2076  EXPECT_EQ(protobuffer.repeated_nested_message(3).bb(), 47110);
2077 }
2078 
2079 TEST_F(RepeatedFieldInsertionIteratorsTest,
2080  AllocatedRepeatedPtrFieldWithStringIntData) {
2081  std::vector<Nested*> data;
2082  TestAllTypes goldenproto;
2083  for (int i = 0; i < 10; ++i) {
2084  Nested* new_data = new Nested;
2085  new_data->set_bb(i);
2086  data.push_back(new_data);
2087 
2088  new_data = goldenproto.add_repeated_nested_message();
2089  new_data->set_bb(i);
2090  }
2091  TestAllTypes testproto;
2092  std::copy(data.begin(), data.end(),
2094  testproto.mutable_repeated_nested_message()));
2095  EXPECT_EQ(testproto.DebugString(), goldenproto.DebugString());
2096 }
2097 
2098 TEST_F(RepeatedFieldInsertionIteratorsTest,
2099  AllocatedRepeatedPtrFieldWithString) {
2100  std::vector<std::string*> data;
2101  TestAllTypes goldenproto;
2102  for (int i = 0; i < 10; ++i) {
2103  std::string* new_data = new std::string;
2104  *new_data = "name-" + StrCat(i);
2105  data.push_back(new_data);
2106 
2107  new_data = goldenproto.add_repeated_string();
2108  *new_data = "name-" + StrCat(i);
2109  }
2110  TestAllTypes testproto;
2111  std::copy(data.begin(), data.end(),
2113  testproto.mutable_repeated_string()));
2114  EXPECT_EQ(testproto.DebugString(), goldenproto.DebugString());
2115 }
2116 
2117 TEST_F(RepeatedFieldInsertionIteratorsTest,
2118  UnsafeArenaAllocatedRepeatedPtrFieldWithStringIntData) {
2119  std::vector<Nested*> data;
2120  Arena arena;
2121  auto* goldenproto = Arena::CreateMessage<TestAllTypes>(&arena);
2122  for (int i = 0; i < 10; ++i) {
2123  auto* new_data = goldenproto->add_repeated_nested_message();
2124  new_data->set_bb(i);
2125  data.push_back(new_data);
2126  }
2127  auto* testproto = Arena::CreateMessage<TestAllTypes>(&arena);
2128  std::copy(data.begin(), data.end(),
2130  testproto->mutable_repeated_nested_message()));
2131  EXPECT_EQ(testproto->DebugString(), goldenproto->DebugString());
2132 }
2133 
2134 TEST_F(RepeatedFieldInsertionIteratorsTest,
2135  UnsafeArenaAllocatedRepeatedPtrFieldWithString) {
2136  std::vector<std::string*> data;
2137  Arena arena;
2138  auto* goldenproto = Arena::CreateMessage<TestAllTypes>(&arena);
2139  for (int i = 0; i < 10; ++i) {
2140  auto* new_data = goldenproto->add_repeated_string();
2141  *new_data = "name-" + StrCat(i);
2142  data.push_back(new_data);
2143  }
2144  auto* testproto = Arena::CreateMessage<TestAllTypes>(&arena);
2145  std::copy(data.begin(), data.end(),
2147  testproto->mutable_repeated_string()));
2148  EXPECT_EQ(testproto->DebugString(), goldenproto->DebugString());
2149 }
2150 
2151 TEST_F(RepeatedFieldInsertionIteratorsTest, MoveStrings) {
2152  std::vector<std::string> src = {"a", "b", "c", "d"};
2153  std::vector<std::string> copy =
2154  src; // copy since move leaves in undefined state
2155  TestAllTypes testproto;
2156  std::move(copy.begin(), copy.end(),
2157  RepeatedFieldBackInserter(testproto.mutable_repeated_string()));
2158 
2159  ASSERT_THAT(testproto.repeated_string(), testing::ElementsAreArray(src));
2160 }
2161 
2162 TEST_F(RepeatedFieldInsertionIteratorsTest, MoveProtos) {
2163  auto make_nested = [](int32 x) {
2164  Nested ret;
2165  ret.set_bb(x);
2166  return ret;
2167  };
2168  std::vector<Nested> src = {make_nested(3), make_nested(5), make_nested(7)};
2169  std::vector<Nested> copy = src; // copy since move leaves in undefined state
2170  TestAllTypes testproto;
2171  std::move(
2172  copy.begin(), copy.end(),
2173  RepeatedFieldBackInserter(testproto.mutable_repeated_nested_message()));
2174 
2175  ASSERT_EQ(src.size(), testproto.repeated_nested_message_size());
2176  for (int i = 0; i < src.size(); ++i) {
2177  EXPECT_EQ(src[i].DebugString(),
2178  testproto.repeated_nested_message(i).DebugString());
2179  }
2180 }
2181 
2182 } // namespace
2183 
2184 } // namespace protobuf
2185 } // namespace google
2186 
2187 #include <google/protobuf/port_undef.inc>
google::protobuf::RepeatedPtrField< std::string >::iterator
internal::RepeatedPtrIterator< std::string > iterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:861
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
google::protobuf::RepeatedPtrField< std::string >
regen-readme.it
it
Definition: regen-readme.py:15
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
protobuffer
TestAllTypes protobuffer
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1981
proto_array_
RepeatedField< int > proto_array_
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1594
absl::str_format_internal::LengthMod::j
@ j
X
#define X(c)
Large
Definition: donotoptimize_assembly_test.cc:22
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
google::protobuf.internal.python_message.MergeFrom
MergeFrom
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1339
capacity
uint16_t capacity
Definition: protobuf/src/google/protobuf/descriptor.cc:948
y
const double y
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3611
google::protobuf::RepeatedField::end
iterator end()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1372
bar
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:562
google::protobuf::RepeatedPtrField< std::string >::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:880
copy
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
Definition: message_compress.cc:145
google::protobuf.internal::true_type
integral_constant< bool, true > true_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/template_util.h:89
google::protobuf::RepeatedField::rend
reverse_iterator rend()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:232
google::protobuf::python::cmessage::CopyFrom
static PyObject * CopyFrom(CMessage *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1862
google::protobuf.internal::false_type
integral_constant< bool, false > false_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/template_util.h:90
Arena
Definition: arena.c:39
DebugString
std::string DebugString(const google::protobuf::Message &message)
Definition: bloaty/tests/test.h:60
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::RepeatedPtrField::end
iterator end()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2449
binary_size.new_size
def new_size
Definition: binary_size.py:124
google::protobuf::RepeatedPtrField< std::string >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:879
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
foo
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:546
gen_header_frame.vals
list vals
Definition: gen_header_frame.py:73
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
EXPECT_LE
#define EXPECT_LE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2030
xds_manager.p
p
Definition: xds_manager.py:60
z
Uncopyable z
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3612
google::protobuf::RepeatedField::Add
void Add(const Element &value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1210
google::protobuf::RepeatedField::Clear
void Clear()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1273
words
std::vector< std::string > words
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1977
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.cc:1482
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
testing::ElementsAreArray
internal::ElementsAreArrayMatcher< typename ::std::iterator_traits< Iter >::value_type > ElementsAreArray(Iter first, Iter last)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8465
RepeatedField::size
int size
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:407
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
testing::ElementsAre
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13040
google::protobuf::AllocatedRepeatedPtrFieldBackInserter
internal::AllocatedRepeatedPtrFieldBackInsertIterator< T > AllocatedRepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2632
start
static uint64_t start
Definition: benchmark-pound.c:74
google::protobuf::int32
int32_t int32
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:150
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
xds_interop_client.int
int
Definition: xds_interop_client.py:113
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
ASSERT_LT
#define ASSERT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2068
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
google::protobuf.internal::CalculateReserveSize
int CalculateReserveSize(int total_size, int new_size)
Definition: protobuf/src/google/protobuf/repeated_field.h:889
ASSERT_THAT
#define ASSERT_THAT(value, matcher)
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
google::protobuf::RepeatedPtrField::pointer_begin
pointer_iterator pointer_begin()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2465
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
google::protobuf::RepeatedPtrField< std::string >::const_iterator
internal::RepeatedPtrIterator< const std::string > const_iterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:862
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
google::protobuf::TEST
TEST(ArenaTest, ArenaConstructable)
Definition: bloaty/third_party/protobuf/src/google/protobuf/arena_unittest.cc:156
g
struct @717 g
google::protobuf::RepeatedField::rbegin
reverse_iterator rbegin()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:228
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
absl::synchronization_internal::Sort
static void Sort(const Vec< Node * > &, Vec< int32_t > *delta)
Definition: abseil-cpp/absl/synchronization/internal/graphcycles.cc:603
google_benchmark.example.empty
def empty(state)
Definition: example.py:31
value
const char * value
Definition: hpack_parser_table.cc:165
fibonacci
std::list< int > fibonacci
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1976
absl::flags_internal::CopyConstruct
void CopyConstruct(FlagOpFn op, const void *src, void *dst)
Definition: abseil-cpp/absl/flags/internal/flag.h:115
halves
std::list< double > halves
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1975
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
google::protobuf::RepeatedField::begin
iterator begin()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1358
google::protobuf::RepeatedFieldBackInserter
internal::RepeatedFieldBackInsertIterator< T > RepeatedFieldBackInserter(RepeatedField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2605
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
google::protobuf::TEST_F
TEST_F(DynamicMessageTest, Descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/dynamic_message_unittest.cc:126
first
StrT first
Definition: cxa_demangle.cpp:4884
EXPECT_LT
#define EXPECT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2032
const_proto_array_
const RepeatedPtrField< std::string > * const_proto_array_
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1773
values
std::array< int64_t, Size > values
Definition: abseil-cpp/absl/container/btree_benchmark.cc:608
xds_manager.num
num
Definition: xds_manager.py:56
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:153
EXPECT_GE
#define EXPECT_GE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2034
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
google::protobuf::RepeatedField::Get
const Element & Get(int index) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1175
google::protobuf.internal::kRepeatedFieldLowerClampLimit
constexpr int kRepeatedFieldLowerClampLimit
Definition: protobuf/src/google/protobuf/repeated_field.h:86
google::protobuf::RepeatedPtrField< std::string >::pointer_iterator
internal::RepeatedPtrOverPtrsIterator< std::string *, void * > pointer_iterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:893
iter
Definition: test_winkernel.cpp:47
google::protobuf::RepeatedPtrFieldBackInserter
internal::RepeatedPtrFieldBackInsertIterator< T > RepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2613
google::protobuf::RepeatedPtrField< std::string >::value_type
std::string value_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:863
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
nested_ptrs
std::vector< Nested * > nested_ptrs
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1980
google::protobuf::UnsafeArenaAllocatedRepeatedPtrFieldBackInserter
internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator< T > UnsafeArenaAllocatedRepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2651
google::protobuf::RepeatedPtrField::begin
iterator begin()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2434
absl::Fibonacci
constexpr uint64_t Fibonacci(unsigned char n, uint64_t a=0, uint64_t b=1)
Definition: bloaty/third_party/abseil-cpp/absl/strings/cord.cc:73
nesteds
Nested nesteds[2]
Definition: protobuf/src/google/protobuf/repeated_field_unittest.cc:1979
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
binary_size.old_size
old_size
Definition: binary_size.py:125
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2056
google::protobuf::RepeatedPtrField< std::string >::const_pointer_iterator
internal::RepeatedPtrOverPtrsIterator< const std::string *const, const void *const > const_pointer_iterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:896
google::protobuf::RepeatedPtrField::pointer_end
pointer_iterator pointer_end()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2475
RepeatedField
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:403


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:04