simpletest.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 "simpletest.h"
  26. #include "stepchildenummessage.h"
  27. #include "simpleboolmessage.h"
  28. #include "simpleintmessage.h"
  29. #include "simplesintmessage.h"
  30. #include "simpleuintmessage.h"
  31. #include "simpleint64message.h"
  32. #include "simplesint64message.h"
  33. #include "simpleuint64message.h"
  34. #include "simplefixedint32message.h"
  35. #include "simplefixedint64message.h"
  36. #include "simplesfixedint32message.h"
  37. #include "simplesfixedint64message.h"
  38. #include "simplestringmessage.h"
  39. #include "simplefloatmessage.h"
  40. #include "simpledoublemessage.h"
  41. #include "simpleenummessage.h"
  42. #include "simpleenumlistmessage.h"
  43. #include "simplefileenummessage.h"
  44. #include "simpleexternalenummessage.h"
  45. #include "externalcomplexmessage.h"
  46. #include "complexmessage.h"
  47. #include "simplebytesmessage.h"
  48. #include "repeatedintmessage.h"
  49. #include "repeatedbytesmessage.h"
  50. #include "repeateddoublemessage.h"
  51. #include "repeatedcomplexmessage.h"
  52. #include "repeatedfloatmessage.h"
  53. #include "repeatedsintmessage.h"
  54. #include "repeatedstringmessage.h"
  55. #include "repeateduintmessage.h"
  56. #include "repeatedint64message.h"
  57. #include "repeatedsint64message.h"
  58. #include "repeateduint64message.h"
  59. #include "repeatedfixedintmessage.h"
  60. #include "repeatedsfixedintmessage.h"
  61. #include "repeatedfixedint64message.h"
  62. #include "repeatedsfixedint64message.h"
  63. #include "repeatedexternalcomplexmessage.h"
  64. #include "simplesint32stringmapmessage.h"
  65. #include "simplestringstringmapmessage.h"
  66. #include "emptymessage.h"
  67. #include "globalenums.h"
  68. #include "qtprotobuf.h"
  69. #include <QVariantList>
  70. #include <QMetaProperty>
  71. using namespace qtprotobufnamespace::tests;
  72. using namespace qtprotobuf::tests;
  73. using namespace qtprotobuf;
  74. SimpleTest::SimpleTest()
  75. {
  76. QtProtobuf::init();
  77. }
  78. TEST_F(SimpleTest, SimpleBoolMessageTest)
  79. {
  80. const char* propertyName = "testFieldBool";
  81. SimpleBoolMessage test;
  82. int propertyNumber = SimpleBoolMessage::propertyOrdering.at(1); //See simpletest.proto
  83. ASSERT_STREQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).typeName(), "bool");
  84. ASSERT_EQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<bool>());
  85. ASSERT_STREQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  86. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(true)));
  87. ASSERT_EQ(test.property(propertyName).toBool(), true);
  88. ASSERT_EQ(test.testFieldBool(), true);
  89. }
  90. TEST_F(SimpleTest, SimpleIntMessageTest)
  91. {
  92. const char* propertyName = "testFieldInt";
  93. SimpleIntMessage test;
  94. int propertyNumber = SimpleIntMessage::propertyOrdering.at(1); //See simpletest.proto
  95. ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32");
  96. ASSERT_EQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<int32>());
  97. ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  98. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32>(1)));
  99. ASSERT_EQ(test.property(propertyName).value<int32>(), 1);
  100. ASSERT_EQ(test.testFieldInt(), 1);
  101. }
  102. TEST_F(SimpleTest, SimpleSIntMessageTest)
  103. {
  104. const char* propertyName = "testFieldInt";
  105. SimpleSIntMessage test;
  106. int propertyNumber = SimpleSIntMessage::propertyOrdering.at(1); //See simpletest.proto
  107. ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32");
  108. ASSERT_EQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<sint32>());
  109. ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  110. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32>(1)));
  111. ASSERT_EQ(test.property(propertyName).value<sint32>(), 1);
  112. ASSERT_EQ(test.testFieldInt(), 1);
  113. }
  114. TEST_F(SimpleTest, SimpleUIntMessageTest)
  115. {
  116. const char* propertyName = "testFieldInt";
  117. SimpleUIntMessage test;
  118. int propertyNumber = SimpleUIntMessage::propertyOrdering.at(1); //See simpletest.proto
  119. ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint32");
  120. ASSERT_EQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<uint32>());
  121. ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  122. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32>(1)));
  123. ASSERT_EQ(test.property(propertyName).value<uint32>(), 1);
  124. ASSERT_EQ(test.testFieldInt(), 1);
  125. }
  126. TEST_F(SimpleTest, SimpleInt64MessageTest)
  127. {
  128. const char* propertyName = "testFieldInt";
  129. SimpleInt64Message test;
  130. int propertyNumber = SimpleInt64Message::propertyOrdering.at(1); //See simpletest.proto
  131. ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int64");
  132. ASSERT_EQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<int64>());
  133. ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  134. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64>(1)));
  135. ASSERT_EQ(test.property(propertyName).value<int64>(), 1);
  136. ASSERT_EQ(test.testFieldInt(), 1);
  137. }
  138. TEST_F(SimpleTest, SimpleSInt64MessageTest)
  139. {
  140. const char* propertyName = "testFieldInt";
  141. SimpleSInt64Message test;
  142. int propertyNumber = SimpleSInt64Message::propertyOrdering.at(1); //See simpletest.proto
  143. ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint64");
  144. ASSERT_EQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<sint64>());
  145. ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  146. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64>(1)));
  147. ASSERT_EQ(test.property(propertyName).value<sint64>(), 1);
  148. ASSERT_EQ(test.testFieldInt(), 1);
  149. }
  150. TEST_F(SimpleTest, SimpleUInt64MessageTest)
  151. {
  152. const char* propertyName = "testFieldInt";
  153. SimpleUInt64Message test;
  154. int propertyNumber = SimpleUInt64Message::propertyOrdering.at(1); //See simpletest.proto
  155. ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint64");
  156. ASSERT_EQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<uint64>());
  157. ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  158. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64>(1)));
  159. ASSERT_EQ(test.property(propertyName).value<uint64>(), 1);
  160. ASSERT_EQ(test.testFieldInt(), 1);
  161. }
  162. TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
  163. {
  164. const char* propertyName = "testFieldFixedInt32";
  165. SimpleFixedInt32Message test;
  166. int propertyNumber = SimpleFixedInt32Message::propertyOrdering.at(1); //See simpletest.proto
  167. ASSERT_EQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<fixed32>());
  168. ASSERT_STREQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fixed32");
  169. ASSERT_STREQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  170. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32>(1)));
  171. ASSERT_EQ(test.property(propertyName).value<fixed32>(), 1);
  172. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  173. }
  174. TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
  175. {
  176. const char* propertyName = "testFieldFixedInt64";
  177. SimpleFixedInt64Message test;
  178. int propertyNumber = SimpleFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  179. ASSERT_EQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<fixed64>());
  180. ASSERT_STREQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fixed64");
  181. ASSERT_STREQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  182. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64>(1)));
  183. ASSERT_EQ(test.property(propertyName).value<fixed64>(), 1);
  184. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  185. }
  186. TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
  187. {
  188. const char* propertyName = "testFieldFixedInt32";
  189. SimpleSFixedInt32Message test;
  190. int propertyNumber = SimpleSFixedInt32Message::propertyOrdering.at(1); //See simpletest.proto
  191. ASSERT_EQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<sfixed32>());
  192. ASSERT_STREQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfixed32");
  193. ASSERT_STREQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  194. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32>(1)));
  195. ASSERT_EQ(test.property(propertyName).value<sfixed32>(), 1);
  196. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  197. }
  198. TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
  199. {
  200. const char* propertyName = "testFieldFixedInt64";
  201. SimpleSFixedInt64Message test;
  202. int propertyNumber = SimpleSFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  203. ASSERT_EQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<sfixed64>());
  204. ASSERT_STREQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfixed64");
  205. ASSERT_STREQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  206. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64>(1)));
  207. ASSERT_EQ(test.property(propertyName).value<sfixed64>(), 1);
  208. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  209. }
  210. TEST_F(SimpleTest, SimpleStringMessageTest)
  211. {
  212. const char* propertyName = "testFieldString";
  213. SimpleStringMessage test;
  214. int propertyNumber = SimpleStringMessage::propertyOrdering.at(6); //See simpletest.proto
  215. ASSERT_EQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QString);
  216. ASSERT_STREQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  217. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(QString("test1"))));
  218. ASSERT_STREQ(test.property(propertyName).toString().toStdString().c_str(), "test1");
  219. ASSERT_STREQ(test.testFieldString().toStdString().c_str(), "test1");
  220. }
  221. TEST_F(SimpleTest, SimpleFloatMessageTest)
  222. {
  223. const char* propertyName = "testFieldFloat";
  224. SimpleFloatMessage test;
  225. int propertyNumber = SimpleFloatMessage::propertyOrdering.at(7); //See simpletest.proto
  226. ASSERT_EQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Float);
  227. ASSERT_STREQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).name(), "testFieldFloat");
  228. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<float>(1.55f)));
  229. ASSERT_TRUE(qFuzzyCompare(test.property(propertyName).toFloat(), 1.55f));
  230. ASSERT_TRUE(qFuzzyCompare(test.testFieldFloat(), 1.55f));
  231. }
  232. TEST_F(SimpleTest, SimpleDoubleMessageTest)
  233. {
  234. const char* propertyName = "testFieldDouble";
  235. SimpleDoubleMessage test;
  236. int propertyNumber = SimpleDoubleMessage::propertyOrdering.at(8); //See simpletest.proto
  237. ASSERT_EQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Double);
  238. ASSERT_STREQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  239. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<double>(0.55)));
  240. ASSERT_FLOAT_EQ(test.property(propertyName).toDouble(), 0.55);
  241. ASSERT_FLOAT_EQ(test.testFieldDouble(), 0.55);
  242. }
  243. TEST_F(SimpleTest, SimpleLocalEnumTest)
  244. {
  245. ASSERT_GT(SimpleEnumMessage::staticMetaObject.enumeratorCount(), 0);
  246. QMetaEnum simpleEnum;
  247. for (int i = 0; i < SimpleEnumMessage::staticMetaObject.enumeratorCount(); i++) {
  248. QMetaEnum tmp = SimpleEnumMessage::staticMetaObject.enumerator(i);
  249. if (QString(tmp.name()) == QString("LocalEnum")) {
  250. simpleEnum = tmp;
  251. break;
  252. }
  253. }
  254. ASSERT_TRUE(simpleEnum.isValid());
  255. ASSERT_STREQ(simpleEnum.key(0), "LOCAL_ENUM_VALUE0");
  256. ASSERT_STREQ(simpleEnum.key(1), "LOCAL_ENUM_VALUE1");
  257. ASSERT_STREQ(simpleEnum.key(2), "LOCAL_ENUM_VALUE2");
  258. ASSERT_STREQ(simpleEnum.key(3), "LOCAL_ENUM_VALUE3");
  259. ASSERT_EQ(simpleEnum.value(0), 0);
  260. ASSERT_EQ(simpleEnum.value(1), 1);
  261. ASSERT_EQ(simpleEnum.value(2), 2);
  262. ASSERT_EQ(simpleEnum.value(3), 3);
  263. }
  264. TEST_F(SimpleTest, SimpleLocalEnumListTest)
  265. {
  266. ASSERT_GT(SimpleEnumListMessage::staticMetaObject.enumeratorCount(), 0);
  267. const char* propertyName = "localEnumList";
  268. SimpleEnumListMessage test;
  269. int propertyNumber = SimpleEnumListMessage::propertyOrdering.at(1); //See simpletest.proto
  270. ASSERT_STREQ(SimpleEnumListMessage::staticMetaObject.property(propertyNumber).typeName(), "SimpleEnumListMessage::LocalEnumList");
  271. ASSERT_EQ(SimpleEnumListMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobufnamespace::tests::SimpleEnumListMessage::LocalEnumList>());
  272. ASSERT_STREQ(SimpleEnumListMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  273. SimpleEnumListMessage::LocalEnumList value({SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  274. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  275. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  276. SimpleEnumListMessage::LOCAL_ENUM_VALUE3});
  277. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumListMessage::LocalEnumList>(value)));
  278. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumListMessage::LocalEnumList>() == value);
  279. ASSERT_TRUE(test.localEnumList() == value);
  280. }
  281. TEST_F(SimpleTest, SimpleExternalEnumMessageTest)
  282. {
  283. const char* propertyName = "externalEnum";
  284. using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::GlobalEnums;
  285. ExternalGlobalEnums::registerTypes();
  286. SimpleExternalEnumMessage test;
  287. int propertyNumber = SimpleExternalEnumMessage::propertyOrdering.at(1); //See externalpackagetest.proto
  288. ASSERT_STREQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace1::externaltests::GlobalEnums::ExternalTestEnum");
  289. ASSERT_EQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<ExternalGlobalEnums::ExternalTestEnum>());
  290. ASSERT_STREQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  291. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4)));
  292. ASSERT_TRUE(test.property(propertyName).value<ExternalGlobalEnums::ExternalTestEnum>() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  293. ASSERT_TRUE(test.externalEnum() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  294. }
  295. TEST_F(SimpleTest, SimpleEnumsTest)
  296. {
  297. ASSERT_GT(GlobalEnums::staticMetaObject.enumeratorCount(), 0);
  298. QMetaEnum simpleEnum;
  299. for (int i = 0; i < GlobalEnums::staticMetaObject.enumeratorCount(); i++) {
  300. QMetaEnum tmp = GlobalEnums::staticMetaObject.enumerator(i);
  301. if (QString(tmp.name()) == QString("TestEnum")) {
  302. simpleEnum = tmp;
  303. break;
  304. }
  305. }
  306. ASSERT_TRUE(simpleEnum.isValid());
  307. ASSERT_STREQ(simpleEnum.key(0), "TEST_ENUM_VALUE0");
  308. ASSERT_STREQ(simpleEnum.key(1), "TEST_ENUM_VALUE1");
  309. ASSERT_STREQ(simpleEnum.key(2), "TEST_ENUM_VALUE2");
  310. ASSERT_STREQ(simpleEnum.key(3), "TEST_ENUM_VALUE3");
  311. ASSERT_STREQ(simpleEnum.key(4), "TEST_ENUM_VALUE4");
  312. ASSERT_EQ(simpleEnum.value(0), 0);
  313. ASSERT_EQ(simpleEnum.value(1), 1);
  314. ASSERT_EQ(simpleEnum.value(2), 2);
  315. ASSERT_EQ(simpleEnum.value(3), 4);
  316. ASSERT_EQ(simpleEnum.value(4), 3);
  317. }
  318. TEST_F(SimpleTest, SimpleFileEnumsTest)
  319. {
  320. const char* propertyName = "globalEnumList";
  321. SimpleFileEnumMessage test;
  322. int propertyNumber = SimpleFileEnumMessage::propertyOrdering.at(2); //See simpletest.proto
  323. ASSERT_STREQ(SimpleFileEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::GlobalEnums::TestEnumList");
  324. ASSERT_EQ(SimpleFileEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobufnamespace::tests::GlobalEnums::TestEnumList>());
  325. ASSERT_STREQ(SimpleFileEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  326. GlobalEnums::TestEnumList value({GlobalEnums::TEST_ENUM_VALUE1,
  327. GlobalEnums::TEST_ENUM_VALUE3,
  328. GlobalEnums::TEST_ENUM_VALUE4,
  329. GlobalEnums::TEST_ENUM_VALUE2,
  330. GlobalEnums::TEST_ENUM_VALUE1});
  331. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<GlobalEnums::TestEnumList>(value)));
  332. ASSERT_TRUE(test.property(propertyName).value<GlobalEnums::TestEnumList>() == value);
  333. ASSERT_TRUE(test.globalEnumList() == value);
  334. }
  335. TEST_F(SimpleTest, ComplexMessageTest)
  336. {
  337. ComplexMessage msg;
  338. }
  339. TEST_F(SimpleTest, SimpleBytesMessageTest)
  340. {
  341. const char* propertyName = "testFieldBytes";
  342. SimpleBytesMessage test;
  343. int propertyNumber = SimpleBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  344. ASSERT_EQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QByteArray);
  345. ASSERT_STREQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  346. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArray>("\x01\x02\x03\x04\x05")));
  347. ASSERT_TRUE(test.property(propertyName).toByteArray() == QByteArray("\x01\x02\x03\x04\x05"));
  348. ASSERT_TRUE(test.testFieldBytes() == QByteArray("\x01\x02\x03\x04\x05"));
  349. }
  350. TEST_F(SimpleTest, SimpleExternalComplexMessageTest)
  351. {
  352. const char* propertyName = "localList";
  353. qtprotobufnamespace1::externaltests::SimpleExternalMessage test;
  354. int propertyNumber = qtprotobufnamespace1::externaltests::SimpleExternalMessage::propertyOrdering.at(1);
  355. ASSERT_STREQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32List");
  356. ASSERT_EQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int32List>());
  357. ASSERT_STREQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  358. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  359. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  360. ASSERT_TRUE(test.localList() == int32List({1, 2, 3, 4, 5}));
  361. }
  362. TEST_F(SimpleTest, RepeatedExternalComplexMessageTest)
  363. {
  364. const char* propertyName = "testExternalComplex";
  365. RepeatedExternalComplexMessage test;
  366. int propertyNumber = RepeatedExternalComplexMessage::propertyOrdering.at(1); //See simpletest.proto
  367. ASSERT_STREQ(RepeatedExternalComplexMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace1::externaltests::ExternalComplexMessageList");
  368. ASSERT_EQ(RepeatedExternalComplexMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobufnamespace1::externaltests::ExternalComplexMessageList>());
  369. ASSERT_STREQ(RepeatedExternalComplexMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  370. qtprotobufnamespace1::externaltests::SimpleExternalMessage complexMessage;
  371. complexMessage.setLocalList({1, 2, 3, 4, 5});
  372. QSharedPointer<qtprotobufnamespace1::externaltests::ExternalComplexMessage> externalMessage(new qtprotobufnamespace1::externaltests::ExternalComplexMessage);
  373. externalMessage->setTestFieldInt(complexMessage);
  374. qtprotobufnamespace1::externaltests::ExternalComplexMessageList complexMessageList;
  375. complexMessageList << externalMessage;
  376. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(complexMessageList)));
  377. ASSERT_TRUE(test.property(propertyName).value<qtprotobufnamespace1::externaltests::ExternalComplexMessageList>() == complexMessageList);
  378. ASSERT_TRUE(test.testExternalComplex() == complexMessageList);
  379. }
  380. TEST_F(SimpleTest, RepeatedStringMessageTest)
  381. {
  382. const char* propertyName = "testRepeatedString";
  383. RepeatedStringMessage test;
  384. int propertyNumber = RepeatedStringMessage::propertyOrdering.at(1); //See simpletest.proto
  385. ASSERT_STREQ(RepeatedStringMessage::staticMetaObject.property(propertyNumber).typeName(), "QStringList");
  386. ASSERT_EQ(RepeatedStringMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<QStringList>());
  387. ASSERT_STREQ(RepeatedStringMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  388. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QStringList>({"Text", "tryam"})));
  389. ASSERT_TRUE(test.property(propertyName).value<QStringList>() == QStringList({"Text", "tryam"}));
  390. ASSERT_TRUE(test.testRepeatedString() == QStringList({"Text", "tryam"}));
  391. }
  392. TEST_F(SimpleTest, RepeatedIntMessageTest)
  393. {
  394. const char* propertyName = "testRepeatedInt";
  395. RepeatedIntMessage test;
  396. int propertyNumber = RepeatedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  397. ASSERT_STREQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32List");
  398. ASSERT_EQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int32List>());
  399. ASSERT_STREQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  400. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  401. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  402. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  403. test.testRepeatedInt().append(66);
  404. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5, 66}));
  405. test.testRepeatedInt().pop_back();
  406. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  407. }
  408. TEST_F(SimpleTest, RepeatedDoubleMessageTest)
  409. {
  410. const char* propertyName = "testRepeatedDouble";
  411. RepeatedDoubleMessage test;
  412. int propertyNumber = RepeatedDoubleMessage::propertyOrdering.at(1); //See simpletest.proto
  413. ASSERT_STREQ(RepeatedDoubleMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::DoubleList");
  414. ASSERT_EQ(RepeatedDoubleMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::DoubleList>());
  415. ASSERT_STREQ(RepeatedDoubleMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  416. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobuf::DoubleList>({1.0, 2.3, 3, 4.7, 5.9})));
  417. ASSERT_TRUE(test.property(propertyName).value<qtprotobuf::DoubleList>() == qtprotobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  418. ASSERT_TRUE(test.testRepeatedDouble() == qtprotobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  419. test.testRepeatedDouble().append(6.6);
  420. ASSERT_TRUE(test.testRepeatedDouble() == qtprotobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9, 6.6}));
  421. test.testRepeatedDouble().pop_back();
  422. ASSERT_TRUE(test.testRepeatedDouble() == qtprotobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  423. }
  424. TEST_F(SimpleTest, RepeatedFloatMessageTest)
  425. {
  426. const char* propertyName = "testRepeatedFloat";
  427. RepeatedFloatMessage test;
  428. int propertyNumber = RepeatedFloatMessage::propertyOrdering.at(1); //See simpletest.proto
  429. ASSERT_STREQ(RepeatedFloatMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::FloatList");
  430. ASSERT_EQ(RepeatedFloatMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::FloatList>());
  431. ASSERT_STREQ(RepeatedFloatMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  432. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobuf::FloatList>({1.0f, 2.3f, 3, 4.7f, 5.9f})));
  433. ASSERT_TRUE(test.property(propertyName).value<qtprotobuf::FloatList>() == qtprotobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  434. ASSERT_TRUE(test.testRepeatedFloat() == qtprotobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  435. test.testRepeatedFloat().append(6.6f);
  436. ASSERT_TRUE(test.testRepeatedFloat() == qtprotobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f, 6.6f}));
  437. test.testRepeatedFloat().pop_back();
  438. ASSERT_TRUE(test.testRepeatedFloat() == qtprotobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  439. }
  440. TEST_F(SimpleTest, RepeatedBytesMessageTest)
  441. {
  442. const char* propertyName = "testRepeatedBytes";
  443. RepeatedBytesMessage test;
  444. int propertyNumber = RepeatedBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  445. ASSERT_STREQ(RepeatedBytesMessage::staticMetaObject.property(propertyNumber).typeName(), "QByteArrayList");
  446. ASSERT_EQ(RepeatedBytesMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<QByteArrayList>());
  447. ASSERT_STREQ(RepeatedBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  448. QByteArrayList bList;
  449. bList << "\x01\x02\x03\x04\x05";
  450. bList << "\x01\x05\x03\x04\x03";
  451. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArrayList>(bList)));
  452. ASSERT_TRUE(test.property(propertyName).value<QByteArrayList>() == bList);
  453. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  454. bList << "\x01\x05\x03\x03";
  455. test.testRepeatedBytes() << "\x01\x05\x03\x03";
  456. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  457. bList.pop_back();
  458. test.testRepeatedBytes().pop_back();
  459. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  460. }
  461. TEST_F(SimpleTest, RepeatedSIntMessageTest)
  462. {
  463. const char* propertyName = "testRepeatedInt";
  464. RepeatedSIntMessage test;
  465. int propertyNumber = RepeatedSIntMessage::propertyOrdering.at(1); //See simpletest.proto
  466. ASSERT_STREQ(RepeatedSIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32List");
  467. ASSERT_EQ(RepeatedSIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sint32List>());
  468. ASSERT_STREQ(RepeatedSIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  469. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32List>({1, 2, 3, 4, 5})));
  470. ASSERT_TRUE(test.property(propertyName).value<sint32List>() == sint32List({1, 2, 3, 4, 5}));
  471. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  472. test.testRepeatedInt() << 6;
  473. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5, 6}));
  474. test.testRepeatedInt().pop_back();
  475. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  476. }
  477. TEST_F(SimpleTest, RepeatedUIntMessageTest)
  478. {
  479. const char* propertyName = "testRepeatedInt";
  480. RepeatedUIntMessage test;
  481. int propertyNumber = RepeatedUIntMessage::propertyOrdering.at(1); //See simpletest.proto
  482. ASSERT_STREQ(RepeatedUIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint32List");
  483. ASSERT_EQ(RepeatedUIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::uint32List>());
  484. ASSERT_STREQ(RepeatedUIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  485. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32List>({1, 2, 3, 4, 5})));
  486. ASSERT_TRUE(test.property(propertyName).value<uint32List>() == uint32List({1, 2, 3, 4, 5}));
  487. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  488. test.testRepeatedInt().append(6);
  489. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5,6}));
  490. test.testRepeatedInt().pop_back();
  491. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  492. }
  493. TEST_F(SimpleTest, RepeatedInt64MessageTest)
  494. {
  495. const char* propertyName = "testRepeatedInt";
  496. RepeatedInt64Message test;
  497. int propertyNumber = RepeatedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  498. ASSERT_STREQ(RepeatedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int64List");
  499. ASSERT_EQ(RepeatedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int64List>());
  500. ASSERT_STREQ(RepeatedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  501. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64List>({1, 2, 3, 4, 5})));
  502. ASSERT_TRUE(test.property(propertyName).value<int64List>() == int64List({1, 2, 3, 4, 5}));
  503. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  504. test.testRepeatedInt().append(69);
  505. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5, 69}));
  506. test.testRepeatedInt().pop_back();
  507. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  508. }
  509. TEST_F(SimpleTest, RepeatedSInt64MessageTest)
  510. {
  511. const char* propertyName = "testRepeatedInt";
  512. RepeatedSInt64Message test;
  513. int propertyNumber = RepeatedSInt64Message::propertyOrdering.at(1); //See simpletest.proto
  514. ASSERT_STREQ(RepeatedSInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint64List");
  515. ASSERT_EQ(RepeatedSInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sint64List>());
  516. ASSERT_STREQ(RepeatedSInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  517. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64List>({1, 2, 3, 4, 5})));
  518. ASSERT_TRUE(test.property(propertyName).value<sint64List>() == sint64List({1, 2, 3, 4, 5}));
  519. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  520. test.testRepeatedInt() << 96;
  521. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5, 96}));
  522. test.testRepeatedInt().pop_back();
  523. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  524. }
  525. TEST_F(SimpleTest, RepeatedUInt64MessageTest)
  526. {
  527. const char* propertyName = "testRepeatedInt";
  528. RepeatedUInt64Message test;
  529. int propertyNumber = RepeatedUInt64Message::propertyOrdering.at(1); //See simpletest.proto
  530. ASSERT_STREQ(RepeatedUInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint64List");
  531. ASSERT_EQ(RepeatedUInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::uint64List>());
  532. ASSERT_STREQ(RepeatedUInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  533. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64List>({1, 2, 3, 4, 5})));
  534. ASSERT_TRUE(test.property(propertyName).value<uint64List>() == uint64List({1, 2, 3, 4, 5}));
  535. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  536. test.testRepeatedInt().append(96);
  537. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5, 96}));
  538. test.testRepeatedInt().pop_back();
  539. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  540. }
  541. TEST_F(SimpleTest, RepeatedFixedIntMessageTest)
  542. {
  543. const char* propertyName = "testRepeatedInt";
  544. RepeatedFixedIntMessage test;
  545. int propertyNumber = RepeatedFixedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  546. ASSERT_STREQ(RepeatedFixedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fixed32List");
  547. ASSERT_EQ(RepeatedFixedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::fixed32List>());
  548. ASSERT_STREQ(RepeatedFixedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  549. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32List>({1, 2, 3, 4, 5})));
  550. ASSERT_TRUE(test.property(propertyName).value<fixed32List>() == fixed32List({1, 2, 3, 4, 5}));
  551. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  552. test.testRepeatedInt() << 0;
  553. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5, 0}));
  554. test.testRepeatedInt().pop_back();
  555. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  556. }
  557. TEST_F(SimpleTest, RepeatedFixedInt64MessageTest)
  558. {
  559. const char* propertyName = "testRepeatedInt";
  560. RepeatedFixedInt64Message test;
  561. int propertyNumber = RepeatedFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  562. ASSERT_STREQ(RepeatedFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fixed64List");
  563. ASSERT_EQ(RepeatedFixedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::fixed64List>());
  564. ASSERT_STREQ(RepeatedFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  565. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64List>({1, 2, 3, 4, 5})));
  566. ASSERT_TRUE(test.property(propertyName).value<fixed64List>() == fixed64List({1, 2, 3, 4, 5}));
  567. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  568. test.testRepeatedInt() << 0;
  569. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5, 0}));
  570. test.testRepeatedInt().pop_back();
  571. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  572. }
  573. TEST_F(SimpleTest, RepeatedSFixedIntMessageTest)
  574. {
  575. const char* propertyName = "testRepeatedInt";
  576. RepeatedSFixedIntMessage test;
  577. int propertyNumber = RepeatedSFixedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  578. ASSERT_STREQ(RepeatedSFixedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfixed32List");
  579. ASSERT_EQ(RepeatedSFixedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sfixed32List>());
  580. ASSERT_STREQ(RepeatedSFixedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  581. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32List>({1, 2, 3, 4, 5})));
  582. ASSERT_TRUE(test.property(propertyName).value<sfixed32List>() == sfixed32List({1, 2, 3, 4, 5}));
  583. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  584. test.testRepeatedInt() << 0;
  585. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5, 0}));
  586. test.testRepeatedInt().pop_back();
  587. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  588. }
  589. TEST_F(SimpleTest, RepeatedSFixedInt64MessageTest)
  590. {
  591. const char* propertyName = "testRepeatedInt";
  592. RepeatedSFixedInt64Message test;
  593. int propertyNumber = RepeatedSFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  594. ASSERT_STREQ(RepeatedSFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfixed64List");
  595. ASSERT_EQ(RepeatedSFixedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sfixed64List>());
  596. ASSERT_STREQ(RepeatedSFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  597. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64List>({1, 2, 3, 4, 5})));
  598. ASSERT_TRUE(test.property(propertyName).value<sfixed64List>() == sfixed64List({1, 2, 3, 4, 5}));
  599. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  600. test.testRepeatedInt() << 0;
  601. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5, 0}));
  602. test.testRepeatedInt().pop_back();
  603. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  604. }
  605. TEST_F(SimpleTest, StepChildEnumMessageTest)
  606. {
  607. qtprotobufnamespace::tests::SimpleEnumMessage::registerTypes();
  608. const char* propertyName = "localStepChildEnum";
  609. StepChildEnumMessage test;
  610. int propertyNumber = StepChildEnumMessage::propertyOrdering.at(1); //See simpletest.proto
  611. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum");
  612. ASSERT_EQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum>());
  613. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  614. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum>(qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2)));
  615. ASSERT_TRUE(test.property(propertyName).value<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum>() == qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  616. ASSERT_TRUE(test.localStepChildEnum() == qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  617. }
  618. TEST_F(SimpleTest, StepChildEnumListMessageTest)
  619. {
  620. qtprotobufnamespace::tests::SimpleEnumMessage::registerTypes();
  621. const char* propertyName = "localStepChildList";
  622. StepChildEnumMessage test;
  623. int propertyNumber = StepChildEnumMessage::propertyOrdering.at(2); //See simpletest.proto
  624. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumList");
  625. ASSERT_EQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumList>());
  626. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  627. qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumList value({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  628. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  629. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  630. SimpleEnumMessage::LOCAL_ENUM_VALUE3});
  631. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumList>(value)));
  632. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnumList>() == value);
  633. ASSERT_TRUE(test.localStepChildList() == value);
  634. }
  635. TEST_F(SimpleTest, SimpleSInt32StringMapMessageTest)
  636. {
  637. const char* propertyName = "mapField";
  638. SimpleSInt32StringMapMessage::registerTypes();
  639. SimpleSInt32StringMapMessage test;
  640. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleSInt32StringMapMessage::MapFieldEntry>()));
  641. int propertyNumber = SimpleSInt32StringMapMessage::propertyOrdering.at(1); //See simpletest.proto
  642. ASSERT_STREQ(SimpleSInt32StringMapMessage::staticMetaObject.property(propertyNumber).typeName(), "SimpleSInt32StringMapMessage::MapFieldEntry");
  643. ASSERT_EQ(SimpleSInt32StringMapMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleSInt32StringMapMessage::MapFieldEntry>());
  644. ASSERT_STREQ(SimpleSInt32StringMapMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  645. SimpleSInt32StringMapMessage::MapFieldEntry testMap = {{10, {"Some 10"}}, {0, {"Some 0"}}, {44, {"Some 44"}}};
  646. test.setMapField(testMap);
  647. ASSERT_TRUE(test.property(propertyName).value<SimpleSInt32StringMapMessage::MapFieldEntry>() == testMap);
  648. ASSERT_TRUE(test.mapField() == testMap);
  649. ASSERT_STREQ(test.mapField()[10].toStdString().c_str(), "Some 10");
  650. ASSERT_STREQ(test.mapField()[0].toStdString().c_str(), "Some 0");
  651. ASSERT_STREQ(test.mapField()[44].toStdString().c_str(), "Some 44");
  652. test.mapField()[66] = "Some 66";
  653. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some 66");
  654. test.mapField()[66] = "Some default";
  655. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some default");
  656. }
  657. TEST_F(SimpleTest, SimpleStringStringMapMessageTest)
  658. {
  659. const char* propertyName = "mapField";
  660. SimpleStringStringMapMessage::registerTypes();
  661. SimpleStringStringMapMessage test;
  662. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleStringStringMapMessage::MapFieldEntry>()));
  663. int propertyNumber = SimpleStringStringMapMessage::propertyOrdering.at(13); //See simpletest.proto
  664. ASSERT_STREQ(SimpleStringStringMapMessage::staticMetaObject.property(propertyNumber).typeName(), "SimpleStringStringMapMessage::MapFieldEntry");
  665. ASSERT_EQ(SimpleStringStringMapMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleStringStringMapMessage::MapFieldEntry>());
  666. ASSERT_STREQ(SimpleStringStringMapMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  667. SimpleStringStringMapMessage::MapFieldEntry testMap = {{"key 10", "Some 10"}, {"key 0", "Some 0"}, {"key 44", "Some 44"}};
  668. test.setMapField(testMap);
  669. ASSERT_TRUE(test.property(propertyName).value<SimpleStringStringMapMessage::MapFieldEntry>() == testMap);
  670. ASSERT_TRUE(test.mapField() == testMap);
  671. ASSERT_STREQ(test.mapField()["key 10"].toStdString().c_str(), "Some 10");
  672. ASSERT_STREQ(test.mapField()["key 0"].toStdString().c_str(), "Some 0");
  673. ASSERT_STREQ(test.mapField()["key 44"].toStdString().c_str(), "Some 44");
  674. test.mapField()["key 66"] = "Some 66";
  675. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some 66");
  676. test.mapField()["key 66"] = "Some default";
  677. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some default");
  678. }
  679. TEST_F(SimpleTest, EmptyMessageTest)
  680. {
  681. EmptyMessage::registerTypes();
  682. ASSERT_EQ(0, EmptyMessage::propertyOrdering.size());
  683. ASSERT_EQ(1, EmptyMessage::staticMetaObject.propertyCount());
  684. }