serializationtest.cpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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 "serializationtest.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 SerializationTest::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 SerializationTest::SetUp()
  40. {
  41. serializer.reset(new QProtobufSerializer);
  42. }
  43. TEST_F(SerializationTest, IntMessageSerializeTest)
  44. {
  45. SimpleIntMessage test;
  46. test.setTestFieldInt(15);
  47. QByteArray result = test.serialize(serializer.get());
  48. ASSERT_EQ(result.size(), 2);
  49. ASSERT_STREQ(result.toHex().toStdString().c_str(), "080f");
  50. test.setTestFieldInt(300);
  51. result = test.serialize(serializer.get());
  52. ASSERT_EQ(result.size(), 3);
  53. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ac02");
  54. test.setTestFieldInt(65545);
  55. result = test.serialize(serializer.get());
  56. ASSERT_EQ(result.size(), 4);
  57. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08898004");
  58. test.setTestFieldInt(0);
  59. result = test.serialize(serializer.get());
  60. ASSERT_EQ(result.size(), 0);
  61. test.setTestFieldInt(INT8_MAX + 1);
  62. result = test.serialize(serializer.get());
  63. ASSERT_EQ(result.size(), 3);
  64. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088001");
  65. test.setTestFieldInt(INT16_MAX + 1);
  66. result = test.serialize(serializer.get());
  67. ASSERT_EQ(result.size(), 4);
  68. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08808002");
  69. test.setTestFieldInt(INT8_MAX);
  70. result = test.serialize(serializer.get());
  71. ASSERT_EQ(result.size(), 2);
  72. ASSERT_STREQ(result.toHex().toStdString().c_str(), "087f");
  73. test.setTestFieldInt(INT16_MAX);
  74. result = test.serialize(serializer.get());
  75. ASSERT_EQ(result.size(), 4);
  76. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffff01");
  77. test.setTestFieldInt(INT32_MAX);
  78. result = test.serialize(serializer.get());
  79. ASSERT_EQ(result.size(), 6);
  80. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff07");
  81. test.setTestFieldInt(-1);
  82. result = test.serialize(serializer.get());
  83. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff0f");
  84. test.setTestFieldInt(-462);
  85. result = test.serialize(serializer.get());
  86. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08b2fcffff0f");
  87. test.setTestFieldInt(-63585);
  88. result = test.serialize(serializer.get());
  89. ASSERT_STREQ(result.toHex().toStdString().c_str(), "089f8ffcff0f");
  90. test.setTestFieldInt(INT8_MIN);
  91. result = test.serialize(serializer.get());
  92. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0880ffffff0f");
  93. test.setTestFieldInt(INT16_MIN);
  94. result = test.serialize(serializer.get());
  95. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088080feff0f");
  96. test.setTestFieldInt(INT32_MIN);
  97. result = test.serialize(serializer.get());
  98. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088080808008");
  99. test.setTestFieldInt(INT8_MIN - 1);
  100. result = test.serialize(serializer.get());
  101. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fffeffff0f");
  102. test.setTestFieldInt(INT16_MIN - 1);
  103. result = test.serialize(serializer.get());
  104. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fffffdff0f");
  105. }
  106. TEST_F(SerializationTest, UIntMessageSerializeTest)
  107. {
  108. SimpleUIntMessage test;
  109. test.setTestFieldInt(15);
  110. QByteArray result = test.serialize(serializer.get());
  111. ASSERT_EQ(result.size(), 2);
  112. ASSERT_STREQ(result.toHex().toStdString().c_str(), "080f");
  113. test.setTestFieldInt(300);
  114. result = test.serialize(serializer.get());
  115. ASSERT_EQ(result.size(), 3);
  116. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ac02");
  117. test.setTestFieldInt(65545);
  118. result = test.serialize(serializer.get());
  119. ASSERT_EQ(result.size(), 4);
  120. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08898004");
  121. test.setTestFieldInt(0);
  122. result = test.serialize(serializer.get());
  123. ASSERT_EQ(result.size(), 0);
  124. test.setTestFieldInt(UINT8_MAX + 1);
  125. result = test.serialize(serializer.get());
  126. ASSERT_EQ(result.size(), 3);
  127. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088002");
  128. test.setTestFieldInt(UINT16_MAX + 1);
  129. result = test.serialize(serializer.get());
  130. ASSERT_EQ(result.size(), 4);
  131. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08808004");
  132. test.setTestFieldInt(UINT8_MAX);
  133. result = test.serialize(serializer.get());
  134. ASSERT_EQ(result.size(), 3);
  135. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ff01");
  136. test.setTestFieldInt(UINT16_MAX);
  137. result = test.serialize(serializer.get());
  138. ASSERT_EQ(result.size(), 4);
  139. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffff03");
  140. test.setTestFieldInt(UINT32_MAX);
  141. result = test.serialize(serializer.get());
  142. ASSERT_EQ(result.size(), 6);
  143. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff0f");
  144. }
  145. TEST_F(SerializationTest, SIntMessageSerializeTest)
  146. {
  147. SimpleSIntMessage test;
  148. test.setTestFieldInt(15);
  149. QByteArray result = test.serialize(serializer.get());
  150. ASSERT_EQ(result.size(), 2);
  151. ASSERT_STREQ(result.toHex().toStdString().c_str(), "081e");
  152. test.setTestFieldInt(300);
  153. result = test.serialize(serializer.get());
  154. ASSERT_EQ(result.size(), 3);
  155. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08d804");
  156. test.setTestFieldInt(65545);
  157. result = test.serialize(serializer.get());
  158. ASSERT_EQ(result.size(), 4);
  159. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08928008");
  160. test.setTestFieldInt(0);
  161. result = test.serialize(serializer.get());
  162. ASSERT_EQ(result.size(), 0);
  163. test.setTestFieldInt(INT8_MAX + 1);
  164. result = test.serialize(serializer.get());
  165. ASSERT_EQ(result.size(), 3);
  166. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088002");
  167. test.setTestFieldInt(INT16_MAX + 1);
  168. result = test.serialize(serializer.get());
  169. ASSERT_EQ(result.size(), 4);
  170. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08808004");
  171. test.setTestFieldInt(INT8_MAX);
  172. result = test.serialize(serializer.get());
  173. ASSERT_EQ(result.size(), 3);
  174. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fe01");
  175. test.setTestFieldInt(INT16_MAX);
  176. result = test.serialize(serializer.get());
  177. ASSERT_EQ(result.size(), 4);
  178. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08feff03");
  179. test.setTestFieldInt(INT32_MAX);
  180. result = test.serialize(serializer.get());
  181. ASSERT_EQ(result.size(), 6);
  182. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08feffffff0f");
  183. test.setTestFieldInt(-1);
  184. result = test.serialize(serializer.get());
  185. ASSERT_EQ(result.size(), 2);
  186. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0801");
  187. test.setTestFieldInt(-462);
  188. result = test.serialize(serializer.get());
  189. ASSERT_EQ(result.size(), 3);
  190. ASSERT_STREQ(result.toHex().toStdString().c_str(), "089b07");
  191. test.setTestFieldInt(-63585);
  192. result = test.serialize(serializer.get());
  193. ASSERT_EQ(result.size(), 4);
  194. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08c1e107");
  195. test.setTestFieldInt(INT8_MIN);
  196. result = test.serialize(serializer.get());
  197. ASSERT_EQ(result.size(), 3);
  198. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ff01");
  199. test.setTestFieldInt(INT16_MIN);
  200. result = test.serialize(serializer.get());
  201. ASSERT_EQ(result.size(), 4);
  202. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffff03");
  203. test.setTestFieldInt(INT32_MIN);
  204. result = test.serialize(serializer.get());
  205. ASSERT_EQ(result.size(), 6);
  206. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff0f");
  207. test.setTestFieldInt(INT8_MIN - 1);
  208. result = test.serialize(serializer.get());
  209. ASSERT_EQ(result.size(), 3);
  210. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088102");
  211. test.setTestFieldInt(INT16_MIN - 1);
  212. result = test.serialize(serializer.get());
  213. ASSERT_EQ(result.size(), 4);
  214. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08818004");
  215. }
  216. TEST_F(SerializationTest, Int64MessageSerializeTest)
  217. {
  218. SimpleInt64Message test;
  219. test.setTestFieldInt(15);
  220. QByteArray result = test.serialize(serializer.get());
  221. ASSERT_EQ(result.size(), 2);
  222. ASSERT_STREQ(result.toHex().toStdString().c_str(), "080f");
  223. test.setTestFieldInt(300);
  224. result = test.serialize(serializer.get());
  225. ASSERT_EQ(result.size(), 3);
  226. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ac02");
  227. test.setTestFieldInt(65545);
  228. result = test.serialize(serializer.get());
  229. ASSERT_EQ(result.size(), 4);
  230. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08898004");
  231. test.setTestFieldInt(0);
  232. result = test.serialize(serializer.get());
  233. ASSERT_EQ(result.size(), 0);
  234. test.setTestFieldInt(INT8_MAX + 1);
  235. result = test.serialize(serializer.get());
  236. ASSERT_EQ(result.size(), 3);
  237. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088001");
  238. test.setTestFieldInt(INT16_MAX + 1);
  239. result = test.serialize(serializer.get());
  240. ASSERT_EQ(result.size(), 4);
  241. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08808002");
  242. test.setTestFieldInt((qlonglong)(INT32_MAX) + 1);
  243. result = test.serialize(serializer.get());
  244. ASSERT_EQ(result.size(), 6);
  245. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088080808008");
  246. test.setTestFieldInt(INT8_MAX);
  247. result = test.serialize(serializer.get());
  248. ASSERT_EQ(result.size(), 2);
  249. ASSERT_STREQ(result.toHex().toStdString().c_str(), "087f");
  250. test.setTestFieldInt(INT16_MAX);
  251. result = test.serialize(serializer.get());
  252. ASSERT_EQ(result.size(), 4);
  253. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffff01");
  254. test.setTestFieldInt(INT32_MAX);
  255. result = test.serialize(serializer.get());
  256. ASSERT_EQ(result.size(), 6);
  257. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff07");
  258. test.setTestFieldInt(INT64_MAX);
  259. result = test.serialize(serializer.get());
  260. ASSERT_EQ(result.size(), 10);
  261. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffffffffffff7f");
  262. test.setTestFieldInt(-1);
  263. result = test.serialize(serializer.get());
  264. ASSERT_EQ(result.size(), 11);
  265. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffffffffffffff01");
  266. test.setTestFieldInt(-462);
  267. result = test.serialize(serializer.get());
  268. ASSERT_EQ(result.size(), 11);
  269. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08b2fcffffffffffffff01");
  270. test.setTestFieldInt(-63585);
  271. result = test.serialize(serializer.get());
  272. ASSERT_EQ(result.size(), 11);
  273. ASSERT_STREQ(result.toHex().toStdString().c_str(), "089f8ffcffffffffffff01");
  274. test.setTestFieldInt(INT8_MIN);
  275. result = test.serialize(serializer.get());
  276. ASSERT_EQ(result.size(), 11);
  277. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0880ffffffffffffffff01");
  278. test.setTestFieldInt(INT16_MIN);
  279. result = test.serialize(serializer.get());
  280. ASSERT_EQ(result.size(), 11);
  281. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088080feffffffffffff01");
  282. test.setTestFieldInt(INT32_MIN);
  283. result = test.serialize(serializer.get());
  284. ASSERT_EQ(result.size(), 11);
  285. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0880808080f8ffffffff01");
  286. test.setTestFieldInt(INT8_MIN - 1);
  287. result = test.serialize(serializer.get());
  288. ASSERT_EQ(result.size(), 11);
  289. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fffeffffffffffffff01");
  290. test.setTestFieldInt(INT16_MIN - 1);
  291. result = test.serialize(serializer.get());
  292. ASSERT_EQ(result.size(), 11);
  293. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fffffdffffffffffff01");
  294. test.setTestFieldInt((qlonglong)INT32_MIN - 1);
  295. result = test.serialize(serializer.get());
  296. ASSERT_EQ(result.size(), 11);
  297. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fffffffff7ffffffff01");
  298. test.setTestFieldInt(INT64_MIN);
  299. result = test.serialize(serializer.get());
  300. ASSERT_EQ(result.size(), 11);
  301. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0880808080808080808001");
  302. }
  303. TEST_F(SerializationTest, UInt64MessageSerializeTest)
  304. {
  305. SimpleUInt64Message test;
  306. test.setTestFieldInt(15);
  307. QByteArray result = test.serialize(serializer.get());
  308. ASSERT_EQ(result.size(), 2);
  309. ASSERT_STREQ(result.toHex().toStdString().c_str(), "080f");
  310. test.setTestFieldInt(300);
  311. result = test.serialize(serializer.get());
  312. ASSERT_EQ(result.size(), 3);
  313. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ac02");
  314. test.setTestFieldInt(65545);
  315. result = test.serialize(serializer.get());
  316. ASSERT_EQ(result.size(), 4);
  317. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08898004");
  318. test.setTestFieldInt(0);
  319. result = test.serialize(serializer.get());
  320. ASSERT_EQ(result.size(), 0);
  321. test.setTestFieldInt(UINT8_MAX + 1);
  322. result = test.serialize(serializer.get());
  323. ASSERT_EQ(result.size(), 3);
  324. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088002");
  325. test.setTestFieldInt(UINT16_MAX + 1);
  326. result = test.serialize(serializer.get());
  327. ASSERT_EQ(result.size(), 4);
  328. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08808004");
  329. test.setTestFieldInt(((uint64_t)UINT32_MAX) + 1);
  330. result = test.serialize(serializer.get());
  331. ASSERT_EQ(result.size(), 6);
  332. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088080808010");
  333. test.setTestFieldInt(UINT8_MAX);
  334. result = test.serialize(serializer.get());
  335. ASSERT_EQ(result.size(), 3);
  336. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ff01");
  337. test.setTestFieldInt(UINT16_MAX);
  338. result = test.serialize(serializer.get());
  339. ASSERT_EQ(result.size(), 4);
  340. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffff03");
  341. test.setTestFieldInt(UINT32_MAX);
  342. result = test.serialize(serializer.get());
  343. ASSERT_EQ(result.size(), 6);
  344. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff0f");
  345. test.setTestFieldInt(UINT64_MAX);
  346. result = test.serialize(serializer.get());
  347. ASSERT_EQ(result.size(), 11);
  348. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffffffffffffff01");
  349. }
  350. TEST_F(SerializationTest, SInt64MessageSerializeTest)
  351. {
  352. SimpleSInt64Message test;
  353. test.setTestFieldInt(15);
  354. QByteArray result = test.serialize(serializer.get());
  355. ASSERT_EQ(result.size(), 2);
  356. ASSERT_STREQ(result.toHex().toStdString().c_str(), "081e");
  357. test.setTestFieldInt(300);
  358. result = test.serialize(serializer.get());
  359. ASSERT_EQ(result.size(), 3);
  360. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08d804");
  361. test.setTestFieldInt(65545);
  362. result = test.serialize(serializer.get());
  363. ASSERT_EQ(result.size(), 4);
  364. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08928008");
  365. test.setTestFieldInt(0);
  366. result = test.serialize(serializer.get());
  367. ASSERT_EQ(result.size(), 0);
  368. test.setTestFieldInt(INT8_MAX + 1);
  369. result = test.serialize(serializer.get());
  370. ASSERT_EQ(result.size(), 3);
  371. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088002");
  372. test.setTestFieldInt(INT16_MAX + 1);
  373. result = test.serialize(serializer.get());
  374. ASSERT_EQ(result.size(), 4);
  375. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08808004");
  376. test.setTestFieldInt(INT8_MAX);
  377. result = test.serialize(serializer.get());
  378. ASSERT_EQ(result.size(), 3);
  379. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08fe01");
  380. test.setTestFieldInt(INT16_MAX);
  381. result = test.serialize(serializer.get());
  382. ASSERT_EQ(result.size(), 4);
  383. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08feff03");
  384. test.setTestFieldInt(INT32_MAX);
  385. result = test.serialize(serializer.get());
  386. ASSERT_EQ(result.size(), 6);
  387. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08feffffff0f");
  388. test.setTestFieldInt(INT64_MAX);
  389. result = test.serialize(serializer.get());
  390. ASSERT_EQ(result.size(), 11);
  391. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08feffffffffffffffff01");
  392. test.setTestFieldInt(-1);
  393. result = test.serialize(serializer.get());
  394. ASSERT_EQ(result.size(), 2);
  395. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0801");
  396. test.setTestFieldInt(-462);
  397. result = test.serialize(serializer.get());
  398. ASSERT_EQ(result.size(), 3);
  399. ASSERT_STREQ(result.toHex().toStdString().c_str(), "089b07");
  400. test.setTestFieldInt(-63585);
  401. result = test.serialize(serializer.get());
  402. ASSERT_EQ(result.size(), 4);
  403. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08c1e107");
  404. test.setTestFieldInt(INT8_MIN);
  405. result = test.serialize(serializer.get());
  406. ASSERT_EQ(result.size(), 3);
  407. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ff01");
  408. test.setTestFieldInt(INT16_MIN);
  409. result = test.serialize(serializer.get());
  410. ASSERT_EQ(result.size(), 4);
  411. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffff03");
  412. test.setTestFieldInt(INT32_MIN);
  413. result = test.serialize(serializer.get());
  414. ASSERT_EQ(result.size(), 6);
  415. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffff0f");
  416. test.setTestFieldInt(INT64_MIN);
  417. result = test.serialize(serializer.get());
  418. ASSERT_EQ(result.size(), 11);
  419. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08ffffffffffffffffff01");
  420. test.setTestFieldInt(INT8_MIN - 1);
  421. result = test.serialize(serializer.get());
  422. ASSERT_EQ(result.size(), 3);
  423. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088102");
  424. test.setTestFieldInt(INT16_MIN - 1);
  425. result = test.serialize(serializer.get());
  426. ASSERT_EQ(result.size(), 4);
  427. ASSERT_STREQ(result.toHex().toStdString().c_str(), "08818004");
  428. test.setTestFieldInt((qlonglong)INT32_MIN - 1);
  429. result = test.serialize(serializer.get());
  430. ASSERT_EQ(result.size(), 6);
  431. ASSERT_STREQ(result.toHex().toStdString().c_str(), "088180808010");
  432. }
  433. TEST_F(SerializationTest, FixedInt32MessageSerializeTest)
  434. {
  435. constexpr int Fixed32MessageSize = 5;
  436. SimpleFixedInt32Message test;
  437. test.setTestFieldFixedInt32(15);
  438. QByteArray result = test.serialize(serializer.get());
  439. ASSERT_EQ(result.size(), Fixed32MessageSize);
  440. ASSERT_TRUE(result == QByteArray::fromHex("0d0f000000"));
  441. test.setTestFieldFixedInt32(300);
  442. result = test.serialize(serializer.get());
  443. ASSERT_EQ(result.size(), Fixed32MessageSize);
  444. ASSERT_TRUE(result == QByteArray::fromHex("0d2c010000"));
  445. test.setTestFieldFixedInt32(65545);
  446. result = test.serialize(serializer.get());
  447. ASSERT_EQ(result.size(), Fixed32MessageSize);
  448. ASSERT_TRUE(result == QByteArray::fromHex("0d09000100"));
  449. test.setTestFieldFixedInt32(0);
  450. result = test.serialize(serializer.get());
  451. ASSERT_EQ(result.size(), Fixed32MessageSize);
  452. ASSERT_TRUE(result == QByteArray::fromHex("0d00000000"));
  453. test.setTestFieldFixedInt32(UINT8_MAX + 1);
  454. result = test.serialize(serializer.get());
  455. ASSERT_EQ(result.size(), Fixed32MessageSize);
  456. ASSERT_TRUE(result == QByteArray::fromHex("0d00010000"));
  457. test.setTestFieldFixedInt32(UINT16_MAX + 1);
  458. result = test.serialize(serializer.get());
  459. ASSERT_EQ(result.size(), Fixed32MessageSize);
  460. ASSERT_TRUE(result == QByteArray::fromHex("0d00000100"));
  461. test.setTestFieldFixedInt32(UINT8_MAX);
  462. result = test.serialize(serializer.get());
  463. ASSERT_EQ(result.size(), Fixed32MessageSize);
  464. ASSERT_TRUE(result == QByteArray::fromHex("0dff000000"));
  465. test.setTestFieldFixedInt32(UINT16_MAX);
  466. result = test.serialize(serializer.get());
  467. ASSERT_EQ(result.size(), Fixed32MessageSize);
  468. ASSERT_TRUE(result == QByteArray::fromHex("0dffff0000"));
  469. test.setTestFieldFixedInt32(UINT32_MAX);
  470. result = test.serialize(serializer.get());
  471. ASSERT_EQ(result.size(), Fixed32MessageSize);
  472. ASSERT_TRUE(result == QByteArray::fromHex("0dffffffff"));
  473. }
  474. TEST_F(SerializationTest, FixedInt64MessageSerializeTest)
  475. {
  476. constexpr int Fixed64MessageSize = 9;
  477. SimpleFixedInt64Message test;
  478. test.setTestFieldFixedInt64(15);
  479. QByteArray result = test.serialize(serializer.get());
  480. ASSERT_EQ(result.size(), Fixed64MessageSize);
  481. ASSERT_TRUE(result == QByteArray::fromHex("090f00000000000000"));
  482. test.setTestFieldFixedInt64(300);
  483. result = test.serialize(serializer.get());
  484. ASSERT_EQ(result.size(), Fixed64MessageSize);
  485. ASSERT_TRUE(result == QByteArray::fromHex("092c01000000000000"));
  486. test.setTestFieldFixedInt64(65545);
  487. result = test.serialize(serializer.get());
  488. ASSERT_EQ(result.size(), Fixed64MessageSize);
  489. ASSERT_TRUE(result == QByteArray::fromHex("090900010000000000"));
  490. test.setTestFieldFixedInt64(0);
  491. result = test.serialize(serializer.get());
  492. ASSERT_EQ(result.size(), Fixed64MessageSize);
  493. ASSERT_TRUE(result == QByteArray::fromHex("090000000000000000"));
  494. test.setTestFieldFixedInt64(UINT8_MAX + 1);
  495. result = test.serialize(serializer.get());
  496. ASSERT_EQ(result.size(), Fixed64MessageSize);
  497. ASSERT_TRUE(result == QByteArray::fromHex("090001000000000000"));
  498. test.setTestFieldFixedInt64(UINT16_MAX + 1);
  499. result = test.serialize(serializer.get());
  500. ASSERT_EQ(result.size(), Fixed64MessageSize);
  501. ASSERT_TRUE(result == QByteArray::fromHex("090000010000000000"));
  502. test.setTestFieldFixedInt64((unsigned long long)(UINT32_MAX) + 1);
  503. result = test.serialize(serializer.get());
  504. ASSERT_EQ(result.size(), Fixed64MessageSize);
  505. ASSERT_TRUE(result == QByteArray::fromHex("090000000001000000"));
  506. test.setTestFieldFixedInt64(UINT8_MAX);
  507. result = test.serialize(serializer.get());
  508. ASSERT_EQ(result.size(), Fixed64MessageSize);
  509. ASSERT_TRUE(result == QByteArray::fromHex("09ff00000000000000"));
  510. test.setTestFieldFixedInt64(UINT16_MAX);
  511. result = test.serialize(serializer.get());
  512. ASSERT_EQ(result.size(), Fixed64MessageSize);
  513. ASSERT_TRUE(result == QByteArray::fromHex("09ffff000000000000"));
  514. test.setTestFieldFixedInt64(UINT32_MAX);
  515. result = test.serialize(serializer.get());
  516. ASSERT_EQ(result.size(), Fixed64MessageSize);
  517. ASSERT_TRUE(result == QByteArray::fromHex("09ffffffff00000000"));
  518. test.setTestFieldFixedInt64(UINT64_MAX);
  519. result = test.serialize(serializer.get());
  520. ASSERT_EQ(result.size(), Fixed64MessageSize);
  521. ASSERT_TRUE(result == QByteArray::fromHex("09ffffffffffffffff"));
  522. }
  523. TEST_F(SerializationTest, SFixedInt32MessageSerializeTest)
  524. {
  525. constexpr int Fixed32MessageSize = 5;
  526. SimpleSFixedInt32Message test;
  527. test.setTestFieldFixedInt32(15);
  528. QByteArray result = test.serialize(serializer.get());
  529. ASSERT_EQ(result.size(), Fixed32MessageSize);
  530. ASSERT_TRUE(result == QByteArray::fromHex("0d0f000000"));
  531. test.setTestFieldFixedInt32(300);
  532. result = test.serialize(serializer.get());
  533. ASSERT_EQ(result.size(), Fixed32MessageSize);
  534. ASSERT_TRUE(result == QByteArray::fromHex("0d2c010000"));
  535. test.setTestFieldFixedInt32(65545);
  536. result = test.serialize(serializer.get());
  537. ASSERT_EQ(result.size(), Fixed32MessageSize);
  538. ASSERT_TRUE(result == QByteArray::fromHex("0d09000100"));
  539. test.setTestFieldFixedInt32(0);
  540. result = test.serialize(serializer.get());
  541. ASSERT_EQ(result.size(), Fixed32MessageSize);
  542. ASSERT_TRUE(result == QByteArray::fromHex("0d00000000"));
  543. test.setTestFieldFixedInt32(INT8_MAX + 1);
  544. result = test.serialize(serializer.get());
  545. ASSERT_EQ(result.size(), Fixed32MessageSize);
  546. ASSERT_TRUE(result == QByteArray::fromHex("0d80000000"));
  547. test.setTestFieldFixedInt32(INT16_MAX + 1);
  548. result = test.serialize(serializer.get());
  549. ASSERT_EQ(result.size(), Fixed32MessageSize);
  550. ASSERT_TRUE(result == QByteArray::fromHex("0d00800000"));
  551. test.setTestFieldFixedInt32(INT8_MAX);
  552. result = test.serialize(serializer.get());
  553. ASSERT_EQ(result.size(), Fixed32MessageSize);
  554. ASSERT_TRUE(result == QByteArray::fromHex("0d7f000000"));
  555. test.setTestFieldFixedInt32(INT16_MAX);
  556. result = test.serialize(serializer.get());
  557. ASSERT_EQ(result.size(), Fixed32MessageSize);
  558. ASSERT_TRUE(result == QByteArray::fromHex("0dff7f0000"));
  559. test.setTestFieldFixedInt32(INT8_MIN - 1);
  560. result = test.serialize(serializer.get());
  561. ASSERT_EQ(result.size(), Fixed32MessageSize);
  562. ASSERT_TRUE(result == QByteArray::fromHex("0d7fffffff"));
  563. test.setTestFieldFixedInt32(INT16_MIN - 1);
  564. result = test.serialize(serializer.get());
  565. ASSERT_EQ(result.size(), Fixed32MessageSize);
  566. ASSERT_TRUE(result == QByteArray::fromHex("0dff7fffff"));
  567. test.setTestFieldFixedInt32(INT8_MIN);
  568. result = test.serialize(serializer.get());
  569. ASSERT_EQ(result.size(), Fixed32MessageSize);
  570. ASSERT_TRUE(result == QByteArray::fromHex("0d80ffffff"));
  571. test.setTestFieldFixedInt32(INT16_MIN);
  572. result = test.serialize(serializer.get());
  573. ASSERT_EQ(result.size(), Fixed32MessageSize);
  574. ASSERT_TRUE(result == QByteArray::fromHex("0d0080ffff"));
  575. test.setTestFieldFixedInt32(INT32_MIN);
  576. result = test.serialize(serializer.get());
  577. ASSERT_EQ(result.size(), Fixed32MessageSize);
  578. ASSERT_TRUE(result == QByteArray::fromHex("0d00000080"));
  579. }
  580. TEST_F(SerializationTest, SFixedInt64MessageSerializeTest)
  581. {
  582. constexpr int Fixed64MessageSize = 9;
  583. SimpleSFixedInt64Message test;
  584. test.setTestFieldFixedInt64(15);
  585. QByteArray result = test.serialize(serializer.get());
  586. ASSERT_EQ(result.size(), Fixed64MessageSize);
  587. ASSERT_TRUE(result == QByteArray::fromHex("090f00000000000000"));
  588. test.setTestFieldFixedInt64(300);
  589. result = test.serialize(serializer.get());
  590. ASSERT_EQ(result.size(), Fixed64MessageSize);
  591. ASSERT_TRUE(result == QByteArray::fromHex("092c01000000000000"));
  592. test.setTestFieldFixedInt64(65545);
  593. result = test.serialize(serializer.get());
  594. ASSERT_EQ(result.size(), Fixed64MessageSize);
  595. ASSERT_TRUE(result == QByteArray::fromHex("090900010000000000"));
  596. test.setTestFieldFixedInt64(0);
  597. result = test.serialize(serializer.get());
  598. ASSERT_EQ(result.size(), Fixed64MessageSize);
  599. ASSERT_TRUE(result == QByteArray::fromHex("090000000000000000"));
  600. test.setTestFieldFixedInt64(INT8_MAX + 1);
  601. result = test.serialize(serializer.get());
  602. ASSERT_EQ(result.size(), Fixed64MessageSize);
  603. ASSERT_TRUE(result == QByteArray::fromHex("098000000000000000"));
  604. test.setTestFieldFixedInt64(INT16_MAX + 1);
  605. result = test.serialize(serializer.get());
  606. ASSERT_EQ(result.size(), Fixed64MessageSize);
  607. ASSERT_TRUE(result == QByteArray::fromHex("090080000000000000"));
  608. test.setTestFieldFixedInt64((unsigned long long)(INT32_MAX) + 1);
  609. result = test.serialize(serializer.get());
  610. ASSERT_EQ(result.size(), Fixed64MessageSize);
  611. ASSERT_TRUE(result == QByteArray::fromHex("090000008000000000"));
  612. test.setTestFieldFixedInt64(INT8_MAX);
  613. result = test.serialize(serializer.get());
  614. ASSERT_EQ(result.size(), Fixed64MessageSize);
  615. ASSERT_TRUE(result == QByteArray::fromHex("097f00000000000000"));
  616. test.setTestFieldFixedInt64(INT16_MAX);
  617. result = test.serialize(serializer.get());
  618. ASSERT_EQ(result.size(), Fixed64MessageSize);
  619. ASSERT_TRUE(result == QByteArray::fromHex("09ff7f000000000000"));
  620. test.setTestFieldFixedInt64(INT32_MAX);
  621. result = test.serialize(serializer.get());
  622. ASSERT_EQ(result.size(), Fixed64MessageSize);
  623. ASSERT_TRUE(result == QByteArray::fromHex("09ffffff7f00000000"));
  624. test.setTestFieldFixedInt64(INT64_MAX);
  625. result = test.serialize(serializer.get());
  626. ASSERT_EQ(result.size(), Fixed64MessageSize);
  627. ASSERT_TRUE(result == QByteArray::fromHex("09ffffffffffffff7f"));
  628. test.setTestFieldFixedInt64(INT8_MIN - 1);
  629. result = test.serialize(serializer.get());
  630. ASSERT_EQ(result.size(), Fixed64MessageSize);
  631. ASSERT_TRUE(result == QByteArray::fromHex("097fffffffffffffff"));
  632. test.setTestFieldFixedInt64(INT16_MIN - 1);
  633. result = test.serialize(serializer.get());
  634. ASSERT_EQ(result.size(), Fixed64MessageSize);
  635. ASSERT_TRUE(result == QByteArray::fromHex("09ff7fffffffffffff"));
  636. test.setTestFieldFixedInt64((qlonglong)INT32_MIN - 1);
  637. result = test.serialize(serializer.get());
  638. ASSERT_EQ(result.size(), Fixed64MessageSize);
  639. ASSERT_TRUE(result == QByteArray::fromHex("09ffffff7fffffffff"));
  640. test.setTestFieldFixedInt64(INT8_MIN);
  641. result = test.serialize(serializer.get());
  642. ASSERT_EQ(result.size(), Fixed64MessageSize);
  643. ASSERT_TRUE(result == QByteArray::fromHex("0980ffffffffffffff"));
  644. test.setTestFieldFixedInt64(INT16_MIN);
  645. result = test.serialize(serializer.get());
  646. ASSERT_EQ(result.size(), Fixed64MessageSize);
  647. ASSERT_TRUE(result == QByteArray::fromHex("090080ffffffffffff"));
  648. test.setTestFieldFixedInt64(INT32_MIN);
  649. result = test.serialize(serializer.get());
  650. ASSERT_EQ(result.size(), Fixed64MessageSize);
  651. ASSERT_TRUE(result == QByteArray::fromHex("0900000080ffffffff"));
  652. test.setTestFieldFixedInt64(INT64_MIN);
  653. result = test.serialize(serializer.get());
  654. ASSERT_EQ(result.size(), Fixed64MessageSize);
  655. ASSERT_TRUE(result == QByteArray::fromHex("090000000000000080"));
  656. }
  657. TEST_F(SerializationTest, FloatMessageSerializeTest)
  658. {
  659. constexpr int FloatMessageSize = 5;
  660. SimpleFloatMessage test;
  661. test.setTestFieldFloat(0.1f);
  662. QByteArray result = test.serialize(serializer.get());
  663. ASSERT_EQ(result.size(), FloatMessageSize);
  664. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3dcdcccc3d");
  665. test.setTestFieldFloat(FLT_MIN);
  666. result = test.serialize(serializer.get());
  667. ASSERT_EQ(result.size(), FloatMessageSize);
  668. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3d00008000");
  669. test.setTestFieldFloat(FLT_MAX);
  670. result = test.serialize(serializer.get());
  671. ASSERT_EQ(result.size(), FloatMessageSize);
  672. ASSERT_EQ(result.at(0), 0x3d);
  673. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3dffff7f7f");
  674. test.setTestFieldFloat(-4.2f);
  675. result = test.serialize(serializer.get());
  676. ASSERT_EQ(result.size(), FloatMessageSize);
  677. ASSERT_EQ(result.at(0), 0x3d);
  678. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3d666686c0");
  679. test.setTestFieldFloat(-0.0f);
  680. result = test.serialize(serializer.get());
  681. ASSERT_EQ(result.size(), FloatMessageSize);
  682. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3d00000080");
  683. }
  684. TEST_F(SerializationTest, DoubleMessageSerializeTest)
  685. {
  686. constexpr int DoubleMessageSize = 9;
  687. SimpleDoubleMessage test;
  688. test.setTestFieldDouble(0.1);
  689. QByteArray result = test.serialize(serializer.get());
  690. ASSERT_EQ(result.size(), DoubleMessageSize);
  691. ASSERT_STREQ(result.toHex().toStdString().c_str(), "419a9999999999b93f");
  692. test.setTestFieldDouble(DBL_MIN);
  693. result = test.serialize(serializer.get());
  694. ASSERT_EQ(result.size(), DoubleMessageSize);
  695. ASSERT_STREQ(result.toHex().toStdString().c_str(), "410000000000001000");
  696. test.setTestFieldDouble(DBL_MAX);
  697. result = test.serialize(serializer.get());
  698. ASSERT_EQ(result.size(), DoubleMessageSize);
  699. ASSERT_STREQ(result.toHex().toStdString().c_str(), "41ffffffffffffef7f");
  700. test.setTestFieldDouble(-4.2);
  701. result = test.serialize(serializer.get());
  702. ASSERT_EQ(result.size(), DoubleMessageSize);
  703. ASSERT_STREQ(result.toHex().toStdString().c_str(), "41cdcccccccccc10c0");
  704. test.setTestFieldDouble(0.0);
  705. result = test.serialize(serializer.get());
  706. ASSERT_EQ(result.size(), DoubleMessageSize);
  707. ASSERT_STREQ(result.toHex().toStdString().c_str(), "410000000000000000");
  708. }
  709. TEST_F(SerializationTest, StringMessageSerializeTest)
  710. {
  711. SimpleStringMessage test;
  712. test.setTestFieldString("qwerty");
  713. QByteArray result = test.serialize(serializer.get());
  714. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3206717765727479");
  715. test.setTestFieldString("oepSNLIVG08UJpk2W7JtTkkBxyK06X0lQ6ML7IMd55K8XC1Tpsc1kDWym5v8z68b4FQup9O95QSgAvjHIA15OX6Bu68esbQFT9LPzSADJ6qSGBTYBHX5QSZg32trCdHMj80XuDHqyBgM4uf6RKq2mgWb8Ovxxr0NwLxjHOfhJ8Mrfd2R7hbUgjespbYoQhbgHEj2gKEV3QvnumYmrVXe1BkCzZhKVXodDhj0OfAE67viAy4i3Oag1hr1z4Azo8O5Xq68POEZ1CsZPo2DXNNR8ebVCdYOz0Q6JLPSl5jasLCFrQN7EiVNjQmCrSsZHRgLNylvgoEFxGYxXJ9gmK4mr0OGdZcGJORRGZOQCpQMhXmhezFalNIJXMPPXaRVXiRhRAPCNUEie8DtaCWAMqz4nNUxRMZ5UcXBXsXPshygzkyyXnNWTIDojFlrcsnKqSkQ1G6E85gSZbtIYBh7sqO6GDXHjOrXVaVCVCUubjcJKThlyslt29zHuIs5JGppXxX1");
  716. result = test.serialize(serializer.get());
  717. ASSERT_STREQ(result.toHex().toStdString().c_str(), "3280046f6570534e4c4956473038554a706b3257374a74546b6b4278794b303658306c51364d4c37494d6435354b3858433154707363316b4457796d3576387a3638623446517570394f393551536741766a48494131354f583642753638657362514654394c507a5341444a367153474254594248583551535a67333274724364484d6a383058754448717942674d34756636524b71326d675762384f76787872304e774c786a484f66684a384d726664325237686255676a65737062596f5168626748456a32674b45563351766e756d596d7256586531426b437a5a684b56586f6444686a304f6641453637766941793469334f6167316872317a34417a6f384f3558713638504f455a3143735a506f3244584e4e52386562564364594f7a3051364a4c50536c356a61734c434672514e374569564e6a516d437253735a4852674c4e796c76676f454678475978584a39676d4b346d72304f47645a63474a4f5252475a4f514370514d68586d68657a46616c4e494a584d50505861525658695268524150434e55456965384474614357414d717a346e4e5578524d5a355563584258735850736879677a6b7979586e4e575449446f6a466c7263736e4b71536b5131473645383567535a6274495942683773714f36474458486a4f72585661564356435575626a634a4b54686c79736c7432397a48754973354a47707058785831");
  718. }
  719. TEST_F(SerializationTest, ComplexTypeSerializeTest)
  720. {
  721. SimpleStringMessage stringMsg;
  722. stringMsg.setTestFieldString("qwerty");
  723. ComplexMessage test;
  724. test.setTestFieldInt(42);
  725. test.setTestComplexField(stringMsg);
  726. QByteArray result = test.serialize(serializer.get());
  727. //qDebug() << "result" << result.toHex();
  728. ASSERT_TRUE(result == QByteArray::fromHex("12083206717765727479082a")
  729. || result == QByteArray::fromHex("082a12083206717765727479"));
  730. stringMsg.setTestFieldString("YVRfJvjxqbgvFwS1YvOZXgtj5ffGLS7AiNHz9oZIoKbm7z8H79xBuyPkpQXvGoO09OY9xRawx3eOAs9xjoTA1xJhrw28TAcq1CebYlC9WUfQC6hIantaNdyHiKToffi0Zt7la42SRxXZSP4GuxbcZIp53pJnyCwfCy1qdFczT0dmn7h8fpyAdemEavwFeda4d0PApGfSU2jLt39X8kYUBxNM2WgALRBgHdVde87q6Pi5U69TjhMd28W1SFD1DxyogCCrqOct2ZPICoLnrqdF3OdNzjRVLfeyvQ8LgLvRNFR9WfWAyAz79nKgBamd8Ntlvt4Mg35E5gVS2g7AQ7rkm72cBdnW9sCEyGabeXAuH5j4GRbuLT7qBZWDcFLF4SsCdS3WfFGdNHfwaijzykByo71PvFVlTXH2WJWoFvR5FALjBTn7bCdP0pAiSbLCY8Xz2Msc3dBb5Ff9GISPbUpNmUvBdMZMHQvqOmTNXEPpN0b74MDOMQfWJShOo3NkAvMjs");
  731. test.setTestFieldInt(42);
  732. test.setTestComplexField(stringMsg);
  733. result = test.serialize(serializer.get());
  734. //qDebug() << "result" << result.toHex();
  735. ASSERT_TRUE(result == QByteArray::fromHex("128404328104595652664a766a78716267764677533159764f5a5867746a356666474c533741694e487a396f5a496f4b626d377a3848373978427579506b70515876476f4f30394f5939785261777833654f417339786a6f544131784a68727732385441637131436562596c43395755665143366849616e74614e647948694b546f666669305a74376c613432535278585a53503447757862635a49703533704a6e79437766437931716446637a5430646d6e3768386670794164656d456176774665646134643050417047665355326a4c74333958386b595542784e4d325767414c524267486456646538377136506935553639546a684d6432385731534644314478796f67434372714f6374325a5049436f4c6e72716446334f644e7a6a52564c6665797651384c674c76524e4652395766574179417a37396e4b6742616d64384e746c7674344d6733354535675653326737415137726b6d37326342646e5739734345794761626558417548356a34475262754c543771425a574463464c463453734364533357664647644e48667761696a7a796b42796f3731507646566c54584832574a576f4676523546414c6a42546e37624364503070416953624c435938587a324d73633364426235466639474953506255704e6d557642644d5a4d485176714f6d544e584550704e306237344d444f4d5166574a53684f6f334e6b41764d6a73082a")
  736. ||result == QByteArray::fromHex("082a128404328104595652664a766a78716267764677533159764f5a5867746a356666474c533741694e487a396f5a496f4b626d377a3848373978427579506b70515876476f4f30394f5939785261777833654f417339786a6f544131784a68727732385441637131436562596c43395755665143366849616e74614e647948694b546f666669305a74376c613432535278585a53503447757862635a49703533704a6e79437766437931716446637a5430646d6e3768386670794164656d456176774665646134643050417047665355326a4c74333958386b595542784e4d325767414c524267486456646538377136506935553639546a684d6432385731534644314478796f67434372714f6374325a5049436f4c6e72716446334f644e7a6a52564c6665797651384c674c76524e4652395766574179417a37396e4b6742616d64384e746c7674344d6733354535675653326737415137726b6d37326342646e5739734345794761626558417548356a34475262754c543771425a574463464c463453734364533357664647644e48667761696a7a796b42796f3731507646566c54584832574a576f4676523546414c6a42546e37624364503070416953624c435938587a324d73633364426235466639474953506255704e6d557642644d5a4d485176714f6d544e584550704e306237344d444f4d5166574a53684f6f334e6b41764d6a73"));
  737. stringMsg.setTestFieldString("qwerty");
  738. test.setTestFieldInt(-45);
  739. test.setTestComplexField(stringMsg);
  740. result = test.serialize(serializer.get());
  741. // qDebug() << "result" << result.toHex();
  742. ASSERT_TRUE(result == QByteArray::fromHex("1208320671776572747908d3ffffff0f")
  743. || result == QByteArray::fromHex("08d3ffffff0f12083206717765727479"));
  744. }
  745. TEST_F(SerializationTest, RepeatedIntMessageTest)
  746. {
  747. RepeatedIntMessage test;
  748. test.setTestRepeatedInt({0, 1, 321, -65999, 123245, -3, 3});
  749. QByteArray result = test.serialize(serializer.get());
  750. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a120001c102b1fcfbff0fedc207fdffffff0f03");
  751. test.setTestRepeatedInt(int32List());
  752. result = test.serialize(serializer.get());
  753. ASSERT_TRUE(result.isEmpty());
  754. }
  755. TEST_F(SerializationTest, RepeatedSIntMessageTest)
  756. {
  757. RepeatedSIntMessage test;
  758. test.setTestRepeatedInt({1, 321, -65999, 123245, -3, 3, 0});
  759. QByteArray result = test.serialize(serializer.get());
  760. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a0c0282059d8708da850f050600");
  761. test.setTestRepeatedInt(sint32List());
  762. result = test.serialize(serializer.get());
  763. ASSERT_TRUE(result.isEmpty());
  764. }
  765. TEST_F(SerializationTest, RepeatedUIntMessageTest)
  766. {
  767. RepeatedUIntMessage test;
  768. test.setTestRepeatedInt({1, 0, 321, 65999, 123245, 3});
  769. QByteArray result = test.serialize(serializer.get());
  770. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a0b0100c102cf8304edc20703");
  771. test.setTestRepeatedInt(uint32List());
  772. result = test.serialize(serializer.get());
  773. ASSERT_TRUE(result.isEmpty());
  774. }
  775. TEST_F(SerializationTest, RepeatedInt64MessageTest)
  776. {
  777. RepeatedInt64Message test;
  778. test.setTestRepeatedInt({1, 321, -65999, 12324523123123, -3, 0, 3});
  779. QByteArray result = test.serialize(serializer.get());
  780. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a2001c102b1fcfbffffffffffff01b3c3cab6d8e602fdffffffffffffffff010003");
  781. test.setTestRepeatedInt(int64List());
  782. result = test.serialize(serializer.get());
  783. ASSERT_TRUE(result.isEmpty());
  784. }
  785. TEST_F(SerializationTest, RepeatedSInt64MessageTest)
  786. {
  787. RepeatedSInt64Message test;
  788. test.setTestRepeatedInt({1, 321, -65999, 12324523123123, 0, -3, 3});
  789. QByteArray result = test.serialize(serializer.get());
  790. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a100282059d8708e68695edb0cd05000506");
  791. test.setTestRepeatedInt(sint64List());
  792. result = test.serialize(serializer.get());
  793. ASSERT_TRUE(result.isEmpty());
  794. }
  795. TEST_F(SerializationTest, RepeatedUInt64MessageTest)
  796. {
  797. RepeatedUInt64Message test;
  798. test.setTestRepeatedInt({1, 321, 0, 65999, 123245, 123245324235425234, 3});
  799. QByteArray result = test.serialize(serializer.get());
  800. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a1401c10200cf8304edc207d28b9fda82dff6da0103");
  801. test.setTestRepeatedInt(uint64List());
  802. result = test.serialize(serializer.get());
  803. ASSERT_TRUE(result.isEmpty());
  804. }
  805. TEST_F(SerializationTest, RepeatedFixedIntMessageTest)
  806. {
  807. RepeatedFixedIntMessage test;
  808. test.setTestRepeatedInt({1, 321, 65999, 12324523, 3, 3, 0});
  809. QByteArray result = test.serialize(serializer.get());
  810. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a1c0100000041010000cf010100ab0ebc00030000000300000000000000");
  811. test.setTestRepeatedInt(fixed32List());
  812. result = test.serialize(serializer.get());
  813. ASSERT_TRUE(result.isEmpty());
  814. }
  815. TEST_F(SerializationTest, RepeatedSFixedIntMessageTest)
  816. {
  817. RepeatedSFixedIntMessage test;
  818. test.setTestRepeatedInt({0, 1, 321, -65999, 12324523, -3, 3});
  819. QByteArray result = test.serialize(serializer.get());
  820. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a1c00000000010000004101000031fefeffab0ebc00fdffffff03000000");
  821. test.setTestRepeatedInt(sfixed32List());
  822. result = test.serialize(serializer.get());
  823. ASSERT_TRUE(result.isEmpty());
  824. }
  825. TEST_F(SerializationTest, RepeatedFixedInt64MessageTest)
  826. {
  827. RepeatedFixedInt64Message test;
  828. test.setTestRepeatedInt({1, 321, 65999, 123245324235425234, 3, 3, 0});
  829. QByteArray result = test.serialize(serializer.get());
  830. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a3801000000000000004101000000000000cf01010000000000d2c5472bf8dab501030000000000000003000000000000000000000000000000");
  831. test.setTestRepeatedInt(fixed64List());
  832. result = test.serialize(serializer.get());
  833. ASSERT_TRUE(result.isEmpty());
  834. }
  835. TEST_F(SerializationTest, RepeatedSFixedInt64MessageTest)
  836. {
  837. RepeatedSFixedInt64Message test;
  838. test.setTestRepeatedInt({1, 321, -65999, 123245324235425234, -3, 3, 0});
  839. QByteArray result = test.serialize(serializer.get());
  840. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a380100000000000000410100000000000031fefeffffffffffd2c5472bf8dab501fdffffffffffffff03000000000000000000000000000000");
  841. test.setTestRepeatedInt(sfixed64List());
  842. result = test.serialize(serializer.get());
  843. ASSERT_TRUE(result.isEmpty());
  844. }
  845. TEST_F(SerializationTest, RepeatedStringMessageTest)
  846. {
  847. RepeatedStringMessage test;
  848. test.setTestRepeatedString({"aaaa","bbbbb","ccc","dddddd","eeeee", ""});
  849. QByteArray result = test.serialize(serializer.get());
  850. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a04616161610a0562626262620a036363630a066464646464640a0565656565650a00");
  851. test.setTestRepeatedString(QStringList());
  852. result = test.serialize(serializer.get());
  853. ASSERT_TRUE(result.isEmpty());
  854. }
  855. TEST_F(SerializationTest, RepeatedDoubleMessageTest)
  856. {
  857. RepeatedDoubleMessage test;
  858. test.setTestRepeatedDouble({0.1, 0.2, 0.3, 0.4, 0.5});
  859. QByteArray result = test.serialize(serializer.get());
  860. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a289a9999999999b93f9a9999999999c93f333333333333d33f9a9999999999d93f000000000000e03f");
  861. test.setTestRepeatedDouble(DoubleList());
  862. result = test.serialize(serializer.get());
  863. ASSERT_TRUE(result.isEmpty());
  864. }
  865. TEST_F(SerializationTest, RepeatedBytesMessageTest)
  866. {
  867. RepeatedBytesMessage test;
  868. test.setTestRepeatedBytes({QByteArray::fromHex("010203040506"),
  869. QByteArray::fromHex("ffffffff"),
  870. QByteArray::fromHex("eaeaeaeaea"),
  871. QByteArray::fromHex("010203040506")});
  872. QByteArray result = test.serialize(serializer.get());
  873. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a060102030405060a04ffffffff0a05eaeaeaeaea0a06010203040506");
  874. test.setTestRepeatedBytes(QByteArrayList());
  875. result = test.serialize(serializer.get());
  876. ASSERT_TRUE(result.isEmpty());
  877. test.setTestRepeatedBytes({QByteArray::fromHex("010203040506"),
  878. QByteArray::fromHex(""),
  879. QByteArray::fromHex("eaeaeaeaea"),
  880. QByteArray::fromHex("010203040506")});
  881. result = test.serialize(serializer.get());
  882. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a060102030405060a000a05eaeaeaeaea0a06010203040506");
  883. }
  884. TEST_F(SerializationTest, RepeatedFloatMessageTest)
  885. {
  886. RepeatedFloatMessage test;
  887. test.setTestRepeatedFloat({0.4f, 1.2f, 0.5f, 1.4f, 0.6f});
  888. QByteArray result = test.serialize(serializer.get());
  889. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0a14cdcccc3e9a99993f0000003f3333b33f9a99193f");
  890. test.setTestRepeatedFloat(FloatList());
  891. result = test.serialize(serializer.get());
  892. ASSERT_TRUE(result.isEmpty());
  893. }
  894. TEST_F(SerializationTest, RepeatedComplexMessageTest)
  895. {
  896. SimpleStringMessage stringMsg;
  897. stringMsg.setTestFieldString("qwerty");
  898. QSharedPointer<ComplexMessage> msg(new ComplexMessage);
  899. msg->setTestFieldInt(25);
  900. msg->setTestComplexField(stringMsg);
  901. RepeatedComplexMessage test;
  902. test.setTestRepeatedComplex({msg, msg, msg});
  903. QByteArray result = test.serialize(serializer.get());
  904. qDebug() << "result " << result.toHex();
  905. ASSERT_TRUE(result == QByteArray::fromHex("0a0c0819120832067177657274790a0c0819120832067177657274790a0c081912083206717765727479")
  906. || result == QByteArray::fromHex("0a0c1208320671776572747908190a0c1208320671776572747908190a0c120832067177657274790819"));
  907. test.setTestRepeatedComplex({});
  908. result = test.serialize(serializer.get());
  909. ASSERT_TRUE(result.isEmpty());
  910. }
  911. TEST_F(SerializationTest, BoolMessageSerializeTest)
  912. {
  913. SimpleBoolMessage test;
  914. test.setTestFieldBool(true);
  915. QByteArray result = test.serialize(serializer.get());
  916. ASSERT_EQ(2, result.size());
  917. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0801");
  918. test.setTestFieldBool(false);
  919. result = test.serialize(serializer.get());
  920. ASSERT_EQ(0, result.size());
  921. ASSERT_STREQ(result.toHex().toStdString().c_str(), "");
  922. }
  923. TEST_F(SerializationTest, SimpleEnumMessageSerializeTest)
  924. {
  925. SimpleEnumMessage test;
  926. test.setLocalEnum(SimpleEnumMessage::LOCAL_ENUM_VALUE2);
  927. QByteArray result = test.serialize(serializer.get());
  928. ASSERT_EQ(2, result.size());
  929. ASSERT_STREQ(result.toHex().toStdString().c_str(), "0802");
  930. }
  931. TEST_F(SerializationTest, SimpleFixed32StringMapSerializeTest)
  932. {
  933. SimpleFixed32StringMapMessage test;
  934. test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
  935. QByteArray result = test.serialize(serializer.get());
  936. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  937. "3a0a0d0a000000120374656e3a0e0d0f00000012076669667465656e3a110d2a000000120a666f757274792074776f");
  938. }
  939. TEST_F(SerializationTest, SimpleSFixed32StringMapSerializeTest)
  940. {
  941. SimpleSFixed32StringMapMessage test;
  942. test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
  943. QByteArray result = test.serialize(serializer.get());
  944. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  945. "4a170dd6ffffff12106d696e757320666f757274792074776f4a0a0d0a000000120374656e4a0e0d0f00000012076669667465656e");
  946. }
  947. TEST_F(SerializationTest, SimpleInt32StringMapSerializeTest)
  948. {
  949. SimpleInt32StringMapMessage test;
  950. test.setMapField({{-10, {"minus ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
  951. QByteArray result = test.serialize(serializer.get());
  952. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  953. "1a1108f6ffffff0f12096d696e75732074656e1a0b080f12076669667465656e1a0e082a120a666f757274792074776f");
  954. }
  955. TEST_F(SerializationTest, SimpleSInt32StringMapSerializeTest)
  956. {
  957. SimpleSInt32StringMapMessage test;
  958. test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
  959. QByteArray result = test.serialize(serializer.get());
  960. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  961. "0a14085312106d696e757320666f757274792074776f0a070814120374656e0a0b081e12076669667465656e");
  962. }
  963. TEST_F(SerializationTest, SimpleUInt32StringMapSerializeTest)
  964. {
  965. SimpleUInt32StringMapMessage test;
  966. test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
  967. QByteArray result = test.serialize(serializer.get());
  968. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  969. "2a07080a120374656e2a0b080f12076669667465656e2a0e082a120a666f757274792074776f");
  970. }
  971. TEST_F(SerializationTest, SimpleFixed64StringMapSerializeTest)
  972. {
  973. SimpleFixed64StringMapMessage test;
  974. test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
  975. QByteArray result = test.serialize(serializer.get());
  976. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  977. "420e090a00000000000000120374656e4212090f0000000000000012076669667465656e4215092a00000000000000120a666f757274792074776f");
  978. }
  979. TEST_F(SerializationTest, SimpleSFixed64StringMapSerializeTest)
  980. {
  981. SimpleSFixed64StringMapMessage test;
  982. test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
  983. QByteArray result = test.serialize(serializer.get());
  984. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  985. "521b09d6ffffffffffffff12106d696e757320666f757274792074776f520e090a00000000000000120374656e5212090f0000000000000012076669667465656e");
  986. }
  987. TEST_F(SerializationTest, SimpleInt64StringMapSerializeTest)
  988. {
  989. SimpleInt64StringMapMessage test;
  990. test.setMapField({{-10, {"minus ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
  991. QByteArray result = test.serialize(serializer.get());
  992. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  993. "221608f6ffffffffffffffff0112096d696e75732074656e220b080f12076669667465656e220e082a120a666f757274792074776f");
  994. }
  995. TEST_F(SerializationTest, SimpleSInt64StringMapSerializeTest)
  996. {
  997. SimpleSInt64StringMapMessage test;
  998. test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
  999. QByteArray result = test.serialize(serializer.get());
  1000. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1001. "1214085312106d696e757320666f757274792074776f12070814120374656e120b081e12076669667465656e");
  1002. }
  1003. TEST_F(SerializationTest, SimpleUInt64StringMapSerializeTest)
  1004. {
  1005. SimpleUInt64StringMapMessage test;
  1006. test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
  1007. QByteArray result = test.serialize(serializer.get());
  1008. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1009. "3207080a120374656e320b080f12076669667465656e320e082a120a666f757274792074776f");
  1010. }
  1011. TEST_F(SerializationTest, SimpleStringStringMapSerializeTest)
  1012. {
  1013. SimpleStringStringMapMessage test;
  1014. test.setMapField({{"ben", "ten"}, {"what is the answer?", "fourty two"}, {"sweet", "fifteen"}});
  1015. QByteArray result = test.serialize(serializer.get());
  1016. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1017. "6a0a0a0362656e120374656e6a100a05737765657412076669667465656e6a210a13776861742069732074686520616e737765723f120a666f757274792074776f");
  1018. }
  1019. TEST_F(SerializationTest, FieldIndexRangeTest)
  1020. {
  1021. FieldIndexTest1Message msg1;
  1022. msg1.setTestField(1);
  1023. QByteArray result = msg1.serialize(serializer.get());
  1024. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1025. "f80102");
  1026. FieldIndexTest2Message msg2;
  1027. msg2.setTestField(1);
  1028. result = msg2.serialize(serializer.get());
  1029. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1030. "f8ff0302");
  1031. FieldIndexTest3Message msg3;
  1032. msg3.setTestField(1);
  1033. result = msg3.serialize(serializer.get());
  1034. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1035. "f8ffff0702");
  1036. FieldIndexTest4Message msg4;
  1037. msg4.setTestField(1);
  1038. result = msg4.serialize(serializer.get());
  1039. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1040. "f8ffffff0f02");
  1041. }
  1042. TEST_F(SerializationTest, SimpleEnumListMessageTest)
  1043. {
  1044. SimpleEnumListMessage msg;
  1045. msg.setLocalEnumList({SimpleEnumListMessage::LOCAL_ENUM_VALUE0,
  1046. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  1047. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  1048. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  1049. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  1050. SimpleEnumListMessage::LOCAL_ENUM_VALUE3});
  1051. QByteArray result = msg.serialize(serializer.get());
  1052. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1053. "0a06000102010203");
  1054. msg.setLocalEnumList({});
  1055. result = msg.serialize(serializer.get());
  1056. ASSERT_STREQ(result.toHex().toStdString().c_str(),
  1057. "");
  1058. }
  1059. TEST_F(SerializationTest, EmptyBytesMessageTest)
  1060. {
  1061. SimpleBytesMessage msg;
  1062. QByteArray result = msg.serialize(serializer.get());
  1063. ASSERT_TRUE(result.isEmpty());
  1064. }
  1065. TEST_F(SerializationTest, EmptyStringMessageTest)
  1066. {
  1067. SimpleStringMessage msg;
  1068. QByteArray result = msg.serialize(serializer.get());
  1069. ASSERT_TRUE(result.isEmpty());
  1070. }
  1071. TEST_F(SerializationTest, DISABLED_BenchmarkTest)
  1072. {
  1073. SimpleIntMessage msg;
  1074. for (int i = INT16_MIN; i < INT16_MAX; i++) {
  1075. msg.setTestFieldInt(i);
  1076. msg.serialize(serializer.get());
  1077. }
  1078. }