simpletest.cpp 38 KB

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