simpletest.cpp.inc 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Viktor Kopp <vifactor@gmail.com>
  5. *
  6. * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <QVariantList>
  26. #include <QMetaProperty>
  27. #include <QSignalSpy>
  28. #include <gtest/gtest.h>
  29. #include "../testscommon.h"
  30. using namespace qtprotobufnamespace::tests;
  31. namespace QtProtobuf {
  32. namespace tests {
  33. class SimpleTest : public ::testing::Test
  34. {
  35. public:
  36. // see simpletest.proto for property names and their field indices
  37. SimpleTest()
  38. {
  39. }
  40. static void SetUpTestCase();
  41. };
  42. void SimpleTest::SetUpTestCase()
  43. {
  44. QtProtobuf::qRegisterProtobufTypes();
  45. }
  46. TEST_F(SimpleTest, SimpleBoolMessageTest)
  47. {
  48. const char *propertyName = "testFieldBool";
  49. assertMessagePropertyRegistered<SimpleBoolMessage, bool>(1, "bool", propertyName);
  50. SimpleBoolMessage test;
  51. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(true)));
  52. ASSERT_EQ(test.property(propertyName).value<bool>(), true);
  53. ASSERT_EQ(test.testFieldBool(), true);
  54. EXPECT_EQ(SimpleBoolMessage::TestFieldBoolProtoFieldNumber, 1);
  55. }
  56. TEST_F(SimpleTest, SimpleIntMessageTest)
  57. {
  58. const char *propertyName = "testFieldInt_p";
  59. assertMessagePropertyRegistered<SimpleIntMessage, int32>(1, "QtProtobuf::int32", propertyName);
  60. SimpleIntMessage test;
  61. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32>(1)));
  62. ASSERT_EQ(test.property(propertyName).value<int32>(), 1);
  63. ASSERT_EQ(test.testFieldInt(), 1);
  64. EXPECT_EQ(SimpleIntMessage::TestFieldIntProtoFieldNumber, 1);
  65. }
  66. TEST_F(SimpleTest, SimpleSIntMessageTest)
  67. {
  68. const char *propertyName = "testFieldInt";
  69. assertMessagePropertyRegistered<SimpleSIntMessage, sint32>(1, "QtProtobuf::sint32", propertyName);
  70. SimpleSIntMessage test;
  71. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32>(1)));
  72. ASSERT_EQ(test.property(propertyName).value<sint32>(), 1);
  73. ASSERT_EQ(test.testFieldInt(), 1);
  74. EXPECT_EQ(SimpleSIntMessage::TestFieldIntProtoFieldNumber, 1);
  75. }
  76. TEST_F(SimpleTest, SimpleUIntMessageTest)
  77. {
  78. const char *propertyName = "testFieldInt";
  79. assertMessagePropertyRegistered<SimpleUIntMessage, uint32>(1, "QtProtobuf::uint32", propertyName);
  80. SimpleUIntMessage test;
  81. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32>(1)));
  82. ASSERT_EQ(test.property(propertyName).value<uint32>(), 1);
  83. ASSERT_EQ(test.testFieldInt(), 1);
  84. EXPECT_EQ(SimpleUIntMessage::TestFieldIntProtoFieldNumber, 1);
  85. }
  86. TEST_F(SimpleTest, SimpleInt64MessageTest)
  87. {
  88. const char *propertyName = "testFieldInt";
  89. assertMessagePropertyRegistered<SimpleInt64Message, int64>(1, "QtProtobuf::int64", propertyName);
  90. SimpleInt64Message test;
  91. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64>(1)));
  92. ASSERT_EQ(test.property(propertyName).value<int64>(), 1);
  93. ASSERT_EQ(test.testFieldInt(), 1);
  94. EXPECT_EQ(SimpleInt64Message::TestFieldIntProtoFieldNumber, 1);
  95. }
  96. TEST_F(SimpleTest, SimpleSInt64MessageTest)
  97. {
  98. const char *propertyName = "testFieldInt";
  99. assertMessagePropertyRegistered<SimpleSInt64Message, sint64>(1, "QtProtobuf::sint64", propertyName);
  100. SimpleSInt64Message test;
  101. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64>(1)));
  102. ASSERT_EQ(test.property(propertyName).value<sint64>(), 1);
  103. ASSERT_EQ(test.testFieldInt(), 1);
  104. EXPECT_EQ(SimpleSInt64Message::TestFieldIntProtoFieldNumber, 1);
  105. }
  106. TEST_F(SimpleTest, SimpleUInt64MessageTest)
  107. {
  108. const char *propertyName = "testFieldInt";
  109. assertMessagePropertyRegistered<SimpleUInt64Message, uint64>(1, "QtProtobuf::uint64", propertyName);
  110. SimpleUInt64Message test;
  111. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64>(1)));
  112. ASSERT_EQ(test.property(propertyName).value<uint64>(), 1);
  113. ASSERT_EQ(test.testFieldInt(), 1);
  114. EXPECT_EQ(SimpleUInt64Message::TestFieldIntProtoFieldNumber, 1);
  115. }
  116. TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
  117. {
  118. const char *propertyName = "testFieldFixedInt32_p";
  119. assertMessagePropertyRegistered<SimpleFixedInt32Message, fixed32>(1, "QtProtobuf::fixed32", propertyName);
  120. SimpleFixedInt32Message test;
  121. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32>(1)));
  122. ASSERT_EQ(test.property(propertyName).value<fixed32>(), 1);
  123. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  124. EXPECT_EQ(SimpleFixedInt32Message::TestFieldFixedInt32ProtoFieldNumber, 1);
  125. }
  126. TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
  127. {
  128. const char *propertyName = "testFieldFixedInt64";
  129. assertMessagePropertyRegistered<SimpleFixedInt64Message, fixed64>(1, "QtProtobuf::fixed64", propertyName);
  130. SimpleFixedInt64Message test;
  131. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64>(1)));
  132. ASSERT_EQ(test.property(propertyName).value<fixed64>(), 1);
  133. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  134. EXPECT_EQ(SimpleFixedInt64Message::TestFieldFixedInt64ProtoFieldNumber, 1);
  135. }
  136. TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
  137. {
  138. const char *propertyName = "testFieldFixedInt32_p";
  139. assertMessagePropertyRegistered<SimpleSFixedInt32Message, sfixed32>(1, "QtProtobuf::sfixed32", propertyName);
  140. SimpleSFixedInt32Message test;
  141. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32>(1)));
  142. ASSERT_EQ(test.property(propertyName).value<sfixed32>(), 1);
  143. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  144. EXPECT_EQ(SimpleSFixedInt32Message::TestFieldFixedInt32ProtoFieldNumber, 1);
  145. }
  146. TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
  147. {
  148. const char *propertyName = "testFieldFixedInt64";
  149. assertMessagePropertyRegistered<SimpleSFixedInt64Message, sfixed64>(1, "QtProtobuf::sfixed64", propertyName);
  150. SimpleSFixedInt64Message test;
  151. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64>(1)));
  152. ASSERT_EQ(test.property(propertyName).value<sfixed64>(), 1);
  153. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  154. EXPECT_EQ(SimpleSFixedInt64Message::TestFieldFixedInt64ProtoFieldNumber, 1);
  155. }
  156. TEST_F(SimpleTest, SimpleStringMessageTest)
  157. {
  158. const char *propertyName = "testFieldString";
  159. SimpleStringMessage test;
  160. int propertyNumber = SimpleStringMessage::propertyOrdering.at(6); //See simpletest.proto
  161. ASSERT_EQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QString);
  162. ASSERT_STREQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  163. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(QString("test1"))));
  164. ASSERT_STREQ(test.property(propertyName).toString().toStdString().c_str(), "test1");
  165. ASSERT_STREQ(test.testFieldString().toStdString().c_str(), "test1");
  166. EXPECT_EQ(SimpleStringMessage::TestFieldStringProtoFieldNumber, 6);
  167. }
  168. TEST_F(SimpleTest, SimpleFloatMessageTest)
  169. {
  170. const char *propertyName = "testFieldFloat";
  171. SimpleFloatMessage test;
  172. int propertyNumber = SimpleFloatMessage::propertyOrdering.at(7); //See simpletest.proto
  173. ASSERT_EQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Float);
  174. ASSERT_STREQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).name(), "testFieldFloat");
  175. float assignedValue = 1.55f;
  176. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<float>(assignedValue)));
  177. ASSERT_FLOAT_EQ(test.property(propertyName).toFloat(), assignedValue);
  178. ASSERT_FLOAT_EQ(test.testFieldFloat(), assignedValue);
  179. EXPECT_EQ(SimpleFloatMessage::TestFieldFloatProtoFieldNumber, 7);
  180. }
  181. TEST_F(SimpleTest, SimpleDoubleMessageTest)
  182. {
  183. const char *propertyName = "testFieldDouble";
  184. SimpleDoubleMessage test;
  185. int propertyNumber = SimpleDoubleMessage::propertyOrdering.at(8); //See simpletest.proto
  186. ASSERT_EQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Double);
  187. ASSERT_STREQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  188. double assignedValue = 0.55;
  189. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<double>(assignedValue)));
  190. ASSERT_DOUBLE_EQ(test.property(propertyName).toDouble(), assignedValue);
  191. ASSERT_DOUBLE_EQ(test.testFieldDouble(), assignedValue);
  192. EXPECT_EQ(SimpleDoubleMessage::TestFieldDoubleProtoFieldNumber, 8);
  193. }
  194. TEST_F(SimpleTest, SimpleLocalEnumTest)
  195. {
  196. ASSERT_GT(SimpleEnumMessage::staticMetaObject.enumeratorCount(), 0);
  197. QMetaEnum simpleEnum;
  198. for (int i = 0; i < SimpleEnumMessage::staticMetaObject.enumeratorCount(); i++) {
  199. QMetaEnum tmp = SimpleEnumMessage::staticMetaObject.enumerator(i);
  200. if (QString(tmp.name()) == QString("LocalEnum")) {
  201. simpleEnum = tmp;
  202. break;
  203. }
  204. }
  205. ASSERT_TRUE(simpleEnum.isValid());
  206. ASSERT_STREQ(simpleEnum.key(0), "LOCAL_ENUM_VALUE0");
  207. ASSERT_STREQ(simpleEnum.key(1), "LOCAL_ENUM_VALUE1");
  208. ASSERT_STREQ(simpleEnum.key(2), "LOCAL_ENUM_VALUE2");
  209. ASSERT_STREQ(simpleEnum.key(3), "LOCAL_ENUM_VALUE3");
  210. ASSERT_EQ(simpleEnum.value(0), 0);
  211. ASSERT_EQ(simpleEnum.value(1), 1);
  212. ASSERT_EQ(simpleEnum.value(2), 2);
  213. ASSERT_EQ(simpleEnum.value(3), 3);
  214. }
  215. TEST_F(SimpleTest, SimpleLocalEnumListTest)
  216. {
  217. ASSERT_GT(SimpleEnumListMessage::staticMetaObject.enumeratorCount(), 0);
  218. const char *propertyName = "localEnumListData";
  219. assertMessagePropertyRegistered<SimpleEnumListMessage, SimpleEnumListMessage::LocalEnumRepeated>(1, "qtprotobufnamespace::tests::SimpleEnumListMessage::LocalEnumRepeated", propertyName);
  220. SimpleEnumListMessage::LocalEnumRepeated value({SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  221. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  222. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  223. SimpleEnumListMessage::LOCAL_ENUM_VALUE3});
  224. SimpleEnumListMessage test;
  225. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumListMessage::LocalEnumRepeated>(value)));
  226. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumListMessage::LocalEnumRepeated>() == value);
  227. ASSERT_TRUE(test.localEnumList() == value);
  228. }
  229. TEST_F(SimpleTest, SimpleExternalEnumMessageTest)
  230. {
  231. using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::ExternalTestEnumGadget;
  232. const char *propertyName = "externalEnum";
  233. assertMessagePropertyRegistered<SimpleExternalEnumMessage, ExternalGlobalEnums::ExternalTestEnum>(1, "qtprotobufnamespace1::externaltests::ExternalTestEnumGadget::ExternalTestEnum", propertyName);
  234. SimpleExternalEnumMessage test;
  235. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4)));
  236. ASSERT_TRUE(test.property(propertyName).value<ExternalGlobalEnums::ExternalTestEnum>() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  237. ASSERT_TRUE(test.externalEnum() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  238. }
  239. TEST_F(SimpleTest, SimpleEnumsTest)
  240. {
  241. EXPECT_GT(TestEnumGadget::staticMetaObject.enumeratorCount(), 0);
  242. QMetaEnum testEnum;
  243. for (int i = 0; i < TestEnumGadget::staticMetaObject.enumeratorCount(); i++) {
  244. QMetaEnum tmp = TestEnumGadget::staticMetaObject.enumerator(i);
  245. if (QString(tmp.name()) == QString("TestEnum")) {
  246. testEnum = tmp;
  247. break;
  248. }
  249. }
  250. ASSERT_TRUE(testEnum.isValid());
  251. ASSERT_STREQ(testEnum.key(0), "TEST_ENUM_VALUE0");
  252. ASSERT_STREQ(testEnum.key(1), "TEST_ENUM_VALUE1");
  253. ASSERT_STREQ(testEnum.key(2), "TEST_ENUM_VALUE2");
  254. ASSERT_STREQ(testEnum.key(3), "TEST_ENUM_VALUE3");
  255. ASSERT_STREQ(testEnum.key(4), "TEST_ENUM_VALUE4");
  256. ASSERT_EQ(testEnum.value(0), 0);
  257. ASSERT_EQ(testEnum.value(1), 1);
  258. ASSERT_EQ(testEnum.value(2), 2);
  259. ASSERT_EQ(testEnum.value(3), 4);
  260. ASSERT_EQ(testEnum.value(4), 3);
  261. for (int i = 0; i < TestEnumSecondInFileGadget::staticMetaObject.enumeratorCount(); i++) {
  262. QMetaEnum tmp = TestEnumSecondInFileGadget::staticMetaObject.enumerator(i);
  263. if (QString(tmp.name()) == QString("TestEnumSecondInFile")) {
  264. testEnum = tmp;
  265. break;
  266. }
  267. }
  268. ASSERT_TRUE(testEnum.isValid());
  269. ASSERT_STREQ(testEnum.key(0), "TEST_ENUM_SIF_VALUE0");
  270. ASSERT_STREQ(testEnum.key(1), "TEST_ENUM_SIF_VALUE1");
  271. ASSERT_STREQ(testEnum.key(2), "TEST_ENUM_SIF_VALUE2");
  272. ASSERT_EQ(testEnum.value(0), 0);
  273. ASSERT_EQ(testEnum.value(1), 1);
  274. ASSERT_EQ(testEnum.value(2), 2);
  275. }
  276. TEST_F(SimpleTest, SimpleFileEnumsTest)
  277. {
  278. const char *propertyName = "globalEnumListData";
  279. assertMessagePropertyRegistered<SimpleFileEnumMessage, TestEnumGadget::TestEnumRepeated>(2, "qtprotobufnamespace::tests::TestEnumGadget::TestEnumRepeated", propertyName);
  280. TestEnumGadget::TestEnumRepeated value{TestEnumGadget::TEST_ENUM_VALUE1,
  281. TestEnumGadget::TEST_ENUM_VALUE3,
  282. TestEnumGadget::TEST_ENUM_VALUE4,
  283. TestEnumGadget::TEST_ENUM_VALUE2,
  284. TestEnumGadget::TEST_ENUM_VALUE1};
  285. SimpleFileEnumMessage test;
  286. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<TestEnumGadget::TestEnumRepeated>(value)));
  287. ASSERT_TRUE(test.property(propertyName).value<TestEnumGadget::TestEnumRepeated>() == value);
  288. ASSERT_TRUE(test.globalEnumList() == value);
  289. }
  290. TEST_F(SimpleTest, ComplexMessageTest)
  291. {
  292. const char *propertyName = "testComplexField";
  293. assertMessagePropertyRegistered<qtprotobufnamespace::tests::ComplexMessage, qtprotobufnamespace::tests::SimpleStringMessage*>(
  294. 2, "qtprotobufnamespace::tests::SimpleStringMessage*", propertyName);
  295. ComplexMessage test;
  296. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleStringMessage*>(new qtprotobufnamespace::tests::SimpleStringMessage{"test qwerty"})));
  297. ASSERT_TRUE(*(test.property(propertyName).value<qtprotobufnamespace::tests::SimpleStringMessage*>()) == qtprotobufnamespace::tests::SimpleStringMessage{"test qwerty"});
  298. ASSERT_TRUE(test.testComplexField() == qtprotobufnamespace::tests::SimpleStringMessage{"test qwerty"});
  299. }
  300. TEST_F(SimpleTest, SimpleBytesMessageTest)
  301. {
  302. const char *propertyName = "testFieldBytes";
  303. SimpleBytesMessage test;
  304. int propertyNumber = SimpleBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  305. ASSERT_EQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QByteArray);
  306. ASSERT_STREQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  307. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArray>("\x01\x02\x03\x04\x05")));
  308. ASSERT_TRUE(test.property(propertyName).toByteArray() == QByteArray("\x01\x02\x03\x04\x05"));
  309. ASSERT_TRUE(test.testFieldBytes() == QByteArray("\x01\x02\x03\x04\x05"));
  310. }
  311. TEST_F(SimpleTest, SimpleExternalComplexMessageTest)
  312. {
  313. const char *propertyName = "localListData";
  314. assertMessagePropertyRegistered<qtprotobufnamespace1::externaltests::SimpleExternalMessage, int32List>(
  315. 1, "QtProtobuf::int32List", propertyName);
  316. qtprotobufnamespace1::externaltests::SimpleExternalMessage test;
  317. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  318. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  319. ASSERT_TRUE(test.localList() == int32List({1, 2, 3, 4, 5}));
  320. }
  321. TEST_F(SimpleTest, RepeatedExternalComplexMessageTest)
  322. {
  323. const char *propertyName = "testExternalComplexData";
  324. assertMessagePropertyRegistered<RepeatedExternalComplexMessage, qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>(
  325. 1, "qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated", propertyName);
  326. qtprotobufnamespace1::externaltests::SimpleExternalMessage complexMessage;
  327. complexMessage.setLocalList({1, 2, 3, 4, 5});
  328. QSharedPointer<qtprotobufnamespace1::externaltests::ExternalComplexMessage> externalMessage(new qtprotobufnamespace1::externaltests::ExternalComplexMessage);
  329. externalMessage->setTestFieldInt(complexMessage);
  330. qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated complexMessageList;
  331. complexMessageList << externalMessage;
  332. RepeatedExternalComplexMessage test;
  333. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(complexMessageList)));
  334. ASSERT_TRUE(test.property(propertyName).value<qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>() == complexMessageList);
  335. ASSERT_TRUE(test.testExternalComplex() == complexMessageList);
  336. }
  337. TEST_F(SimpleTest, RepeatedStringMessageTest)
  338. {
  339. const char *propertyName = "testRepeatedStringData";
  340. assertMessagePropertyRegistered<RepeatedStringMessage, QStringList>(1, "QStringList", propertyName);
  341. RepeatedStringMessage test;
  342. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QStringList>({"Text", "tryam"})));
  343. ASSERT_TRUE(test.property(propertyName).value<QStringList>() == QStringList({"Text", "tryam"}));
  344. ASSERT_TRUE(test.testRepeatedString() == QStringList({"Text", "tryam"}));
  345. }
  346. TEST_F(SimpleTest, RepeatedIntMessageTest)
  347. {
  348. const char *propertyName = "testRepeatedIntData";
  349. assertMessagePropertyRegistered<RepeatedIntMessage, int32List>(1, "QtProtobuf::int32List", propertyName);
  350. RepeatedIntMessage test;
  351. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  352. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  353. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  354. test.testRepeatedInt().append(66);
  355. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5, 66}));
  356. test.testRepeatedInt().pop_back();
  357. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  358. }
  359. TEST_F(SimpleTest, RepeatedDoubleMessageTest)
  360. {
  361. const char *propertyName = "testRepeatedDoubleData";
  362. assertMessagePropertyRegistered<RepeatedDoubleMessage, DoubleList>(1, "QtProtobuf::DoubleList", propertyName);
  363. RepeatedDoubleMessage test;
  364. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::DoubleList>({1.0, 2.3, 3, 4.7, 5.9})));
  365. ASSERT_TRUE(test.property(propertyName).value<QtProtobuf::DoubleList>() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  366. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  367. test.testRepeatedDouble().append(6.6);
  368. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9, 6.6}));
  369. test.testRepeatedDouble().pop_back();
  370. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  371. }
  372. TEST_F(SimpleTest, RepeatedFloatMessageTest)
  373. {
  374. const char *propertyName = "testRepeatedFloatData";
  375. assertMessagePropertyRegistered<RepeatedFloatMessage, FloatList>(1, "QtProtobuf::FloatList", propertyName);
  376. RepeatedFloatMessage test;
  377. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::FloatList>({1.0f, 2.3f, 3, 4.7f, 5.9f})));
  378. ASSERT_TRUE(test.property(propertyName).value<QtProtobuf::FloatList>() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  379. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  380. test.testRepeatedFloat().append(6.6f);
  381. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f, 6.6f}));
  382. test.testRepeatedFloat().pop_back();
  383. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  384. }
  385. TEST_F(SimpleTest, RepeatedBytesMessageTest)
  386. {
  387. const char *propertyName = "testRepeatedBytesData";
  388. assertMessagePropertyRegistered<RepeatedBytesMessage, QByteArrayList>(1, "QByteArrayList", propertyName);
  389. QByteArrayList bList;
  390. bList << "\x01\x02\x03\x04\x05";
  391. bList << "\x01\x05\x03\x04\x03";
  392. RepeatedBytesMessage test;
  393. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArrayList>(bList)));
  394. ASSERT_TRUE(test.property(propertyName).value<QByteArrayList>() == bList);
  395. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  396. bList << "\x01\x05\x03\x03";
  397. test.testRepeatedBytes() << "\x01\x05\x03\x03";
  398. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  399. bList.pop_back();
  400. test.testRepeatedBytes().pop_back();
  401. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  402. }
  403. TEST_F(SimpleTest, RepeatedSIntMessageTest)
  404. {
  405. const char *propertyName = "testRepeatedIntData";
  406. assertMessagePropertyRegistered<RepeatedSIntMessage, sint32List>(1, "QtProtobuf::sint32List", propertyName);
  407. RepeatedSIntMessage test;
  408. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32List>({1, 2, 3, 4, 5})));
  409. ASSERT_TRUE(test.property(propertyName).value<sint32List>() == sint32List({1, 2, 3, 4, 5}));
  410. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  411. test.testRepeatedInt() << 6;
  412. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5, 6}));
  413. test.testRepeatedInt().pop_back();
  414. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  415. }
  416. TEST_F(SimpleTest, RepeatedUIntMessageTest)
  417. {
  418. const char *propertyName = "testRepeatedIntData";
  419. assertMessagePropertyRegistered<RepeatedUIntMessage, uint32List>(1, "QtProtobuf::uint32List", propertyName);
  420. RepeatedUIntMessage test;
  421. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32List>({1, 2, 3, 4, 5})));
  422. ASSERT_TRUE(test.property(propertyName).value<uint32List>() == uint32List({1, 2, 3, 4, 5}));
  423. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  424. test.testRepeatedInt().append(6);
  425. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5,6}));
  426. test.testRepeatedInt().pop_back();
  427. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  428. }
  429. TEST_F(SimpleTest, RepeatedInt64MessageTest)
  430. {
  431. const char *propertyName = "testRepeatedIntData";
  432. assertMessagePropertyRegistered<RepeatedInt64Message, int64List>(1, "QtProtobuf::int64List", propertyName);
  433. RepeatedInt64Message test;
  434. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64List>({1, 2, 3, 4, 5})));
  435. ASSERT_TRUE(test.property(propertyName).value<int64List>() == int64List({1, 2, 3, 4, 5}));
  436. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  437. test.testRepeatedInt().append(69);
  438. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5, 69}));
  439. test.testRepeatedInt().pop_back();
  440. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  441. }
  442. TEST_F(SimpleTest, RepeatedSInt64MessageTest)
  443. {
  444. const char *propertyName = "testRepeatedIntData";
  445. assertMessagePropertyRegistered<RepeatedSInt64Message, sint64List>(1, "QtProtobuf::sint64List", propertyName);
  446. RepeatedSInt64Message test;
  447. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64List>({1, 2, 3, 4, 5})));
  448. ASSERT_TRUE(test.property(propertyName).value<sint64List>() == sint64List({1, 2, 3, 4, 5}));
  449. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  450. test.testRepeatedInt() << 96;
  451. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5, 96}));
  452. test.testRepeatedInt().pop_back();
  453. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  454. }
  455. TEST_F(SimpleTest, RepeatedUInt64MessageTest)
  456. {
  457. const char *propertyName = "testRepeatedIntData";
  458. assertMessagePropertyRegistered<RepeatedUInt64Message, uint64List>(1, "QtProtobuf::uint64List", propertyName);
  459. RepeatedUInt64Message test;
  460. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64List>({1, 2, 3, 4, 5})));
  461. ASSERT_TRUE(test.property(propertyName).value<uint64List>() == uint64List({1, 2, 3, 4, 5}));
  462. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  463. test.testRepeatedInt().append(96);
  464. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5, 96}));
  465. test.testRepeatedInt().pop_back();
  466. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  467. }
  468. TEST_F(SimpleTest, RepeatedFixedIntMessageTest)
  469. {
  470. const char *propertyName = "testRepeatedIntData";
  471. assertMessagePropertyRegistered<RepeatedFixedIntMessage, fixed32List>(1, "QtProtobuf::fixed32List", propertyName);
  472. RepeatedFixedIntMessage test;
  473. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32List>({1, 2, 3, 4, 5})));
  474. ASSERT_TRUE(test.property(propertyName).value<fixed32List>() == fixed32List({1, 2, 3, 4, 5}));
  475. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  476. test.testRepeatedInt() << 0;
  477. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5, 0}));
  478. test.testRepeatedInt().pop_back();
  479. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  480. }
  481. TEST_F(SimpleTest, RepeatedFixedInt64MessageTest)
  482. {
  483. const char *propertyName = "testRepeatedIntData";
  484. assertMessagePropertyRegistered<RepeatedFixedInt64Message, fixed64List>(1, "QtProtobuf::fixed64List", propertyName);
  485. RepeatedFixedInt64Message test;
  486. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64List>({1, 2, 3, 4, 5})));
  487. ASSERT_TRUE(test.property(propertyName).value<fixed64List>() == fixed64List({1, 2, 3, 4, 5}));
  488. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  489. test.testRepeatedInt() << 0;
  490. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5, 0}));
  491. test.testRepeatedInt().pop_back();
  492. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  493. }
  494. TEST_F(SimpleTest, RepeatedSFixedIntMessageTest)
  495. {
  496. const char *propertyName = "testRepeatedIntData";
  497. assertMessagePropertyRegistered<RepeatedSFixedIntMessage, sfixed32List>(1, "QtProtobuf::sfixed32List", propertyName);
  498. RepeatedSFixedIntMessage test;
  499. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32List>({1, 2, 3, 4, 5})));
  500. ASSERT_TRUE(test.property(propertyName).value<sfixed32List>() == sfixed32List({1, 2, 3, 4, 5}));
  501. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  502. test.testRepeatedInt() << 0;
  503. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5, 0}));
  504. test.testRepeatedInt().pop_back();
  505. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  506. }
  507. TEST_F(SimpleTest, RepeatedSFixedInt64MessageTest)
  508. {
  509. const char *propertyName = "testRepeatedIntData";
  510. assertMessagePropertyRegistered<RepeatedSFixedInt64Message, QtProtobuf::sfixed64List>(1, "QtProtobuf::sfixed64List", propertyName);
  511. RepeatedSFixedInt64Message test;
  512. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64List>({1, 2, 3, 4, 5})));
  513. ASSERT_TRUE(test.property(propertyName).value<sfixed64List>() == sfixed64List({1, 2, 3, 4, 5}));
  514. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  515. test.testRepeatedInt() << 0;
  516. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5, 0}));
  517. test.testRepeatedInt().pop_back();
  518. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  519. }
  520. TEST_F(SimpleTest, StepChildEnumMessageTest)
  521. {
  522. const char *propertyName = "localStepChildEnum";
  523. assertMessagePropertyRegistered<StepChildEnumMessage, SimpleEnumMessage::LocalEnum>(1, "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum", propertyName);
  524. StepChildEnumMessage test;
  525. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnum>(SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2)));
  526. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  527. ASSERT_TRUE(test.localStepChildEnum() == SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  528. }
  529. TEST_F(SimpleTest, StepChildEnumListMessageTest)
  530. {
  531. const char *propertyName = "localStepChildListData";
  532. assertMessagePropertyRegistered<StepChildEnumMessage, SimpleEnumMessage::LocalEnumRepeated>(2, "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumRepeated", propertyName);
  533. SimpleEnumMessage::LocalEnumRepeated value({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  534. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  535. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  536. SimpleEnumMessage::LOCAL_ENUM_VALUE3});
  537. StepChildEnumMessage test;
  538. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumRepeated>(value)));
  539. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnumRepeated>() == value);
  540. ASSERT_TRUE(test.localStepChildList() == value);
  541. }
  542. TEST_F(SimpleTest, SimpleSInt32StringMapMessageTest)
  543. {
  544. const char *propertyName = "mapField";
  545. assertMessagePropertyRegistered<SimpleSInt32StringMapMessage, SimpleSInt32StringMapMessage::MapFieldEntry>(1, "qtprotobufnamespace::tests::SimpleSInt32StringMapMessage::MapFieldEntry", propertyName);
  546. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleSInt32StringMapMessage::MapFieldEntry>()));
  547. SimpleSInt32StringMapMessage::MapFieldEntry testMap = {{10, {"Some 10"}}, {0, {"Some 0"}}, {44, {"Some 44"}}};
  548. SimpleSInt32StringMapMessage test;
  549. test.setMapField(testMap);
  550. ASSERT_TRUE(test.property(propertyName).value<SimpleSInt32StringMapMessage::MapFieldEntry>() == testMap);
  551. ASSERT_TRUE(test.mapField() == testMap);
  552. ASSERT_STREQ(test.mapField()[10].toStdString().c_str(), "Some 10");
  553. ASSERT_STREQ(test.mapField()[0].toStdString().c_str(), "Some 0");
  554. ASSERT_STREQ(test.mapField()[44].toStdString().c_str(), "Some 44");
  555. test.mapField()[66] = "Some 66";
  556. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some 66");
  557. test.mapField()[66] = "Some default";
  558. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some default");
  559. }
  560. TEST_F(SimpleTest, SimpleStringStringMapMessageTest)
  561. {
  562. const char *propertyName = "mapField";
  563. assertMessagePropertyRegistered<SimpleStringStringMapMessage, SimpleStringStringMapMessage::MapFieldEntry>(13, "qtprotobufnamespace::tests::SimpleStringStringMapMessage::MapFieldEntry", propertyName);
  564. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleStringStringMapMessage::MapFieldEntry>()));
  565. SimpleStringStringMapMessage::MapFieldEntry testMap = {{"key 10", "Some 10"}, {"key 0", "Some 0"}, {"key 44", "Some 44"}};
  566. SimpleStringStringMapMessage test;
  567. test.setMapField(testMap);
  568. ASSERT_TRUE(test.property(propertyName).value<SimpleStringStringMapMessage::MapFieldEntry>() == testMap);
  569. ASSERT_TRUE(test.mapField() == testMap);
  570. ASSERT_STREQ(test.mapField()["key 10"].toStdString().c_str(), "Some 10");
  571. ASSERT_STREQ(test.mapField()["key 0"].toStdString().c_str(), "Some 0");
  572. ASSERT_STREQ(test.mapField()["key 44"].toStdString().c_str(), "Some 44");
  573. test.mapField()["key 66"] = "Some 66";
  574. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some 66");
  575. test.mapField()["key 66"] = "Some default";
  576. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some default");
  577. }
  578. TEST_F(SimpleTest, EmptyMessageTest)
  579. {
  580. ASSERT_EQ(EmptyMessage::propertyOrdering.size(), 0);
  581. ASSERT_EQ(EmptyMessage::staticMetaObject.propertyCount(), 1);
  582. }
  583. TEST_F(SimpleTest, AssignmentOperatorTest)
  584. {
  585. const char *propertyName = "testFieldInt";
  586. SimpleIntMessage test;
  587. SimpleIntMessage test2{35};
  588. QSignalSpy updateSpy(&test, &SimpleIntMessage::testFieldIntChanged);
  589. test.setProperty(propertyName, QVariant::fromValue<int32>(15));
  590. test.setTestFieldInt(25);
  591. test = test2;
  592. test = test;
  593. test = test2;
  594. ASSERT_EQ(test2.testFieldInt(), test.testFieldInt());
  595. ASSERT_EQ(3, updateSpy.count());
  596. }
  597. TEST_F(SimpleTest, MoveOperatorTest)
  598. {
  599. const char *propertyName = "testFieldInt";
  600. SimpleIntMessage test;
  601. SimpleIntMessage test2{35};
  602. QSignalSpy updateSpy(&test, &SimpleIntMessage::testFieldIntChanged);
  603. QSignalSpy movedUpdateSpy(&test2, &SimpleIntMessage::testFieldIntChanged);
  604. SimpleIntMessage test3(std::move(test2));
  605. test2.setTestFieldInt(35);
  606. test.setProperty(propertyName, QVariant::fromValue<int32>(15));
  607. test.setTestFieldInt(25);
  608. test = std::move(test2);
  609. ASSERT_EQ(35, test.testFieldInt());
  610. ASSERT_EQ(0, test2.testFieldInt());
  611. ASSERT_EQ(3, updateSpy.count());
  612. ASSERT_EQ(3, movedUpdateSpy.count());
  613. }
  614. TEST_F(SimpleTest, MoveOperatorRepeatedTest)
  615. {
  616. const char *propertyName = "testRepeatedIntData";
  617. RepeatedIntMessage test;
  618. RepeatedIntMessage test2{{55,44,11,33}};
  619. QSignalSpy updateSpy(&test, &RepeatedIntMessage::testRepeatedIntChanged);
  620. QSignalSpy movedUpdateSpy(&test2, &RepeatedIntMessage::testRepeatedIntChanged);
  621. RepeatedIntMessage test3(std::move(test2));
  622. test2.setTestRepeatedInt({55,44,11,35});
  623. test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::int32List>({55}));
  624. test.setTestRepeatedInt({44});
  625. test = std::move(test2);
  626. ASSERT_EQ(QtProtobuf::int32List({55,44,11,35}), test.testRepeatedInt());
  627. ASSERT_TRUE(test2.testRepeatedInt().isEmpty());
  628. ASSERT_EQ(3, updateSpy.count());
  629. ASSERT_EQ(3, movedUpdateSpy.count());
  630. }
  631. TEST_F(SimpleTest, UnderscoresTest)
  632. {
  633. //Sanity compilation checks
  634. Message_Uderscore_name msg1;
  635. MessageUderscorename msg2;
  636. MessageUnderscoreField msg3;
  637. PriorMessageUnderscoreField msg4;
  638. FollowingMessageUnderscoreField msg5;
  639. CombinedMessageUnderscoreField msg6;
  640. assertMessagePropertyRegistered<MessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  641. assertMessagePropertyRegistered<PriorMessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  642. assertMessagePropertyRegistered<PriorMessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  643. assertMessagePropertyRegistered<FollowingMessageUnderscoreField , sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  644. assertMessagePropertyRegistered<CombinedMessageUnderscoreField , sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  645. }
  646. TEST_F(SimpleTest, SequenceTest)
  647. {
  648. assertMessagePropertyRegistered<sequence::TestMessageSequence, sequence::TestMessageSequence2*>(1, "qtprotobufnamespace::tests::sequence::TestMessageSequence2*", "testField");
  649. assertMessagePropertyRegistered<sequence::TestMessageSequence2, bool>(1, "bool", "testField");
  650. }
  651. TEST_F(SimpleTest, CyclingTest)
  652. {
  653. assertMessagePropertyRegistered<sequence::CyclingFirstDependency, sequence::CyclingSecondDependency*>(1, "qtprotobufnamespace::tests::sequence::CyclingSecondDependency*", "testField");
  654. assertMessagePropertyRegistered<sequence::CyclingSecondDependency, sequence::CyclingFirstDependency*>(1, "qtprotobufnamespace::tests::sequence::CyclingFirstDependency*", "testField");
  655. sequence::CyclingFirstDependency test;
  656. sequence::CyclingSecondDependency test2;
  657. test.setTestField(test2);
  658. test2.setTestField(test);
  659. }
  660. TEST_F(SimpleTest, UpperCaseTest)
  661. {
  662. assertMessagePropertyRegistered<MessageUpperCase, sint32>(1, "QtProtobuf::sint32", "testField");
  663. }
  664. TEST_F(SimpleTest, ReservedTest)
  665. {
  666. assertMessagePropertyRegistered<MessageReserved, sint32>(1, "QtProtobuf::sint32", "import_proto");
  667. assertMessagePropertyRegistered<MessageReserved, sint32>(2, "QtProtobuf::sint32", "property_proto");
  668. assertMessagePropertyRegistered<MessageReserved, sint32>(3, "QtProtobuf::sint32", "id_proto");
  669. }
  670. TEST_F(SimpleTest, ReservedUpperCaseTest)
  671. {
  672. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(1, "QtProtobuf::sint32", "import_proto");
  673. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(2, "QtProtobuf::sint32", "property_proto");
  674. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(3, "QtProtobuf::sint32", "id_proto");
  675. }
  676. TEST_F(SimpleTest, ReservedEnumTest)
  677. {
  678. ASSERT_GT(MessageEnumReserved::staticMetaObject.enumeratorCount(), 0);
  679. QMetaEnum simpleEnum;
  680. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  681. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  682. if (QString(tmp.name()) == QString("ReservedEnum")) {
  683. simpleEnum = tmp;
  684. break;
  685. }
  686. }
  687. ASSERT_TRUE(simpleEnum.isValid());
  688. ASSERT_STREQ(simpleEnum.key(0), "Import");
  689. ASSERT_STREQ(simpleEnum.key(1), "Property");
  690. ASSERT_STREQ(simpleEnum.key(2), "Id");
  691. ASSERT_EQ(simpleEnum.value(0), 0);
  692. ASSERT_EQ(simpleEnum.value(1), 1);
  693. ASSERT_EQ(simpleEnum.value(2), 2);
  694. }
  695. TEST_F(SimpleTest, LowerCaseEnumTest)
  696. {
  697. ASSERT_GT(MessageEnumReserved::staticMetaObject.enumeratorCount(), 0);
  698. QMetaEnum simpleEnum;
  699. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  700. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  701. if (QString(tmp.name()) == QString("LowerCaseEnum")) {
  702. simpleEnum = tmp;
  703. break;
  704. }
  705. }
  706. ASSERT_TRUE(simpleEnum.isValid());
  707. ASSERT_STREQ(simpleEnum.key(0), "EnumValue0");
  708. ASSERT_STREQ(simpleEnum.key(1), "EnumValue1");
  709. ASSERT_STREQ(simpleEnum.key(2), "EnumValue2");
  710. }
  711. TEST_F(SimpleTest, MapRepeatedFieldSequenceTest)
  712. {
  713. assertMessagePropertyRegistered<sequence::RepeatedFieldSequence, sequence::RepeatedFieldSequence2Repeated>(1, "qtprotobufnamespace::tests::sequence::RepeatedFieldSequence2Repeated", "testFieldData");
  714. assertMessagePropertyRegistered<sequence::MapFieldSequence, sequence::MapFieldSequence::TestFieldEntry>(1, "qtprotobufnamespace::tests::sequence::MapFieldSequence::TestFieldEntry", "testField");
  715. }
  716. } // tests
  717. } // qtprotobuf