map_test_util_impl.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__
  31. #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__
  32. #include <google/protobuf/stubs/logging.h>
  33. #include <google/protobuf/stubs/common.h>
  34. #include <gtest/gtest.h>
  35. namespace google {
  36. namespace protobuf_unittest {} // forward declaration
  37. namespace protobuf {
  38. namespace unittest = ::protobuf_unittest;
  39. class MapTestUtilImpl {
  40. public:
  41. // Set every field in the TestMap message to a unique value.
  42. template <typename EnumType, EnumType enum_value0,
  43. EnumType enum_value1, typename MapMessage>
  44. static void SetMapFields(MapMessage* message);
  45. // Set every field in the TestArenaMap message to a unique value.
  46. template <typename EnumType, EnumType enum_value0,
  47. EnumType enum_value1, typename MapMessage>
  48. static void SetArenaMapFields(MapMessage* message);
  49. // Set every field in the message to a default value.
  50. template <typename MapMessage>
  51. static void SetMapFieldsInitialized(MapMessage* message);
  52. // Modify all the map fields of the message (which should already have been
  53. // initialized with SetMapFields()).
  54. template <typename EnumType, EnumType enum_value, typename MapMessage>
  55. static void ModifyMapFields(MapMessage* message);
  56. // Check that all fields have the values that they should have after
  57. // SetMapFields() is called.
  58. template <typename EnumType, EnumType enum_value0,
  59. EnumType enum_value1, typename MapMessage>
  60. static void ExpectMapFieldsSet(const MapMessage& message);
  61. // Check that all fields have the values that they should have after
  62. // SetMapFields() is called for TestArenaMap.
  63. template <typename EnumType, EnumType enum_value0,
  64. EnumType enum_value1, typename MapMessage>
  65. static void ExpectArenaMapFieldsSet(const MapMessage& message);
  66. // Check that all fields have the values that they should have after
  67. // SetMapFieldsInitialized() is called.
  68. template <typename EnumType, EnumType enum_value, typename MapMessage>
  69. static void ExpectMapFieldsSetInitialized(const MapMessage& message);
  70. // Expect that the message is modified as would be expected from
  71. // ModifyMapFields().
  72. template <typename EnumType, EnumType enum_value0,
  73. EnumType enum_value1, typename MapMessage>
  74. static void ExpectMapFieldsModified(const MapMessage& message);
  75. // Check that all fields are empty.
  76. template <typename MapMessage>
  77. static void ExpectClear(const MapMessage& message);
  78. // // Check that all map fields have the given size.
  79. // template <typename MapMessage>
  80. // static void ExpectMapsSize(const MapMessage& message, int size);
  81. // // Get pointers of map entries at given index.
  82. // static std::vector<const Message*> GetMapEntries(
  83. // const MapMessage& message, int index);
  84. // // Get pointers of map entries from release.
  85. // static std::vector<const Message*> GetMapEntriesFromRelease(
  86. // MapMessage* message);
  87. };
  88. template <typename EnumType, EnumType enum_value0,
  89. EnumType enum_value1, typename MapMessage>
  90. void MapTestUtilImpl::SetMapFields(MapMessage* message) {
  91. // Add first element.
  92. (*message->mutable_map_int32_int32())[0] = 0;
  93. (*message->mutable_map_int64_int64())[0] = 0;
  94. (*message->mutable_map_uint32_uint32())[0] = 0;
  95. (*message->mutable_map_uint64_uint64())[0] = 0;
  96. (*message->mutable_map_sint32_sint32())[0] = 0;
  97. (*message->mutable_map_sint64_sint64())[0] = 0;
  98. (*message->mutable_map_fixed32_fixed32())[0] = 0;
  99. (*message->mutable_map_fixed64_fixed64())[0] = 0;
  100. (*message->mutable_map_sfixed32_sfixed32())[0] = 0;
  101. (*message->mutable_map_sfixed64_sfixed64())[0] = 0;
  102. (*message->mutable_map_int32_float())[0] = 0.0;
  103. (*message->mutable_map_int32_double())[0] = 0.0;
  104. (*message->mutable_map_bool_bool())[0] = false;
  105. (*message->mutable_map_string_string())["0"] = "0";
  106. (*message->mutable_map_int32_bytes())[0] = "0";
  107. (*message->mutable_map_int32_enum())[0] = enum_value0;
  108. (*message->mutable_map_int32_foreign_message())[0].set_c(0);
  109. // Add second element
  110. (*message->mutable_map_int32_int32())[1] = 1;
  111. (*message->mutable_map_int64_int64())[1] = 1;
  112. (*message->mutable_map_uint32_uint32())[1] = 1;
  113. (*message->mutable_map_uint64_uint64())[1] = 1;
  114. (*message->mutable_map_sint32_sint32())[1] = 1;
  115. (*message->mutable_map_sint64_sint64())[1] = 1;
  116. (*message->mutable_map_fixed32_fixed32())[1] = 1;
  117. (*message->mutable_map_fixed64_fixed64())[1] = 1;
  118. (*message->mutable_map_sfixed32_sfixed32())[1] = 1;
  119. (*message->mutable_map_sfixed64_sfixed64())[1] = 1;
  120. (*message->mutable_map_int32_float())[1] = 1.0;
  121. (*message->mutable_map_int32_double())[1] = 1.0;
  122. (*message->mutable_map_bool_bool())[1] = true;
  123. (*message->mutable_map_string_string())["1"] = "1";
  124. (*message->mutable_map_int32_bytes())[1] = "1";
  125. (*message->mutable_map_int32_enum())[1] = enum_value1;
  126. (*message->mutable_map_int32_foreign_message())[1].set_c(1);
  127. }
  128. template <typename EnumType, EnumType enum_value0,
  129. EnumType enum_value1, typename MapMessage>
  130. void MapTestUtilImpl::SetArenaMapFields(MapMessage* message) {
  131. // Add first element.
  132. (*message->mutable_map_int32_int32())[0] = 0;
  133. (*message->mutable_map_int64_int64())[0] = 0;
  134. (*message->mutable_map_uint32_uint32())[0] = 0;
  135. (*message->mutable_map_uint64_uint64())[0] = 0;
  136. (*message->mutable_map_sint32_sint32())[0] = 0;
  137. (*message->mutable_map_sint64_sint64())[0] = 0;
  138. (*message->mutable_map_fixed32_fixed32())[0] = 0;
  139. (*message->mutable_map_fixed64_fixed64())[0] = 0;
  140. (*message->mutable_map_sfixed32_sfixed32())[0] = 0;
  141. (*message->mutable_map_sfixed64_sfixed64())[0] = 0;
  142. (*message->mutable_map_int32_float())[0] = 0.0;
  143. (*message->mutable_map_int32_double())[0] = 0.0;
  144. (*message->mutable_map_bool_bool())[0] = false;
  145. (*message->mutable_map_string_string())["0"] = "0";
  146. (*message->mutable_map_int32_bytes())[0] = "0";
  147. (*message->mutable_map_int32_enum())[0] = enum_value0;
  148. (*message->mutable_map_int32_foreign_message())[0].set_c(0);
  149. (*message->mutable_map_int32_foreign_message_no_arena())[0].set_c(0);
  150. // Add second element
  151. (*message->mutable_map_int32_int32())[1] = 1;
  152. (*message->mutable_map_int64_int64())[1] = 1;
  153. (*message->mutable_map_uint32_uint32())[1] = 1;
  154. (*message->mutable_map_uint64_uint64())[1] = 1;
  155. (*message->mutable_map_sint32_sint32())[1] = 1;
  156. (*message->mutable_map_sint64_sint64())[1] = 1;
  157. (*message->mutable_map_fixed32_fixed32())[1] = 1;
  158. (*message->mutable_map_fixed64_fixed64())[1] = 1;
  159. (*message->mutable_map_sfixed32_sfixed32())[1] = 1;
  160. (*message->mutable_map_sfixed64_sfixed64())[1] = 1;
  161. (*message->mutable_map_int32_float())[1] = 1.0;
  162. (*message->mutable_map_int32_double())[1] = 1.0;
  163. (*message->mutable_map_bool_bool())[1] = true;
  164. (*message->mutable_map_string_string())["1"] = "1";
  165. (*message->mutable_map_int32_bytes())[1] = "1";
  166. (*message->mutable_map_int32_enum())[1] = enum_value1;
  167. (*message->mutable_map_int32_foreign_message())[1].set_c(1);
  168. (*message->mutable_map_int32_foreign_message_no_arena())[1].set_c(1);
  169. }
  170. template <typename MapMessage>
  171. void MapTestUtilImpl::SetMapFieldsInitialized(MapMessage* message) {
  172. // Add first element using bracket operator, which should assign default
  173. // value automatically.
  174. (*message->mutable_map_int32_int32())[0];
  175. (*message->mutable_map_int64_int64())[0];
  176. (*message->mutable_map_uint32_uint32())[0];
  177. (*message->mutable_map_uint64_uint64())[0];
  178. (*message->mutable_map_sint32_sint32())[0];
  179. (*message->mutable_map_sint64_sint64())[0];
  180. (*message->mutable_map_fixed32_fixed32())[0];
  181. (*message->mutable_map_fixed64_fixed64())[0];
  182. (*message->mutable_map_sfixed32_sfixed32())[0];
  183. (*message->mutable_map_sfixed64_sfixed64())[0];
  184. (*message->mutable_map_int32_float())[0];
  185. (*message->mutable_map_int32_double())[0];
  186. (*message->mutable_map_bool_bool())[0];
  187. (*message->mutable_map_string_string())["0"];
  188. (*message->mutable_map_int32_bytes())[0];
  189. (*message->mutable_map_int32_enum())[0];
  190. (*message->mutable_map_int32_foreign_message())[0];
  191. }
  192. template <typename EnumType, EnumType enum_value, typename MapMessage>
  193. void MapTestUtilImpl::ModifyMapFields(MapMessage* message) {
  194. (*message->mutable_map_int32_int32())[1] = 2;
  195. (*message->mutable_map_int64_int64())[1] = 2;
  196. (*message->mutable_map_uint32_uint32())[1] = 2;
  197. (*message->mutable_map_uint64_uint64())[1] = 2;
  198. (*message->mutable_map_sint32_sint32())[1] = 2;
  199. (*message->mutable_map_sint64_sint64())[1] = 2;
  200. (*message->mutable_map_fixed32_fixed32())[1] = 2;
  201. (*message->mutable_map_fixed64_fixed64())[1] = 2;
  202. (*message->mutable_map_sfixed32_sfixed32())[1] = 2;
  203. (*message->mutable_map_sfixed64_sfixed64())[1] = 2;
  204. (*message->mutable_map_int32_float())[1] = 2.0;
  205. (*message->mutable_map_int32_double())[1] = 2.0;
  206. (*message->mutable_map_bool_bool())[1] = false;
  207. (*message->mutable_map_string_string())["1"] = "2";
  208. (*message->mutable_map_int32_bytes())[1] = "2";
  209. (*message->mutable_map_int32_enum())[1] = enum_value;
  210. (*message->mutable_map_int32_foreign_message())[1].set_c(2);
  211. }
  212. template <typename MapMessage>
  213. void MapTestUtilImpl::ExpectClear(const MapMessage& message) {
  214. EXPECT_EQ(0, message.map_int32_int32().size());
  215. EXPECT_EQ(0, message.map_int64_int64().size());
  216. EXPECT_EQ(0, message.map_uint32_uint32().size());
  217. EXPECT_EQ(0, message.map_uint64_uint64().size());
  218. EXPECT_EQ(0, message.map_sint32_sint32().size());
  219. EXPECT_EQ(0, message.map_sint64_sint64().size());
  220. EXPECT_EQ(0, message.map_fixed32_fixed32().size());
  221. EXPECT_EQ(0, message.map_fixed64_fixed64().size());
  222. EXPECT_EQ(0, message.map_sfixed32_sfixed32().size());
  223. EXPECT_EQ(0, message.map_sfixed64_sfixed64().size());
  224. EXPECT_EQ(0, message.map_int32_float().size());
  225. EXPECT_EQ(0, message.map_int32_double().size());
  226. EXPECT_EQ(0, message.map_bool_bool().size());
  227. EXPECT_EQ(0, message.map_string_string().size());
  228. EXPECT_EQ(0, message.map_int32_bytes().size());
  229. EXPECT_EQ(0, message.map_int32_enum().size());
  230. EXPECT_EQ(0, message.map_int32_foreign_message().size());
  231. }
  232. template <typename EnumType, EnumType enum_value0,
  233. EnumType enum_value1, typename MapMessage>
  234. void MapTestUtilImpl::ExpectMapFieldsSet(const MapMessage& message) {
  235. ASSERT_EQ(2, message.map_int32_int32().size());
  236. ASSERT_EQ(2, message.map_int64_int64().size());
  237. ASSERT_EQ(2, message.map_uint32_uint32().size());
  238. ASSERT_EQ(2, message.map_uint64_uint64().size());
  239. ASSERT_EQ(2, message.map_sint32_sint32().size());
  240. ASSERT_EQ(2, message.map_sint64_sint64().size());
  241. ASSERT_EQ(2, message.map_fixed32_fixed32().size());
  242. ASSERT_EQ(2, message.map_fixed64_fixed64().size());
  243. ASSERT_EQ(2, message.map_sfixed32_sfixed32().size());
  244. ASSERT_EQ(2, message.map_sfixed64_sfixed64().size());
  245. ASSERT_EQ(2, message.map_int32_float().size());
  246. ASSERT_EQ(2, message.map_int32_double().size());
  247. ASSERT_EQ(2, message.map_bool_bool().size());
  248. ASSERT_EQ(2, message.map_string_string().size());
  249. ASSERT_EQ(2, message.map_int32_bytes().size());
  250. ASSERT_EQ(2, message.map_int32_enum().size());
  251. ASSERT_EQ(2, message.map_int32_foreign_message().size());
  252. EXPECT_EQ(0, message.map_int32_int32().at(0));
  253. EXPECT_EQ(0, message.map_int64_int64().at(0));
  254. EXPECT_EQ(0, message.map_uint32_uint32().at(0));
  255. EXPECT_EQ(0, message.map_uint64_uint64().at(0));
  256. EXPECT_EQ(0, message.map_sint32_sint32().at(0));
  257. EXPECT_EQ(0, message.map_sint64_sint64().at(0));
  258. EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
  259. EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
  260. EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
  261. EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
  262. EXPECT_EQ(0, message.map_int32_float().at(0));
  263. EXPECT_EQ(0, message.map_int32_double().at(0));
  264. EXPECT_EQ(false, message.map_bool_bool().at(0));
  265. EXPECT_EQ("0", message.map_string_string().at("0"));
  266. EXPECT_EQ("0", message.map_int32_bytes().at(0));
  267. EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
  268. EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
  269. EXPECT_EQ(1, message.map_int32_int32().at(1));
  270. EXPECT_EQ(1, message.map_int64_int64().at(1));
  271. EXPECT_EQ(1, message.map_uint32_uint32().at(1));
  272. EXPECT_EQ(1, message.map_uint64_uint64().at(1));
  273. EXPECT_EQ(1, message.map_sint32_sint32().at(1));
  274. EXPECT_EQ(1, message.map_sint64_sint64().at(1));
  275. EXPECT_EQ(1, message.map_fixed32_fixed32().at(1));
  276. EXPECT_EQ(1, message.map_fixed64_fixed64().at(1));
  277. EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1));
  278. EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1));
  279. EXPECT_EQ(1, message.map_int32_float().at(1));
  280. EXPECT_EQ(1, message.map_int32_double().at(1));
  281. EXPECT_EQ(true, message.map_bool_bool().at(1));
  282. EXPECT_EQ("1", message.map_string_string().at("1"));
  283. EXPECT_EQ("1", message.map_int32_bytes().at(1));
  284. EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
  285. EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c());
  286. }
  287. template <typename EnumType, EnumType enum_value0,
  288. EnumType enum_value1, typename MapMessage>
  289. void MapTestUtilImpl::ExpectArenaMapFieldsSet(const MapMessage& message) {
  290. EXPECT_EQ(2, message.map_int32_int32().size());
  291. EXPECT_EQ(2, message.map_int64_int64().size());
  292. EXPECT_EQ(2, message.map_uint32_uint32().size());
  293. EXPECT_EQ(2, message.map_uint64_uint64().size());
  294. EXPECT_EQ(2, message.map_sint32_sint32().size());
  295. EXPECT_EQ(2, message.map_sint64_sint64().size());
  296. EXPECT_EQ(2, message.map_fixed32_fixed32().size());
  297. EXPECT_EQ(2, message.map_fixed64_fixed64().size());
  298. EXPECT_EQ(2, message.map_sfixed32_sfixed32().size());
  299. EXPECT_EQ(2, message.map_sfixed64_sfixed64().size());
  300. EXPECT_EQ(2, message.map_int32_float().size());
  301. EXPECT_EQ(2, message.map_int32_double().size());
  302. EXPECT_EQ(2, message.map_bool_bool().size());
  303. EXPECT_EQ(2, message.map_string_string().size());
  304. EXPECT_EQ(2, message.map_int32_bytes().size());
  305. EXPECT_EQ(2, message.map_int32_enum().size());
  306. EXPECT_EQ(2, message.map_int32_foreign_message().size());
  307. EXPECT_EQ(2, message.map_int32_foreign_message_no_arena().size());
  308. EXPECT_EQ(0, message.map_int32_int32().at(0));
  309. EXPECT_EQ(0, message.map_int64_int64().at(0));
  310. EXPECT_EQ(0, message.map_uint32_uint32().at(0));
  311. EXPECT_EQ(0, message.map_uint64_uint64().at(0));
  312. EXPECT_EQ(0, message.map_sint32_sint32().at(0));
  313. EXPECT_EQ(0, message.map_sint64_sint64().at(0));
  314. EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
  315. EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
  316. EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
  317. EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
  318. EXPECT_EQ(0, message.map_int32_float().at(0));
  319. EXPECT_EQ(0, message.map_int32_double().at(0));
  320. EXPECT_EQ(false, message.map_bool_bool().at(0));
  321. EXPECT_EQ("0", message.map_string_string().at("0"));
  322. EXPECT_EQ("0", message.map_int32_bytes().at(0));
  323. EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
  324. EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
  325. EXPECT_EQ(0, message.map_int32_foreign_message_no_arena().at(0).c());
  326. EXPECT_EQ(1, message.map_int32_int32().at(1));
  327. EXPECT_EQ(1, message.map_int64_int64().at(1));
  328. EXPECT_EQ(1, message.map_uint32_uint32().at(1));
  329. EXPECT_EQ(1, message.map_uint64_uint64().at(1));
  330. EXPECT_EQ(1, message.map_sint32_sint32().at(1));
  331. EXPECT_EQ(1, message.map_sint64_sint64().at(1));
  332. EXPECT_EQ(1, message.map_fixed32_fixed32().at(1));
  333. EXPECT_EQ(1, message.map_fixed64_fixed64().at(1));
  334. EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1));
  335. EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1));
  336. EXPECT_EQ(1, message.map_int32_float().at(1));
  337. EXPECT_EQ(1, message.map_int32_double().at(1));
  338. EXPECT_EQ(true, message.map_bool_bool().at(1));
  339. EXPECT_EQ("1", message.map_string_string().at("1"));
  340. EXPECT_EQ("1", message.map_int32_bytes().at(1));
  341. EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
  342. EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c());
  343. EXPECT_EQ(1, message.map_int32_foreign_message_no_arena().at(1).c());
  344. }
  345. template <typename EnumType, EnumType enum_value, typename MapMessage>
  346. void MapTestUtilImpl::ExpectMapFieldsSetInitialized(
  347. const MapMessage& message) {
  348. EXPECT_EQ(1, message.map_int32_int32().size());
  349. EXPECT_EQ(1, message.map_int64_int64().size());
  350. EXPECT_EQ(1, message.map_uint32_uint32().size());
  351. EXPECT_EQ(1, message.map_uint64_uint64().size());
  352. EXPECT_EQ(1, message.map_sint32_sint32().size());
  353. EXPECT_EQ(1, message.map_sint64_sint64().size());
  354. EXPECT_EQ(1, message.map_fixed32_fixed32().size());
  355. EXPECT_EQ(1, message.map_fixed64_fixed64().size());
  356. EXPECT_EQ(1, message.map_sfixed32_sfixed32().size());
  357. EXPECT_EQ(1, message.map_sfixed64_sfixed64().size());
  358. EXPECT_EQ(1, message.map_int32_float().size());
  359. EXPECT_EQ(1, message.map_int32_double().size());
  360. EXPECT_EQ(1, message.map_bool_bool().size());
  361. EXPECT_EQ(1, message.map_string_string().size());
  362. EXPECT_EQ(1, message.map_int32_bytes().size());
  363. EXPECT_EQ(1, message.map_int32_enum().size());
  364. EXPECT_EQ(1, message.map_int32_foreign_message().size());
  365. EXPECT_EQ(0, message.map_int32_int32().at(0));
  366. EXPECT_EQ(0, message.map_int64_int64().at(0));
  367. EXPECT_EQ(0, message.map_uint32_uint32().at(0));
  368. EXPECT_EQ(0, message.map_uint64_uint64().at(0));
  369. EXPECT_EQ(0, message.map_sint32_sint32().at(0));
  370. EXPECT_EQ(0, message.map_sint64_sint64().at(0));
  371. EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
  372. EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
  373. EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
  374. EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
  375. EXPECT_EQ(0, message.map_int32_float().at(0));
  376. EXPECT_EQ(0, message.map_int32_double().at(0));
  377. EXPECT_EQ(false, message.map_bool_bool().at(0));
  378. EXPECT_EQ("", message.map_string_string().at("0"));
  379. EXPECT_EQ("", message.map_int32_bytes().at(0));
  380. EXPECT_EQ(enum_value, message.map_int32_enum().at(0));
  381. EXPECT_EQ(0, message.map_int32_foreign_message().at(0).ByteSize());
  382. }
  383. template <typename EnumType, EnumType enum_value0,
  384. EnumType enum_value1, typename MapMessage>
  385. void MapTestUtilImpl::ExpectMapFieldsModified(
  386. const MapMessage& message) {
  387. // ModifyMapFields only sets the second element of each field. In addition to
  388. // verifying this, we also verify that the first element and size were *not*
  389. // modified.
  390. EXPECT_EQ(2, message.map_int32_int32().size());
  391. EXPECT_EQ(2, message.map_int64_int64().size());
  392. EXPECT_EQ(2, message.map_uint32_uint32().size());
  393. EXPECT_EQ(2, message.map_uint64_uint64().size());
  394. EXPECT_EQ(2, message.map_sint32_sint32().size());
  395. EXPECT_EQ(2, message.map_sint64_sint64().size());
  396. EXPECT_EQ(2, message.map_fixed32_fixed32().size());
  397. EXPECT_EQ(2, message.map_fixed64_fixed64().size());
  398. EXPECT_EQ(2, message.map_sfixed32_sfixed32().size());
  399. EXPECT_EQ(2, message.map_sfixed64_sfixed64().size());
  400. EXPECT_EQ(2, message.map_int32_float().size());
  401. EXPECT_EQ(2, message.map_int32_double().size());
  402. EXPECT_EQ(2, message.map_bool_bool().size());
  403. EXPECT_EQ(2, message.map_string_string().size());
  404. EXPECT_EQ(2, message.map_int32_bytes().size());
  405. EXPECT_EQ(2, message.map_int32_enum().size());
  406. EXPECT_EQ(2, message.map_int32_foreign_message().size());
  407. EXPECT_EQ(0, message.map_int32_int32().at(0));
  408. EXPECT_EQ(0, message.map_int64_int64().at(0));
  409. EXPECT_EQ(0, message.map_uint32_uint32().at(0));
  410. EXPECT_EQ(0, message.map_uint64_uint64().at(0));
  411. EXPECT_EQ(0, message.map_sint32_sint32().at(0));
  412. EXPECT_EQ(0, message.map_sint64_sint64().at(0));
  413. EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
  414. EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
  415. EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
  416. EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
  417. EXPECT_EQ(0, message.map_int32_float().at(0));
  418. EXPECT_EQ(0, message.map_int32_double().at(0));
  419. EXPECT_EQ(false, message.map_bool_bool().at(0));
  420. EXPECT_EQ("0", message.map_string_string().at("0"));
  421. EXPECT_EQ("0", message.map_int32_bytes().at(0));
  422. EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
  423. EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
  424. // Actually verify the second (modified) elements now.
  425. EXPECT_EQ(2, message.map_int32_int32().at(1));
  426. EXPECT_EQ(2, message.map_int64_int64().at(1));
  427. EXPECT_EQ(2, message.map_uint32_uint32().at(1));
  428. EXPECT_EQ(2, message.map_uint64_uint64().at(1));
  429. EXPECT_EQ(2, message.map_sint32_sint32().at(1));
  430. EXPECT_EQ(2, message.map_sint64_sint64().at(1));
  431. EXPECT_EQ(2, message.map_fixed32_fixed32().at(1));
  432. EXPECT_EQ(2, message.map_fixed64_fixed64().at(1));
  433. EXPECT_EQ(2, message.map_sfixed32_sfixed32().at(1));
  434. EXPECT_EQ(2, message.map_sfixed64_sfixed64().at(1));
  435. EXPECT_EQ(2, message.map_int32_float().at(1));
  436. EXPECT_EQ(2, message.map_int32_double().at(1));
  437. EXPECT_EQ(false, message.map_bool_bool().at(1));
  438. EXPECT_EQ("2", message.map_string_string().at("1"));
  439. EXPECT_EQ("2", message.map_int32_bytes().at(1));
  440. EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
  441. EXPECT_EQ(2, message.map_int32_foreign_message().at(1).c());
  442. }
  443. } // namespace protobuf
  444. } // namespace google
  445. #endif // GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__