simpletest.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 "globalenums.h"
  48. #include "qtprotobuf.h"
  49. #include <QVariantList>
  50. #include <QMetaProperty>
  51. using namespace qtprotobufnamespace::tests;
  52. using namespace qtprotobuf::tests;
  53. using namespace qtprotobuf;
  54. SimpleTest::SimpleTest()
  55. {
  56. QtProtobuf::init();
  57. }
  58. TEST_F(SimpleTest, SimpleBoolMessageTest)
  59. {
  60. const char* propertyName = "testFieldBool";
  61. SimpleBoolMessage test;
  62. int propertyNumber = SimpleBoolMessage::propertyOrdering.at(1); //See simpletest.proto
  63. ASSERT_STREQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).typeName(), "bool");
  64. ASSERT_EQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<bool>());
  65. ASSERT_STREQ(SimpleBoolMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  66. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(true)));
  67. ASSERT_EQ(test.property(propertyName).toBool(), true);
  68. ASSERT_EQ(test.testFieldBool(), true);
  69. }
  70. TEST_F(SimpleTest, SimpleIntMessageTest)
  71. {
  72. const char* propertyName = "testFieldInt";
  73. SimpleIntMessage test;
  74. int propertyNumber = SimpleIntMessage::propertyOrdering.at(1); //See simpletest.proto
  75. ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32");
  76. ASSERT_EQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<int32>());
  77. ASSERT_STREQ(SimpleIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  78. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  79. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  80. ASSERT_EQ(test.testFieldInt(), 1);
  81. }
  82. TEST_F(SimpleTest, SimpleSIntMessageTest)
  83. {
  84. const char* propertyName = "testFieldInt";
  85. SimpleSIntMessage test;
  86. int propertyNumber = SimpleSIntMessage::propertyOrdering.at(1); //See simpletest.proto
  87. ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32");
  88. ASSERT_EQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sint32>());
  89. ASSERT_STREQ(SimpleSIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  90. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  91. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  92. ASSERT_EQ(test.testFieldInt(), 1);
  93. }
  94. TEST_F(SimpleTest, SimpleUIntMessageTest)
  95. {
  96. const char* propertyName = "testFieldInt";
  97. SimpleUIntMessage test;
  98. int propertyNumber = SimpleUIntMessage::propertyOrdering.at(1); //See simpletest.proto
  99. ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint32");
  100. ASSERT_EQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<uint32>());
  101. ASSERT_STREQ(SimpleUIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  102. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  103. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  104. ASSERT_EQ(test.testFieldInt(), 1);
  105. }
  106. TEST_F(SimpleTest, SimpleInt64MessageTest)
  107. {
  108. const char* propertyName = "testFieldInt";
  109. SimpleInt64Message test;
  110. int propertyNumber = SimpleInt64Message::propertyOrdering.at(1); //See simpletest.proto
  111. ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int64");
  112. ASSERT_EQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<int64>());
  113. ASSERT_STREQ(SimpleInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  114. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  115. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  116. ASSERT_EQ(test.testFieldInt(), 1);
  117. }
  118. TEST_F(SimpleTest, SimpleSInt64MessageTest)
  119. {
  120. const char* propertyName = "testFieldInt";
  121. SimpleSInt64Message test;
  122. int propertyNumber = SimpleSInt64Message::propertyOrdering.at(1); //See simpletest.proto
  123. ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint64");
  124. ASSERT_EQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sint64>());
  125. ASSERT_STREQ(SimpleSInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  126. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  127. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  128. ASSERT_EQ(test.testFieldInt(), 1);
  129. }
  130. TEST_F(SimpleTest, SimpleUInt64MessageTest)
  131. {
  132. const char* propertyName = "testFieldInt";
  133. SimpleUInt64Message test;
  134. int propertyNumber = SimpleUInt64Message::propertyOrdering.at(1); //See simpletest.proto
  135. ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::uint64");
  136. ASSERT_EQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<uint64>());
  137. ASSERT_STREQ(SimpleUInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  138. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  139. ASSERT_EQ(test.property(propertyName).toInt(), 1);
  140. ASSERT_EQ(test.testFieldInt(), 1);
  141. }
  142. TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
  143. {
  144. const char* propertyName = "testFieldFixedInt32";
  145. SimpleFixedInt32Message test;
  146. int propertyNumber = SimpleFixedInt32Message::propertyOrdering.at(1); //See simpletest.proto
  147. ASSERT_EQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<fint32>());
  148. ASSERT_STREQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fint32");
  149. ASSERT_STREQ(SimpleFixedInt32Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  150. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  151. ASSERT_EQ(test.property(propertyName).value<fint32>(), 1);
  152. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  153. }
  154. TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
  155. {
  156. const char* propertyName = "testFieldFixedInt64";
  157. SimpleFixedInt64Message test;
  158. int propertyNumber = SimpleFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  159. ASSERT_EQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<fint64>());
  160. ASSERT_STREQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::fint64");
  161. ASSERT_STREQ(SimpleFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  162. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  163. ASSERT_EQ(test.property(propertyName).value<fint64>(), 1);
  164. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  165. }
  166. TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
  167. {
  168. const char* propertyName = "testFieldFixedInt32";
  169. SimpleSFixedInt32Message test;
  170. int propertyNumber = SimpleSFixedInt32Message::propertyOrdering.at(1); //See simpletest.proto
  171. ASSERT_EQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sfint32>());
  172. ASSERT_STREQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfint32");
  173. ASSERT_STREQ(SimpleSFixedInt32Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  174. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  175. ASSERT_EQ(test.property(propertyName).value<fint32>(), 1);
  176. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  177. }
  178. TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
  179. {
  180. const char* propertyName = "testFieldFixedInt64";
  181. SimpleSFixedInt64Message test;
  182. int propertyNumber = SimpleSFixedInt64Message::propertyOrdering.at(1); //See simpletest.proto
  183. ASSERT_EQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).type(), qMetaTypeId<sfint64>());
  184. ASSERT_STREQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sfint64");
  185. ASSERT_STREQ(SimpleSFixedInt64Message::staticMetaObject.property(propertyNumber).name(), propertyName);
  186. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(1)));
  187. ASSERT_EQ(test.property(propertyName).value<fint64>(), 1);
  188. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  189. }
  190. TEST_F(SimpleTest, SimpleStringMessageTest)
  191. {
  192. const char* propertyName = "testFieldString";
  193. SimpleStringMessage test;
  194. int propertyNumber = SimpleStringMessage::propertyOrdering.at(6); //See simpletest.proto
  195. ASSERT_EQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QString);
  196. ASSERT_STREQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  197. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(QString("test1"))));
  198. ASSERT_STREQ(test.property(propertyName).toString().toStdString().c_str(), "test1");
  199. ASSERT_STREQ(test.testFieldString().toStdString().c_str(), "test1");
  200. }
  201. TEST_F(SimpleTest, SimpleFloatMessageTest)
  202. {
  203. const char* propertyName = "testFieldFloat";
  204. SimpleFloatMessage test;
  205. int propertyNumber = SimpleFloatMessage::propertyOrdering.at(7); //See simpletest.proto
  206. ASSERT_EQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Float);
  207. ASSERT_STREQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).name(), "testFieldFloat");
  208. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<float>(1.55f)));
  209. ASSERT_TRUE(qFuzzyCompare(test.property(propertyName).toFloat(), 1.55f));
  210. ASSERT_TRUE(qFuzzyCompare(test.testFieldFloat(), 1.55f));
  211. }
  212. TEST_F(SimpleTest, SimpleDoubleMessageTest)
  213. {
  214. const char* propertyName = "testFieldDouble";
  215. SimpleDoubleMessage test;
  216. int propertyNumber = SimpleDoubleMessage::propertyOrdering.at(8); //See simpletest.proto
  217. ASSERT_EQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Double);
  218. ASSERT_STREQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  219. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<double>(0.55)));
  220. ASSERT_FLOAT_EQ(test.property(propertyName).toDouble(), 0.55);
  221. ASSERT_FLOAT_EQ(test.testFieldDouble(), 0.55);
  222. }
  223. TEST_F(SimpleTest, SimpleLocalEnumsTest)
  224. {
  225. ASSERT_GT(SimpleEnumMessage::staticMetaObject.enumeratorCount(), 0);
  226. QMetaEnum simpleEnum;
  227. for (int i = 0; i < SimpleEnumMessage::staticMetaObject.enumeratorCount(); i++) {
  228. QMetaEnum tmp = SimpleEnumMessage::staticMetaObject.enumerator(i);
  229. if (QString(tmp.name()) == QString("LocalEnum")) {
  230. simpleEnum = tmp;
  231. break;
  232. }
  233. }
  234. ASSERT_TRUE(simpleEnum.isValid());
  235. ASSERT_STREQ(simpleEnum.key(0), "LOCAL_ENUM_VALUE0");
  236. ASSERT_STREQ(simpleEnum.key(1), "LOCAL_ENUM_VALUE1");
  237. ASSERT_STREQ(simpleEnum.key(2), "LOCAL_ENUM_VALUE2");
  238. ASSERT_STREQ(simpleEnum.key(3), "LOCAL_ENUM_VALUE3");
  239. ASSERT_EQ(simpleEnum.value(0), 0);
  240. ASSERT_EQ(simpleEnum.value(1), 1);
  241. ASSERT_EQ(simpleEnum.value(2), 2);
  242. ASSERT_EQ(simpleEnum.value(3), 3);
  243. const char* propertyName = "localEnumList";
  244. SimpleEnumMessage test;
  245. int propertyNumber = SimpleEnumMessage::propertyOrdering.at(2); //See simpletest.proto
  246. ASSERT_STREQ(SimpleEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "LocalEnumList");
  247. ASSERT_EQ(SimpleEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleEnumMessage::LocalEnumList>());
  248. ASSERT_STREQ(SimpleEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  249. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  250. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  251. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  252. SimpleEnumMessage::LOCAL_ENUM_VALUE3})));
  253. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  254. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  255. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  256. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  257. ASSERT_TRUE(test.localEnumList() == SimpleEnumMessage::LocalEnumList({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  258. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  259. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  260. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  261. }
  262. TEST_F(SimpleTest, SimpleExternalEnumMessageTest)
  263. {
  264. const char* propertyName = "externalEnum";
  265. using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::GlobalEnums;
  266. SimpleExternalEnumMessage test;
  267. int propertyNumber = SimpleExternalEnumMessage::propertyOrdering.at(1); //See externalpackagetest.proto
  268. ASSERT_STREQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace1::externaltests::GlobalEnums::ExternalTestEnum");
  269. ASSERT_EQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<ExternalGlobalEnums::ExternalTestEnum>());
  270. ASSERT_STREQ(SimpleExternalEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  271. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4)));
  272. ASSERT_TRUE(test.property(propertyName).value<ExternalGlobalEnums::ExternalTestEnum>() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  273. ASSERT_TRUE(test.externalEnum() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  274. }
  275. TEST_F(SimpleTest, SimpleEnumsTest)
  276. {
  277. ASSERT_GT(GlobalEnums::staticMetaObject.enumeratorCount(), 0);
  278. QMetaEnum simpleEnum;
  279. for (int i = 0; i < GlobalEnums::staticMetaObject.enumeratorCount(); i++) {
  280. QMetaEnum tmp = GlobalEnums::staticMetaObject.enumerator(i);
  281. if (QString(tmp.name()) == QString("TestEnum")) {
  282. simpleEnum = tmp;
  283. break;
  284. }
  285. }
  286. ASSERT_TRUE(simpleEnum.isValid());
  287. ASSERT_STREQ(simpleEnum.key(0), "TEST_ENUM_VALUE0");
  288. ASSERT_STREQ(simpleEnum.key(1), "TEST_ENUM_VALUE1");
  289. ASSERT_STREQ(simpleEnum.key(2), "TEST_ENUM_VALUE2");
  290. ASSERT_STREQ(simpleEnum.key(3), "TEST_ENUM_VALUE3");
  291. ASSERT_STREQ(simpleEnum.key(4), "TEST_ENUM_VALUE4");
  292. ASSERT_EQ(simpleEnum.value(0), 0);
  293. ASSERT_EQ(simpleEnum.value(1), 1);
  294. ASSERT_EQ(simpleEnum.value(2), 2);
  295. ASSERT_EQ(simpleEnum.value(3), 4);
  296. ASSERT_EQ(simpleEnum.value(4), 3);
  297. }
  298. TEST_F(SimpleTest, ComplexMessageTest)
  299. {
  300. ComplexMessage msg;
  301. }
  302. TEST_F(SimpleTest, SimpleBytesMessageTest)
  303. {
  304. const char* propertyName = "testFieldBytes";
  305. SimpleBytesMessage test;
  306. int propertyNumber = SimpleBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  307. ASSERT_EQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QByteArray);
  308. ASSERT_STREQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  309. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArray>("\x01\x02\x03\x04\x05")));
  310. ASSERT_TRUE(test.property(propertyName).toByteArray() == QByteArray("\x01\x02\x03\x04\x05"));
  311. ASSERT_TRUE(test.testFieldBytes() == QByteArray("\x01\x02\x03\x04\x05"));
  312. }
  313. TEST_F(SimpleTest, SimpleExternalComplexMessageTest)
  314. {
  315. const char* propertyName = "localList";
  316. qtprotobufnamespace1::externaltests::SimpleExternalMessage test;
  317. int propertyNumber = qtprotobufnamespace1::externaltests::SimpleExternalMessage::propertyOrdering.at(1);
  318. ASSERT_STREQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::int32List");
  319. ASSERT_EQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::int32List>());
  320. ASSERT_STREQ(qtprotobufnamespace1::externaltests::SimpleExternalMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  321. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  322. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  323. ASSERT_TRUE(test.localList() == int32List({1, 2, 3, 4, 5}));
  324. }
  325. TEST_F(SimpleTest, RepeatedIntMessageTest)
  326. {
  327. const char* propertyName = "testRepeatedInt";
  328. RepeatedIntMessage test;
  329. int propertyNumber = RepeatedIntMessage::propertyOrdering.at(1); //See simpletest.proto
  330. ASSERT_STREQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobuf::sint32List");
  331. ASSERT_EQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<qtprotobuf::sint32List>());
  332. ASSERT_STREQ(RepeatedIntMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  333. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32List>({1, 2, 3, 4, 5})));
  334. ASSERT_TRUE(test.property(propertyName).value<sint32List>() == sint32List({1, 2, 3, 4, 5}));
  335. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  336. }
  337. TEST_F(SimpleTest, StepChildEnumMessageTest)
  338. {
  339. const char* propertyName = "localStepChildEnum";
  340. StepChildEnumMessage test;
  341. int propertyNumber = StepChildEnumMessage::propertyOrdering.at(1); //See simpletest.proto
  342. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum");
  343. ASSERT_EQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleEnumMessage::LocalEnum>());
  344. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  345. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum>(SimpleEnumMessage::LOCAL_ENUM_VALUE2)));
  346. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == SimpleEnumMessage::LOCAL_ENUM_VALUE2);
  347. ASSERT_TRUE(test.localStepChildEnum() == SimpleEnumMessage::LOCAL_ENUM_VALUE2);
  348. }
  349. TEST_F(SimpleTest, StepChildEnumListMessageTest)
  350. {
  351. const char* propertyName = "localStepChildList";
  352. StepChildEnumMessage test;
  353. int propertyNumber = StepChildEnumMessage::propertyOrdering.at(2); //See simpletest.proto
  354. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).typeName(), "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumList");
  355. ASSERT_EQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<SimpleEnumMessage::LocalEnumList>());
  356. ASSERT_STREQ(StepChildEnumMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  357. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  358. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  359. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  360. SimpleEnumMessage::LOCAL_ENUM_VALUE3})));
  361. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == QVariant::fromValue<SimpleEnumMessage::LocalEnumList>({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  362. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  363. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  364. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  365. ASSERT_TRUE(test.localStepChildList() == SimpleEnumMessage::LocalEnumList({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  366. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  367. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  368. SimpleEnumMessage::LOCAL_ENUM_VALUE3}));
  369. }