jsondeserializationtest.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2020 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <gtest/gtest.h>
  26. #include <QByteArray>
  27. #include <QString>
  28. #include <qprotobufjsonserializer.h>
  29. #include "simpletest.qpb.h"
  30. using namespace qtprotobufnamespace::tests;
  31. namespace QtProtobuf {
  32. namespace tests {
  33. class JsonDeserializationTest : public ::testing::Test
  34. {
  35. public:
  36. JsonDeserializationTest() = default;
  37. void SetUp() override;
  38. static void SetUpTestCase() {
  39. QtProtobuf::qRegisterProtobufTypes();
  40. }
  41. protected:
  42. std::unique_ptr<QProtobufJsonSerializer> serializer;
  43. };
  44. void JsonDeserializationTest::SetUp() {
  45. serializer.reset(new QProtobufJsonSerializer);
  46. }
  47. TEST_F(JsonDeserializationTest, FixedInt32MessageSerializeTest)
  48. {
  49. SimpleFixedInt32Message msg;
  50. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\": 5}"));
  51. EXPECT_EQ(msg.testFieldFixedInt32(), 5);
  52. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\": 0}"));
  53. EXPECT_EQ(msg.testFieldFixedInt32(), 0);
  54. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\":555}"));
  55. EXPECT_EQ(msg.testFieldFixedInt32(), 555);
  56. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\":555}"));
  57. EXPECT_EQ(msg.testFieldFixedInt32(), 555);
  58. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\":null}"));
  59. EXPECT_EQ(msg.testFieldFixedInt32(), 0);
  60. }
  61. TEST_F(JsonDeserializationTest, SFixedInt32MessageSerializeTest)
  62. {
  63. SimpleSFixedInt32Message msg;
  64. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\":555}"));
  65. EXPECT_EQ(msg.testFieldFixedInt32(), 555);
  66. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\":-555}"));
  67. EXPECT_EQ(msg.testFieldFixedInt32(), -555);
  68. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt32\":null}"));
  69. EXPECT_EQ(msg.testFieldFixedInt32(), 0);
  70. }
  71. TEST_F(JsonDeserializationTest, Int32MessageSerializeTest)
  72. {
  73. SimpleIntMessage msg;
  74. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":555}"));
  75. EXPECT_EQ(msg.testFieldInt(), 555);
  76. }
  77. TEST_F(JsonDeserializationTest, SInt32MessageSerializeTest)
  78. {
  79. SimpleSIntMessage msg;
  80. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":555}"));
  81. EXPECT_EQ(msg.testFieldInt(), 555);
  82. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":-555}"));
  83. EXPECT_EQ(msg.testFieldInt(), -555);
  84. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":null}"));
  85. EXPECT_EQ(msg.testFieldInt(), 0);
  86. }
  87. TEST_F(JsonDeserializationTest, UInt32MessageSerializeTest)
  88. {
  89. SimpleUIntMessage msg;
  90. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":555}"));
  91. EXPECT_EQ(msg.testFieldInt(), 555);
  92. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":null}"));
  93. EXPECT_EQ(msg.testFieldInt(), 0);
  94. }
  95. TEST_F(JsonDeserializationTest, FixedInt64MessageSerializeTest)
  96. {
  97. SimpleFixedInt64Message msg;
  98. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt64\":555}"));
  99. EXPECT_EQ(msg.testFieldFixedInt64(), 555);
  100. msg.deserialize(serializer.get(), QByteArray("{\"testFieldFixedInt64\":null}"));
  101. EXPECT_EQ(msg.testFieldFixedInt64(), 0);
  102. }
  103. TEST_F(JsonDeserializationTest, Int64MessageSerializeTest)
  104. {
  105. SimpleInt64Message msg;
  106. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":555}"));
  107. EXPECT_EQ(msg.testFieldInt(), 555);
  108. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":null}"));
  109. EXPECT_EQ(msg.testFieldInt(), 0);
  110. }
  111. TEST_F(JsonDeserializationTest, SInt64MessageSerializeTest)
  112. {
  113. SimpleSInt64Message msg;
  114. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":555}"));
  115. EXPECT_EQ(msg.testFieldInt(), 555);
  116. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":-555}"));
  117. EXPECT_EQ(msg.testFieldInt(), -555);
  118. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":null}"));
  119. EXPECT_EQ(msg.testFieldInt(), 0);
  120. }
  121. TEST_F(JsonDeserializationTest, UInt64MessageSerializeTest)
  122. {
  123. SimpleUInt64Message msg;
  124. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":555}"));
  125. EXPECT_EQ(msg.testFieldInt(), 555);
  126. msg.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":null}"));
  127. EXPECT_EQ(msg.testFieldInt(), 0);
  128. }
  129. TEST_F(JsonDeserializationTest, FloatMessageSerializeTest)
  130. {
  131. SimpleFloatMessage test;
  132. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\": 0.1}"));
  133. EXPECT_EQ(test.testFieldFloat(), 0.1f);
  134. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\": 1.17549e-38}"));
  135. EXPECT_EQ(test.testFieldFloat(), 1.17549e-38f);
  136. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\": 3.40282e+38}"));
  137. EXPECT_EQ(test.testFieldFloat(), 3.40282e+38f);
  138. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\": -4.2}"));
  139. EXPECT_EQ(test.testFieldFloat(), -4.2f);
  140. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\": 0}"));
  141. EXPECT_EQ(test.testFieldFloat(), 0.0f);
  142. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\": 0.0}"));
  143. EXPECT_EQ(test.testFieldFloat(), 0.0f);
  144. test.setTestFieldFloat(-4.2f);
  145. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\":null}"));
  146. EXPECT_EQ(test.testFieldFloat(), 0);
  147. test.setTestFieldFloat(-4.2f);
  148. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\":\"NaN\"}"));
  149. EXPECT_EQ(test.testFieldFloat(), 0);
  150. test.setTestFieldFloat(-4.2f);
  151. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\":\"Infinity\"}"));
  152. EXPECT_EQ(test.testFieldFloat(), 0);
  153. test.setTestFieldFloat(-4.2f);
  154. test.deserialize(serializer.get(), QByteArray("{\"testFieldFloat\":\"-Infinity\"}"));
  155. EXPECT_EQ(test.testFieldFloat(), 0);
  156. }
  157. TEST_F(JsonDeserializationTest, DoubleMessageSerializeTest)
  158. {
  159. SimpleDoubleMessage test;
  160. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\": 0.1}"));
  161. EXPECT_EQ(test.testFieldDouble(), 0.1);
  162. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\": 2.2250738585072014e-308}"));
  163. EXPECT_EQ(test.testFieldDouble(), 2.2250738585072014e-308);
  164. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\": 1.7976931348623157e+308}"));
  165. EXPECT_EQ(test.testFieldDouble(), 1.7976931348623157e+308);
  166. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\": 0}"));
  167. EXPECT_EQ(test.testFieldDouble(), 0);
  168. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\": 0.0}"));
  169. EXPECT_EQ(test.testFieldDouble(), 0);
  170. test.setTestFieldDouble(-4.2);
  171. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\":null}"));
  172. EXPECT_EQ(test.testFieldDouble(), 0);
  173. test.setTestFieldDouble(-4.2);
  174. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\":\"NaN\"}"));
  175. EXPECT_EQ(test.testFieldDouble(), 0);
  176. test.setTestFieldDouble(-4.2);
  177. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\":\"Infinity\"}"));
  178. EXPECT_EQ(test.testFieldDouble(), 0);
  179. test.setTestFieldDouble(-4.2);
  180. test.deserialize(serializer.get(), QByteArray("{\"testFieldDouble\":\"-Infinity\"}"));
  181. EXPECT_EQ(test.testFieldDouble(), 0);
  182. }
  183. TEST_F(JsonDeserializationTest, StringMessageSerializeTest)
  184. {
  185. SimpleStringMessage test;
  186. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":\"qwerty\"}"));
  187. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "qwerty");
  188. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":\"\"}"));
  189. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "");
  190. test.setTestFieldString("qwerty");
  191. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":null}"));
  192. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "");
  193. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":\"null\"}"));
  194. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "null");
  195. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":\"NaN\"}"));
  196. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "NaN");
  197. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":\"Infinity\"}"));
  198. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "Infinity");
  199. test.deserialize(serializer.get(), QByteArray("{\"testFieldString\":\"-Infinity\"}"));
  200. EXPECT_STREQ(test.testFieldString().toStdString().c_str(), "-Infinity");
  201. }
  202. TEST_F(JsonDeserializationTest, BytesMessageSerializeTest)
  203. {
  204. SimpleBytesMessage test;
  205. test.deserialize(serializer.get(), QByteArray("{\"testFieldBytes\":\"ABKEBDKBBFlWAFJmSnZqeHFiZ3ZGd1MxWXZPWlhndGo1ZmZHTFM3QAFpTkh6OW9aSW9LYm03ejhIATc5eEJ1cAlQa3BRWHZHb08wOU9ZOXhSYXd4M2VPQXM5eGpvVEExeEpocncyOFRBY3ExQ2ViWWxDOVdVZlFDNmhJYW50YU5keUhpS1RvZmZpMFp0N2xhNDJTUnhYWlNQNEd1eGJjWklwNTNwSm55Q3dmQ3kxcWRGY3pUMGRtbjdoOGZweUFkZW1FYXZ3RmVkYTRkMFBBcEdmU1Uyakx0MzlYOGtZVUJ4Tk0yV2dBTFJCZ0hkVmRlODdxNlBpNVU2OVRqaE1kMjhXMVNGRDFEeHlvZ0NDcnFPY3QyWlBJQ29MbnJxZEYzT2ROempSVkxmZXl2UThMZ0x2Uk5GUjlXZldBeUF6NzluS2dCYW1kOE50bHZ0NE1nMzVFNWdWUzJnN0FRN3JrbTcyY0Jkblc5c0NFeUdhYmVYQXVINWo0R1JidUxUN3FCWldEY0ZMRjRTc0NkUzNXZkZHZE5IZndhaWp6eWtCeW83MVB2RlZsVFhIMldKV29GdlI1RkFMakJUbjdiQ2RQMHBBaVNiTENZOFh6Mk1zYzNkQmI1RmY5R0lTUGJVcE5tVXZCZE1aTUhRdnFPbVROWEVQcE4wYjc0TURPTVFmV0pTaE9vM05rQXZNanMIKg\"}"));
  206. EXPECT_STREQ(test.testFieldBytes().toHex().toStdString().c_str(), "0012840432810459560052664a766a78716267764677533159764f5a5867746a356666474c53374001694e487a396f5a496f4b626d377a38480137397842757009506b70515876476f4f30394f5939785261777833654f417339786a6f544131784a68727732385441637131436562596c43395755665143366849616e74614e647948694b546f666669305a74376c613432535278585a53503447757862635a49703533704a6e79437766437931716446637a5430646d6e3768386670794164656d456176774665646134643050417047665355326a4c74333958386b595542784e4d325767414c524267486456646538377136506935553639546a684d6432385731534644314478796f67434372714f6374325a5049436f4c6e72716446334f644e7a6a52564c6665797651384c674c76524e4652395766574179417a37396e4b6742616d64384e746c7674344d6733354535675653326737415137726b6d37326342646e5739734345794761626558417548356a34475262754c543771425a574463464c463453734364533357664647644e48667761696a7a796b42796f3731507646566c54584832574a576f4676523546414c6a42546e37624364503070416953624c435938587a324d73633364426235466639474953506255704e6d557642644d5a4d485176714f6d544e584550704e306237344d444f4d5166574a53684f6f334e6b41764d6a73082a");
  207. test.deserialize(serializer.get(), QByteArray("{\"testFieldBytes\":\"\"}"));
  208. EXPECT_TRUE(test.testFieldBytes().isEmpty());
  209. test.setTestFieldBytes("qwerty");
  210. test.deserialize(serializer.get(), QByteArray("{\"testFieldBytes\":null}"));
  211. EXPECT_TRUE(test.testFieldBytes().isEmpty());
  212. }
  213. TEST_F(JsonDeserializationTest, ComplexTypeSerializeTest)
  214. {
  215. ComplexMessage test;
  216. test.deserialize(serializer.get(), QByteArray("{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":42}"));
  217. EXPECT_EQ(test.testFieldInt(), 42);
  218. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  219. test.setTestFieldInt(99);
  220. test.setTestComplexField({});
  221. test.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":42,\"testComplexField\":{\"testFieldString\":\"qwerty\"}}"));
  222. EXPECT_EQ(test.testFieldInt(), 42);
  223. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  224. test.setTestFieldInt(0);
  225. test.setTestComplexField({});
  226. test.deserialize(serializer.get(), QByteArray("{\"testComplexField\":{\"testFieldString\":\"YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs\"},\"testFieldInt\":42}"));
  227. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs");
  228. EXPECT_EQ(test.testFieldInt(), 42);
  229. test.setTestFieldInt(0);
  230. test.setTestComplexField({});
  231. test.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":42,\"testComplexField\":{\"testFieldString\":\"YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs\"}}"));
  232. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs");
  233. EXPECT_EQ(test.testFieldInt(), 42);
  234. test.setTestFieldInt(0);
  235. test.setTestComplexField({});
  236. test.deserialize(serializer.get(), QByteArray("{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":-45}"));
  237. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  238. EXPECT_EQ(test.testFieldInt(), -45);
  239. test.setTestFieldInt(0);
  240. test.setTestComplexField({});
  241. test.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":-45,\"testComplexField\":{\"testFieldString\":\"qwerty\"}}"));
  242. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  243. EXPECT_EQ(test.testFieldInt(), -45);
  244. test.deserialize(serializer.get(), QByteArray("{\"testFieldInt\":-45,\"testComplexField\":null"));
  245. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  246. EXPECT_EQ(test.testFieldInt(), -45);
  247. }
  248. TEST_F(JsonDeserializationTest, RepeatedIntMessageTest)
  249. {
  250. RepeatedIntMessage test;
  251. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[0,1,321,-65999,123245,-3,3]}");
  252. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::int32List({0, 1, 321, -65999, 123245, -3, 3}));
  253. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  254. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  255. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[0,1,321,-65999,123245,-3,3,null]}");
  256. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::int32List({0, 1, 321, -65999, 123245, -3, 3,0}));
  257. test.deserialize(serializer.get(), "{\"testRepeatedInt\":null}");
  258. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  259. }
  260. TEST_F(JsonDeserializationTest, RepeatedSIntMessageTest)
  261. {
  262. RepeatedSIntMessage test;
  263. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,-65999,123245,-3,3,0]}");
  264. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::sint32List({1, 321, -65999, 123245, -3, 3, 0}));
  265. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  266. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  267. }
  268. TEST_F(JsonDeserializationTest, RepeatedUIntMessageTest)
  269. {
  270. RepeatedUIntMessage test;
  271. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,0,321,65999,123245,3]}");
  272. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::uint32List({1, 0, 321, 65999, 123245, 3}));
  273. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  274. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  275. }
  276. TEST_F(JsonDeserializationTest, RepeatedInt64MessageTest)
  277. {
  278. RepeatedInt64Message test;
  279. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,-65999,12324523123123,-3,0,3]}");
  280. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::int64List({1, 321, -65999, 12324523123123, -3, 0, 3}));
  281. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  282. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  283. }
  284. TEST_F(JsonDeserializationTest, RepeatedSInt64MessageTest)
  285. {
  286. RepeatedSInt64Message test;
  287. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,-65999,12324523123123,0,-3,3]}");
  288. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::sint64List({1, 321, -65999, 12324523123123, 0, -3, 3}));
  289. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  290. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  291. }
  292. TEST_F(JsonDeserializationTest, RepeatedUInt64MessageTest)
  293. {
  294. RepeatedUInt64Message test;
  295. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,0,65999,123245,123245324235425234,3]}");
  296. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::uint64List({1, 321, 0, 65999, 123245, 123245324235425234, 3}));
  297. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  298. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  299. }
  300. TEST_F(JsonDeserializationTest, RepeatedFixedIntMessageTest)
  301. {
  302. RepeatedFixedIntMessage test;
  303. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,65999,12324523,3,3,0]}");
  304. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::fixed32List({1, 321, 65999, 12324523, 3, 3, 0}));
  305. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  306. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  307. }
  308. TEST_F(JsonDeserializationTest, RepeatedSFixedIntMessageTest)
  309. {
  310. RepeatedSFixedIntMessage test;
  311. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[0,1,321,-65999,12324523,-3,3]}");
  312. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::sfixed32List({0, 1, 321, -65999, 12324523, -3, 3}));
  313. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  314. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  315. }
  316. TEST_F(JsonDeserializationTest, RepeatedFixedInt64MessageTest)
  317. {
  318. RepeatedFixedInt64Message test;
  319. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,65999,123245324235425234,3,3,0]}");
  320. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::fixed64List({1, 321, 65999, 123245324235425234, 3, 3, 0}));
  321. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  322. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  323. }
  324. TEST_F(JsonDeserializationTest, RepeatedSFixedInt64MessageTest)
  325. {
  326. RepeatedSFixedInt64Message test;
  327. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,-65999,123245324235425234,-3,3,0]}");
  328. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::sfixed64List({1, 321, -65999, 123245324235425234, -3, 3, 0}));
  329. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,-65999,11,123245324235425234,-3,3,0]}");
  330. EXPECT_TRUE(test.testRepeatedInt() == QtProtobuf::sfixed64List({1, 321, -65999, 11, 123245324235425234, -3, 3, 0}));
  331. test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]}");
  332. EXPECT_TRUE(test.testRepeatedInt().isEmpty());
  333. }
  334. TEST_F(JsonDeserializationTest, RepeatedStringMessageTest)
  335. {
  336. RepeatedStringMessage test;
  337. test.deserialize(serializer.get(), "{\"testRepeatedString\":[\"aaaa\",\"bbbbb\",\"ccc\",\"dddddd\",\"eeeee\",\"\"]}");
  338. EXPECT_TRUE(test.testRepeatedString() == QStringList({"aaaa","bbbbb","ccc","dddddd","eeeee",""}));
  339. test.deserialize(serializer.get(), "{\"testRepeatedString\":[]}");
  340. EXPECT_TRUE(test.testRepeatedString().isEmpty());
  341. test.deserialize(serializer.get(), "{\"testRepeatedString\":[\"aaaa\",\"bbbbb\",\"ccc\",\"dddddd\",\"eeeee\",null]}");
  342. EXPECT_TRUE(test.testRepeatedString() == QStringList({"aaaa","bbbbb","ccc","dddddd","eeeee",""}));
  343. test.deserialize(serializer.get(), "{\"testRepeatedString\":null}");
  344. EXPECT_TRUE(test.testRepeatedString().isEmpty());
  345. }
  346. TEST_F(JsonDeserializationTest, RepeatedDoubleMessageTest)
  347. {
  348. RepeatedDoubleMessage test;
  349. test.deserialize(serializer.get(), "{\"testRepeatedDouble\":[0.1,0.2,0.3,0.4,0.5]}");
  350. EXPECT_TRUE(test.testRepeatedDouble() == QList<double>({0.1, 0.2, 0.3, 0.4, 0.5}));
  351. test.deserialize(serializer.get(), "{\"testRepeatedDouble\":[]}");
  352. EXPECT_TRUE(test.testRepeatedDouble().isEmpty());
  353. test.deserialize(serializer.get(), "{\"testRepeatedDouble\":[0.4,1.2,0.5,1.4,0.6,null]}");
  354. EXPECT_TRUE(test.testRepeatedDouble() == QList<double>({0.4, 1.2, 0.5, 1.4, 0.6, 0.0}));
  355. test.deserialize(serializer.get(), "{\"testRepeatedDouble\":null}");
  356. EXPECT_TRUE(test.testRepeatedDouble().isEmpty());
  357. test.deserialize(serializer.get(), "{\"testRepeatedDouble\":[0.4,1.2,0.5,1.4,0.6,\"NaN\"]}");
  358. EXPECT_TRUE(test.testRepeatedDouble() == QList<double>({0.4, 1.2, 0.5, 1.4, 0.6, 0.0}));
  359. test.deserialize(serializer.get(), "{\"testRepeatedDouble\":[\"Infinity\",1.4,\"-Infinity\",\"NaN\"]}");
  360. EXPECT_TRUE(test.testRepeatedDouble() == QList<double>({0.0, 1.4, 0.0, 0.0}));
  361. }
  362. TEST_F(JsonDeserializationTest, RepeatedBytesMessageTest)
  363. {
  364. RepeatedBytesMessage test;
  365. test.deserialize(serializer.get(), "{\"testRepeatedBytes\":[\"AQIDBAUG\",\"/////w==\",\"6urq6uo=\",\"AQIDBAUG\"]}");
  366. EXPECT_TRUE(test.testRepeatedBytes() == QList<QByteArray>({QByteArray::fromHex("010203040506"),
  367. QByteArray::fromHex("ffffffff"),
  368. QByteArray::fromHex("eaeaeaeaea"),
  369. QByteArray::fromHex("010203040506")}));
  370. test.deserialize(serializer.get(), "{\"testRepeatedBytes\":[]}");
  371. EXPECT_TRUE(test.testRepeatedBytes().isEmpty());
  372. test.deserialize(serializer.get(), "{\"testRepeatedBytes\":[\"AQIDBAUG\",\"\",\"6urq6uo=\",\"AQIDBAUG\"]}");
  373. EXPECT_TRUE(test.testRepeatedBytes() == QList<QByteArray>({QByteArray::fromHex("010203040506"),
  374. QByteArray::fromHex(""),
  375. QByteArray::fromHex("eaeaeaeaea"),
  376. QByteArray::fromHex("010203040506")}));
  377. test.deserialize(serializer.get(), "{\"testRepeatedBytes\":null}");
  378. EXPECT_TRUE(test.testRepeatedBytes().isEmpty());
  379. test.deserialize(serializer.get(), "{\"testRepeatedBytes\":[\"AQIDBAUG\",null,\"6urq6uo=\",\"AQIDBAUG\"]}");
  380. EXPECT_TRUE(test.testRepeatedBytes() == QList<QByteArray>({QByteArray::fromHex("010203040506"),
  381. QByteArray::fromHex(""),
  382. QByteArray::fromHex("eaeaeaeaea"),
  383. QByteArray::fromHex("010203040506")}));
  384. }
  385. TEST_F(JsonDeserializationTest, RepeatedFloatMessageTest)
  386. {
  387. RepeatedFloatMessage test;
  388. test.deserialize(serializer.get(), "{\"testRepeatedFloat\":[0.4,1.2,0.5,1.4,0.6]}");
  389. EXPECT_TRUE(test.testRepeatedFloat() == QList<float>({0.4f, 1.2f, 0.5f, 1.4f, 0.6f}));
  390. test.deserialize(serializer.get(), "{\"testRepeatedFloat\":[]}");
  391. EXPECT_TRUE(test.testRepeatedFloat().isEmpty());
  392. test.deserialize(serializer.get(), "{\"testRepeatedFloat\":[0.4,1.2,0.5,1.4,0.6,null]}");
  393. EXPECT_TRUE(test.testRepeatedFloat() == QList<float>({0.4f, 1.2f, 0.5f, 1.4f, 0.6f, 0.0f}));
  394. test.deserialize(serializer.get(), "{\"testRepeatedFloat\":null}");
  395. EXPECT_TRUE(test.testRepeatedFloat().isEmpty());
  396. test.deserialize(serializer.get(), "{\"testRepeatedFloat\":[0.4,1.2,0.5,1.4,0.6,\"NaN\"]}");
  397. EXPECT_TRUE(test.testRepeatedFloat() == QList<float>({0.4f, 1.2f, 0.5f, 1.4f, 0.6f, 0.0f}));
  398. test.deserialize(serializer.get(), "{\"testRepeatedFloat\":[\"Infinity\",1.4,\"-Infinity\",\"NaN\"]}");
  399. EXPECT_TRUE(test.testRepeatedFloat() == QList<float>({0.0f, 1.4f, 0.0f, 0.0f}));
  400. }
  401. TEST_F(JsonDeserializationTest, BoolMessageSerializeTest)
  402. {
  403. SimpleBoolMessage test;
  404. test.deserialize(serializer.get(), "{\"testFieldBool\":true}");
  405. EXPECT_TRUE(test.testFieldBool());
  406. test.deserialize(serializer.get(), "{\"testFieldBool\":false}");
  407. EXPECT_FALSE(test.testFieldBool());
  408. test.setTestFieldBool(false);
  409. test.deserialize(serializer.get(), "{\"testFieldBool\":1}");
  410. EXPECT_FALSE(test.testFieldBool());
  411. test.setTestFieldBool(true);
  412. test.deserialize(serializer.get(), "{\"testFieldBool\":0}");
  413. EXPECT_TRUE(test.testFieldBool());
  414. test.setTestFieldBool(false);
  415. test.deserialize(serializer.get(), "{\"testFieldBool\":\"true\"}");
  416. EXPECT_FALSE(test.testFieldBool());
  417. test.setTestFieldBool(true);
  418. test.deserialize(serializer.get(), "{\"testFieldBool\":\"false\"}");
  419. EXPECT_TRUE(test.testFieldBool());
  420. test.setTestFieldBool(false);
  421. test.deserialize(serializer.get(), "{\"testFieldBool\":1.0}");
  422. EXPECT_FALSE(test.testFieldBool());
  423. test.setTestFieldBool(true);
  424. test.deserialize(serializer.get(), "{\"testFieldBool\":0.0}");
  425. EXPECT_TRUE(test.testFieldBool());
  426. }
  427. TEST_F(JsonDeserializationTest, SimpleEnumMessageSerializeTest)
  428. {
  429. SimpleEnumMessage test;
  430. test.deserialize(serializer.get(), "{\"localEnum\":\"LOCAL_ENUM_VALUE2\"}");
  431. EXPECT_EQ(test.localEnum(), SimpleEnumMessage::LOCAL_ENUM_VALUE2);
  432. }
  433. TEST_F(JsonDeserializationTest, SimpleEnumListMessageTest)
  434. {
  435. SimpleEnumListMessage test;
  436. test.deserialize(serializer.get(), "{\"localEnumList\":[\"LOCAL_ENUM_VALUE0\",\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\",\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\",\"LOCAL_ENUM_VALUE3\"]}");
  437. EXPECT_TRUE(test.localEnumList() == SimpleEnumListMessage::LocalEnumRepeated({SimpleEnumListMessage::LOCAL_ENUM_VALUE0,
  438. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  439. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  440. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  441. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  442. SimpleEnumListMessage::LOCAL_ENUM_VALUE3}));
  443. test.deserialize(serializer.get(), "{\"localEnumList\":[]}");
  444. EXPECT_TRUE(test.localEnumList().isEmpty());
  445. test.deserialize(serializer.get(), "{\"localEnumList\":[\"LOCAL_ENUM_VALUE0\",\"LOCAL_ENUM_VALUE1\",null,\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\",\"LOCAL_ENUM_VALUE3\"]}");
  446. EXPECT_TRUE(test.localEnumList() == SimpleEnumListMessage::LocalEnumRepeated({SimpleEnumListMessage::LOCAL_ENUM_VALUE0,
  447. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  448. SimpleEnumListMessage::LOCAL_ENUM_VALUE0,
  449. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  450. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  451. SimpleEnumListMessage::LOCAL_ENUM_VALUE3}));
  452. test.deserialize(serializer.get(), "{\"localEnumList\":null}");
  453. EXPECT_TRUE(test.localEnumList().isEmpty());
  454. }
  455. TEST_F(JsonDeserializationTest, RepeatedComplexMessageTest)
  456. {
  457. RepeatedComplexMessage test;
  458. test.deserialize(serializer.get(), "{\"testRepeatedComplex\":[{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25},{\"testComplexField\":{\"testFieldString\":\"\"},\"testFieldInt\":25},{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25}]}");
  459. ASSERT_EQ(test.testRepeatedComplex().size(), 3);
  460. EXPECT_EQ(test.testRepeatedComplex()[0]->testFieldInt(), 25);
  461. EXPECT_EQ(test.testRepeatedComplex()[1]->testFieldInt(), 25);
  462. EXPECT_EQ(test.testRepeatedComplex()[2]->testFieldInt(), 25);
  463. EXPECT_STREQ(test.testRepeatedComplex()[0]->testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  464. EXPECT_STREQ(test.testRepeatedComplex()[1]->testComplexField().testFieldString().toStdString().c_str(), "");
  465. EXPECT_STREQ(test.testRepeatedComplex()[2]->testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  466. test.deserialize(serializer.get(), "{\"testRepeatedComplex\":[]}");
  467. EXPECT_TRUE(test.testRepeatedComplex().isEmpty());
  468. }
  469. TEST_F(JsonDeserializationTest, SimpleFixed32StringMapSerializeTest)
  470. {
  471. SimpleFixed32StringMapMessage test;
  472. test.deserialize(serializer.get(), "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\",\"0\":\"\"}}");
  473. ASSERT_EQ(test.mapField().size(), 4);
  474. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  475. EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
  476. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  477. EXPECT_STREQ(test.mapField()[0].toStdString().c_str(), "");
  478. }
  479. TEST_F(JsonDeserializationTest, SimpleSFixed32StringMapSerializeTest)
  480. {
  481. SimpleSFixed32StringMapMessage test;
  482. test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
  483. ASSERT_EQ(test.mapField().size(), 3);
  484. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  485. EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
  486. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  487. }
  488. TEST_F(JsonDeserializationTest, SimpleInt32StringMapSerializeTest)
  489. {
  490. SimpleInt32StringMapMessage test;
  491. test.deserialize(serializer.get(), "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
  492. ASSERT_EQ(test.mapField().size(), 3);
  493. EXPECT_STREQ(test.mapField()[-10].toStdString().c_str(), "minus ten");
  494. EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
  495. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  496. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  497. ASSERT_EQ(test.mapField().size(), 0);
  498. }
  499. TEST_F(JsonDeserializationTest, SimpleSInt32StringMapSerializeTest)
  500. {
  501. SimpleSInt32StringMapMessage test;
  502. test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
  503. ASSERT_EQ(test.mapField().size(), 3);
  504. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  505. EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
  506. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  507. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  508. ASSERT_EQ(test.mapField().size(), 0);
  509. }
  510. TEST_F(JsonDeserializationTest, SimpleUInt32StringMapSerializeTest)
  511. {
  512. SimpleUInt32StringMapMessage test;
  513. test.deserialize(serializer.get(), "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
  514. ASSERT_EQ(test.mapField().size(), 3);
  515. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  516. EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
  517. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  518. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  519. ASSERT_EQ(test.mapField().size(), 0);
  520. }
  521. TEST_F(JsonDeserializationTest, SimpleFixed64StringMapSerializeTest)
  522. {
  523. SimpleFixed64StringMapMessage test;
  524. test.deserialize(serializer.get(), "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
  525. ASSERT_EQ(test.mapField().size(), 3);
  526. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  527. EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
  528. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  529. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  530. ASSERT_EQ(test.mapField().size(), 0);
  531. }
  532. TEST_F(JsonDeserializationTest, SimpleSFixed64StringMapSerializeTest)
  533. {
  534. SimpleSFixed64StringMapMessage test;
  535. test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
  536. ASSERT_EQ(test.mapField().size(), 3);
  537. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  538. EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
  539. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  540. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  541. ASSERT_EQ(test.mapField().size(), 0);
  542. }
  543. TEST_F(JsonDeserializationTest, SimpleInt64StringMapSerializeTest)
  544. {
  545. SimpleInt64StringMapMessage test;
  546. test.deserialize(serializer.get(), "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
  547. ASSERT_EQ(test.mapField().size(), 3);
  548. EXPECT_STREQ(test.mapField()[-10].toStdString().c_str(), "minus ten");
  549. EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
  550. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  551. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  552. ASSERT_EQ(test.mapField().size(), 0);
  553. }
  554. TEST_F(JsonDeserializationTest, SimpleSInt64StringMapSerializeTest)
  555. {
  556. SimpleSInt64StringMapMessage test;
  557. test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
  558. ASSERT_EQ(test.mapField().size(), 3);
  559. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  560. EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
  561. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  562. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  563. ASSERT_EQ(test.mapField().size(), 0);
  564. }
  565. TEST_F(JsonDeserializationTest, SimpleUInt64StringMapSerializeTest)
  566. {
  567. SimpleUInt64StringMapMessage test;
  568. test.deserialize(serializer.get(), "{\"mapField\":{\"42\":\"fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
  569. ASSERT_EQ(test.mapField().size(), 3);
  570. EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
  571. EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
  572. EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
  573. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  574. ASSERT_EQ(test.mapField().size(), 0);
  575. }
  576. TEST_F(JsonDeserializationTest, SimpleStringStringMapSerializeTest)
  577. {
  578. SimpleStringStringMapMessage test;
  579. test.deserialize(serializer.get(), "{\"mapField\":{\"ben\":\"ten\",\"sweet\":\"fifteen\",\"what is the answer?\":\"fourty two\"}}");
  580. ASSERT_EQ(test.mapField().size(), 3);
  581. EXPECT_STREQ(test.mapField()["ben"].toStdString().c_str(), "ten");
  582. EXPECT_STREQ(test.mapField()["what is the answer?"].toStdString().c_str(), "fourty two");
  583. EXPECT_STREQ(test.mapField()["sweet"].toStdString().c_str(), "fifteen");
  584. test.deserialize(serializer.get(), "{\"mapField\":{}}");
  585. ASSERT_EQ(test.mapField().size(), 0);
  586. }
  587. }
  588. }