From 81b59d1492ee064fb65f0d309897a6dd9c3759d2 Mon Sep 17 00:00:00 2001 From: Tatiana Borisova Date: Fri, 24 Jan 2025 18:10:45 +0100 Subject: [PATCH] Add tests for rvalue setters in the generated code - add rvalue tests for message types, repeated and map types, oneof, other non-trivially copyable types(QString QByteArray and QDatetime) Note, skipping optional, since it is already implemented in void QtProtobufOptionalTest::move(). Task-number: QTBUG-128388 Change-Id: If36d05de659181c547a836aeb84d5f9da38709bd Reviewed-by: Dennis Oberst --- .../basic/tst_protobuf_basictypes.cpp | 149 +++++++++++- .../protobuf/basic/tst_protobuf_maptypes.cpp | 65 +++++- .../basic/tst_protobuf_repeatedtypes.cpp | 218 +++++++++++++++++- .../qtprotobufqttypescoretest.cpp | 16 ++ 4 files changed, 435 insertions(+), 13 deletions(-) diff --git a/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp b/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp index 3e618057..b50c56b0 100644 --- a/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp +++ b/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp @@ -42,6 +42,7 @@ private Q_SLOTS: void assignmentOperatorTest(); void moveOperatorTest(); void rvalueSettersTest(); + void rvalueOneOfSettersTest(); void invalidMessageConstructorTest(); }; @@ -449,18 +450,148 @@ void QtProtobufTypesGenerationTest::moveOperatorTest() void QtProtobufTypesGenerationTest::rvalueSettersTest() { + { + // String and ComplexMessage tests + ComplexMessage complexField; + SimpleStringMessage stringField; + stringField.setTestFieldString("Value1"); + complexField.setTestComplexField(std::move(stringField)); + + stringField = complexField.testComplexField(); + auto stringFieldCopy = complexField.testComplexField(); + stringFieldCopy.setTestFieldString("Value2"); + complexField.setTestComplexField(std::move(stringFieldCopy)); + ComplexMessage complexFieldCopy = complexField; + + QCOMPARE_EQ(stringField.testFieldString(), "Value1"); + QCOMPARE_EQ(complexField.testComplexField().testFieldString(), "Value2"); + QCOMPARE_EQ(complexField, complexFieldCopy); + + stringFieldCopy = complexField.testComplexField(); + SimpleStringMessage newStringField; + newStringField.setTestFieldString("Value3"); + complexField.setTestComplexField(std::move(newStringField)); + QCOMPARE_NE(complexField, complexFieldCopy); + } + + { + // BytesMessage test + SimpleBytesMessage bytesMsg; + bytesMsg.setTestFieldBytes("\x01\x02\x03\x04\x05"); + SimpleBytesMessage bytesMsgCopy = bytesMsg; + QCOMPARE_EQ(bytesMsg.testFieldBytes(), "\x01\x02\x03\x04\x05"); + QCOMPARE_EQ(bytesMsg, bytesMsgCopy); + + bytesMsg.setTestFieldBytes("\x01\x02\x03\x04\x05\x05"); + QCOMPARE_NE(bytesMsg.testFieldBytes(), "\x01\x02\x03\x04\x05"); + QCOMPARE_NE(bytesMsg, bytesMsgCopy); + } +} + +void QtProtobufTypesGenerationTest::rvalueOneOfSettersTest() +{ + // OneOf test + OneofMessage oneOfField; + QVERIFY(!oneOfField.hasTestOneofComplexField()); + QVERIFY(!oneOfField.hasTestOneofSecondComplexField()); + QVERIFY(!oneOfField.hasSecondComplexField()); + QVERIFY(!oneOfField.hasSecondSecondComplexField()); + ComplexMessage complexField; - SimpleStringMessage stringField; - stringField.setTestFieldString("Value1"); - complexField.setTestComplexField(std::move(stringField)); + { + SimpleStringMessage stringField; + stringField.setTestFieldString("Value1"); + complexField.setTestComplexField(std::move(stringField)); - stringField = complexField.testComplexField(); - auto stringFieldCopy = complexField.testComplexField(); - stringFieldCopy.setTestFieldString("Value2"); - complexField.setTestComplexField(std::move(stringFieldCopy)); + ComplexMessage complexFieldCopy = complexField; + oneOfField.setTestOneofComplexField(std::move(complexFieldCopy)); + OneofMessage oneOfFieldCopy = oneOfField; - QCOMPARE(stringField.testFieldString(), "Value1"); - QCOMPARE(complexField.testComplexField().testFieldString(), "Value2"); + QVERIFY(oneOfField.hasTestOneofComplexField()); + QCOMPARE_EQ(oneOfField, oneOfFieldCopy); + QCOMPARE_EQ(oneOfField.testOneofComplexField().testComplexField().testFieldString(), + "Value1"); + QVERIFY(!oneOfField.hasTestOneofSecondComplexField()); + QVERIFY(!oneOfField.hasSecondComplexField()); + QVERIFY(!oneOfField.hasSecondSecondComplexField()); + + oneOfField.setTestOneofComplexField(ComplexMessage()); + QCOMPARE_NE(oneOfField, oneOfFieldCopy); + QCOMPARE_NE(oneOfField.testOneofComplexField().testComplexField().testFieldString(), + "Value1"); + } + { + SimpleStringMessage stringField; + stringField.setTestFieldString("Value2"); + complexField.setTestComplexField(std::move(stringField)); + + ComplexMessage complexFieldCopy = complexField; + oneOfField.setTestOneofSecondComplexField(std::move(complexFieldCopy)); + OneofMessage oneOfFieldCopy = oneOfField; + + QVERIFY(!oneOfField.hasTestOneofComplexField()); + QVERIFY(oneOfField.hasTestOneofSecondComplexField()); + QCOMPARE_EQ(oneOfField, oneOfFieldCopy); + QCOMPARE_EQ(oneOfField.testOneofSecondComplexField().testComplexField().testFieldString(), + "Value2"); + QVERIFY(!oneOfField.hasSecondComplexField()); + QVERIFY(!oneOfField.hasSecondSecondComplexField()); + + oneOfField.setTestOneofSecondComplexField(ComplexMessage()); + QCOMPARE_NE(oneOfField, oneOfFieldCopy); + QCOMPARE_NE(oneOfField.testOneofSecondComplexField().testComplexField().testFieldString(), + "Value2"); + } + + { + SimpleStringMessage stringField; + stringField.setTestFieldString("Value3"); + complexField.setTestComplexField(std::move(stringField)); + + ComplexMessage complexFieldCopy = complexField; + oneOfField.setSecondComplexField(std::move(complexFieldCopy)); + OneofMessage oneOfFieldCopy = oneOfField; + + QCOMPARE_EQ(oneOfField, oneOfFieldCopy); + QVERIFY(!oneOfField.hasTestOneofComplexField()); + QVERIFY(oneOfField.hasTestOneofSecondComplexField()); + QCOMPARE_NE(oneOfField.testOneofSecondComplexField().testComplexField().testFieldString(), + "Value2"); + QVERIFY(oneOfField.hasSecondComplexField()); + QCOMPARE_EQ(oneOfField.secondComplexField().testComplexField().testFieldString(), + "Value3"); + QVERIFY(!oneOfField.hasSecondSecondComplexField()); + + oneOfField.setSecondComplexField(ComplexMessage()); + QCOMPARE_NE(oneOfField, oneOfFieldCopy); + QCOMPARE_NE(oneOfField.secondComplexField().testComplexField().testFieldString(), + "Value3"); + } + + { + SimpleStringMessage stringField; + stringField.setTestFieldString("Value4"); + complexField.setTestComplexField(std::move(stringField)); + + ComplexMessage complexFieldCopy = complexField; + oneOfField.setSecondSecondComplexField(std::move(complexFieldCopy)); + OneofMessage oneOfFieldCopy = oneOfField; + + QCOMPARE_EQ(oneOfField, oneOfFieldCopy); + QVERIFY(!oneOfField.hasTestOneofComplexField()); + QVERIFY(oneOfField.hasTestOneofSecondComplexField()); + QCOMPARE_NE(oneOfField.testOneofSecondComplexField().testComplexField().testFieldString(), + "Value2"); + QVERIFY(!oneOfField.hasSecondComplexField()); + QVERIFY(oneOfField.hasSecondSecondComplexField()); + QCOMPARE_EQ(oneOfField.secondSecondComplexField().testComplexField().testFieldString(), + "Value4"); + + oneOfField.setSecondSecondComplexField(ComplexMessage()); + QCOMPARE_NE(oneOfField, oneOfFieldCopy); + QCOMPARE_NE(oneOfField.secondSecondComplexField().testComplexField().testFieldString(), + "Value4"); + } } void QtProtobufTypesGenerationTest::invalidMessageConstructorTest() diff --git a/tests/auto/protobuf/basic/tst_protobuf_maptypes.cpp b/tests/auto/protobuf/basic/tst_protobuf_maptypes.cpp index 7ad1b889..2411243f 100644 --- a/tests/auto/protobuf/basic/tst_protobuf_maptypes.cpp +++ b/tests/auto/protobuf/basic/tst_protobuf_maptypes.cpp @@ -42,6 +42,22 @@ void QtProtobufMapTypesGenerationTest::sInt32StringMapMessageTest() QCOMPARE(test.mapField().value(10), "Some 10"_L1); QCOMPARE(test.mapField().value(0), "Some 0"_L1); QCOMPARE(test.mapField().value(44), "Some 44"_L1); + + //rvalue test + { + SimpleSInt32StringMapMessage::MapFieldEntry si32Map = {{10, {"Some 10"}}, + {0, {"Some 0"}}, + {44, {"Some 44"}}}; + SimpleSInt32StringMapMessage::MapFieldEntry testMapCopy = si32Map; + SimpleSInt32StringMapMessage test; + test.setMapField(std::move(testMapCopy)); + SimpleSInt32StringMapMessage testCopy = test; + QCOMPARE_EQ(test.mapField(), si32Map); + QCOMPARE_EQ(testCopy, test); + test.setMapField({{10, {"Some 10"}}, {0, {"Some 0"}}, {44, {"Some 42"}}}); + QCOMPARE_NE(test.mapField(), si32Map); + QCOMPARE_NE(testCopy, test); + } } void QtProtobufMapTypesGenerationTest::stringStringMapMessageTest() @@ -61,9 +77,25 @@ void QtProtobufMapTypesGenerationTest::stringStringMapMessageTest() QCOMPARE(test.mapField().value("key 10"), "Some 10"_L1); QCOMPARE(test.mapField().value("key 0"), "Some 0"_L1); QCOMPARE(test.mapField().value("key 44"), "Some 44"_L1); + + // rvalue test + { + SimpleStringStringMapMessage::MapFieldEntry stringStringMap = {{"key 10", "Some 10"}, + {"key 0", "Some 0"}, + {"key 44", "Some 44"}}; + SimpleStringStringMapMessage::MapFieldEntry testMapCopy = stringStringMap; + SimpleStringStringMapMessage test; + test.setMapField(std::move(testMapCopy)); + SimpleStringStringMapMessage testCopy = test; + QCOMPARE_EQ(test.mapField(), stringStringMap); + QCOMPARE_EQ(testCopy, test); + test.setMapField({{"key 10", "Some 10"}, {"key 0", "Some 1"}, {"key 44", "Some 44"}}); + QCOMPARE_NE(test.mapField(), stringStringMap); + QCOMPARE_NE(testCopy, test); + } } -void QtProtobufMapTypesGenerationTest::simpleInt32ComplexMessageMapMessageCompareTest() +SimpleInt32ComplexMessageMapMessage::MapFieldEntry getComplexMap() { SimpleStringMessage stringMsg; ComplexMessage msg1; @@ -86,12 +118,39 @@ void QtProtobufMapTypesGenerationTest::simpleInt32ComplexMessageMapMessageCompar msg4.setTestFieldInt(20); msg4.setTestComplexField(stringMsg); + return SimpleInt32ComplexMessageMapMessage::MapFieldEntry({ { 20, msg1 }, { 30, msg2}, + { 40, msg3 }, { 50, msg4 } }); +} + +void QtProtobufMapTypesGenerationTest::simpleInt32ComplexMessageMapMessageCompareTest() +{ + SimpleInt32ComplexMessageMapMessage::MapFieldEntry clxMsg = getComplexMap(); SimpleInt32ComplexMessageMapMessage test1; - test1.setMapField({ { 20, msg1 }, { 30, msg2 } }); + test1.setMapField({ {20, clxMsg.value(20)}, {30, clxMsg.value(30)} }); SimpleInt32ComplexMessageMapMessage test2; - test2.setMapField({ { 20, msg3 }, { 30, msg4 } }); + test2.setMapField({ {20, clxMsg.value(40)}, {30, clxMsg.value(50)} }); QCOMPARE(test1, test2); + + // rvalue test + { + SimpleInt32ComplexMessageMapMessage::MapFieldEntry int32ComplexMap = getComplexMap(); + SimpleInt32ComplexMessageMapMessage::MapFieldEntry testMapCopy = int32ComplexMap; + SimpleInt32ComplexMessageMapMessage test; + test.setMapField(std::move(testMapCopy)); + SimpleInt32ComplexMessageMapMessage testCopy = test; + QCOMPARE_EQ(test.mapField(), int32ComplexMap); + QCOMPARE_EQ(testCopy, test); + + SimpleStringMessage stringMsg; + ComplexMessage msg1; + stringMsg.setTestFieldString("qwerty"); + msg1.setTestFieldInt(10); + msg1.setTestComplexField(stringMsg); + test.setMapField(SimpleInt32ComplexMessageMapMessage::MapFieldEntry({ { 20, msg1 } })); + QCOMPARE_NE(test.mapField(), int32ComplexMap); + QCOMPARE_NE(testCopy, test); + } } QTEST_MAIN(QtProtobufMapTypesGenerationTest) diff --git a/tests/auto/protobuf/basic/tst_protobuf_repeatedtypes.cpp b/tests/auto/protobuf/basic/tst_protobuf_repeatedtypes.cpp index e755ae77..fb57a15c 100644 --- a/tests/auto/protobuf/basic/tst_protobuf_repeatedtypes.cpp +++ b/tests/auto/protobuf/basic/tst_protobuf_repeatedtypes.cpp @@ -299,7 +299,223 @@ void QtProtobufRepeatedTypesGenerationTest::repeatedComplexMessageCompareTest() void QtProtobufRepeatedTypesGenerationTest::rvalueSettersTest() { - RepeatedIntMessage test; + { + QStringList stringList = QStringList({"Text", "tryam"}); + QStringList stringListCopy = stringList; + RepeatedStringMessage test; + test.setTestRepeatedString(std::move(stringListCopy)); + RepeatedStringMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedString(), stringList); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedString(QStringList({"Text", "tryam1"})); + QCOMPARE_NE(test.testRepeatedString(), stringList); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::doubleList dList = QtProtobuf::doubleList({1.0, 2.3, 3, 4.7, 5.9}); + QtProtobuf::doubleList dListCopy = dList; + RepeatedDoubleMessage test; + test.setTestRepeatedDouble(std::move(dListCopy)); + RepeatedDoubleMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedDouble(), dList); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedDouble(QtProtobuf::doubleList({1.0, 2, 3, 4.7, 5.9})); + QCOMPARE_NE(test.testRepeatedDouble(), dList); + QCOMPARE_NE(test, testCopy); + } + { + QByteArrayList bList = QByteArrayList({"\x01\x02\x03\x04\x05", "\x01\x05\x03\x04\x03"}); + QByteArrayList bListCopy = bList; + RepeatedBytesMessage test; + test.setTestRepeatedBytes(std::move(bListCopy)); + RepeatedBytesMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedBytes(), bList); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedBytes(QByteArrayList({"\x01\x02\x03\x04\x05"})); + QCOMPARE_NE(test.testRepeatedBytes(), bList); + } + { + QtProtobuf::floatList fList = QtProtobuf::floatList({1.0f, 2.3f, 3, 4.7f, 5.9f}); + QtProtobuf::floatList fListCopy = fList; + RepeatedFloatMessage test; + test.setTestRepeatedFloat(std::move(fListCopy)); + RepeatedFloatMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedFloat(), fList); + + test.setTestRepeatedFloat(QtProtobuf::floatList({1.0f, 2.3f, 3, 4.7f})); + QCOMPARE_NE(test.testRepeatedFloat(), fList); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::sint32List si32List = QtProtobuf::sint32List({1, 2, 3, 4, 5}); + QtProtobuf::sint32List si32ListCopy = si32List; + RepeatedSIntMessage test; + test.setTestRepeatedInt(std::move(si32ListCopy)); + RepeatedSIntMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), si32List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::sint32List({1, 5})); + QCOMPARE_NE(test.testRepeatedInt(), si32List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::int32List i32List = QtProtobuf::int32List({ 55, 44, 11, 35 }); + QtProtobuf::int32List i32ListCopy = i32List; + RepeatedIntMessage test; + test.setTestRepeatedInt(std::move(i32ListCopy)); + RepeatedIntMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), i32List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::int32List({ -55, 44, 11, 35 })); + QCOMPARE_NE(test.testRepeatedInt(), i32List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::uint32List ui32List = QtProtobuf::uint32List({1, 2, 3, 4, 5}); + QtProtobuf::uint32List ui32ListCopy = ui32List; + RepeatedUIntMessage test; + test.setTestRepeatedInt(std::move(ui32ListCopy)); + RepeatedUIntMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), ui32List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::uint32List({1, 3, 4, 5})); + QCOMPARE_NE(test.testRepeatedInt(), ui32List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::sint64List si64List = QtProtobuf::sint64List({1, 2, 3, 4, 5}); + QtProtobuf::sint64List si64ListCopy = si64List; + RepeatedSInt64Message test; + test.setTestRepeatedInt(std::move(si64ListCopy)); + RepeatedSInt64Message testCopy = test; + QCOMPARE(test.testRepeatedInt(), si64List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::sint64List()); + QCOMPARE_NE(test.testRepeatedInt(), si64List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::int64List i64List = QtProtobuf::int64List({ 55, 44, 11, 35 }); + QtProtobuf::int64List i64ListCopy = i64List; + RepeatedInt64Message test; + test.setTestRepeatedInt(std::move(i64ListCopy)); + RepeatedInt64Message testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), i64List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::int64List({ 44, 11, 35 })); + QCOMPARE_NE(test.testRepeatedInt(), i64List); + } + { + QtProtobuf::uint64List ui64List = QtProtobuf::uint64List({81, 2, 3, 44, 5}); + QtProtobuf::uint64List ui64ListCopy = ui64List; + RepeatedUInt64Message test; + test.setTestRepeatedInt(std::move(ui64ListCopy)); + RepeatedUInt64Message testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), ui64List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::uint64List()); + QCOMPARE_NE(test.testRepeatedInt(), ui64List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::fixed32List f32List = QtProtobuf::fixed32List({1, 2, 3, 4, 5}); + QtProtobuf::fixed32List fixed32ListCopy = f32List; + RepeatedFixedIntMessage test; + test.setTestRepeatedInt(std::move(fixed32ListCopy)); + RepeatedFixedIntMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), f32List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::fixed32List({1, 2, 4, 5})); + QCOMPARE_NE(test.testRepeatedInt(), f32List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::sfixed32List sf32List = QtProtobuf::sfixed32List({1, 2, 3, 4, 5}); + QtProtobuf::sfixed32List sf32ListCopy = sf32List; + RepeatedSFixedIntMessage test; + test.setTestRepeatedInt(std::move(sf32ListCopy)); + RepeatedSFixedIntMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), sf32List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::sfixed32List({15, 3})); + QCOMPARE_NE(test.testRepeatedInt(), sf32List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::fixed64List f64List = QtProtobuf::fixed64List({1, 2, 3, 4, 5}); + QtProtobuf::fixed64List fixed64ListCopy = f64List; + RepeatedFixedInt64Message test; + test.setTestRepeatedInt(std::move(fixed64ListCopy)); + RepeatedFixedInt64Message testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), f64List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::fixed64List({1, 2, 3, 4, 5, 6, 7})); + QCOMPARE_NE(test.testRepeatedInt(), f64List); + QCOMPARE_NE(test, testCopy); + } + { + QtProtobuf::sfixed64List sf64List = QtProtobuf::sfixed64List({1, 2, 3, 4, 5}); + QtProtobuf::sfixed64List sf64ListCopy = sf64List; + RepeatedSFixedInt64Message test; + test.setTestRepeatedInt(std::move(sf64ListCopy)); + RepeatedSFixedInt64Message testCopy = test; + QCOMPARE_EQ(test.testRepeatedInt(), sf64List); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedInt(QtProtobuf::sfixed64List({0, 1, 2, 3, 4, 5})); + QCOMPARE_NE(test.testRepeatedInt(), sf64List); + QCOMPARE_NE(test, testCopy); + } + { + SimpleStringMessage stringMsg; + + ComplexMessage msg1; + stringMsg.setTestFieldString("qwerty"); + msg1.setTestFieldInt(10); + msg1.setTestComplexField(stringMsg); + + ComplexMessage msg2; + stringMsg.setTestFieldString("ytrewq"); + msg2.setTestFieldInt(20); + msg2.setTestComplexField(stringMsg); + + RepeatedComplexMessage repeatedMsg; + auto copyObj = { msg1, msg2 }; + repeatedMsg.setTestRepeatedComplex(std::move(copyObj)); + RepeatedComplexMessage testCopy = repeatedMsg; + QList list = { msg1, msg2 }; + QCOMPARE_EQ(repeatedMsg.testRepeatedComplex(), list); + QCOMPARE_EQ(repeatedMsg, testCopy); + + repeatedMsg.setTestRepeatedComplex({ msg2, msg1 }); + QCOMPARE_NE(repeatedMsg.testRepeatedComplex(), list); + QCOMPARE_NE(repeatedMsg, testCopy); + } + { + QtProtobuf::boolList blnList = QtProtobuf::boolList({false, false, false, true, false}); + QtProtobuf::boolList bListCopy = blnList; + RepeatedBoolMessage test; + test.setTestRepeatedBool(std::move(bListCopy)); + RepeatedBoolMessage testCopy = test; + QCOMPARE_EQ(test.testRepeatedBool(), blnList); + QCOMPARE_EQ(test, testCopy); + + test.setTestRepeatedBool(QtProtobuf::boolList({false})); + QCOMPARE_NE(test.testRepeatedBool(), blnList); + QCOMPARE_NE(test, testCopy); + } } QTEST_MAIN(QtProtobufRepeatedTypesGenerationTest) diff --git a/tests/auto/protobufqttypes/qtprotobufqttypescoretest.cpp b/tests/auto/protobufqttypes/qtprotobufqttypescoretest.cpp index 1d643769..9e4cfb98 100644 --- a/tests/auto/protobufqttypes/qtprotobufqttypescoretest.cpp +++ b/tests/auto/protobufqttypes/qtprotobufqttypescoretest.cpp @@ -336,6 +336,22 @@ void QtProtobufQtTypesQtCoreTest::qDateTime() msg.deserialize(&serializer, QByteArray::fromHex(emptyValue)); QVERIFY(msg.testField().isNull()); } + + // rvalue test + { + QDateTime dateTime = {date, QTime(7, 30, 21, 321), zone}; + QDateTime dateTimeCopy = dateTime; + msg.setTestField(std::move(dateTime)); + QDateTimeMessage msgCopy = msg; + QCOMPARE_EQ(msg.testField(), dateTimeCopy); + QCOMPARE_EQ(msg, msgCopy); + + msg.setTestField({ QDate(2011, 3, 14), + QTime(6, 30, 21, 321), + QTimeZone(QTimeZone::UTC) }); + QCOMPARE_NE(msg.testField(), dateTimeCopy); + QCOMPARE_NE(msg, msgCopy); + } } void QtProtobufQtTypesQtCoreTest::qSize()