simpletest.cpp.inc 36 KB

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