诸暨麻将添加redis
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

272 строки
13 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. #include <google/protobuf/map_test_util_impl.h>
  31. #include <google/protobuf/descriptor.h>
  32. #include <google/protobuf/message.h>
  33. namespace google {
  34. namespace protobuf {
  35. class MapTestUtil {
  36. public:
  37. // Set every field in the TestMap message to a unique value.
  38. static void SetMapFields(UNITTEST::TestMap* message);
  39. // Set every field in the TestArenaMap message to a unique value.
  40. static void SetArenaMapFields(UNITTEST::TestArenaMap* message);
  41. // Set every field in the message to a default value.
  42. static void SetMapFieldsInitialized(UNITTEST::TestMap* message);
  43. // Modify all the map fields of the message (which should already have been
  44. // initialized with SetMapFields()).
  45. static void ModifyMapFields(UNITTEST::TestMap* message);
  46. // Check that all fields have the values that they should have after
  47. // SetMapFields() is called.
  48. static void ExpectMapFieldsSet(const UNITTEST::TestMap& message);
  49. // Check that all fields have the values that they should have after
  50. // SetMapFields() is called for TestArenaMap.
  51. static void ExpectArenaMapFieldsSet(const UNITTEST::TestArenaMap& message);
  52. // Check that all fields have the values that they should have after
  53. // SetMapFieldsInitialized() is called.
  54. static void ExpectMapFieldsSetInitialized(const UNITTEST::TestMap& message);
  55. // Expect that the message is modified as would be expected from
  56. // ModifyMapFields().
  57. static void ExpectMapFieldsModified(const UNITTEST::TestMap& message);
  58. // Check that all fields are empty.
  59. static void ExpectClear(const UNITTEST::TestMap& message);
  60. // Check that all map fields have the given size.
  61. static void ExpectMapsSize(const UNITTEST::TestMap& message, int size);
  62. // Get pointers of map entries at given index.
  63. static std::vector<const Message*> GetMapEntries(
  64. const UNITTEST::TestMap& message, int index);
  65. // Get pointers of map entries from release.
  66. static std::vector<const Message*> GetMapEntriesFromRelease(
  67. UNITTEST::TestMap* message);
  68. };
  69. inline void MapTestUtil::SetMapFields(UNITTEST::TestMap* message) {
  70. MapTestUtilImpl::SetMapFields<UNITTEST::MapEnum, UNITTEST::MAP_ENUM_BAR,
  71. UNITTEST::MAP_ENUM_BAZ>(message);
  72. }
  73. inline void MapTestUtil::SetArenaMapFields(UNITTEST::TestArenaMap* message) {
  74. MapTestUtilImpl::SetArenaMapFields<UNITTEST::MapEnum, UNITTEST::MAP_ENUM_BAR,
  75. UNITTEST::MAP_ENUM_BAZ>(message);
  76. }
  77. inline void MapTestUtil::SetMapFieldsInitialized(UNITTEST::TestMap* message) {
  78. MapTestUtilImpl::SetMapFieldsInitialized(message);
  79. }
  80. inline void MapTestUtil::ModifyMapFields(UNITTEST::TestMap* message) {
  81. MapTestUtilImpl::ModifyMapFields<UNITTEST::MapEnum, UNITTEST::MAP_ENUM_FOO>(
  82. message);
  83. }
  84. inline void MapTestUtil::ExpectClear(const UNITTEST::TestMap& message) {
  85. MapTestUtilImpl::ExpectClear(message);
  86. }
  87. inline void MapTestUtil::ExpectMapFieldsSet(const UNITTEST::TestMap& message) {
  88. MapTestUtilImpl::ExpectMapFieldsSet<UNITTEST::MapEnum, UNITTEST::MAP_ENUM_BAR,
  89. UNITTEST::MAP_ENUM_BAZ>(message);
  90. }
  91. inline void MapTestUtil::ExpectArenaMapFieldsSet(
  92. const UNITTEST::TestArenaMap& message) {
  93. MapTestUtilImpl::ExpectArenaMapFieldsSet<
  94. UNITTEST::MapEnum, UNITTEST::MAP_ENUM_BAR, UNITTEST::MAP_ENUM_BAZ>(
  95. message);
  96. }
  97. inline void MapTestUtil::ExpectMapFieldsSetInitialized(
  98. const UNITTEST::TestMap& message) {
  99. MapTestUtilImpl::ExpectMapFieldsSetInitialized<UNITTEST::MapEnum,
  100. UNITTEST::MAP_ENUM_FOO>(
  101. message);
  102. }
  103. inline void MapTestUtil::ExpectMapFieldsModified(
  104. const UNITTEST::TestMap& message) {
  105. MapTestUtilImpl::ExpectMapFieldsModified<
  106. UNITTEST::MapEnum, UNITTEST::MAP_ENUM_BAR, UNITTEST::MAP_ENUM_FOO>(
  107. message);
  108. }
  109. inline void MapTestUtil::ExpectMapsSize(const UNITTEST::TestMap& message,
  110. int size) {
  111. const Descriptor* descriptor = message.GetDescriptor();
  112. EXPECT_EQ(size, message.GetReflection()->FieldSize(
  113. message, descriptor->FindFieldByName("map_int32_int32")));
  114. EXPECT_EQ(size, message.GetReflection()->FieldSize(
  115. message, descriptor->FindFieldByName("map_int64_int64")));
  116. EXPECT_EQ(size,
  117. message.GetReflection()->FieldSize(
  118. message, descriptor->FindFieldByName("map_uint32_uint32")));
  119. EXPECT_EQ(size,
  120. message.GetReflection()->FieldSize(
  121. message, descriptor->FindFieldByName("map_uint64_uint64")));
  122. EXPECT_EQ(size,
  123. message.GetReflection()->FieldSize(
  124. message, descriptor->FindFieldByName("map_sint32_sint32")));
  125. EXPECT_EQ(size,
  126. message.GetReflection()->FieldSize(
  127. message, descriptor->FindFieldByName("map_sint64_sint64")));
  128. EXPECT_EQ(size,
  129. message.GetReflection()->FieldSize(
  130. message, descriptor->FindFieldByName("map_fixed32_fixed32")));
  131. EXPECT_EQ(size,
  132. message.GetReflection()->FieldSize(
  133. message, descriptor->FindFieldByName("map_fixed64_fixed64")));
  134. EXPECT_EQ(size,
  135. message.GetReflection()->FieldSize(
  136. message, descriptor->FindFieldByName("map_sfixed32_sfixed32")));
  137. EXPECT_EQ(size,
  138. message.GetReflection()->FieldSize(
  139. message, descriptor->FindFieldByName("map_sfixed64_sfixed64")));
  140. EXPECT_EQ(size, message.GetReflection()->FieldSize(
  141. message, descriptor->FindFieldByName("map_int32_float")));
  142. EXPECT_EQ(size,
  143. message.GetReflection()->FieldSize(
  144. message, descriptor->FindFieldByName("map_int32_double")));
  145. EXPECT_EQ(size, message.GetReflection()->FieldSize(
  146. message, descriptor->FindFieldByName("map_bool_bool")));
  147. EXPECT_EQ(size,
  148. message.GetReflection()->FieldSize(
  149. message, descriptor->FindFieldByName("map_string_string")));
  150. EXPECT_EQ(size, message.GetReflection()->FieldSize(
  151. message, descriptor->FindFieldByName("map_int32_bytes")));
  152. EXPECT_EQ(
  153. size,
  154. message.GetReflection()->FieldSize(
  155. message, descriptor->FindFieldByName("map_int32_foreign_message")));
  156. }
  157. inline std::vector<const Message*> MapTestUtil::GetMapEntries(
  158. const UNITTEST::TestMap& message, int index) {
  159. const Descriptor* descriptor = message.GetDescriptor();
  160. std::vector<const Message*> result;
  161. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  162. message, descriptor->FindFieldByName("map_int32_int32"), index));
  163. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  164. message, descriptor->FindFieldByName("map_int64_int64"), index));
  165. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  166. message, descriptor->FindFieldByName("map_uint32_uint32"), index));
  167. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  168. message, descriptor->FindFieldByName("map_uint64_uint64"), index));
  169. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  170. message, descriptor->FindFieldByName("map_sint32_sint32"), index));
  171. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  172. message, descriptor->FindFieldByName("map_sint64_sint64"), index));
  173. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  174. message, descriptor->FindFieldByName("map_fixed32_fixed32"), index));
  175. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  176. message, descriptor->FindFieldByName("map_fixed64_fixed64"), index));
  177. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  178. message, descriptor->FindFieldByName("map_sfixed32_sfixed32"), index));
  179. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  180. message, descriptor->FindFieldByName("map_sfixed64_sfixed64"), index));
  181. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  182. message, descriptor->FindFieldByName("map_int32_float"), index));
  183. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  184. message, descriptor->FindFieldByName("map_int32_double"), index));
  185. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  186. message, descriptor->FindFieldByName("map_bool_bool"), index));
  187. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  188. message, descriptor->FindFieldByName("map_string_string"), index));
  189. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  190. message, descriptor->FindFieldByName("map_int32_bytes"), index));
  191. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  192. message, descriptor->FindFieldByName("map_int32_enum"), index));
  193. result.push_back(&message.GetReflection()->GetRepeatedMessage(
  194. message, descriptor->FindFieldByName("map_int32_foreign_message"),
  195. index));
  196. return result;
  197. }
  198. inline std::vector<const Message*> MapTestUtil::GetMapEntriesFromRelease(
  199. UNITTEST::TestMap* message) {
  200. const Descriptor* descriptor = message->GetDescriptor();
  201. std::vector<const Message*> result;
  202. result.push_back(message->GetReflection()->ReleaseLast(
  203. message, descriptor->FindFieldByName("map_int32_int32")));
  204. result.push_back(message->GetReflection()->ReleaseLast(
  205. message, descriptor->FindFieldByName("map_int64_int64")));
  206. result.push_back(message->GetReflection()->ReleaseLast(
  207. message, descriptor->FindFieldByName("map_uint32_uint32")));
  208. result.push_back(message->GetReflection()->ReleaseLast(
  209. message, descriptor->FindFieldByName("map_uint64_uint64")));
  210. result.push_back(message->GetReflection()->ReleaseLast(
  211. message, descriptor->FindFieldByName("map_sint32_sint32")));
  212. result.push_back(message->GetReflection()->ReleaseLast(
  213. message, descriptor->FindFieldByName("map_sint64_sint64")));
  214. result.push_back(message->GetReflection()->ReleaseLast(
  215. message, descriptor->FindFieldByName("map_fixed32_fixed32")));
  216. result.push_back(message->GetReflection()->ReleaseLast(
  217. message, descriptor->FindFieldByName("map_fixed64_fixed64")));
  218. result.push_back(message->GetReflection()->ReleaseLast(
  219. message, descriptor->FindFieldByName("map_sfixed32_sfixed32")));
  220. result.push_back(message->GetReflection()->ReleaseLast(
  221. message, descriptor->FindFieldByName("map_sfixed64_sfixed64")));
  222. result.push_back(message->GetReflection()->ReleaseLast(
  223. message, descriptor->FindFieldByName("map_int32_float")));
  224. result.push_back(message->GetReflection()->ReleaseLast(
  225. message, descriptor->FindFieldByName("map_int32_double")));
  226. result.push_back(message->GetReflection()->ReleaseLast(
  227. message, descriptor->FindFieldByName("map_bool_bool")));
  228. result.push_back(message->GetReflection()->ReleaseLast(
  229. message, descriptor->FindFieldByName("map_string_string")));
  230. result.push_back(message->GetReflection()->ReleaseLast(
  231. message, descriptor->FindFieldByName("map_int32_bytes")));
  232. result.push_back(message->GetReflection()->ReleaseLast(
  233. message, descriptor->FindFieldByName("map_int32_enum")));
  234. result.push_back(message->GetReflection()->ReleaseLast(
  235. message, descriptor->FindFieldByName("map_int32_foreign_message")));
  236. return result;
  237. }
  238. } // namespace protobuf
  239. } // namespace google