诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1515 regels
66 KiB

  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_H__
  31. #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__
  32. #include <google/protobuf/map_unittest.pb.h>
  33. #define UNITTEST ::protobuf_unittest
  34. // Must define UNITTEST before including map_test_util.inc.
  35. #include <google/protobuf/map_test_util.inc>
  36. #undef UNITTEST
  37. #include <google/protobuf/port_def.inc>
  38. namespace google {
  39. namespace protobuf {
  40. namespace unittest = ::protobuf_unittest;
  41. // Like above, but use the reflection interface.
  42. class MapReflectionTester {
  43. public:
  44. // base_descriptor must be a descriptor for TestMap, which is used for
  45. // MapReflectionTester to fetch the FieldDescriptors needed to use the
  46. // reflection interface.
  47. explicit MapReflectionTester(const Descriptor* base_descriptor);
  48. void SetMapFieldsViaReflection(Message* message);
  49. void SetMapFieldsViaMapReflection(Message* message);
  50. void ClearMapFieldsViaReflection(Message* message);
  51. void ModifyMapFieldsViaReflection(Message* message);
  52. void RemoveLastMapsViaReflection(Message* message);
  53. void ReleaseLastMapsViaReflection(Message* message);
  54. void SwapMapsViaReflection(Message* message);
  55. void MutableUnknownFieldsOfMapFieldsViaReflection(Message* message);
  56. void ExpectMapFieldsSetViaReflection(const Message& message);
  57. void ExpectMapFieldsSetViaReflectionIterator(Message* message);
  58. void ExpectClearViaReflection(const Message& message);
  59. void ExpectClearViaReflectionIterator(Message* message);
  60. void GetMapValueViaMapReflection(Message* message,
  61. const std::string& field_name,
  62. const MapKey& map_key, MapValueRef* map_val);
  63. Message* GetMapEntryViaReflection(Message* message,
  64. const std::string& field_name, int index);
  65. MapIterator MapBegin(Message* message, const std::string& field_name);
  66. MapIterator MapEnd(Message* message, const std::string& field_name);
  67. private:
  68. const FieldDescriptor* F(const std::string& name);
  69. const Descriptor* base_descriptor_;
  70. const EnumValueDescriptor* map_enum_bar_;
  71. const EnumValueDescriptor* map_enum_baz_;
  72. const EnumValueDescriptor* map_enum_foo_;
  73. const FieldDescriptor* foreign_c_;
  74. const FieldDescriptor* map_int32_int32_key_;
  75. const FieldDescriptor* map_int32_int32_val_;
  76. const FieldDescriptor* map_int64_int64_key_;
  77. const FieldDescriptor* map_int64_int64_val_;
  78. const FieldDescriptor* map_uint32_uint32_key_;
  79. const FieldDescriptor* map_uint32_uint32_val_;
  80. const FieldDescriptor* map_uint64_uint64_key_;
  81. const FieldDescriptor* map_uint64_uint64_val_;
  82. const FieldDescriptor* map_sint32_sint32_key_;
  83. const FieldDescriptor* map_sint32_sint32_val_;
  84. const FieldDescriptor* map_sint64_sint64_key_;
  85. const FieldDescriptor* map_sint64_sint64_val_;
  86. const FieldDescriptor* map_fixed32_fixed32_key_;
  87. const FieldDescriptor* map_fixed32_fixed32_val_;
  88. const FieldDescriptor* map_fixed64_fixed64_key_;
  89. const FieldDescriptor* map_fixed64_fixed64_val_;
  90. const FieldDescriptor* map_sfixed32_sfixed32_key_;
  91. const FieldDescriptor* map_sfixed32_sfixed32_val_;
  92. const FieldDescriptor* map_sfixed64_sfixed64_key_;
  93. const FieldDescriptor* map_sfixed64_sfixed64_val_;
  94. const FieldDescriptor* map_int32_float_key_;
  95. const FieldDescriptor* map_int32_float_val_;
  96. const FieldDescriptor* map_int32_double_key_;
  97. const FieldDescriptor* map_int32_double_val_;
  98. const FieldDescriptor* map_bool_bool_key_;
  99. const FieldDescriptor* map_bool_bool_val_;
  100. const FieldDescriptor* map_string_string_key_;
  101. const FieldDescriptor* map_string_string_val_;
  102. const FieldDescriptor* map_int32_bytes_key_;
  103. const FieldDescriptor* map_int32_bytes_val_;
  104. const FieldDescriptor* map_int32_enum_key_;
  105. const FieldDescriptor* map_int32_enum_val_;
  106. const FieldDescriptor* map_int32_foreign_message_key_;
  107. const FieldDescriptor* map_int32_foreign_message_val_;
  108. };
  109. inline MapReflectionTester::MapReflectionTester(
  110. const Descriptor* base_descriptor)
  111. : base_descriptor_(base_descriptor) {
  112. const DescriptorPool* pool = base_descriptor->file()->pool();
  113. std::string package = base_descriptor->file()->package();
  114. map_enum_foo_ = pool->FindEnumValueByName(package + ".MAP_ENUM_FOO");
  115. map_enum_bar_ = pool->FindEnumValueByName(package + ".MAP_ENUM_BAR");
  116. map_enum_baz_ = pool->FindEnumValueByName(package + ".MAP_ENUM_BAZ");
  117. foreign_c_ = pool->FindFieldByName(package + ".ForeignMessage.c");
  118. map_int32_int32_key_ =
  119. pool->FindFieldByName(package + ".TestMap.MapInt32Int32Entry.key");
  120. map_int32_int32_val_ =
  121. pool->FindFieldByName(package + ".TestMap.MapInt32Int32Entry.value");
  122. map_int64_int64_key_ =
  123. pool->FindFieldByName(package + ".TestMap.MapInt64Int64Entry.key");
  124. map_int64_int64_val_ =
  125. pool->FindFieldByName(package + ".TestMap.MapInt64Int64Entry.value");
  126. map_uint32_uint32_key_ =
  127. pool->FindFieldByName(package + ".TestMap.MapUint32Uint32Entry.key");
  128. map_uint32_uint32_val_ =
  129. pool->FindFieldByName(package + ".TestMap.MapUint32Uint32Entry.value");
  130. map_uint64_uint64_key_ =
  131. pool->FindFieldByName(package + ".TestMap.MapUint64Uint64Entry.key");
  132. map_uint64_uint64_val_ =
  133. pool->FindFieldByName(package + ".TestMap.MapUint64Uint64Entry.value");
  134. map_sint32_sint32_key_ =
  135. pool->FindFieldByName(package + ".TestMap.MapSint32Sint32Entry.key");
  136. map_sint32_sint32_val_ =
  137. pool->FindFieldByName(package + ".TestMap.MapSint32Sint32Entry.value");
  138. map_sint64_sint64_key_ =
  139. pool->FindFieldByName(package + ".TestMap.MapSint64Sint64Entry.key");
  140. map_sint64_sint64_val_ =
  141. pool->FindFieldByName(package + ".TestMap.MapSint64Sint64Entry.value");
  142. map_fixed32_fixed32_key_ =
  143. pool->FindFieldByName(package + ".TestMap.MapFixed32Fixed32Entry.key");
  144. map_fixed32_fixed32_val_ =
  145. pool->FindFieldByName(package + ".TestMap.MapFixed32Fixed32Entry.value");
  146. map_fixed64_fixed64_key_ =
  147. pool->FindFieldByName(package + ".TestMap.MapFixed64Fixed64Entry.key");
  148. map_fixed64_fixed64_val_ =
  149. pool->FindFieldByName(package + ".TestMap.MapFixed64Fixed64Entry.value");
  150. map_sfixed32_sfixed32_key_ =
  151. pool->FindFieldByName(package + ".TestMap.MapSfixed32Sfixed32Entry.key");
  152. map_sfixed32_sfixed32_val_ = pool->FindFieldByName(
  153. package + ".TestMap.MapSfixed32Sfixed32Entry.value");
  154. map_sfixed64_sfixed64_key_ =
  155. pool->FindFieldByName(package + ".TestMap.MapSfixed64Sfixed64Entry.key");
  156. map_sfixed64_sfixed64_val_ = pool->FindFieldByName(
  157. package + ".TestMap.MapSfixed64Sfixed64Entry.value");
  158. map_int32_float_key_ =
  159. pool->FindFieldByName(package + ".TestMap.MapInt32FloatEntry.key");
  160. map_int32_float_val_ =
  161. pool->FindFieldByName(package + ".TestMap.MapInt32FloatEntry.value");
  162. map_int32_double_key_ =
  163. pool->FindFieldByName(package + ".TestMap.MapInt32DoubleEntry.key");
  164. map_int32_double_val_ =
  165. pool->FindFieldByName(package + ".TestMap.MapInt32DoubleEntry.value");
  166. map_bool_bool_key_ =
  167. pool->FindFieldByName(package + ".TestMap.MapBoolBoolEntry.key");
  168. map_bool_bool_val_ =
  169. pool->FindFieldByName(package + ".TestMap.MapBoolBoolEntry.value");
  170. map_string_string_key_ =
  171. pool->FindFieldByName(package + ".TestMap.MapStringStringEntry.key");
  172. map_string_string_val_ =
  173. pool->FindFieldByName(package + ".TestMap.MapStringStringEntry.value");
  174. map_int32_bytes_key_ =
  175. pool->FindFieldByName(package + ".TestMap.MapInt32BytesEntry.key");
  176. map_int32_bytes_val_ =
  177. pool->FindFieldByName(package + ".TestMap.MapInt32BytesEntry.value");
  178. map_int32_enum_key_ =
  179. pool->FindFieldByName(package + ".TestMap.MapInt32EnumEntry.key");
  180. map_int32_enum_val_ =
  181. pool->FindFieldByName(package + ".TestMap.MapInt32EnumEntry.value");
  182. map_int32_foreign_message_key_ = pool->FindFieldByName(
  183. package + ".TestMap.MapInt32ForeignMessageEntry.key");
  184. map_int32_foreign_message_val_ = pool->FindFieldByName(
  185. package + ".TestMap.MapInt32ForeignMessageEntry.value");
  186. EXPECT_FALSE(map_enum_foo_ == nullptr);
  187. EXPECT_FALSE(map_enum_bar_ == nullptr);
  188. EXPECT_FALSE(map_enum_baz_ == nullptr);
  189. EXPECT_FALSE(map_int32_int32_key_ == nullptr);
  190. EXPECT_FALSE(map_int32_int32_val_ == nullptr);
  191. EXPECT_FALSE(map_int64_int64_key_ == nullptr);
  192. EXPECT_FALSE(map_int64_int64_val_ == nullptr);
  193. EXPECT_FALSE(map_uint32_uint32_key_ == nullptr);
  194. EXPECT_FALSE(map_uint32_uint32_val_ == nullptr);
  195. EXPECT_FALSE(map_uint64_uint64_key_ == nullptr);
  196. EXPECT_FALSE(map_uint64_uint64_val_ == nullptr);
  197. EXPECT_FALSE(map_sint32_sint32_key_ == nullptr);
  198. EXPECT_FALSE(map_sint32_sint32_val_ == nullptr);
  199. EXPECT_FALSE(map_sint64_sint64_key_ == nullptr);
  200. EXPECT_FALSE(map_sint64_sint64_val_ == nullptr);
  201. EXPECT_FALSE(map_fixed32_fixed32_key_ == nullptr);
  202. EXPECT_FALSE(map_fixed32_fixed32_val_ == nullptr);
  203. EXPECT_FALSE(map_fixed64_fixed64_key_ == nullptr);
  204. EXPECT_FALSE(map_fixed64_fixed64_val_ == nullptr);
  205. EXPECT_FALSE(map_sfixed32_sfixed32_key_ == nullptr);
  206. EXPECT_FALSE(map_sfixed32_sfixed32_val_ == nullptr);
  207. EXPECT_FALSE(map_sfixed64_sfixed64_key_ == nullptr);
  208. EXPECT_FALSE(map_sfixed64_sfixed64_val_ == nullptr);
  209. EXPECT_FALSE(map_int32_float_key_ == nullptr);
  210. EXPECT_FALSE(map_int32_float_val_ == nullptr);
  211. EXPECT_FALSE(map_int32_double_key_ == nullptr);
  212. EXPECT_FALSE(map_int32_double_val_ == nullptr);
  213. EXPECT_FALSE(map_bool_bool_key_ == nullptr);
  214. EXPECT_FALSE(map_bool_bool_val_ == nullptr);
  215. EXPECT_FALSE(map_string_string_key_ == nullptr);
  216. EXPECT_FALSE(map_string_string_val_ == nullptr);
  217. EXPECT_FALSE(map_int32_bytes_key_ == nullptr);
  218. EXPECT_FALSE(map_int32_bytes_val_ == nullptr);
  219. EXPECT_FALSE(map_int32_enum_key_ == nullptr);
  220. EXPECT_FALSE(map_int32_enum_val_ == nullptr);
  221. EXPECT_FALSE(map_int32_foreign_message_key_ == nullptr);
  222. EXPECT_FALSE(map_int32_foreign_message_val_ == nullptr);
  223. }
  224. // Shorthand to get a FieldDescriptor for a field of unittest::TestMap.
  225. inline const FieldDescriptor* MapReflectionTester::F(const std::string& name) {
  226. const FieldDescriptor* result = nullptr;
  227. result = base_descriptor_->FindFieldByName(name);
  228. GOOGLE_CHECK(result != nullptr);
  229. return result;
  230. }
  231. inline void MapReflectionTester::SetMapFieldsViaReflection(Message* message) {
  232. const Reflection* reflection = message->GetReflection();
  233. Message* sub_message = nullptr;
  234. Message* sub_foreign_message = nullptr;
  235. // Add first element.
  236. sub_message = reflection->AddMessage(message, F("map_int32_int32"));
  237. sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_key_, 0);
  238. sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_val_, 0);
  239. sub_message = reflection->AddMessage(message, F("map_int64_int64"));
  240. sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_key_, 0);
  241. sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_val_, 0);
  242. sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
  243. sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_key_,
  244. 0);
  245. sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_val_,
  246. 0);
  247. sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
  248. sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_key_,
  249. 0);
  250. sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_val_,
  251. 0);
  252. sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
  253. sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_key_,
  254. 0);
  255. sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_val_,
  256. 0);
  257. sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
  258. sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_key_,
  259. 0);
  260. sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_val_,
  261. 0);
  262. sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
  263. sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_key_,
  264. 0);
  265. sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_val_,
  266. 0);
  267. sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
  268. sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_key_,
  269. 0);
  270. sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_val_,
  271. 0);
  272. sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
  273. sub_message->GetReflection()->SetInt32(sub_message,
  274. map_sfixed32_sfixed32_key_, 0);
  275. sub_message->GetReflection()->SetInt32(sub_message,
  276. map_sfixed32_sfixed32_val_, 0);
  277. sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
  278. sub_message->GetReflection()->SetInt64(sub_message,
  279. map_sfixed64_sfixed64_key_, 0);
  280. sub_message->GetReflection()->SetInt64(sub_message,
  281. map_sfixed64_sfixed64_val_, 0);
  282. sub_message = reflection->AddMessage(message, F("map_int32_float"));
  283. sub_message->GetReflection()->SetInt32(sub_message, map_int32_float_key_, 0);
  284. sub_message->GetReflection()->SetFloat(sub_message, map_int32_float_val_,
  285. 0.0);
  286. sub_message = reflection->AddMessage(message, F("map_int32_double"));
  287. sub_message->GetReflection()->SetInt32(sub_message, map_int32_double_key_, 0);
  288. sub_message->GetReflection()->SetDouble(sub_message, map_int32_double_val_,
  289. 0.0);
  290. sub_message = reflection->AddMessage(message, F("map_bool_bool"));
  291. sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_key_, false);
  292. sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_val_, false);
  293. sub_message = reflection->AddMessage(message, F("map_string_string"));
  294. sub_message->GetReflection()->SetString(sub_message, map_string_string_key_,
  295. "0");
  296. sub_message->GetReflection()->SetString(sub_message, map_string_string_val_,
  297. "0");
  298. sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
  299. sub_message->GetReflection()->SetInt32(sub_message, map_int32_bytes_key_, 0);
  300. sub_message->GetReflection()->SetString(sub_message, map_int32_bytes_val_,
  301. "0");
  302. sub_message = reflection->AddMessage(message, F("map_int32_enum"));
  303. sub_message->GetReflection()->SetInt32(sub_message, map_int32_enum_key_, 0);
  304. sub_message->GetReflection()->SetEnum(sub_message, map_int32_enum_val_,
  305. map_enum_bar_);
  306. sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
  307. sub_message->GetReflection()->SetInt32(sub_message,
  308. map_int32_foreign_message_key_, 0);
  309. sub_foreign_message = sub_message->GetReflection()->MutableMessage(
  310. sub_message, map_int32_foreign_message_val_, nullptr);
  311. sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
  312. foreign_c_, 0);
  313. // Add second element
  314. sub_message = reflection->AddMessage(message, F("map_int32_int32"));
  315. sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_key_, 1);
  316. sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_val_, 1);
  317. sub_message = reflection->AddMessage(message, F("map_int64_int64"));
  318. sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_key_, 1);
  319. sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_val_, 1);
  320. sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
  321. sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_key_,
  322. 1);
  323. sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_val_,
  324. 1);
  325. sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
  326. sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_key_,
  327. 1);
  328. sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_val_,
  329. 1);
  330. sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
  331. sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_key_,
  332. 1);
  333. sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_val_,
  334. 1);
  335. sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
  336. sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_key_,
  337. 1);
  338. sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_val_,
  339. 1);
  340. sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
  341. sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_key_,
  342. 1);
  343. sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_val_,
  344. 1);
  345. sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
  346. sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_key_,
  347. 1);
  348. sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_val_,
  349. 1);
  350. sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
  351. sub_message->GetReflection()->SetInt32(sub_message,
  352. map_sfixed32_sfixed32_key_, 1);
  353. sub_message->GetReflection()->SetInt32(sub_message,
  354. map_sfixed32_sfixed32_val_, 1);
  355. sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
  356. sub_message->GetReflection()->SetInt64(sub_message,
  357. map_sfixed64_sfixed64_key_, 1);
  358. sub_message->GetReflection()->SetInt64(sub_message,
  359. map_sfixed64_sfixed64_val_, 1);
  360. sub_message = reflection->AddMessage(message, F("map_int32_float"));
  361. sub_message->GetReflection()->SetInt32(sub_message, map_int32_float_key_, 1);
  362. sub_message->GetReflection()->SetFloat(sub_message, map_int32_float_val_,
  363. 1.0);
  364. sub_message = reflection->AddMessage(message, F("map_int32_double"));
  365. sub_message->GetReflection()->SetInt32(sub_message, map_int32_double_key_, 1);
  366. sub_message->GetReflection()->SetDouble(sub_message, map_int32_double_val_,
  367. 1.0);
  368. sub_message = reflection->AddMessage(message, F("map_bool_bool"));
  369. sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_key_, true);
  370. sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_val_, true);
  371. sub_message = reflection->AddMessage(message, F("map_string_string"));
  372. sub_message->GetReflection()->SetString(sub_message, map_string_string_key_,
  373. "1");
  374. sub_message->GetReflection()->SetString(sub_message, map_string_string_val_,
  375. "1");
  376. sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
  377. sub_message->GetReflection()->SetInt32(sub_message, map_int32_bytes_key_, 1);
  378. sub_message->GetReflection()->SetString(sub_message, map_int32_bytes_val_,
  379. "1");
  380. sub_message = reflection->AddMessage(message, F("map_int32_enum"));
  381. sub_message->GetReflection()->SetInt32(sub_message, map_int32_enum_key_, 1);
  382. sub_message->GetReflection()->SetEnum(sub_message, map_int32_enum_val_,
  383. map_enum_baz_);
  384. sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
  385. sub_message->GetReflection()->SetInt32(sub_message,
  386. map_int32_foreign_message_key_, 1);
  387. sub_foreign_message = sub_message->GetReflection()->MutableMessage(
  388. sub_message, map_int32_foreign_message_val_, nullptr);
  389. sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
  390. foreign_c_, 1);
  391. }
  392. inline void MapReflectionTester::SetMapFieldsViaMapReflection(
  393. Message* message) {
  394. const Reflection* reflection = message->GetReflection();
  395. Message* sub_foreign_message = nullptr;
  396. MapValueRef map_val;
  397. // Add first element.
  398. MapKey map_key;
  399. map_key.SetInt32Value(0);
  400. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
  401. map_key, &map_val));
  402. map_val.SetInt32Value(0);
  403. map_key.SetInt64Value(0);
  404. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
  405. map_key, &map_val));
  406. map_val.SetInt64Value(0);
  407. map_key.SetUInt32Value(0);
  408. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  409. message, F("map_uint32_uint32"), map_key, &map_val));
  410. map_val.SetUInt32Value(0);
  411. map_key.SetUInt64Value(0);
  412. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  413. message, F("map_uint64_uint64"), map_key, &map_val));
  414. map_val.SetUInt64Value(0);
  415. map_key.SetInt32Value(0);
  416. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  417. message, F("map_sint32_sint32"), map_key, &map_val));
  418. map_val.SetInt32Value(0);
  419. map_key.SetInt64Value(0);
  420. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  421. message, F("map_sint64_sint64"), map_key, &map_val));
  422. map_val.SetInt64Value(0);
  423. map_key.SetUInt32Value(0);
  424. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  425. message, F("map_fixed32_fixed32"), map_key, &map_val));
  426. map_val.SetUInt32Value(0);
  427. map_key.SetUInt64Value(0);
  428. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  429. message, F("map_fixed64_fixed64"), map_key, &map_val));
  430. map_val.SetUInt64Value(0);
  431. map_key.SetInt32Value(0);
  432. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  433. message, F("map_sfixed32_sfixed32"), map_key, &map_val));
  434. map_val.SetInt32Value(0);
  435. map_key.SetInt64Value(0);
  436. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  437. message, F("map_sfixed64_sfixed64"), map_key, &map_val));
  438. map_val.SetInt64Value(0);
  439. map_key.SetInt32Value(0);
  440. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_float"),
  441. map_key, &map_val));
  442. map_val.SetFloatValue(0.0);
  443. map_key.SetInt32Value(0);
  444. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_double"),
  445. map_key, &map_val));
  446. map_val.SetDoubleValue(0.0);
  447. map_key.SetBoolValue(false);
  448. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_bool_bool"),
  449. map_key, &map_val));
  450. map_val.SetBoolValue(false);
  451. map_key.SetStringValue("0");
  452. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  453. message, F("map_string_string"), map_key, &map_val));
  454. map_val.SetStringValue("0");
  455. map_key.SetInt32Value(0);
  456. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_bytes"),
  457. map_key, &map_val));
  458. map_val.SetStringValue("0");
  459. map_key.SetInt32Value(0);
  460. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_enum"),
  461. map_key, &map_val));
  462. map_val.SetEnumValue(map_enum_bar_->number());
  463. map_key.SetInt32Value(0);
  464. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  465. message, F("map_int32_foreign_message"), map_key, &map_val));
  466. sub_foreign_message = map_val.MutableMessageValue();
  467. sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
  468. foreign_c_, 0);
  469. // Add second element
  470. map_key.SetInt32Value(1);
  471. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
  472. map_key, &map_val));
  473. map_val.SetInt32Value(1);
  474. EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
  475. map_key, &map_val));
  476. map_key.SetInt64Value(1);
  477. EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
  478. map_key, &map_val));
  479. map_val.SetInt64Value(1);
  480. EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
  481. map_key, &map_val));
  482. map_key.SetUInt32Value(1);
  483. reflection->InsertOrLookupMapValue(message, F("map_uint32_uint32"), map_key,
  484. &map_val);
  485. map_val.SetUInt32Value(1);
  486. map_key.SetUInt64Value(1);
  487. reflection->InsertOrLookupMapValue(message, F("map_uint64_uint64"), map_key,
  488. &map_val);
  489. map_val.SetUInt64Value(1);
  490. map_key.SetInt32Value(1);
  491. reflection->InsertOrLookupMapValue(message, F("map_sint32_sint32"), map_key,
  492. &map_val);
  493. map_val.SetInt32Value(1);
  494. map_key.SetInt64Value(1);
  495. reflection->InsertOrLookupMapValue(message, F("map_sint64_sint64"), map_key,
  496. &map_val);
  497. map_val.SetInt64Value(1);
  498. map_key.SetUInt32Value(1);
  499. reflection->InsertOrLookupMapValue(message, F("map_fixed32_fixed32"), map_key,
  500. &map_val);
  501. map_val.SetUInt32Value(1);
  502. map_key.SetUInt64Value(1);
  503. reflection->InsertOrLookupMapValue(message, F("map_fixed64_fixed64"), map_key,
  504. &map_val);
  505. map_val.SetUInt64Value(1);
  506. map_key.SetInt32Value(1);
  507. reflection->InsertOrLookupMapValue(message, F("map_sfixed32_sfixed32"),
  508. map_key, &map_val);
  509. map_val.SetInt32Value(1);
  510. map_key.SetInt64Value(1);
  511. reflection->InsertOrLookupMapValue(message, F("map_sfixed64_sfixed64"),
  512. map_key, &map_val);
  513. map_val.SetInt64Value(1);
  514. map_key.SetInt32Value(1);
  515. reflection->InsertOrLookupMapValue(message, F("map_int32_float"), map_key,
  516. &map_val);
  517. map_val.SetFloatValue(1.0);
  518. map_key.SetInt32Value(1);
  519. reflection->InsertOrLookupMapValue(message, F("map_int32_double"), map_key,
  520. &map_val);
  521. map_val.SetDoubleValue(1.0);
  522. map_key.SetBoolValue(true);
  523. reflection->InsertOrLookupMapValue(message, F("map_bool_bool"), map_key,
  524. &map_val);
  525. map_val.SetBoolValue(true);
  526. map_key.SetStringValue("1");
  527. reflection->InsertOrLookupMapValue(message, F("map_string_string"), map_key,
  528. &map_val);
  529. map_val.SetStringValue("1");
  530. map_key.SetInt32Value(1);
  531. reflection->InsertOrLookupMapValue(message, F("map_int32_bytes"), map_key,
  532. &map_val);
  533. map_val.SetStringValue("1");
  534. map_key.SetInt32Value(1);
  535. reflection->InsertOrLookupMapValue(message, F("map_int32_enum"), map_key,
  536. &map_val);
  537. map_val.SetEnumValue(map_enum_baz_->number());
  538. map_key.SetInt32Value(1);
  539. EXPECT_TRUE(reflection->InsertOrLookupMapValue(
  540. message, F("map_int32_foreign_message"), map_key, &map_val));
  541. sub_foreign_message = map_val.MutableMessageValue();
  542. sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
  543. foreign_c_, 1);
  544. }
  545. inline void MapReflectionTester::GetMapValueViaMapReflection(
  546. Message* message, const std::string& field_name, const MapKey& map_key,
  547. MapValueRef* map_val) {
  548. const Reflection* reflection = message->GetReflection();
  549. EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F(field_name),
  550. map_key, map_val));
  551. }
  552. inline Message* MapReflectionTester::GetMapEntryViaReflection(
  553. Message* message, const std::string& field_name, int index) {
  554. const Reflection* reflection = message->GetReflection();
  555. return reflection->MutableRepeatedMessage(message, F(field_name), index);
  556. }
  557. inline MapIterator MapReflectionTester::MapBegin(
  558. Message* message, const std::string& field_name) {
  559. const Reflection* reflection = message->GetReflection();
  560. return reflection->MapBegin(message, F(field_name));
  561. }
  562. inline MapIterator MapReflectionTester::MapEnd(Message* message,
  563. const std::string& field_name) {
  564. const Reflection* reflection = message->GetReflection();
  565. return reflection->MapEnd(message, F(field_name));
  566. }
  567. inline void MapReflectionTester::ClearMapFieldsViaReflection(Message* message) {
  568. const Reflection* reflection = message->GetReflection();
  569. reflection->ClearField(message, F("map_int32_int32"));
  570. reflection->ClearField(message, F("map_int64_int64"));
  571. reflection->ClearField(message, F("map_uint32_uint32"));
  572. reflection->ClearField(message, F("map_uint64_uint64"));
  573. reflection->ClearField(message, F("map_sint32_sint32"));
  574. reflection->ClearField(message, F("map_sint64_sint64"));
  575. reflection->ClearField(message, F("map_fixed32_fixed32"));
  576. reflection->ClearField(message, F("map_fixed64_fixed64"));
  577. reflection->ClearField(message, F("map_sfixed32_sfixed32"));
  578. reflection->ClearField(message, F("map_sfixed64_sfixed64"));
  579. reflection->ClearField(message, F("map_int32_float"));
  580. reflection->ClearField(message, F("map_int32_double"));
  581. reflection->ClearField(message, F("map_bool_bool"));
  582. reflection->ClearField(message, F("map_string_string"));
  583. reflection->ClearField(message, F("map_int32_bytes"));
  584. reflection->ClearField(message, F("map_int32_enum"));
  585. reflection->ClearField(message, F("map_int32_foreign_message"));
  586. }
  587. inline void MapReflectionTester::ModifyMapFieldsViaReflection(
  588. Message* message) {
  589. const Reflection* reflection = message->GetReflection();
  590. MapValueRef map_val;
  591. Message* sub_foreign_message;
  592. // Modify the second element
  593. MapKey map_key;
  594. map_key.SetInt32Value(1);
  595. EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
  596. map_key, &map_val));
  597. map_val.SetInt32Value(2);
  598. map_key.SetInt64Value(1);
  599. EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
  600. map_key, &map_val));
  601. map_val.SetInt64Value(2);
  602. map_key.SetUInt32Value(1);
  603. EXPECT_FALSE(reflection->InsertOrLookupMapValue(
  604. message, F("map_uint32_uint32"), map_key, &map_val));
  605. map_val.SetUInt32Value(2);
  606. map_key.SetUInt64Value(1);
  607. reflection->InsertOrLookupMapValue(message, F("map_uint64_uint64"), map_key,
  608. &map_val);
  609. map_val.SetUInt64Value(2);
  610. map_key.SetInt32Value(1);
  611. reflection->InsertOrLookupMapValue(message, F("map_sint32_sint32"), map_key,
  612. &map_val);
  613. map_val.SetInt32Value(2);
  614. map_key.SetInt64Value(1);
  615. reflection->InsertOrLookupMapValue(message, F("map_sint64_sint64"), map_key,
  616. &map_val);
  617. map_val.SetInt64Value(2);
  618. map_key.SetUInt32Value(1);
  619. reflection->InsertOrLookupMapValue(message, F("map_fixed32_fixed32"), map_key,
  620. &map_val);
  621. map_val.SetUInt32Value(2);
  622. map_key.SetUInt64Value(1);
  623. reflection->InsertOrLookupMapValue(message, F("map_fixed64_fixed64"), map_key,
  624. &map_val);
  625. map_val.SetUInt64Value(2);
  626. map_key.SetInt32Value(1);
  627. reflection->InsertOrLookupMapValue(message, F("map_sfixed32_sfixed32"),
  628. map_key, &map_val);
  629. map_val.SetInt32Value(2);
  630. map_key.SetInt64Value(1);
  631. reflection->InsertOrLookupMapValue(message, F("map_sfixed64_sfixed64"),
  632. map_key, &map_val);
  633. map_val.SetInt64Value(2);
  634. map_key.SetInt32Value(1);
  635. reflection->InsertOrLookupMapValue(message, F("map_int32_float"), map_key,
  636. &map_val);
  637. map_val.SetFloatValue(2.0);
  638. map_key.SetInt32Value(1);
  639. reflection->InsertOrLookupMapValue(message, F("map_int32_double"), map_key,
  640. &map_val);
  641. map_val.SetDoubleValue(2.0);
  642. map_key.SetBoolValue(true);
  643. reflection->InsertOrLookupMapValue(message, F("map_bool_bool"), map_key,
  644. &map_val);
  645. map_val.SetBoolValue(false);
  646. map_key.SetStringValue("1");
  647. reflection->InsertOrLookupMapValue(message, F("map_string_string"), map_key,
  648. &map_val);
  649. map_val.SetStringValue("2");
  650. map_key.SetInt32Value(1);
  651. reflection->InsertOrLookupMapValue(message, F("map_int32_bytes"), map_key,
  652. &map_val);
  653. map_val.SetStringValue("2");
  654. map_key.SetInt32Value(1);
  655. reflection->InsertOrLookupMapValue(message, F("map_int32_enum"), map_key,
  656. &map_val);
  657. map_val.SetEnumValue(map_enum_foo_->number());
  658. map_key.SetInt32Value(1);
  659. EXPECT_FALSE(reflection->InsertOrLookupMapValue(
  660. message, F("map_int32_foreign_message"), map_key, &map_val));
  661. sub_foreign_message = map_val.MutableMessageValue();
  662. sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
  663. foreign_c_, 2);
  664. }
  665. inline void MapReflectionTester::RemoveLastMapsViaReflection(Message* message) {
  666. const Reflection* reflection = message->GetReflection();
  667. std::vector<const FieldDescriptor*> output;
  668. reflection->ListFields(*message, &output);
  669. for (int i = 0; i < output.size(); ++i) {
  670. const FieldDescriptor* field = output[i];
  671. if (!field->is_repeated()) continue;
  672. reflection->RemoveLast(message, field);
  673. }
  674. }
  675. inline void MapReflectionTester::ReleaseLastMapsViaReflection(
  676. Message* message) {
  677. const Reflection* reflection = message->GetReflection();
  678. std::vector<const FieldDescriptor*> output;
  679. reflection->ListFields(*message, &output);
  680. for (int i = 0; i < output.size(); ++i) {
  681. const FieldDescriptor* field = output[i];
  682. if (!field->is_repeated()) continue;
  683. if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue;
  684. Message* released = reflection->ReleaseLast(message, field);
  685. ASSERT_TRUE(released != nullptr)
  686. << "ReleaseLast returned nullptr for: " << field->name();
  687. delete released;
  688. }
  689. }
  690. inline void MapReflectionTester::SwapMapsViaReflection(Message* message) {
  691. const Reflection* reflection = message->GetReflection();
  692. std::vector<const FieldDescriptor*> output;
  693. reflection->ListFields(*message, &output);
  694. for (int i = 0; i < output.size(); ++i) {
  695. const FieldDescriptor* field = output[i];
  696. if (!field->is_repeated()) continue;
  697. reflection->SwapElements(message, field, 0, 1);
  698. }
  699. }
  700. inline void MapReflectionTester::MutableUnknownFieldsOfMapFieldsViaReflection(
  701. Message* message) {
  702. const Reflection* reflection = message->GetReflection();
  703. Message* sub_message = nullptr;
  704. sub_message = reflection->AddMessage(message, F("map_int32_int32"));
  705. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  706. nullptr);
  707. sub_message = reflection->AddMessage(message, F("map_int64_int64"));
  708. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  709. nullptr);
  710. sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
  711. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  712. nullptr);
  713. sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
  714. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  715. nullptr);
  716. sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
  717. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  718. nullptr);
  719. sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
  720. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  721. nullptr);
  722. sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
  723. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  724. nullptr);
  725. sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
  726. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  727. nullptr);
  728. sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
  729. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  730. nullptr);
  731. sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
  732. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  733. nullptr);
  734. sub_message = reflection->AddMessage(message, F("map_int32_float"));
  735. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  736. nullptr);
  737. sub_message = reflection->AddMessage(message, F("map_int32_double"));
  738. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  739. nullptr);
  740. sub_message = reflection->AddMessage(message, F("map_bool_bool"));
  741. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  742. nullptr);
  743. sub_message = reflection->AddMessage(message, F("map_string_string"));
  744. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  745. nullptr);
  746. sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
  747. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  748. nullptr);
  749. sub_message = reflection->AddMessage(message, F("map_int32_enum"));
  750. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  751. nullptr);
  752. sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
  753. EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
  754. nullptr);
  755. }
  756. inline void MapReflectionTester::ExpectMapFieldsSetViaReflection(
  757. const Message& message) {
  758. std::string scratch;
  759. const Reflection* reflection = message.GetReflection();
  760. const Message* sub_message;
  761. MapKey map_key;
  762. // -----------------------------------------------------------------
  763. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_int32")));
  764. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int64_int64")));
  765. ASSERT_EQ(2, reflection->FieldSize(message, F("map_uint32_uint32")));
  766. ASSERT_EQ(2, reflection->FieldSize(message, F("map_uint64_uint64")));
  767. ASSERT_EQ(2, reflection->FieldSize(message, F("map_sint32_sint32")));
  768. ASSERT_EQ(2, reflection->FieldSize(message, F("map_sint64_sint64")));
  769. ASSERT_EQ(2, reflection->FieldSize(message, F("map_fixed32_fixed32")));
  770. ASSERT_EQ(2, reflection->FieldSize(message, F("map_fixed64_fixed64")));
  771. ASSERT_EQ(2, reflection->FieldSize(message, F("map_sfixed32_sfixed32")));
  772. ASSERT_EQ(2, reflection->FieldSize(message, F("map_sfixed64_sfixed64")));
  773. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_float")));
  774. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_double")));
  775. ASSERT_EQ(2, reflection->FieldSize(message, F("map_bool_bool")));
  776. ASSERT_EQ(2, reflection->FieldSize(message, F("map_string_string")));
  777. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_bytes")));
  778. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_enum")));
  779. ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_foreign_message")));
  780. {
  781. std::map<int32, int32> map;
  782. map[0] = 0;
  783. map[1] = 1;
  784. for (int i = 0; i < 2; i++) {
  785. // Check with RepeatedField Reflection
  786. sub_message =
  787. &reflection->GetRepeatedMessage(message, F("map_int32_int32"), i);
  788. int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
  789. map_int32_int32_key_);
  790. int32 val = sub_message->GetReflection()->GetInt32(*sub_message,
  791. map_int32_int32_val_);
  792. EXPECT_EQ(map[key], val);
  793. // Check with Map Reflection
  794. map_key.SetInt32Value(key);
  795. EXPECT_TRUE(
  796. reflection->ContainsMapKey(message, F("map_int32_int32"), map_key));
  797. }
  798. }
  799. {
  800. std::map<int64, int64> map;
  801. map[0] = 0;
  802. map[1] = 1;
  803. for (int i = 0; i < 2; i++) {
  804. // Check with RepeatedField Reflection
  805. sub_message =
  806. &reflection->GetRepeatedMessage(message, F("map_int64_int64"), i);
  807. int64 key = sub_message->GetReflection()->GetInt64(*sub_message,
  808. map_int64_int64_key_);
  809. int64 val = sub_message->GetReflection()->GetInt64(*sub_message,
  810. map_int64_int64_val_);
  811. EXPECT_EQ(map[key], val);
  812. // Check with Map Reflection
  813. map_key.SetInt64Value(key);
  814. EXPECT_TRUE(
  815. reflection->ContainsMapKey(message, F("map_int64_int64"), map_key));
  816. }
  817. }
  818. {
  819. std::map<uint32, uint32> map;
  820. map[0] = 0;
  821. map[1] = 1;
  822. for (int i = 0; i < 2; i++) {
  823. // Check with RepeatedField Reflection
  824. sub_message =
  825. &reflection->GetRepeatedMessage(message, F("map_uint32_uint32"), i);
  826. uint32 key = sub_message->GetReflection()->GetUInt32(
  827. *sub_message, map_uint32_uint32_key_);
  828. uint32 val = sub_message->GetReflection()->GetUInt32(
  829. *sub_message, map_uint32_uint32_val_);
  830. EXPECT_EQ(map[key], val);
  831. // Check with Map Reflection
  832. map_key.SetUInt32Value(key);
  833. EXPECT_TRUE(
  834. reflection->ContainsMapKey(message, F("map_uint32_uint32"), map_key));
  835. }
  836. }
  837. {
  838. std::map<uint64, uint64> map;
  839. map[0] = 0;
  840. map[1] = 1;
  841. for (int i = 0; i < 2; i++) {
  842. sub_message =
  843. &reflection->GetRepeatedMessage(message, F("map_uint64_uint64"), i);
  844. uint64 key = sub_message->GetReflection()->GetUInt64(
  845. *sub_message, map_uint64_uint64_key_);
  846. uint64 val = sub_message->GetReflection()->GetUInt64(
  847. *sub_message, map_uint64_uint64_val_);
  848. EXPECT_EQ(map[key], val);
  849. // Check with Map Reflection
  850. map_key.SetUInt64Value(key);
  851. EXPECT_TRUE(
  852. reflection->ContainsMapKey(message, F("map_uint64_uint64"), map_key));
  853. }
  854. }
  855. {
  856. std::map<int32, int32> map;
  857. map[0] = 0;
  858. map[1] = 1;
  859. for (int i = 0; i < 2; i++) {
  860. sub_message =
  861. &reflection->GetRepeatedMessage(message, F("map_sint32_sint32"), i);
  862. int32 key = sub_message->GetReflection()->GetInt32(
  863. *sub_message, map_sint32_sint32_key_);
  864. int32 val = sub_message->GetReflection()->GetInt32(
  865. *sub_message, map_sint32_sint32_val_);
  866. EXPECT_EQ(map[key], val);
  867. // Check with Map Reflection
  868. map_key.SetInt32Value(key);
  869. EXPECT_EQ(true, reflection->ContainsMapKey(
  870. message, F("map_sint32_sint32"), map_key));
  871. }
  872. }
  873. {
  874. std::map<int64, int64> map;
  875. map[0] = 0;
  876. map[1] = 1;
  877. for (int i = 0; i < 2; i++) {
  878. sub_message =
  879. &reflection->GetRepeatedMessage(message, F("map_sint64_sint64"), i);
  880. int64 key = sub_message->GetReflection()->GetInt64(
  881. *sub_message, map_sint64_sint64_key_);
  882. int64 val = sub_message->GetReflection()->GetInt64(
  883. *sub_message, map_sint64_sint64_val_);
  884. EXPECT_EQ(map[key], val);
  885. // Check with Map Reflection
  886. map_key.SetInt64Value(key);
  887. EXPECT_EQ(true, reflection->ContainsMapKey(
  888. message, F("map_sint64_sint64"), map_key));
  889. }
  890. }
  891. {
  892. std::map<uint32, uint32> map;
  893. map[0] = 0;
  894. map[1] = 1;
  895. for (int i = 0; i < 2; i++) {
  896. sub_message =
  897. &reflection->GetRepeatedMessage(message, F("map_fixed32_fixed32"), i);
  898. uint32 key = sub_message->GetReflection()->GetUInt32(
  899. *sub_message, map_fixed32_fixed32_key_);
  900. uint32 val = sub_message->GetReflection()->GetUInt32(
  901. *sub_message, map_fixed32_fixed32_val_);
  902. EXPECT_EQ(map[key], val);
  903. // Check with Map Reflection
  904. map_key.SetUInt32Value(key);
  905. EXPECT_EQ(true, reflection->ContainsMapKey(
  906. message, F("map_fixed32_fixed32"), map_key));
  907. }
  908. }
  909. {
  910. std::map<uint64, uint64> map;
  911. map[0] = 0;
  912. map[1] = 1;
  913. for (int i = 0; i < 2; i++) {
  914. sub_message =
  915. &reflection->GetRepeatedMessage(message, F("map_fixed64_fixed64"), i);
  916. uint64 key = sub_message->GetReflection()->GetUInt64(
  917. *sub_message, map_fixed64_fixed64_key_);
  918. uint64 val = sub_message->GetReflection()->GetUInt64(
  919. *sub_message, map_fixed64_fixed64_val_);
  920. EXPECT_EQ(map[key], val);
  921. // Check with Map Reflection
  922. map_key.SetUInt64Value(key);
  923. EXPECT_EQ(true, reflection->ContainsMapKey(
  924. message, F("map_fixed64_fixed64"), map_key));
  925. }
  926. }
  927. {
  928. std::map<int32, int32> map;
  929. map[0] = 0;
  930. map[1] = 1;
  931. for (int i = 0; i < 2; i++) {
  932. sub_message = &reflection->GetRepeatedMessage(
  933. message, F("map_sfixed32_sfixed32"), i);
  934. int32 key = sub_message->GetReflection()->GetInt32(
  935. *sub_message, map_sfixed32_sfixed32_key_);
  936. int32 val = sub_message->GetReflection()->GetInt32(
  937. *sub_message, map_sfixed32_sfixed32_val_);
  938. EXPECT_EQ(map[key], val);
  939. // Check with Map Reflection
  940. map_key.SetInt32Value(key);
  941. EXPECT_EQ(true, reflection->ContainsMapKey(
  942. message, F("map_sfixed32_sfixed32"), map_key));
  943. }
  944. }
  945. {
  946. std::map<int64, int64> map;
  947. map[0] = 0;
  948. map[1] = 1;
  949. for (int i = 0; i < 2; i++) {
  950. sub_message = &reflection->GetRepeatedMessage(
  951. message, F("map_sfixed64_sfixed64"), i);
  952. int64 key = sub_message->GetReflection()->GetInt64(
  953. *sub_message, map_sfixed64_sfixed64_key_);
  954. int64 val = sub_message->GetReflection()->GetInt64(
  955. *sub_message, map_sfixed64_sfixed64_val_);
  956. EXPECT_EQ(map[key], val);
  957. // Check with Map Reflection
  958. map_key.SetInt64Value(key);
  959. EXPECT_EQ(true, reflection->ContainsMapKey(
  960. message, F("map_sfixed64_sfixed64"), map_key));
  961. }
  962. }
  963. {
  964. std::map<int32, float> map;
  965. map[0] = 0.0;
  966. map[1] = 1.0;
  967. for (int i = 0; i < 2; i++) {
  968. sub_message =
  969. &reflection->GetRepeatedMessage(message, F("map_int32_float"), i);
  970. int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
  971. map_int32_float_key_);
  972. float val = sub_message->GetReflection()->GetFloat(*sub_message,
  973. map_int32_float_val_);
  974. EXPECT_EQ(map[key], val);
  975. // Check with Map Reflection
  976. map_key.SetInt32Value(key);
  977. EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_float"),
  978. map_key));
  979. }
  980. }
  981. {
  982. std::map<int32, double> map;
  983. map[0] = 0.0;
  984. map[1] = 1.0;
  985. for (int i = 0; i < 2; i++) {
  986. sub_message =
  987. &reflection->GetRepeatedMessage(message, F("map_int32_double"), i);
  988. int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
  989. map_int32_double_key_);
  990. double val = sub_message->GetReflection()->GetDouble(
  991. *sub_message, map_int32_double_val_);
  992. EXPECT_EQ(map[key], val);
  993. // Check with Map Reflection
  994. map_key.SetInt32Value(key);
  995. EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_double"),
  996. map_key));
  997. }
  998. }
  999. {
  1000. std::map<bool, bool> map;
  1001. map[false] = false;
  1002. map[true] = true;
  1003. for (int i = 0; i < 2; i++) {
  1004. sub_message =
  1005. &reflection->GetRepeatedMessage(message, F("map_bool_bool"), i);
  1006. bool key = sub_message->GetReflection()->GetBool(*sub_message,
  1007. map_bool_bool_key_);
  1008. bool val = sub_message->GetReflection()->GetBool(*sub_message,
  1009. map_bool_bool_val_);
  1010. EXPECT_EQ(map[key], val);
  1011. // Check with Map Reflection
  1012. map_key.SetBoolValue(key);
  1013. EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_bool_bool"),
  1014. map_key));
  1015. }
  1016. }
  1017. {
  1018. std::map<std::string, std::string> map;
  1019. map["0"] = "0";
  1020. map["1"] = "1";
  1021. for (int i = 0; i < 2; i++) {
  1022. sub_message =
  1023. &reflection->GetRepeatedMessage(message, F("map_string_string"), i);
  1024. std::string key = sub_message->GetReflection()->GetString(
  1025. *sub_message, map_string_string_key_);
  1026. std::string val = sub_message->GetReflection()->GetString(
  1027. *sub_message, map_string_string_val_);
  1028. EXPECT_EQ(map[key], val);
  1029. // Check with Map Reflection
  1030. map_key.SetStringValue(key);
  1031. EXPECT_EQ(true, reflection->ContainsMapKey(
  1032. message, F("map_string_string"), map_key));
  1033. }
  1034. }
  1035. {
  1036. std::map<int32, std::string> map;
  1037. map[0] = "0";
  1038. map[1] = "1";
  1039. for (int i = 0; i < 2; i++) {
  1040. sub_message =
  1041. &reflection->GetRepeatedMessage(message, F("map_int32_bytes"), i);
  1042. int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
  1043. map_int32_bytes_key_);
  1044. std::string val = sub_message->GetReflection()->GetString(
  1045. *sub_message, map_int32_bytes_val_);
  1046. EXPECT_EQ(map[key], val);
  1047. // Check with Map Reflection
  1048. map_key.SetInt32Value(key);
  1049. EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_bytes"),
  1050. map_key));
  1051. }
  1052. }
  1053. {
  1054. std::map<int32, const EnumValueDescriptor*> map;
  1055. map[0] = map_enum_bar_;
  1056. map[1] = map_enum_baz_;
  1057. for (int i = 0; i < 2; i++) {
  1058. sub_message =
  1059. &reflection->GetRepeatedMessage(message, F("map_int32_enum"), i);
  1060. int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
  1061. map_int32_enum_key_);
  1062. const EnumValueDescriptor* val = sub_message->GetReflection()->GetEnum(
  1063. *sub_message, map_int32_enum_val_);
  1064. EXPECT_EQ(map[key], val);
  1065. // Check with Map Reflection
  1066. map_key.SetInt32Value(key);
  1067. EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_enum"),
  1068. map_key));
  1069. }
  1070. }
  1071. {
  1072. std::map<int32, int32> map;
  1073. map[0] = 0;
  1074. map[1] = 1;
  1075. for (int i = 0; i < 2; i++) {
  1076. sub_message = &reflection->GetRepeatedMessage(
  1077. message, F("map_int32_foreign_message"), i);
  1078. int32 key = sub_message->GetReflection()->GetInt32(
  1079. *sub_message, map_int32_foreign_message_key_);
  1080. const Message& foreign_message = sub_message->GetReflection()->GetMessage(
  1081. *sub_message, map_int32_foreign_message_val_);
  1082. int32 val = foreign_message.GetReflection()->GetInt32(foreign_message,
  1083. foreign_c_);
  1084. EXPECT_EQ(map[key], val);
  1085. // Check with Map Reflection
  1086. map_key.SetInt32Value(key);
  1087. EXPECT_EQ(true, reflection->ContainsMapKey(
  1088. message, F("map_int32_foreign_message"), map_key));
  1089. }
  1090. }
  1091. }
  1092. inline void MapReflectionTester::ExpectMapFieldsSetViaReflectionIterator(
  1093. Message* message) {
  1094. std::string scratch;
  1095. std::string serialized;
  1096. const Reflection* reflection = message->GetReflection();
  1097. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_int32")));
  1098. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int64_int64")));
  1099. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_uint32_uint32")));
  1100. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_uint64_uint64")));
  1101. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sint32_sint32")));
  1102. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sint64_sint64")));
  1103. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_fixed32_fixed32")));
  1104. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_fixed64_fixed64")));
  1105. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sfixed32_sfixed32")));
  1106. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sfixed64_sfixed64")));
  1107. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_float")));
  1108. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_double")));
  1109. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_bool_bool")));
  1110. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_string_string")));
  1111. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_bytes")));
  1112. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_enum")));
  1113. ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_foreign_message")));
  1114. {
  1115. std::map<int32, int32> map;
  1116. map[0] = 0;
  1117. map[1] = 1;
  1118. int size = 0;
  1119. for (MapIterator iter = reflection->MapBegin(message, F("map_int32_int32"));
  1120. iter != reflection->MapEnd(message, F("map_int32_int32"));
  1121. ++iter, ++size) {
  1122. // Check const methods do not invalidate map.
  1123. message->DebugString();
  1124. message->ShortDebugString();
  1125. message->SerializeToString(&serialized);
  1126. message->SpaceUsedLong();
  1127. message->ByteSizeLong();
  1128. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1129. iter.GetValueRef().GetInt32Value());
  1130. }
  1131. EXPECT_EQ(size, 2);
  1132. }
  1133. {
  1134. std::map<int64, int64> map;
  1135. map[0] = 0;
  1136. map[1] = 1;
  1137. for (MapIterator iter = reflection->MapBegin(message, F("map_int64_int64"));
  1138. iter != reflection->MapEnd(message, F("map_int64_int64")); ++iter) {
  1139. EXPECT_EQ(map[iter.GetKey().GetInt64Value()],
  1140. iter.GetValueRef().GetInt64Value());
  1141. }
  1142. }
  1143. {
  1144. std::map<uint32, uint32> map;
  1145. map[0] = 0;
  1146. map[1] = 1;
  1147. for (MapIterator iter =
  1148. reflection->MapBegin(message, F("map_uint32_uint32"));
  1149. iter != reflection->MapEnd(message, F("map_uint32_uint32")); ++iter) {
  1150. EXPECT_EQ(map[iter.GetKey().GetUInt32Value()],
  1151. iter.GetValueRef().GetUInt32Value());
  1152. }
  1153. }
  1154. {
  1155. std::map<uint64, uint64> map;
  1156. map[0] = 0;
  1157. map[1] = 1;
  1158. for (MapIterator iter =
  1159. reflection->MapBegin(message, F("map_uint64_uint64"));
  1160. iter != reflection->MapEnd(message, F("map_uint64_uint64")); ++iter) {
  1161. EXPECT_EQ(map[iter.GetKey().GetUInt64Value()],
  1162. iter.GetValueRef().GetUInt64Value());
  1163. }
  1164. }
  1165. {
  1166. std::map<int32, int32> map;
  1167. map[0] = 0;
  1168. map[1] = 1;
  1169. for (MapIterator iter =
  1170. reflection->MapBegin(message, F("map_sint32_sint32"));
  1171. iter != reflection->MapEnd(message, F("map_sint32_sint32")); ++iter) {
  1172. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1173. iter.GetValueRef().GetInt32Value());
  1174. }
  1175. }
  1176. {
  1177. std::map<int64, int64> map;
  1178. map[0] = 0;
  1179. map[1] = 1;
  1180. for (MapIterator iter =
  1181. reflection->MapBegin(message, F("map_sint64_sint64"));
  1182. iter != reflection->MapEnd(message, F("map_sint64_sint64")); ++iter) {
  1183. EXPECT_EQ(map[iter.GetKey().GetInt64Value()],
  1184. iter.GetValueRef().GetInt64Value());
  1185. }
  1186. }
  1187. {
  1188. std::map<uint32, uint32> map;
  1189. map[0] = 0;
  1190. map[1] = 1;
  1191. for (MapIterator iter =
  1192. reflection->MapBegin(message, F("map_fixed32_fixed32"));
  1193. iter != reflection->MapEnd(message, F("map_fixed32_fixed32"));
  1194. ++iter) {
  1195. EXPECT_EQ(map[iter.GetKey().GetUInt32Value()],
  1196. iter.GetValueRef().GetUInt32Value());
  1197. }
  1198. }
  1199. {
  1200. std::map<uint64, uint64> map;
  1201. map[0] = 0;
  1202. map[1] = 1;
  1203. for (MapIterator iter =
  1204. reflection->MapBegin(message, F("map_fixed64_fixed64"));
  1205. iter != reflection->MapEnd(message, F("map_fixed64_fixed64"));
  1206. ++iter) {
  1207. EXPECT_EQ(map[iter.GetKey().GetUInt64Value()],
  1208. iter.GetValueRef().GetUInt64Value());
  1209. }
  1210. }
  1211. {
  1212. std::map<int32, int32> map;
  1213. map[0] = 0;
  1214. map[1] = 1;
  1215. for (MapIterator iter =
  1216. reflection->MapBegin(message, F("map_sfixed32_sfixed32"));
  1217. iter != reflection->MapEnd(message, F("map_sfixed32_sfixed32"));
  1218. ++iter) {
  1219. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1220. iter.GetValueRef().GetInt32Value());
  1221. }
  1222. }
  1223. {
  1224. std::map<int32, float> map;
  1225. map[0] = 0.0;
  1226. map[1] = 1.0;
  1227. for (MapIterator iter = reflection->MapBegin(message, F("map_int32_float"));
  1228. iter != reflection->MapEnd(message, F("map_int32_float")); ++iter) {
  1229. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1230. iter.GetValueRef().GetFloatValue());
  1231. }
  1232. }
  1233. {
  1234. std::map<int32, double> map;
  1235. map[0] = 0.0;
  1236. map[1] = 1.0;
  1237. for (MapIterator iter =
  1238. reflection->MapBegin(message, F("map_int32_double"));
  1239. iter != reflection->MapEnd(message, F("map_int32_double")); ++iter) {
  1240. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1241. iter.GetValueRef().GetDoubleValue());
  1242. }
  1243. }
  1244. {
  1245. std::map<bool, bool> map;
  1246. map[false] = false;
  1247. map[true] = true;
  1248. for (MapIterator iter = reflection->MapBegin(message, F("map_bool_bool"));
  1249. iter != reflection->MapEnd(message, F("map_bool_bool")); ++iter) {
  1250. EXPECT_EQ(map[iter.GetKey().GetBoolValue()],
  1251. iter.GetValueRef().GetBoolValue());
  1252. }
  1253. }
  1254. {
  1255. std::map<std::string, std::string> map;
  1256. map["0"] = "0";
  1257. map["1"] = "1";
  1258. int size = 0;
  1259. for (MapIterator iter =
  1260. reflection->MapBegin(message, F("map_string_string"));
  1261. iter != reflection->MapEnd(message, F("map_string_string"));
  1262. ++iter, ++size) {
  1263. // Check const methods do not invalidate map.
  1264. message->DebugString();
  1265. message->ShortDebugString();
  1266. message->SerializeToString(&serialized);
  1267. message->SpaceUsedLong();
  1268. message->ByteSizeLong();
  1269. EXPECT_EQ(map[iter.GetKey().GetStringValue()],
  1270. iter.GetValueRef().GetStringValue());
  1271. }
  1272. EXPECT_EQ(size, 2);
  1273. }
  1274. {
  1275. std::map<int32, std::string> map;
  1276. map[0] = "0";
  1277. map[1] = "1";
  1278. for (MapIterator iter = reflection->MapBegin(message, F("map_int32_bytes"));
  1279. iter != reflection->MapEnd(message, F("map_int32_bytes")); ++iter) {
  1280. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1281. iter.GetValueRef().GetStringValue());
  1282. }
  1283. }
  1284. {
  1285. std::map<int32, const EnumValueDescriptor*> map;
  1286. map[0] = map_enum_bar_;
  1287. map[1] = map_enum_baz_;
  1288. for (MapIterator iter = reflection->MapBegin(message, F("map_int32_enum"));
  1289. iter != reflection->MapEnd(message, F("map_int32_enum")); ++iter) {
  1290. EXPECT_EQ(map[iter.GetKey().GetInt32Value()]->number(),
  1291. iter.GetValueRef().GetEnumValue());
  1292. }
  1293. }
  1294. {
  1295. std::map<int32, int32> map;
  1296. map[0] = 0;
  1297. map[1] = 1;
  1298. int size = 0;
  1299. for (MapIterator iter =
  1300. reflection->MapBegin(message, F("map_int32_foreign_message"));
  1301. iter != reflection->MapEnd(message, F("map_int32_foreign_message"));
  1302. ++iter, ++size) {
  1303. // Check const methods do not invalidate map.
  1304. message->DebugString();
  1305. message->ShortDebugString();
  1306. message->SerializeToString(&serialized);
  1307. message->SpaceUsedLong();
  1308. message->ByteSizeLong();
  1309. const Message& sub_message = iter.GetValueRef().GetMessageValue();
  1310. EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
  1311. sub_message.GetReflection()->GetInt32(sub_message, foreign_c_));
  1312. }
  1313. EXPECT_EQ(size, 2);
  1314. }
  1315. }
  1316. inline void MapReflectionTester::ExpectClearViaReflection(
  1317. const Message& message) {
  1318. const Reflection* reflection = message.GetReflection();
  1319. // Map fields are empty.
  1320. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_int32")));
  1321. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int64_int64")));
  1322. EXPECT_EQ(0, reflection->FieldSize(message, F("map_uint32_uint32")));
  1323. EXPECT_EQ(0, reflection->FieldSize(message, F("map_uint64_uint64")));
  1324. EXPECT_EQ(0, reflection->FieldSize(message, F("map_sint32_sint32")));
  1325. EXPECT_EQ(0, reflection->FieldSize(message, F("map_sint64_sint64")));
  1326. EXPECT_EQ(0, reflection->FieldSize(message, F("map_fixed32_fixed32")));
  1327. EXPECT_EQ(0, reflection->FieldSize(message, F("map_fixed64_fixed64")));
  1328. EXPECT_EQ(0, reflection->FieldSize(message, F("map_sfixed32_sfixed32")));
  1329. EXPECT_EQ(0, reflection->FieldSize(message, F("map_sfixed64_sfixed64")));
  1330. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_float")));
  1331. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_double")));
  1332. EXPECT_EQ(0, reflection->FieldSize(message, F("map_bool_bool")));
  1333. EXPECT_EQ(0, reflection->FieldSize(message, F("map_string_string")));
  1334. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_bytes")));
  1335. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_enum")));
  1336. EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_foreign_message")));
  1337. EXPECT_TRUE(reflection->GetMapData(message, F("map_int32_foreign_message"))
  1338. ->IsMapValid());
  1339. }
  1340. inline void MapReflectionTester::ExpectClearViaReflectionIterator(
  1341. Message* message) {
  1342. const Reflection* reflection = message->GetReflection();
  1343. EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_int32")) ==
  1344. reflection->MapEnd(message, F("map_int32_int32")));
  1345. EXPECT_TRUE(reflection->MapBegin(message, F("map_int64_int64")) ==
  1346. reflection->MapEnd(message, F("map_int64_int64")));
  1347. EXPECT_TRUE(reflection->MapBegin(message, F("map_uint32_uint32")) ==
  1348. reflection->MapEnd(message, F("map_uint32_uint32")));
  1349. EXPECT_TRUE(reflection->MapBegin(message, F("map_uint64_uint64")) ==
  1350. reflection->MapEnd(message, F("map_uint64_uint64")));
  1351. EXPECT_TRUE(reflection->MapBegin(message, F("map_sint32_sint32")) ==
  1352. reflection->MapEnd(message, F("map_sint32_sint32")));
  1353. EXPECT_TRUE(reflection->MapBegin(message, F("map_sint64_sint64")) ==
  1354. reflection->MapEnd(message, F("map_sint64_sint64")));
  1355. EXPECT_TRUE(reflection->MapBegin(message, F("map_fixed32_fixed32")) ==
  1356. reflection->MapEnd(message, F("map_fixed32_fixed32")));
  1357. EXPECT_TRUE(reflection->MapBegin(message, F("map_fixed64_fixed64")) ==
  1358. reflection->MapEnd(message, F("map_fixed64_fixed64")));
  1359. EXPECT_TRUE(reflection->MapBegin(message, F("map_sfixed32_sfixed32")) ==
  1360. reflection->MapEnd(message, F("map_sfixed32_sfixed32")));
  1361. EXPECT_TRUE(reflection->MapBegin(message, F("map_sfixed64_sfixed64")) ==
  1362. reflection->MapEnd(message, F("map_sfixed64_sfixed64")));
  1363. EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_float")) ==
  1364. reflection->MapEnd(message, F("map_int32_float")));
  1365. EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_double")) ==
  1366. reflection->MapEnd(message, F("map_int32_double")));
  1367. EXPECT_TRUE(reflection->MapBegin(message, F("map_bool_bool")) ==
  1368. reflection->MapEnd(message, F("map_bool_bool")));
  1369. EXPECT_TRUE(reflection->MapBegin(message, F("map_string_string")) ==
  1370. reflection->MapEnd(message, F("map_string_string")));
  1371. EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_bytes")) ==
  1372. reflection->MapEnd(message, F("map_int32_bytes")));
  1373. EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_enum")) ==
  1374. reflection->MapEnd(message, F("map_int32_enum")));
  1375. EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_foreign_message")) ==
  1376. reflection->MapEnd(message, F("map_int32_foreign_message")));
  1377. }
  1378. } // namespace protobuf
  1379. } // namespace google
  1380. #include <google/protobuf/port_undef.inc>
  1381. #endif // GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__