deserializationtest.cpp 43 KB

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