simpletest.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 "simpleexternalenummessage.h"
  43. #include "externalcomplexmessage.h"
  44. #include "complexmessage.h"
  45. #include "simplebytesmessage.h"
  46. #include "repeatedintmessage.h"
  47. #include "repeatedsintmessage.h"
  48. #include "repeateduintmessage.h"
  49. #include "repeatedint64message.h"
  50. #include "repeatedsint64message.h"
  51. #include "repeateduint64message.h"
  52. #include "repeatedfixedintmessage.h"
  53. #include "repeatedsfixedintmessage.h"
  54. #include "repeatedfixedint64message.h"
  55. #include "repeatedsfixedint64message.h"
  56. #include "globalenums.h"
  57. #include "qtprotobuf.h"
  58. #include <QVariantList>
  59. #include <QMetaProperty>
  60. using namespace qtprotobufnamespace::tests;
  61. using namespace qtprotobuf::tests;
  62. using namespace qtprotobuf;
  63. SimpleTest::SimpleTest()
  64. {
  65. QtProtobuf::init();
  66. }
  67. TEST_F(SimpleTest, SimpleBoolMessageTest)
  68. {
  69. const char* propertyName = "testFieldBool";
  70. SimpleBoolMessage test;
  71. int propertyNumber = SimpleBoolMessage::propertyOrdering.at(1); //See simpletest.proto
  72. ASSERT_STREQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).typeName(), "bool");
  73. ASSERT_EQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<bool>());
  74. ASSERT_STREQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  75. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(true)));
  76. ASSERT_EQ(test.property(propertyName).toBool(), true);
  77. ASSERT_EQ(test.testFieldBool(), true);
  78. }
  79. TEST_F(SimpleTest, SimpleIntMessageTest)
  80. {
  81. const char* propertyName = "testFieldInt";
  82. SimpleIntMessage test;
  83. int propertyNumber = SimpleIntMessage::propertyOrdering.at(1); //See simpletest.proto
  84. ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32");
  85. ASSERT_EQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<int32>());
  86. ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  87. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  88. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  89. ASSERT_EQ(test.testFieldInt(), 1);
  90. }
  91. TEST_F(SimpleTest, SimpleSIntMessageTest)
  92. {
  93. const char* propertyName = "testFieldInt";
  94. SimpleSIntMessage test;
  95. int propertyNumber = SimpleSIntMessage::propertyOrdering.at(1); //See simpletest.proto
  96. ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32");
  97. ASSERT_EQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sint32>());
  98. ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  99. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  100. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  101. ASSERT_EQ(test.testFieldInt(), 1);
  102. }
  103. TEST_F(SimpleTest, SimpleUIntMessageTest)
  104. {
  105. const char* propertyName = "testFieldInt";
  106. SimpleUIntMessage test;
  107. int propertyNumber = SimpleUIntMessage::propertyOrdering.at(1); //See simpletest.proto
  108. ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint32");
  109. ASSERT_EQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<uint32>());
  110. ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  111. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  112. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  113. ASSERT_EQ(test.testFieldInt(), 1);
  114. }
  115. TEST_F(SimpleTest, SimpleInt64MessageTest)
  116. {
  117. const char* propertyName = "testFieldInt";
  118. SimpleInt64Message test;
  119. int propertyNumber = SimpleInt64Message::propertyOrdering.at(1); //See simpletest.proto
  120. ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int64");
  121. ASSERT_EQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<int64>());
  122. ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  123. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  124. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  125. ASSERT_EQ(test.testFieldInt(), 1);
  126. }
  127. TEST_F(SimpleTest, SimpleSInt64MessageTest)
  128. {
  129. const char* propertyName = "testFieldInt";
  130. SimpleSInt64Message test;
  131. int propertyNumber = SimpleSInt64Message::propertyOrdering.at(1); //See simpletest.proto
  132. ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint64");
  133. ASSERT_EQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sint64>());
  134. ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  135. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  136. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  137. ASSERT_EQ(test.testFieldInt(), 1);
  138. }
  139. TEST_F(SimpleTest, SimpleUInt64MessageTest)
  140. {
  141. const char* propertyName = "testFieldInt";
  142. SimpleUInt64Message test;
  143. int propertyNumber = SimpleUInt64Message::propertyOrdering.at(1); //See simpletest.proto
  144. ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint64");
  145. ASSERT_EQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<uint64>());
  146. ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  147. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  148. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  149. ASSERT_EQ(test.testFieldInt(), 1);
  150. }
  151. TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
  152. {
  153. const char* propertyName = "testFieldFixedInt32";
  154. SimpleFixedInt32Message test;
  155. int propertyNumber = SimpleFixedInt32Message::propertyOrdering.at(1); //See simpletest.proto
  156. ASSERT_EQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<fint32>());
  157. ASSERT_STREQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fint32");
  158. ASSERT_STREQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  159. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  160. ASSERT_EQ(test.property(propertyName).value<fint32>(), 1);
  161. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  162. }
  163. TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
  164. {
  165. const char* propertyName = "testFieldFixedInt64";
  166. SimpleFixedInt64Message test;
  167. int propertyNumber = SimpleFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  168. ASSERT_EQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<fint64>());
  169. ASSERT_STREQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fint64");
  170. ASSERT_STREQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  171. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  172. ASSERT_EQ(test.property(propertyName).value<fint64>(), 1);
  173. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  174. }
  175. TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
  176. {
  177. const char* propertyName = "testFieldFixedInt32";
  178. SimpleSFixedInt32Message test;
  179. int propertyNumber = SimpleSFixedInt32Message::propertyOrdering.at(1); //See simpletest.proto
  180. ASSERT_EQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sfint32>());
  181. ASSERT_STREQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfint32");
  182. ASSERT_STREQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  183. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  184. ASSERT_EQ(test.property(propertyName).value<fint32>(), 1);
  185. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  186. }
  187. TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
  188. {
  189. const char* propertyName = "testFieldFixedInt64";
  190. SimpleSFixedInt64Message test;
  191. int propertyNumber = SimpleSFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  192. ASSERT_EQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sfint64>());
  193. ASSERT_STREQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfint64");
  194. ASSERT_STREQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  195. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  196. ASSERT_EQ(test.property(propertyName).value<fint64>(), 1);
  197. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  198. }
  199. TEST_F(SimpleTest, SimpleStringMessageTest)
  200. {
  201. const char* propertyName = "testFieldString";
  202. SimpleStringMessage test;
  203. int propertyNumber = SimpleStringMessage::propertyOrdering.at(6); //See simpletest.proto
  204. ASSERT_EQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QString);
  205. ASSERT_STREQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  206. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(QString("test1"))));
  207. ASSERT_STREQ(test.property(propertyName).toString().toStdString().c_str(), "test1");
  208. ASSERT_STREQ(test.testFieldString().toStdString().c_str(), "test1");
  209. }
  210. TEST_F(SimpleTest, SimpleFloatMessageTest)
  211. {
  212. const char* propertyName = "testFieldFloat";
  213. SimpleFloatMessage test;
  214. int propertyNumber = SimpleFloatMessage::propertyOrdering.at(7); //See simpletest.proto
  215. ASSERT_EQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Float);
  216. ASSERT_STREQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).name(), "testFieldFloat");
  217. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<float>(1.55f)));
  218. ASSERT_TRUE(qFuzzyCompare(test.property(propertyName).toFloat(), 1.55f));
  219. ASSERT_TRUE(qFuzzyCompare(test.testFieldFloat(), 1.55f));
  220. }
  221. TEST_F(SimpleTest, SimpleDoubleMessageTest)
  222. {
  223. const char* propertyName = "testFieldDouble";
  224. SimpleDoubleMessage test;
  225. int propertyNumber = SimpleDoubleMessage::propertyOrdering.at(8); //See simpletest.proto
  226. ASSERT_EQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Double);
  227. ASSERT_STREQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  228. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<double>(0.55)));
  229. ASSERT_FLOAT_EQ(test.property(propertyName).toDouble(), 0.55);
  230. ASSERT_FLOAT_EQ(test.testFieldDouble(), 0.55);
  231. }
  232. TEST_F(SimpleTest, SimpleLocalEnumsTest)
  233. {
  234. ASSERT_GT(SimpleEnumMessage::staticMetaObject.enumeratorCount(), 0);
  235. QMetaEnum simpleEnum;
  236. for (int i = 0; i < SimpleEnumMessage::staticMetaObject.enumeratorCount(); i++) {
  237. QMetaEnum tmp = SimpleEnumMessage::staticMetaObject.enumerator(i);
  238. if (QString(tmp.name()) == QString("LocalEnum")) {
  239. simpleEnum = tmp;
  240. break;
  241. }
  242. }
  243. ASSERT_TRUE(simpleEnum.isValid());
  244. ASSERT_STREQ(simpleEnum.key(0), "LOCAL_ENUM_VALUE0");
  245. ASSERT_STREQ(simpleEnum.key(1), "LOCAL_ENUM_VALUE1");
  246. ASSERT_STREQ(simpleEnum.key(2), "LOCAL_ENUM_VALUE2");
  247. ASSERT_STREQ(simpleEnum.key(3), "LOCAL_ENUM_VALUE3");
  248. ASSERT_EQ(simpleEnum.value(0), 0);
  249. ASSERT_EQ(simpleEnum.value(1), 1);
  250. ASSERT_EQ(simpleEnum.value(2), 2);
  251. ASSERT_EQ(simpleEnum.value(3), 3);
  252. const char* propertyName = "localEnumList";
  253. SimpleEnumMessage test;
  254. int propertyNumber = SimpleEnumMessage::propertyOrdering.at(2); //See simpletest.proto
  255. ASSERT_STREQ(SimpleEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "LocalEnumList");
  256. ASSERT_EQ(SimpleEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleEnumMessage::LocalEnumList>());
  257. ASSERT_STREQ(SimpleEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  258. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  259. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  260. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  261. SimpleEnumMessage::LOCAL_ENUM_VALUE3})));
  262. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  263. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  264. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  265. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  266. ASSERT_TRUE(test.localEnumList() == SimpleEnumMessage::LocalEnumList({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  267. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  268. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  269. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  270. }
  271. TEST_F(SimpleTest, SimpleExternalEnumMessageTest)
  272. {
  273. const char* propertyName = "externalEnum";
  274. using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::GlobalEnums;
  275. SimpleExternalEnumMessage test;
  276. int propertyNumber = SimpleExternalEnumMessage::propertyOrdering.at(1); //See externalpackagetest.proto
  277. ASSERT_STREQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace1::externaltests::GlobalEnums::ExternalTestEnum");
  278. ASSERT_EQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<ExternalGlobalEnums::ExternalTestEnum>());
  279. ASSERT_STREQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  280. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4)));
  281. ASSERT_TRUE(test.property(propertyName).value<ExternalGlobalEnums::ExternalTestEnum>() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  282. ASSERT_TRUE(test.externalEnum() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  283. }
  284. TEST_F(SimpleTest, SimpleEnumsTest)
  285. {
  286. ASSERT_GT(GlobalEnums::staticMetaObject.enumeratorCount(), 0);
  287. QMetaEnum simpleEnum;
  288. for (int i = 0; i < GlobalEnums::staticMetaObject.enumeratorCount(); i++) {
  289. QMetaEnum tmp = GlobalEnums::staticMetaObject.enumerator(i);
  290. if (QString(tmp.name()) == QString("TestEnum")) {
  291. simpleEnum = tmp;
  292. break;
  293. }
  294. }
  295. ASSERT_TRUE(simpleEnum.isValid());
  296. ASSERT_STREQ(simpleEnum.key(0), "TEST_ENUM_VALUE0");
  297. ASSERT_STREQ(simpleEnum.key(1), "TEST_ENUM_VALUE1");
  298. ASSERT_STREQ(simpleEnum.key(2), "TEST_ENUM_VALUE2");
  299. ASSERT_STREQ(simpleEnum.key(3), "TEST_ENUM_VALUE3");
  300. ASSERT_STREQ(simpleEnum.key(4), "TEST_ENUM_VALUE4");
  301. ASSERT_EQ(simpleEnum.value(0), 0);
  302. ASSERT_EQ(simpleEnum.value(1), 1);
  303. ASSERT_EQ(simpleEnum.value(2), 2);
  304. ASSERT_EQ(simpleEnum.value(3), 4);
  305. ASSERT_EQ(simpleEnum.value(4), 3);
  306. }
  307. TEST_F(SimpleTest, ComplexMessageTest)
  308. {
  309. ComplexMessage msg;
  310. }
  311. TEST_F(SimpleTest, SimpleBytesMessageTest)
  312. {
  313. const char* propertyName = "testFieldBytes";
  314. SimpleBytesMessage test;
  315. int propertyNumber = SimpleBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  316. ASSERT_EQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QByteArray);
  317. ASSERT_STREQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  318. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArray>("\x01\x02\x03\x04\x05")));
  319. ASSERT_TRUE(test.property(propertyName).toByteArray() == QByteArray("\x01\x02\x03\x04\x05"));
  320. ASSERT_TRUE(test.testFieldBytes() == QByteArray("\x01\x02\x03\x04\x05"));
  321. }
  322. TEST_F(SimpleTest, SimpleExternalComplexMessageTest)
  323. {
  324. const char* propertyName = "localList";
  325. qtprotobufnamespace1::externaltests::SimpleExternalMessage test;
  326. int propertyNumber = qtprotobufnamespace1::externaltests::SimpleExternalMessage::propertyOrdering.at(1);
  327. ASSERT_STREQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32List");
  328. ASSERT_EQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int32List>());
  329. ASSERT_STREQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  330. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  331. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  332. ASSERT_TRUE(test.localList() == int32List({1, 2, 3, 4, 5}));
  333. }
  334. TEST_F(SimpleTest, RepeatedIntMessageTest)
  335. {
  336. const char* propertyName = "testRepeatedInt";
  337. RepeatedIntMessage test;
  338. int propertyNumber = RepeatedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  339. ASSERT_STREQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32List");
  340. ASSERT_EQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int32List>());
  341. ASSERT_STREQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  342. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  343. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  344. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  345. }
  346. TEST_F(SimpleTest, RepeatedSIntMessageTest)
  347. {
  348. const char* propertyName = "testRepeatedInt";
  349. RepeatedSIntMessage test;
  350. int propertyNumber = RepeatedSIntMessage::propertyOrdering.at(1); //See simpletest.proto
  351. ASSERT_STREQ(RepeatedSIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32List");
  352. ASSERT_EQ(RepeatedSIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sint32List>());
  353. ASSERT_STREQ(RepeatedSIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  354. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32List>({1, 2, 3, 4, 5})));
  355. ASSERT_TRUE(test.property(propertyName).value<sint32List>() == sint32List({1, 2, 3, 4, 5}));
  356. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  357. }
  358. TEST_F(SimpleTest, RepeatedUIntMessageTest)
  359. {
  360. const char* propertyName = "testRepeatedInt";
  361. RepeatedUIntMessage test;
  362. int propertyNumber = RepeatedUIntMessage::propertyOrdering.at(1); //See simpletest.proto
  363. ASSERT_STREQ(RepeatedUIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint32List");
  364. ASSERT_EQ(RepeatedUIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::uint32List>());
  365. ASSERT_STREQ(RepeatedUIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  366. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32List>({1, 2, 3, 4, 5})));
  367. ASSERT_TRUE(test.property(propertyName).value<uint32List>() == uint32List({1, 2, 3, 4, 5}));
  368. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  369. }
  370. TEST_F(SimpleTest, RepeatedInt64MessageTest)
  371. {
  372. const char* propertyName = "testRepeatedInt";
  373. RepeatedInt64Message test;
  374. int propertyNumber = RepeatedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  375. ASSERT_STREQ(RepeatedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int64List");
  376. ASSERT_EQ(RepeatedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int64List>());
  377. ASSERT_STREQ(RepeatedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  378. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64List>({1, 2, 3, 4, 5})));
  379. ASSERT_TRUE(test.property(propertyName).value<int64List>() == int64List({1, 2, 3, 4, 5}));
  380. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  381. }
  382. TEST_F(SimpleTest, RepeatedSInt64MessageTest)
  383. {
  384. const char* propertyName = "testRepeatedInt";
  385. RepeatedSInt64Message test;
  386. int propertyNumber = RepeatedSInt64Message::propertyOrdering.at(1); //See simpletest.proto
  387. ASSERT_STREQ(RepeatedSInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint64List");
  388. ASSERT_EQ(RepeatedSInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sint64List>());
  389. ASSERT_STREQ(RepeatedSInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  390. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64List>({1, 2, 3, 4, 5})));
  391. ASSERT_TRUE(test.property(propertyName).value<sint64List>() == sint64List({1, 2, 3, 4, 5}));
  392. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  393. }
  394. TEST_F(SimpleTest, RepeatedUInt64MessageTest)
  395. {
  396. const char* propertyName = "testRepeatedInt";
  397. RepeatedUInt64Message test;
  398. int propertyNumber = RepeatedUInt64Message::propertyOrdering.at(1); //See simpletest.proto
  399. ASSERT_STREQ(RepeatedUInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint64List");
  400. ASSERT_EQ(RepeatedUInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::uint64List>());
  401. ASSERT_STREQ(RepeatedUInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  402. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64List>({1, 2, 3, 4, 5})));
  403. ASSERT_TRUE(test.property(propertyName).value<uint64List>() == uint64List({1, 2, 3, 4, 5}));
  404. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  405. }
  406. TEST_F(SimpleTest, RepeatedFixedIntMessageTest)
  407. {
  408. const char* propertyName = "testRepeatedInt";
  409. RepeatedFixedIntMessage test;
  410. int propertyNumber = RepeatedFixedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  411. ASSERT_STREQ(RepeatedFixedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fint32List");
  412. ASSERT_EQ(RepeatedFixedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::fint32List>());
  413. ASSERT_STREQ(RepeatedFixedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  414. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fint32List>({1, 2, 3, 4, 5})));
  415. ASSERT_TRUE(test.property(propertyName).value<fint32List>() == fint32List({1, 2, 3, 4, 5}));
  416. ASSERT_TRUE(test.testRepeatedInt() == fint32List({1, 2, 3, 4, 5}));
  417. }
  418. TEST_F(SimpleTest, RepeatedFixedInt64MessageTest)
  419. {
  420. const char* propertyName = "testRepeatedInt";
  421. RepeatedFixedInt64Message test;
  422. int propertyNumber = RepeatedFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  423. ASSERT_STREQ(RepeatedFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fint64List");
  424. ASSERT_EQ(RepeatedFixedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::fint64List>());
  425. ASSERT_STREQ(RepeatedFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  426. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fint64List>({1, 2, 3, 4, 5})));
  427. ASSERT_TRUE(test.property(propertyName).value<fint64List>() == fint64List({1, 2, 3, 4, 5}));
  428. ASSERT_TRUE(test.testRepeatedInt() == fint64List({1, 2, 3, 4, 5}));
  429. }
  430. TEST_F(SimpleTest, RepeatedSFixedIntMessageTest)
  431. {
  432. const char* propertyName = "testRepeatedInt";
  433. RepeatedSFixedIntMessage test;
  434. int propertyNumber = RepeatedSFixedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  435. ASSERT_STREQ(RepeatedSFixedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfint32List");
  436. ASSERT_EQ(RepeatedSFixedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sfint32List>());
  437. ASSERT_STREQ(RepeatedSFixedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  438. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfint32List>({1, 2, 3, 4, 5})));
  439. ASSERT_TRUE(test.property(propertyName).value<sfint32List>() == sfint32List({1, 2, 3, 4, 5}));
  440. ASSERT_TRUE(test.testRepeatedInt() == sfint32List({1, 2, 3, 4, 5}));
  441. }
  442. TEST_F(SimpleTest, RepeatedSFixedInt64MessageTest)
  443. {
  444. const char* propertyName = "testRepeatedInt";
  445. RepeatedSFixedInt64Message test;
  446. int propertyNumber = RepeatedSFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  447. ASSERT_STREQ(RepeatedSFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfint64List");
  448. ASSERT_EQ(RepeatedSFixedInt64Message::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sfint64List>());
  449. ASSERT_STREQ(RepeatedSFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  450. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfint64List>({1, 2, 3, 4, 5})));
  451. ASSERT_TRUE(test.property(propertyName).value<sfint64List>() == sfint64List({1, 2, 3, 4, 5}));
  452. ASSERT_TRUE(test.testRepeatedInt() == sfint64List({1, 2, 3, 4, 5}));
  453. }
  454. TEST_F(SimpleTest, StepChildEnumMessageTest)
  455. {
  456. const char* propertyName = "localStepChildEnum";
  457. StepChildEnumMessage test;
  458. int propertyNumber = StepChildEnumMessage::propertyOrdering.at(1); //See simpletest.proto
  459. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum");
  460. ASSERT_EQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleEnumMessage::LocalEnum>());
  461. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  462. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum>(SimpleEnumMessage::LOCAL_ENUM_VALUE2)));
  463. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == SimpleEnumMessage::LOCAL_ENUM_VALUE2);
  464. ASSERT_TRUE(test.localStepChildEnum() == SimpleEnumMessage::LOCAL_ENUM_VALUE2);
  465. }
  466. TEST_F(SimpleTest, StepChildEnumListMessageTest)
  467. {
  468. const char* propertyName = "localStepChildList";
  469. StepChildEnumMessage test;
  470. int propertyNumber = StepChildEnumMessage::propertyOrdering.at(2); //See simpletest.proto
  471. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumList");
  472. ASSERT_EQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleEnumMessage::LocalEnumList>());
  473. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  474. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  475. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  476. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  477. SimpleEnumMessage::LOCAL_ENUM_VALUE3})));
  478. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  479. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  480. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  481. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  482. ASSERT_TRUE(test.localStepChildList() == SimpleEnumMessage::LocalEnumList({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  483. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  484. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  485. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  486. }