deserializationtest.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Viktor Kopp <vifactor@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 "deserializationtest.h"
  26. #include "simpletest.qpb.h"
  27. #include "qtprotobuf_global.qpb.h"
  28. using namespace qtprotobufnamespace::tests;
  29. using namespace QtProtobuf::tests;
  30. using namespace QtProtobuf;
  31. void DeserializationTest::SetUpTestCase()
  32. {
  33. //Register all types
  34. QtProtobuf::qRegisterProtobufTypes();
  35. qtprotobufnamespace::tests::qRegisterProtobufTypes();
  36. qtprotobufnamespace1::externaltests::qRegisterProtobufTypes();
  37. qtprotobufnamespace::tests::globalenums::qRegisterProtobufTypes();
  38. }
  39. void DeserializationTest::SetUp()
  40. {
  41. serializer.reset(new QProtobufSerializer);
  42. }
  43. TEST_F(DeserializationTest, FixedInt32MessageDeserializeTest)
  44. {
  45. SimpleFixedInt32Message test;
  46. test.deserialize(serializer.get(), QByteArray::fromHex("0d0f000000"));
  47. ASSERT_EQ(test.testFieldFixedInt32(), 15);
  48. test.deserialize(serializer.get(), QByteArray::fromHex("0d2c010000"));
  49. ASSERT_EQ(test.testFieldFixedInt32(), 300);
  50. test.deserialize(serializer.get(), QByteArray::fromHex("0d09000100"));
  51. ASSERT_EQ(test.testFieldFixedInt32(), 65545);
  52. test.deserialize(serializer.get(), QByteArray::fromHex("0d00000000"));
  53. ASSERT_EQ(test.testFieldFixedInt32(), 0);
  54. test.deserialize(serializer.get(), QByteArray::fromHex("0d2c010000"));
  55. ASSERT_EQ(test.testFieldFixedInt32(), 300);
  56. test.deserialize(serializer.get(), QByteArray::fromHex("0d00010000"));
  57. ASSERT_EQ(test.testFieldFixedInt32(), UINT8_MAX + 1);
  58. test.deserialize(serializer.get(), QByteArray::fromHex("0d00000100"));
  59. ASSERT_EQ(test.testFieldFixedInt32(), UINT16_MAX + 1);
  60. test.deserialize(serializer.get(), QByteArray::fromHex("0dff000000"));
  61. ASSERT_EQ(test.testFieldFixedInt32(), UINT8_MAX);
  62. test.deserialize(serializer.get(), QByteArray::fromHex("0dffff0000"));
  63. ASSERT_EQ(test.testFieldFixedInt32(), UINT16_MAX);
  64. test.deserialize(serializer.get(), QByteArray::fromHex("0dffffffff"));
  65. ASSERT_EQ(test.testFieldFixedInt32(), UINT32_MAX);
  66. }
  67. TEST_F(DeserializationTest, FixedInt64MessageDeserializeTest)
  68. {
  69. SimpleFixedInt64Message test;
  70. test.deserialize(serializer.get(), QByteArray::fromHex("090f00000000000000"));
  71. ASSERT_EQ(test.testFieldFixedInt64(), 15);
  72. test.deserialize(serializer.get(), QByteArray::fromHex("092c01000000000000"));
  73. ASSERT_EQ(test.testFieldFixedInt64(), 300);
  74. test.deserialize(serializer.get(), QByteArray::fromHex("090900010000000000"));
  75. ASSERT_EQ(test.testFieldFixedInt64(), 65545);
  76. test.deserialize(serializer.get(), QByteArray::fromHex("090000000000000000"));
  77. ASSERT_EQ(test.testFieldFixedInt64(), 0);
  78. test.deserialize(serializer.get(), QByteArray::fromHex("090001000000000000"));
  79. ASSERT_EQ(test.testFieldFixedInt64(), UINT8_MAX + 1);
  80. test.deserialize(serializer.get(), QByteArray::fromHex("090000010000000000"));
  81. ASSERT_EQ(test.testFieldFixedInt64(), UINT16_MAX + 1);
  82. test.deserialize(serializer.get(), QByteArray::fromHex("090000000001000000"));
  83. ASSERT_EQ(test.testFieldFixedInt64(), (unsigned long long)(UINT32_MAX) + 1);
  84. test.deserialize(serializer.get(), QByteArray::fromHex("09ff00000000000000"));
  85. ASSERT_EQ(test.testFieldFixedInt64(), UINT8_MAX);
  86. test.deserialize(serializer.get(), QByteArray::fromHex("09ffff000000000000"));
  87. ASSERT_EQ(test.testFieldFixedInt64(), UINT16_MAX);
  88. test.deserialize(serializer.get(), QByteArray::fromHex("09ffffffff00000000"));
  89. ASSERT_EQ(test.testFieldFixedInt64(), UINT32_MAX);
  90. test.deserialize(serializer.get(), QByteArray::fromHex("09ffffffffffffffff"));
  91. ASSERT_EQ(test.testFieldFixedInt64(), UINT64_MAX);
  92. }
  93. TEST_F(DeserializationTest, SFixedInt32MessageDeserializeTest)
  94. {
  95. SimpleSFixedInt32Message test;
  96. test.deserialize(serializer.get(), QByteArray::fromHex("0d0f000000"));
  97. ASSERT_EQ(test.testFieldFixedInt32(), 15);
  98. test.deserialize(serializer.get(), QByteArray::fromHex("0d2c010000"));
  99. ASSERT_EQ(test.testFieldFixedInt32(), 300);
  100. test.deserialize(serializer.get(), QByteArray::fromHex("0d09000100"));
  101. ASSERT_EQ(test.testFieldFixedInt32(), 65545);
  102. test.deserialize(serializer.get(), QByteArray::fromHex("0d00000000"));
  103. ASSERT_EQ(test.testFieldFixedInt32(), 0);
  104. test.deserialize(serializer.get(), QByteArray::fromHex("0d2c010000"));
  105. ASSERT_EQ(test.testFieldFixedInt32(), 300);
  106. test.deserialize(serializer.get(), QByteArray::fromHex("0d80000000"));
  107. ASSERT_EQ(test.testFieldFixedInt32(), INT8_MAX + 1);
  108. test.deserialize(serializer.get(), QByteArray::fromHex("0d00800000"));
  109. ASSERT_EQ(test.testFieldFixedInt32(), INT16_MAX + 1);
  110. test.deserialize(serializer.get(), QByteArray::fromHex("0d7f000000"));
  111. ASSERT_EQ(test.testFieldFixedInt32(), INT8_MAX);
  112. test.deserialize(serializer.get(), QByteArray::fromHex("0dff7f0000"));
  113. ASSERT_EQ(test.testFieldFixedInt32(), INT16_MAX);
  114. test.deserialize(serializer.get(), QByteArray::fromHex("0dffffff7f"));
  115. ASSERT_EQ(test.testFieldFixedInt32(), INT32_MAX);
  116. test.deserialize(serializer.get(), QByteArray::fromHex("0d7fffffff"));
  117. ASSERT_EQ(test.testFieldFixedInt32(), INT8_MIN - 1);
  118. test.deserialize(serializer.get(), QByteArray::fromHex("0dff7fffff"));
  119. ASSERT_EQ(test.testFieldFixedInt32(), INT16_MIN - 1);
  120. test.deserialize(serializer.get(), QByteArray::fromHex("0d80ffffff"));
  121. ASSERT_EQ(test.testFieldFixedInt32(), INT8_MIN);
  122. test.deserialize(serializer.get(), QByteArray::fromHex("0d0080ffff"));
  123. ASSERT_EQ(test.testFieldFixedInt32(), INT16_MIN);
  124. test.deserialize(serializer.get(), QByteArray::fromHex("0d00000080"));
  125. ASSERT_EQ(test.testFieldFixedInt32(), INT32_MIN);
  126. }
  127. TEST_F(DeserializationTest, SFixedInt64MessageDeserializeTest)
  128. {
  129. SimpleSFixedInt64Message test;
  130. test.deserialize(serializer.get(), QByteArray::fromHex("090f00000000000000"));
  131. ASSERT_EQ(test.testFieldFixedInt64(), 15);
  132. test.deserialize(serializer.get(), QByteArray::fromHex("092c01000000000000"));
  133. ASSERT_EQ(test.testFieldFixedInt64(), 300);
  134. test.deserialize(serializer.get(), QByteArray::fromHex("090900010000000000"));
  135. ASSERT_EQ(test.testFieldFixedInt64(), 65545);
  136. test.deserialize(serializer.get(), QByteArray::fromHex("090000000000000000"));
  137. ASSERT_EQ(test.testFieldFixedInt64(), 0);
  138. test.deserialize(serializer.get(), QByteArray::fromHex("098000000000000000"));
  139. ASSERT_EQ(test.testFieldFixedInt64(), INT8_MAX + 1);
  140. test.deserialize(serializer.get(), QByteArray::fromHex("090080000000000000"));
  141. ASSERT_EQ(test.testFieldFixedInt64(), INT16_MAX + 1);
  142. test.deserialize(serializer.get(), QByteArray::fromHex("090000008000000000"));
  143. ASSERT_EQ(test.testFieldFixedInt64(), (unsigned long long)(INT32_MAX) + 1);
  144. test.deserialize(serializer.get(), QByteArray::fromHex("097f00000000000000"));
  145. ASSERT_EQ(test.testFieldFixedInt64(), INT8_MAX);
  146. test.deserialize(serializer.get(), QByteArray::fromHex("09ff7f000000000000"));
  147. ASSERT_EQ(test.testFieldFixedInt64(), INT16_MAX);
  148. test.deserialize(serializer.get(), QByteArray::fromHex("09ffffff7f00000000"));
  149. ASSERT_EQ(test.testFieldFixedInt64(), INT32_MAX);
  150. test.deserialize(serializer.get(), QByteArray::fromHex("09ffffffffffffff7f"));
  151. ASSERT_EQ(test.testFieldFixedInt64(), INT64_MAX);
  152. test.deserialize(serializer.get(), QByteArray::fromHex("097fffffffffffffff"));
  153. ASSERT_EQ(test.testFieldFixedInt64(), INT8_MIN - 1);
  154. test.deserialize(serializer.get(), QByteArray::fromHex("09ff7fffffffffffff"));
  155. ASSERT_EQ(test.testFieldFixedInt64(), INT16_MIN - 1);
  156. test.deserialize(serializer.get(), QByteArray::fromHex("09ffffff7fffffffff"));
  157. ASSERT_EQ(test.testFieldFixedInt64(), (qlonglong)INT32_MIN - 1);
  158. test.deserialize(serializer.get(), QByteArray::fromHex("0980ffffffffffffff"));
  159. ASSERT_EQ(test.testFieldFixedInt64(), INT8_MIN);
  160. test.deserialize(serializer.get(), QByteArray::fromHex("090080ffffffffffff"));
  161. ASSERT_EQ(test.testFieldFixedInt64(), INT16_MIN);
  162. test.deserialize(serializer.get(), QByteArray::fromHex("0900000080ffffffff"));
  163. ASSERT_EQ(test.testFieldFixedInt64(), INT32_MIN);
  164. test.deserialize(serializer.get(), QByteArray::fromHex("090000000000000080"));
  165. ASSERT_EQ(test.testFieldFixedInt64(), INT64_MIN);
  166. }
  167. TEST_F(DeserializationTest, FloatMessageDeserializeTest)
  168. {
  169. SimpleFloatMessage test;
  170. test.deserialize(serializer.get(), QByteArray::fromHex("3dcdcccc3d"));
  171. ASSERT_FLOAT_EQ(test.testFieldFloat(), 0.1f);
  172. test.deserialize(serializer.get(), QByteArray::fromHex("3d00008000"));
  173. ASSERT_FLOAT_EQ(test.testFieldFloat(), FLT_MIN);
  174. test.deserialize(serializer.get(), QByteArray::fromHex("3dffff7f7f"));
  175. ASSERT_FLOAT_EQ(test.testFieldFloat(), FLT_MAX);
  176. test.deserialize(serializer.get(), QByteArray::fromHex("3d666686c0"));
  177. ASSERT_FLOAT_EQ(test.testFieldFloat(), -4.2f);
  178. test.deserialize(serializer.get(), QByteArray::fromHex("3d00000000"));
  179. ASSERT_FLOAT_EQ(test.testFieldFloat(), -0.0f);
  180. }
  181. TEST_F(DeserializationTest, DoubleMessageDeserializeTest)
  182. {
  183. SimpleDoubleMessage test;
  184. test.deserialize(serializer.get(), QByteArray::fromHex("419a9999999999b93f"));
  185. ASSERT_DOUBLE_EQ(0.1, test.testFieldDouble());
  186. test.deserialize(serializer.get(), QByteArray::fromHex("410000000000001000"));
  187. ASSERT_DOUBLE_EQ(DBL_MIN, test.testFieldDouble());
  188. test.deserialize(serializer.get(), QByteArray::fromHex("41ffffffffffffef7f"));
  189. ASSERT_DOUBLE_EQ(DBL_MAX, test.testFieldDouble());
  190. test.deserialize(serializer.get(), QByteArray::fromHex("41cdcccccccccc10c0"));
  191. ASSERT_DOUBLE_EQ(-4.2, test.testFieldDouble());
  192. test.deserialize(serializer.get(), QByteArray::fromHex("410000000000000000"));
  193. ASSERT_DOUBLE_EQ(0.0, test.testFieldDouble());
  194. }
  195. TEST_F(DeserializationTest, IntMessageDeserializeTest)
  196. {
  197. SimpleIntMessage test;
  198. test.deserialize(serializer.get(), QByteArray::fromHex("080f"));
  199. ASSERT_EQ(15, test.testFieldInt());
  200. test.deserialize(serializer.get(), QByteArray::fromHex("08ac02"));
  201. ASSERT_EQ(300, test.testFieldInt());
  202. test.deserialize(serializer.get(), QByteArray::fromHex("08898004"));
  203. ASSERT_EQ(65545, test.testFieldInt());
  204. //FIXME: bug#68
  205. //test.deserialize(serializer.get(), QByteArray::fromHex(""));
  206. //ASSERT_EQ(0, test.testFieldInt());
  207. test.deserialize(serializer.get(), QByteArray::fromHex("088001"));
  208. ASSERT_EQ(INT8_MAX + 1, test.testFieldInt());
  209. test.deserialize(serializer.get(), QByteArray::fromHex("08808002"));
  210. ASSERT_EQ(INT16_MAX + 1, test.testFieldInt());
  211. test.deserialize(serializer.get(), QByteArray::fromHex("087f"));
  212. ASSERT_EQ(INT8_MAX, test.testFieldInt());
  213. test.deserialize(serializer.get(), QByteArray::fromHex("08ffff01"));
  214. ASSERT_EQ(INT16_MAX, test.testFieldInt());
  215. test.deserialize(serializer.get(), QByteArray::fromHex("08ffffffff07"));
  216. ASSERT_EQ(INT32_MAX, test.testFieldInt());
  217. test.deserialize(serializer.get(), QByteArray::fromHex("08ffffffffffffffffff01"));
  218. ASSERT_EQ(-1, test.testFieldInt());
  219. test.deserialize(serializer.get(), QByteArray::fromHex("08b2fcffffffffffffff01"));
  220. ASSERT_EQ(-462, test.testFieldInt());
  221. test.deserialize(serializer.get(), QByteArray::fromHex("089f8ffcffffffffffff01"));
  222. ASSERT_EQ(-63585, test.testFieldInt());
  223. test.deserialize(serializer.get(), QByteArray::fromHex("0880ffffffffffffffff01"));
  224. ASSERT_EQ(INT8_MIN, test.testFieldInt());
  225. test.deserialize(serializer.get(), QByteArray::fromHex("088080feffffffffffff01"));
  226. ASSERT_EQ(INT16_MIN, test.testFieldInt());
  227. test.deserialize(serializer.get(), QByteArray::fromHex("0880808080f8ffffffff01"));
  228. ASSERT_EQ(INT32_MIN, test.testFieldInt());
  229. test.deserialize(serializer.get(), QByteArray::fromHex("08fffeffffffffffffff01"));
  230. ASSERT_EQ(INT8_MIN - 1, test.testFieldInt());
  231. test.deserialize(serializer.get(), QByteArray::fromHex("08fffffdffffffffffff01"));
  232. ASSERT_EQ(INT16_MIN - 1, test.testFieldInt());
  233. }
  234. TEST_F(DeserializationTest, StringMessageDeserializeTest)
  235. {
  236. SimpleStringMessage test;
  237. test.deserialize(serializer.get(), QByteArray::fromHex("3206717765727479"));
  238. ASSERT_STREQ("qwerty", test.testFieldString().toStdString().c_str());
  239. test.deserialize(serializer.get(), QByteArray::fromHex("3280046f6570534e4c4956473038554a706b3257374a74546b6b4278794b303658306c51364d4c37494d6435354b3858433154707363316b4457796d3576387a3638623446517570394f393551536741766a48494131354f583642753638657362514654394c507a5341444a367153474254594248583551535a67333274724364484d6a383058754448717942674d34756636524b71326d675762384f76787872304e774c786a484f66684a384d726664325237686255676a65737062596f5168626748456a32674b45563351766e756d596d7256586531426b437a5a684b56586f6444686a304f6641453637766941793469334f6167316872317a34417a6f384f3558713638504f455a3143735a506f3244584e4e52386562564364594f7a3051364a4c50536c356a61734c434672514e374569564e6a516d437253735a4852674c4e796c76676f454678475978584a39676d4b346d72304f47645a63474a4f5252475a4f514370514d68586d68657a46616c4e494a584d50505861525658695268524150434e55456965384474614357414d717a346e4e5578524d5a355563584258735850736879677a6b7979586e4e575449446f6a466c7263736e4b71536b5131473645383567535a6274495942683773714f36474458486a4f72585661564356435575626a634a4b54686c79736c7432397a48754973354a47707058785831"));
  240. ASSERT_STREQ("oepSNLIVG08UJpk2W7JtTkkBxyK06X0lQ6ML7IMd55K8XC1Tpsc1kDWym5v8z68b4FQup9O95QSgAvjHIA15OX6Bu68esbQFT9LPzSADJ6qSGBTYBHX5QSZg32trCdHMj80XuDHqyBgM4uf6RKq2mgWb8Ovxxr0NwLxjHOfhJ8Mrfd2R7hbUgjespbYoQhbgHEj2gKEV3QvnumYmrVXe1BkCzZhKVXodDhj0OfAE67viAy4i3Oag1hr1z4Azo8O5Xq68POEZ1CsZPo2DXNNR8ebVCdYOz0Q6JLPSl5jasLCFrQN7EiVNjQmCrSsZHRgLNylvgoEFxGYxXJ9gmK4mr0OGdZcGJORRGZOQCpQMhXmhezFalNIJXMPPXaRVXiRhRAPCNUEie8DtaCWAMqz4nNUxRMZ5UcXBXsXPshygzkyyXnNWTIDojFlrcsnKqSkQ1G6E85gSZbtIYBh7sqO6GDXHjOrXVaVCVCUubjcJKThlyslt29zHuIs5JGppXxX1", test.testFieldString().toStdString().c_str());
  241. }
  242. TEST_F(DeserializationTest, ComplexTypeDeserializeTest)
  243. {
  244. ComplexMessage test;
  245. test.deserialize(serializer.get(), QByteArray::fromHex("1208320671776572747908d3ffffffffffffffff01"));
  246. ASSERT_EQ(-45, test.testFieldInt());
  247. ASSERT_TRUE(QString::fromUtf8("qwerty") == test.testComplexField().testFieldString());
  248. test.deserialize(serializer.get(), QByteArray::fromHex("08d3ffffffffffffffff0112083206717765727479"));
  249. ASSERT_EQ(-45, test.testFieldInt());
  250. ASSERT_TRUE(QString::fromUtf8("qwerty") == test.testComplexField().testFieldString());
  251. test.deserialize(serializer.get(), QByteArray::fromHex("128404328104595652664a766a78716267764677533159764f5a5867746a356666474c533741694e487a396f5a496f4b626d377a3848373978427579506b70515876476f4f30394f5939785261777833654f417339786a6f544131784a68727732385441637131436562596c43395755665143366849616e74614e647948694b546f666669305a74376c613432535278585a53503447757862635a49703533704a6e79437766437931716446637a5430646d6e3768386670794164656d456176774665646134643050417047665355326a4c74333958386b595542784e4d325767414c524267486456646538377136506935553639546a684d6432385731534644314478796f67434372714f6374325a5049436f4c6e72716446334f644e7a6a52564c6665797651384c674c76524e4652395766574179417a37396e4b6742616d64384e746c7674344d6733354535675653326737415137726b6d37326342646e5739734345794761626558417548356a34475262754c543771425a574463464c463453734364533357664647644e48667761696a7a796b42796f3731507646566c54584832574a576f4676523546414c6a42546e37624364503070416953624c435938587a324d73633364426235466639474953506255704e6d557642644d5a4d485176714f6d544e584550704e306237344d444f4d5166574a53684f6f334e6b41764d6a73082a"));
  252. ASSERT_EQ(42, test.testFieldInt());
  253. ASSERT_TRUE(QString::fromUtf8("YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs") == test.testComplexField().testFieldString());
  254. test.deserialize(serializer.get(), QByteArray::fromHex("082a128404328104595652664a766a78716267764677533159764f5a5867746a356666474c533741694e487a396f5a496f4b626d377a3848373978427579506b70515876476f4f30394f5939785261777833654f417339786a6f544131784a68727732385441637131436562596c43395755665143366849616e74614e647948694b546f666669305a74376c613432535278585a53503447757862635a49703533704a6e79437766437931716446637a5430646d6e3768386670794164656d456176774665646134643050417047665355326a4c74333958386b595542784e4d325767414c524267486456646538377136506935553639546a684d6432385731534644314478796f67434372714f6374325a5049436f4c6e72716446334f644e7a6a52564c6665797651384c674c76524e4652395766574179417a37396e4b6742616d64384e746c7674344d6733354535675653326737415137726b6d37326342646e5739734345794761626558417548356a34475262754c543771425a574463464c463453734364533357664647644e48667761696a7a796b42796f3731507646566c54584832574a576f4676523546414c6a42546e37624364503070416953624c435938587a324d73633364426235466639474953506255704e6d557642644d5a4d485176714f6d544e584550704e306237344d444f4d5166574a53684f6f334e6b41764d6a73"));
  255. ASSERT_EQ(42, test.testFieldInt());
  256. ASSERT_TRUE(QString::fromUtf8("YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs") == test.testComplexField().testFieldString());
  257. }
  258. TEST_F(DeserializationTest, RepeatedStringMessageTest)
  259. {
  260. RepeatedStringMessage test;
  261. test.deserialize(serializer.get(), QByteArray::fromHex("0a04616161610a0562626262620a036363630a066464646464640a056565656565"));
  262. ASSERT_EQ(5, test.testRepeatedString().count());
  263. ASSERT_TRUE(test.testRepeatedString() == QStringList({"aaaa","bbbbb","ccc","dddddd","eeeee"}));
  264. }
  265. TEST_F(DeserializationTest, RepeatedBytesMessageTest)
  266. {
  267. RepeatedBytesMessage test;
  268. test.deserialize(serializer.get(), QByteArray::fromHex("0a060102030405060a04ffffffff0a05eaeaeaeaea0a06010203040506"));
  269. ASSERT_EQ(4, test.testRepeatedBytes().count());
  270. ASSERT_TRUE(test.testRepeatedBytes() == QByteArrayList({QByteArray::fromHex("010203040506"),
  271. QByteArray::fromHex("ffffffff"),
  272. QByteArray::fromHex("eaeaeaeaea"),
  273. QByteArray::fromHex("010203040506")}));
  274. //TODO: Serialization for list types works partially incorrect because of appending of values to existing
  275. //Need to make decision if deserialize should reset all protobuf properties or not
  276. RepeatedBytesMessage test2;
  277. test2.deserialize(serializer.get(), QByteArray::fromHex("0a060102030405060a000a05eaeaeaeaea0a06010203040506"));
  278. ASSERT_EQ(4, test2.testRepeatedBytes().count());
  279. ASSERT_TRUE(test2.testRepeatedBytes() == QByteArrayList({QByteArray::fromHex("010203040506"),
  280. QByteArray::fromHex(""),
  281. QByteArray::fromHex("eaeaeaeaea"),
  282. QByteArray::fromHex("010203040506")}));
  283. }
  284. TEST_F(DeserializationTest, RepeatedFloatMessageTest)
  285. {
  286. RepeatedFloatMessage test;
  287. test.deserialize(serializer.get(), QByteArray::fromHex("0a14cdcccc3e9a99993f0000003f3333b33f9a99193f"));
  288. ASSERT_EQ(5, test.testRepeatedFloat().count());
  289. ASSERT_TRUE(test.testRepeatedFloat() == FloatList({0.4f, 1.2f, 0.5f, 1.4f, 0.6f}));
  290. }
  291. TEST_F(DeserializationTest, RepeatedDoubleMessageTest)
  292. {
  293. RepeatedDoubleMessage test;
  294. test.deserialize(serializer.get(), QByteArray::fromHex("0a289a9999999999b93f9a9999999999c93f333333333333d33f9a9999999999d93f000000000000e03f"));
  295. ASSERT_EQ(5, test.testRepeatedDouble().count());
  296. ASSERT_TRUE(test.testRepeatedDouble() == DoubleList({0.1, 0.2, 0.3, 0.4, 0.5}));
  297. }
  298. TEST_F(DeserializationTest, RepeatedIntMessageTest)
  299. {
  300. RepeatedIntMessage test;
  301. test.deserialize(serializer.get(), QByteArray::fromHex("0a1101c102b1fcfbff0fedc207fdffffff0f03"));
  302. ASSERT_EQ(6, test.testRepeatedInt().count());
  303. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 321, -65999, 123245, -3, 3}));
  304. RepeatedIntMessage test2;
  305. test2.deserialize(serializer.get(), QByteArray::fromHex("0a1b01c102b1fcfbffffffffffff01edc207fdffffffffffffffff0103"));
  306. ASSERT_EQ(6, test2.testRepeatedInt().count());
  307. ASSERT_TRUE(test2.testRepeatedInt() == int32List({1, 321, -65999, 123245, -3, 3}));
  308. }
  309. TEST_F(DeserializationTest, RepeatedSIntMessageTest)
  310. {
  311. RepeatedSIntMessage test;
  312. test.deserialize(serializer.get(), QByteArray::fromHex("0a0b0282059d8708da850f0506"));
  313. ASSERT_EQ(6, test.testRepeatedInt().count());
  314. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 321, -65999, 123245, -3, 3}));
  315. }
  316. TEST_F(DeserializationTest, RepeatedUIntMessageTest)
  317. {
  318. RepeatedUIntMessage test;
  319. test.deserialize(serializer.get(), QByteArray::fromHex("0a0a01c102cf8304edc20703"));
  320. ASSERT_EQ(5, test.testRepeatedInt().count());
  321. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 321, 65999, 123245, 3}));
  322. }
  323. TEST_F(DeserializationTest, RepeatedInt64MessageTest)
  324. {
  325. RepeatedInt64Message test;
  326. test.deserialize(serializer.get(), QByteArray::fromHex("0a1f01c102b1fcfbffffffffffff01b3c3cab6d8e602fdffffffffffffffff0103"));
  327. ASSERT_EQ(6, test.testRepeatedInt().count());
  328. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 321, -65999, 12324523123123, -3, 3}));
  329. }
  330. TEST_F(DeserializationTest, RepeatedSInt64MessageTest)
  331. {
  332. RepeatedSInt64Message test;
  333. test.deserialize(serializer.get(), QByteArray::fromHex("0a0f0282059d8708e68695edb0cd050506"));
  334. ASSERT_EQ(6, test.testRepeatedInt().count());
  335. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 321, -65999, 12324523123123, -3, 3}));
  336. }
  337. TEST_F(DeserializationTest, RepeatedUInt64MessageTest)
  338. {
  339. RepeatedUInt64Message test;
  340. test.deserialize(serializer.get(), QByteArray::fromHex("0a1301c102cf8304edc207d28b9fda82dff6da0103"));
  341. ASSERT_EQ(6, test.testRepeatedInt().count());
  342. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 321, 65999, 123245, 123245324235425234, 3}));
  343. }
  344. TEST_F(DeserializationTest, RepeatedFixedIntMessageTest)
  345. {
  346. RepeatedFixedIntMessage test;
  347. test.deserialize(serializer.get(), QByteArray::fromHex("0a180100000041010000cf010100ab0ebc000300000003000000"));
  348. ASSERT_EQ(6, test.testRepeatedInt().count());
  349. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 321, 65999, 12324523, 3, 3}));
  350. }
  351. TEST_F(DeserializationTest, RepeatedSFixedIntMessageTest)
  352. {
  353. RepeatedSFixedIntMessage test;
  354. test.deserialize(serializer.get(), QByteArray::fromHex("0a18010000004101000031fefeffab0ebc00fdffffff03000000"));
  355. ASSERT_EQ(6, test.testRepeatedInt().count());
  356. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 321, -65999, 12324523, -3, 3}));
  357. }
  358. TEST_F(DeserializationTest, RepeatedFixedInt64MessageTest)
  359. {
  360. RepeatedFixedInt64Message test;
  361. test.deserialize(serializer.get(), QByteArray::fromHex("0a3001000000000000004101000000000000cf01010000000000d2c5472bf8dab50103000000000000000300000000000000"));
  362. ASSERT_EQ(6, test.testRepeatedInt().count());
  363. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 321, 65999, 123245324235425234, 3, 3}));
  364. }
  365. TEST_F(DeserializationTest, RepeatedSFixedInt64MessageTest)
  366. {
  367. RepeatedSFixedInt64Message test;
  368. test.deserialize(serializer.get(), QByteArray::fromHex("0a300100000000000000410100000000000031fefeffffffffffd2c5472bf8dab501fdffffffffffffff0300000000000000"));
  369. ASSERT_EQ(6, test.testRepeatedInt().count());
  370. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 321, -65999, 123245324235425234, -3, 3}));
  371. }
  372. TEST_F(DeserializationTest, RepeatedComplexMessageTest)
  373. {
  374. RepeatedComplexMessage test;
  375. test.deserialize(serializer.get(), QByteArray::fromHex("0a0c0819120832067177657274790a0c0819120832067177657274790a0c081912083206717765727479"));
  376. ASSERT_EQ(3, test.testRepeatedComplex().count());
  377. ASSERT_EQ(25, test.testRepeatedComplex().at(0)->testFieldInt());
  378. ASSERT_TRUE(test.testRepeatedComplex().at(0)->testComplexField().testFieldString() == QString("qwerty"));
  379. ASSERT_EQ(25, test.testRepeatedComplex().at(1)->testFieldInt());
  380. ASSERT_TRUE(test.testRepeatedComplex().at(1)->testComplexField().testFieldString() == QString("qwerty"));
  381. ASSERT_EQ(25, test.testRepeatedComplex().at(2)->testFieldInt());
  382. ASSERT_TRUE(test.testRepeatedComplex().at(2)->testComplexField().testFieldString() == QString("qwerty"));
  383. //FIXME: This setter should not be called in this test. See bug#69
  384. test.setTestRepeatedComplex({});
  385. test.deserialize(serializer.get(), QByteArray::fromHex("0a1508d3feffffffffffffff0112083206717765727479"));
  386. ASSERT_LT(0, test.testRepeatedComplex().count());
  387. ASSERT_EQ(-173, test.testRepeatedComplex().at(0)->testFieldInt());
  388. ASSERT_TRUE(test.testRepeatedComplex().at(0)->testComplexField().testFieldString() == QString("qwerty"));
  389. }
  390. TEST_F(DeserializationTest, SIntMessageDeserializeTest)
  391. {
  392. SimpleSIntMessage test;
  393. test.deserialize(serializer.get(), QByteArray::fromHex("081e"));
  394. ASSERT_EQ(15, test.testFieldInt());
  395. test.deserialize(serializer.get(), QByteArray::fromHex("08d804"));
  396. ASSERT_EQ(300, test.testFieldInt());
  397. test.deserialize(serializer.get(), QByteArray::fromHex("08928008"));
  398. ASSERT_EQ(65545, test.testFieldInt());
  399. //FIXME: bug#68
  400. //test.deserialize(serializer.get(), QByteArray::fromHex(""));
  401. //ASSERT_EQ(0, test.testFieldInt());
  402. test.deserialize(serializer.get(), QByteArray::fromHex("088002"));
  403. ASSERT_EQ(INT8_MAX + 1, test.testFieldInt());
  404. test.deserialize(serializer.get(), QByteArray::fromHex("08808004"));
  405. ASSERT_EQ(INT16_MAX + 1, test.testFieldInt());
  406. test.deserialize(serializer.get(), QByteArray::fromHex("08fe01"));
  407. ASSERT_EQ(INT8_MAX, test.testFieldInt());
  408. test.deserialize(serializer.get(), QByteArray::fromHex("08feff03"));
  409. ASSERT_EQ(INT16_MAX, test.testFieldInt());
  410. test.deserialize(serializer.get(), QByteArray::fromHex("08feffffff0f"));
  411. ASSERT_EQ(INT32_MAX, test.testFieldInt());
  412. test.deserialize(serializer.get(), QByteArray::fromHex("0801"));
  413. ASSERT_EQ(-1, test.testFieldInt());
  414. test.deserialize(serializer.get(), QByteArray::fromHex("089b07"));
  415. ASSERT_EQ(-462, test.testFieldInt());
  416. test.deserialize(serializer.get(), QByteArray::fromHex("08c1e107"));
  417. ASSERT_EQ(-63585, test.testFieldInt());
  418. test.deserialize(serializer.get(), QByteArray::fromHex("08ff01"));
  419. ASSERT_EQ(INT8_MIN, test.testFieldInt());
  420. test.deserialize(serializer.get(), QByteArray::fromHex("08ffff03"));
  421. ASSERT_EQ(INT16_MIN, test.testFieldInt());
  422. test.deserialize(serializer.get(), QByteArray::fromHex("08ffffffff0f"));
  423. ASSERT_EQ(INT32_MIN, test.testFieldInt());
  424. test.deserialize(serializer.get(), QByteArray::fromHex("088102"));
  425. ASSERT_EQ(INT8_MIN - 1, test.testFieldInt());
  426. test.deserialize(serializer.get(), QByteArray::fromHex("08818004"));
  427. ASSERT_EQ(INT16_MIN - 1, test.testFieldInt());
  428. }
  429. TEST_F(DeserializationTest, UIntMessageDeserializeTest)
  430. {
  431. SimpleUIntMessage test;
  432. test.deserialize(serializer.get(), QByteArray::fromHex("080f"));
  433. ASSERT_EQ(15, test.testFieldInt());
  434. test.deserialize(serializer.get(), QByteArray::fromHex("08ac02"));
  435. ASSERT_EQ(300, test.testFieldInt());
  436. test.deserialize(serializer.get(), QByteArray::fromHex("08898004"));
  437. ASSERT_EQ(65545, test.testFieldInt());
  438. //FIXME: bug#68
  439. //test.deserialize(serializer.get(), QByteArray::fromHex(""));
  440. //ASSERT_EQ(0, test.testFieldInt());
  441. test.deserialize(serializer.get(), QByteArray::fromHex("088002"));
  442. ASSERT_EQ(UINT8_MAX + 1, test.testFieldInt());
  443. test.deserialize(serializer.get(), QByteArray::fromHex("08808004"));
  444. ASSERT_EQ(UINT16_MAX + 1, test.testFieldInt());
  445. test.deserialize(serializer.get(), QByteArray::fromHex("08ff01"));
  446. ASSERT_EQ(UINT8_MAX, test.testFieldInt());
  447. test.deserialize(serializer.get(), QByteArray::fromHex("08ffff03"));
  448. ASSERT_EQ(UINT16_MAX, test.testFieldInt());
  449. test.deserialize(serializer.get(), QByteArray::fromHex("08ffffffff0f"));
  450. ASSERT_EQ(UINT32_MAX, test.testFieldInt());
  451. }
  452. TEST_F(DeserializationTest, BoolDeserializeTest)
  453. {
  454. SimpleBoolMessage test;
  455. test.deserialize(serializer.get(), QByteArray::fromHex("0801"));
  456. ASSERT_EQ(test.testFieldBool(), true);
  457. //FIXME: bug#68
  458. //test.deserialize(serializer.get(), QByteArray::fromHex(""));
  459. test.deserialize(serializer.get(), QByteArray::fromHex("0800"));
  460. ASSERT_EQ(test.testFieldBool(), false);
  461. }
  462. TEST_F(DeserializationTest, SimpleEnumMessageDeserializeTest)
  463. {
  464. SimpleEnumMessage test;
  465. test.deserialize(serializer.get(), QByteArray::fromHex("0803"));
  466. ASSERT_EQ(test.localEnum(), SimpleEnumMessage::LOCAL_ENUM_VALUE3);
  467. }
  468. TEST_F(DeserializationTest, SimpleFixed32StringMapDeserializeTest)
  469. {
  470. SimpleFixed32StringMapMessage test;
  471. test.deserialize(serializer.get(), QByteArray::fromHex("3a0a0d0a000000120374656e3a0e0d0f00000012076669667465656e3a110d2a000000120a666f757274792074776f"));
  472. ASSERT_TRUE(test.mapField() == SimpleFixed32StringMapMessage::MapFieldEntry({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}}));
  473. }
  474. TEST_F(DeserializationTest, SimpleSFixed32StringMapDeserializeTest)
  475. {
  476. SimpleSFixed32StringMapMessage test;
  477. test.deserialize(serializer.get(), QByteArray::fromHex("4a170dd6ffffff12106d696e757320666f757274792074776f4a0a0d0a000000120374656e4a0e0d0f00000012076669667465656e"));
  478. ASSERT_TRUE(test.mapField() == SimpleSFixed32StringMapMessage::MapFieldEntry({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}}));
  479. }
  480. TEST_F(DeserializationTest, SimpleInt32StringMapDeserializeTest)
  481. {
  482. SimpleInt32StringMapMessage test;
  483. test.deserialize(serializer.get(), QByteArray::fromHex("1a1608f6ffffffffffffffff0112096d696e75732074656e1a0b080f12076669667465656e1a0e082a120a666f757274792074776f"));
  484. ASSERT_TRUE(test.mapField() == SimpleInt32StringMapMessage::MapFieldEntry({{-10, {"minus ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}}));
  485. }
  486. TEST_F(DeserializationTest, SimpleSInt32StringMapDeserializeTest)
  487. {
  488. SimpleSInt32StringMapMessage test;
  489. test.deserialize(serializer.get(), QByteArray::fromHex("0a14085312106d696e757320666f757274792074776f0a070814120374656e0a0b081e12076669667465656e"));
  490. ASSERT_TRUE(test.mapField() == SimpleSInt32StringMapMessage::MapFieldEntry({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}}));
  491. }
  492. TEST_F(DeserializationTest, SimpleUInt32StringMapDeserializeTest)
  493. {
  494. SimpleUInt32StringMapMessage test;
  495. test.deserialize(serializer.get(), QByteArray::fromHex("2a07080a120374656e2a0b080f12076669667465656e2a0e082a120a666f757274792074776f"));
  496. ASSERT_TRUE(test.mapField() == SimpleUInt32StringMapMessage::MapFieldEntry({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}}));
  497. }
  498. TEST_F(DeserializationTest, SimpleFixed64StringMapDeserializeTest)
  499. {
  500. SimpleFixed64StringMapMessage test;
  501. test.deserialize(serializer.get(), QByteArray::fromHex("420e090a00000000000000120374656e4212090f0000000000000012076669667465656e4215092a00000000000000120a666f757274792074776f"));
  502. ASSERT_TRUE(test.mapField() == SimpleFixed64StringMapMessage::MapFieldEntry({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}}));
  503. }
  504. TEST_F(DeserializationTest, SimpleSFixed64StringMapDeserializeTest)
  505. {
  506. SimpleSFixed64StringMapMessage test;
  507. test.deserialize(serializer.get(), QByteArray::fromHex("521b09d6ffffffffffffff12106d696e757320666f757274792074776f520e090a00000000000000120374656e5212090f0000000000000012076669667465656e"));
  508. ASSERT_TRUE(test.mapField() == SimpleSFixed64StringMapMessage::MapFieldEntry({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}}));
  509. }
  510. TEST_F(DeserializationTest, SimpleInt64StringMapDeserializeTest)
  511. {
  512. SimpleInt64StringMapMessage test;
  513. test.deserialize(serializer.get(), QByteArray::fromHex("221608f6ffffffffffffffff0112096d696e75732074656e220b080f12076669667465656e220e082a120a666f757274792074776f"));
  514. ASSERT_TRUE(test.mapField() == SimpleInt64StringMapMessage::MapFieldEntry({{-10, {"minus ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}}));
  515. }
  516. TEST_F(DeserializationTest, SimpleSInt64StringMapDeserializeTest)
  517. {
  518. SimpleSInt64StringMapMessage test;
  519. test.deserialize(serializer.get(), QByteArray::fromHex("1214085312106d696e757320666f757274792074776f12070814120374656e120b081e12076669667465656e"));
  520. ASSERT_TRUE(test.mapField() == SimpleSInt64StringMapMessage::MapFieldEntry({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}}));
  521. }
  522. TEST_F(DeserializationTest, SimpleUInt64StringMapDeserializeTest)
  523. {
  524. SimpleUInt64StringMapMessage test;
  525. test.deserialize(serializer.get(), QByteArray::fromHex("3207080a120374656e320b080f12076669667465656e320e082a120a666f757274792074776f"));
  526. ASSERT_TRUE(test.mapField() == SimpleUInt64StringMapMessage::MapFieldEntry({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}}));
  527. }
  528. TEST_F(DeserializationTest, SimpleStringStringMapDeserializeTest)
  529. {
  530. SimpleStringStringMapMessage test;
  531. test.deserialize(serializer.get(), QByteArray::fromHex("6a0a0a0362656e120374656e6a100a05737765657412076669667465656e6a210a13776861742069732074686520616e737765723f120a666f757274792074776f"));
  532. ASSERT_TRUE(test.mapField() == SimpleStringStringMapMessage::MapFieldEntry({{"ben", "ten"}, {"what is the answer?", "fourty two"}, {"sweet", "fifteen"}}));
  533. }
  534. //Complex map
  535. TEST_F(DeserializationTest, SimpleFixed32ComplexMapDeserializeTest)
  536. {
  537. SimpleFixed32ComplexMessageMapMessage test;
  538. test.deserialize(serializer.get(), QByteArray::fromHex("3a180d0a00000012110810120d320b74656e207369787465656e3a230d2a000000121c080a12183216666f757274792074776f2074656e207369787465656e3a110d13000100120a080a120632045755543f"));
  539. ASSERT_TRUE(*test.mapField()[10].data() == ComplexMessage({16, {"ten sixteen"}}));
  540. ASSERT_TRUE(*test.mapField()[42].data() == ComplexMessage({10, {"fourty two ten sixteen"}}));
  541. ASSERT_TRUE(*test.mapField()[65555].data() == ComplexMessage({10, {"WUT?"}}));
  542. }
  543. TEST_F(DeserializationTest, SimpleSFixed32ComplexMapDeserializeTest)
  544. {
  545. SimpleSFixed32ComplexMessageMapMessage test;
  546. test.deserialize(serializer.get(), QByteArray::fromHex("4a290dd6ffffff1222121e321c6d696e757320666f757274792074776f2074656e207369787465656e080a4a180d0a0000001211120d320b74656e207369787465656e08104a110d13000100120a120632045755543f080a"));
  547. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  548. ASSERT_TRUE(*test.mapField()[-42] == ComplexMessage({10 , {"minus fourty two ten sixteen"}}));
  549. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  550. }
  551. TEST_F(DeserializationTest, SimpleInt32ComplexMapDeserializeTest)
  552. {
  553. SimpleInt32ComplexMessageMapMessage test;
  554. test.deserialize(serializer.get(), QByteArray::fromHex("1a2f08d6ffffffffffffffff011222121e321c6d696e757320666f757274792074776f2074656e207369787465656e080a1a15080a1211120d320b74656e207369787465656e08101a1008938004120a120632045755543f080a"));
  555. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  556. ASSERT_TRUE(*test.mapField()[-42] == ComplexMessage({10 , {"minus fourty two ten sixteen"}}));
  557. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  558. }
  559. TEST_F(DeserializationTest, SimpleSInt32ComplexMapDeserializeTest)
  560. {
  561. SimpleSInt32ComplexMessageMapMessage test;
  562. test.deserialize(serializer.get(), QByteArray::fromHex("0a1608a580081210120c320a6d696e7573205755543f080a0a1508141211120d320b74656e207369787465656e08100a200854121c12183216666f757274792074776f2074656e207369787465656e080a"));
  563. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  564. ASSERT_TRUE(*test.mapField()[42] == ComplexMessage({10 , {"fourty two ten sixteen"}}));
  565. ASSERT_TRUE(*test.mapField()[-65555] == ComplexMessage({10 , {"minus WUT?"}}));
  566. }
  567. TEST_F(DeserializationTest, SimpleUInt32ComplexMapDeserializeTest)
  568. {
  569. SimpleUInt32ComplexMessageMapMessage test;
  570. test.deserialize(serializer.get(), QByteArray::fromHex("2a15080a1211120d320b74656e207369787465656e08102a20082a121c12183216666f757274792074776f2074656e207369787465656e080a2a1008938004120a120632045755543f080a"));
  571. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  572. ASSERT_TRUE(*test.mapField()[42] == ComplexMessage({10 , {"fourty two ten sixteen"}}));
  573. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  574. }
  575. TEST_F(DeserializationTest, SimpleFixed64ComplexMapDeserializeTest)
  576. {
  577. SimpleFixed64ComplexMessageMapMessage test;
  578. test.deserialize(serializer.get(), QByteArray::fromHex("421c090a000000000000001211120d320b74656e207369787465656e08104215091300010000000000120a120632045755543f080a422b09ffffffffffffffff1220121c321a6d696e757320666f757274792074776f2074656e204d41414158082a"));
  579. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  580. ASSERT_TRUE(*test.mapField()[UINT64_MAX] == ComplexMessage({42 , {"minus fourty two ten MAAAX"}}));
  581. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  582. }
  583. TEST_F(DeserializationTest, SimpleSFixed64ComplexMapDeserializeTest)
  584. {
  585. SimpleSFixed64ComplexMessageMapMessage test;
  586. test.deserialize(serializer.get(), QByteArray::fromHex("522d09d6ffffffffffffff1222121e321c6d696e757320666f757274792074776f2074656e207369787465656e080a521c090a000000000000001211120d320b74656e207369787465656e08105215091300010000000000120a120632045755543f080a"));
  587. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  588. ASSERT_TRUE(*test.mapField()[-42] == ComplexMessage({10 , {"minus fourty two ten sixteen"}}));
  589. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  590. }
  591. TEST_F(DeserializationTest, SimpleInt64ComplexMapDeserializeTest)
  592. {
  593. SimpleInt64ComplexMessageMapMessage test;
  594. test.deserialize(serializer.get(), QByteArray::fromHex("222f08d6ffffffffffffffff011222121e321c6d696e757320666f757274792074776f2074656e207369787465656e080a2215080a1211120d320b74656e207369787465656e0810221008938004120a120632045755543f080a"));
  595. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  596. ASSERT_TRUE(*test.mapField()[-42] == ComplexMessage({10 , {"minus fourty two ten sixteen"}}));
  597. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  598. }
  599. TEST_F(DeserializationTest, SimpleSInt64ComplexMapDeserializeTest)
  600. {
  601. SimpleSInt64ComplexMessageMapMessage test;
  602. test.deserialize(serializer.get(), QByteArray::fromHex("122608531222121e321c6d696e757320666f757274792074776f2074656e207369787465656e080a121508141211120d320b74656e207369787465656e0810121008a68008120a120632045755543f080a"));
  603. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({16 , {"ten sixteen"}}));
  604. ASSERT_TRUE(*test.mapField()[-42] == ComplexMessage({10 , {"minus fourty two ten sixteen"}}));
  605. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  606. }
  607. TEST_F(DeserializationTest, SimpleUInt64ComplexMapDeserializeTest)
  608. {
  609. SimpleUInt64ComplexMessageMapMessage test;
  610. test.deserialize(serializer.get(), QByteArray::fromHex("3214080a1210120c320a74656e20656c6576656e080b3220082a121c12183216666f757274792074776f2074656e207369787465656e080a321008938004120a120632045755543f080a"));
  611. ASSERT_TRUE(*test.mapField()[10] == ComplexMessage({11 , {"ten eleven"}}));
  612. ASSERT_TRUE(*test.mapField()[42] == ComplexMessage({10 , {"fourty two ten sixteen"}}));
  613. ASSERT_TRUE(*test.mapField()[65555] == ComplexMessage({10 , {"WUT?"}}));
  614. }
  615. TEST_F(DeserializationTest, SimpleStringComplexMapDeserializeTest)
  616. {
  617. SimpleStringComplexMessageMapMessage test;
  618. test.deserialize(serializer.get(), QByteArray::fromHex("6a140a055755543f3f120b120732053f5755543f080a6a170a0362656e1210120c320a74656e20656c6576656e080b6a350a157768657265206973206d792063617220647564653f121c12183216666f757274792074776f2074656e207369787465656e080a"));
  619. ASSERT_TRUE(*test.mapField()["ben"] == ComplexMessage({11 , {"ten eleven"}}));
  620. ASSERT_TRUE(*test.mapField()["where is my car dude?"] == ComplexMessage({10 , {"fourty two ten sixteen"}}));
  621. ASSERT_TRUE(*test.mapField()["WUT??"] == ComplexMessage({10 , {"?WUT?"}}));
  622. }
  623. TEST_F(DeserializationTest, SimpleUInt64ComplexMapInvalidLengthDeserializeTest)
  624. {
  625. SimpleUInt64ComplexMessageMapMessage test;
  626. EXPECT_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("3214080a1210120c320a74656e20656c6576656e080b3220082a121c12183216666f757274792074776f2074656e207369787465656e080a321008938004120a120")),
  627. std::invalid_argument);
  628. ASSERT_TRUE(test.mapField().isEmpty());
  629. }
  630. TEST_F(DeserializationTest, SimpleStringComplexMapInvalidLengthDeserializeTest)
  631. {
  632. SimpleStringComplexMessageMapMessage test;
  633. EXPECT_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("6a140a055755543f3f120b120732053f5755543f080a6a170a0362656e1210120c320a74656e20656c6576656e080b6a350a157768657265206973206d792063617220647564653f121c12183216666f757274792074776f2074656e20736978746565")),
  634. std::out_of_range);
  635. ASSERT_TRUE(*test.mapField()["ben"] == ComplexMessage({11 , {"ten eleven"}}));
  636. ASSERT_TRUE(*test.mapField()["WUT??"] == ComplexMessage({10 , {"?WUT?"}}));
  637. ASSERT_FALSE(test.mapField().contains("where is my car dude?"));
  638. }
  639. TEST_F(DeserializationTest, SimpleUInt64ComplexMapCorruptedDeserializeTest)
  640. {
  641. SimpleUInt64ComplexMessageMapMessage test;
  642. EXPECT_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("3214080a1210120c320a74656e20656c6576656e080b3221233522345b2183216666f757274792074776f2074656e207369787465656e080a321008938004120a120632045755543f080a")),
  643. std::invalid_argument);
  644. ASSERT_TRUE(test.mapField().isEmpty());
  645. }
  646. TEST_F(DeserializationTest, RedundantFieldIsIgnoredAtDeserializationTest)
  647. {
  648. ComplexMessage test;
  649. //3206717765727479 length delimited field number 6
  650. ASSERT_NO_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("120832067177657274793206717765727479")));
  651. EXPECT_EQ(test.testFieldInt(), 0);
  652. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  653. //3dcdcccc3d fixed32 field number 7
  654. ASSERT_NO_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("120832067177657274793dcdcccc3d")));
  655. EXPECT_EQ(test.testFieldInt(), 0);
  656. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  657. //419a9999999999b93f fixed64 field number 8
  658. ASSERT_NO_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("12083206717765727479419a9999999999b93f")));
  659. EXPECT_EQ(test.testFieldInt(), 0);
  660. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  661. //60d3ffffffffffffffff01 varint field number 12
  662. ASSERT_NO_THROW(test.deserialize(serializer.get(), QByteArray::fromHex("60d3ffffffffffffffff0112083206717765727479")));
  663. EXPECT_EQ(test.testFieldInt(), 0);
  664. EXPECT_STREQ(test.testComplexField().testFieldString().toStdString().c_str(), "qwerty");
  665. }
  666. TEST_F(DeserializationTest, FieldIndexRangeTest)
  667. {
  668. FieldIndexTest1Message msg1(0);
  669. msg1.deserialize(serializer.get(), QByteArray::fromHex("f80102"));
  670. ASSERT_EQ(msg1.testField(), 1);
  671. FieldIndexTest2Message msg2(0);
  672. msg2.deserialize(serializer.get(), QByteArray::fromHex("f8ff0302"));
  673. ASSERT_EQ(msg2.testField(), 1);
  674. FieldIndexTest3Message msg3(0);
  675. msg3.deserialize(serializer.get(), QByteArray::fromHex("f8ffff0702"));
  676. ASSERT_EQ(msg3.testField(), 1);
  677. FieldIndexTest4Message msg4(0);
  678. msg4.deserialize(serializer.get(), QByteArray::fromHex("f8ffffff0f02"));
  679. ASSERT_EQ(msg4.testField(), 1);
  680. }
  681. TEST_F(DeserializationTest, SimpleEnumListMessageTest)
  682. {
  683. SimpleEnumListMessage msg;
  684. msg.deserialize(serializer.get(), QByteArray());
  685. ASSERT_TRUE(msg.localEnumList().isEmpty());
  686. msg.deserialize(serializer.get(), QByteArray::fromHex("0a06000102010203"));
  687. ASSERT_TRUE((msg.localEnumList() == SimpleEnumListMessage::LocalEnumRepeated {SimpleEnumListMessage::LOCAL_ENUM_VALUE0,
  688. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  689. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  690. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  691. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  692. SimpleEnumListMessage::LOCAL_ENUM_VALUE3}));
  693. }