aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-11-30 10:45:13 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2020-12-11 15:13:34 +0100
commit2b3abacd157da938be7409a8dbfd066782baf853 (patch)
tree8130b94c4c4820fd3085e300b6e47ed4186295dd /tests
parentc728da31ced8730671578f82727f04b6ae2d8907 (diff)
Fix QCoapOption's copy assignment operator to work on moved-from this
Also added tests verifying copy and assignment operations. Pick-to: 6.0 Change-Id: I56a995dc7e2029c2ce1761f0a0e42f43eeec5c60 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qcoapoption/tst_qcoapoption.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qcoapoption/tst_qcoapoption.cpp b/tests/auto/qcoapoption/tst_qcoapoption.cpp
index fec22b1..8753707 100644
--- a/tests/auto/qcoapoption/tst_qcoapoption.cpp
+++ b/tests/auto/qcoapoption/tst_qcoapoption.cpp
@@ -37,12 +37,51 @@ class tst_QCoapOption : public QObject
Q_OBJECT
private Q_SLOTS:
+ void constructAndAssign();
void constructWithQByteArray();
void constructWithQString();
void constructWithInteger();
void constructWithUtf8Characters();
};
+void tst_QCoapOption::constructAndAssign()
+{
+ QCoapOption option1;
+ QCOMPARE(option1.name(), QCoapOption::Invalid);
+ QCOMPARE(option1.uintValue(), 0);
+ QVERIFY(option1.stringValue().isEmpty());
+ QVERIFY(option1.opaqueValue().isEmpty());
+
+ QCoapOption option2(QCoapOption::Size1, 1);
+ QCOMPARE(option2.name(), QCoapOption::Size1);
+ QCOMPARE(option2.uintValue(), 1);
+
+ // Copy-construction
+ QCoapOption option3(option2);
+ QCOMPARE(option3.name(), QCoapOption::Size1);
+ QCOMPARE(option3.uintValue(), 1);
+
+ // Move-construction
+ QCoapOption option4(std::move(option2));
+ QCOMPARE(option4.name(), QCoapOption::Size1);
+ QCOMPARE(option4.uintValue(), 1);
+
+ // Copy-assignment
+ option4 = option1;
+ QCOMPARE(option4.name(), QCoapOption::Invalid);
+ QCOMPARE(option4.uintValue(), 0);
+
+ // Move-assignment
+ option4 = std::move(option3);
+ QCOMPARE(option4.name(), QCoapOption::Size1);
+ QCOMPARE(option4.uintValue(), 1);
+
+ // Assign to a moved-from
+ option2 = option4;
+ QCOMPARE(option2.name(), QCoapOption::Size1);
+ QCOMPARE(option2.uintValue(), 1);
+}
+
void tst_QCoapOption::constructWithQByteArray()
{
QByteArray ba = "some data";