From f276dd5b7f8b45201949906c3167ff43ecb2caf4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 27 Mar 2015 20:56:44 +0100 Subject: QVarLengthArray: add relational operators <,<=,>,>= std::vector has them, too. [ChangeLog][QtCore][QVarLengthArray] Added relational operators <, <=, >, >= if the element type supports operator<. Change-Id: I69e16d361fd4738a56b292ebfa78316d28871eda Reviewed-by: Thiago Macieira --- .../tools/qvarlengtharray/tst_qvarlengtharray.cpp | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp') diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 40917eebea..60f3009849 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -51,6 +51,7 @@ private slots: void first(); void last(); void squeeze(); + void operators(); void indexOf(); void lastIndexOf(); void contains(); @@ -690,6 +691,49 @@ void tst_QVarLengthArray::squeeze() QCOMPARE(list.capacity(), sizeOnHeap); } +void tst_QVarLengthArray::operators() +{ + QVarLengthArray myvla; + myvla << "A" << "B" << "C"; + QVarLengthArray myvlatwo; + myvlatwo << "D" << "E" << "F"; + QVarLengthArray combined; + combined << "A" << "B" << "C" << "D" << "E" << "F"; + + // != + QVERIFY(myvla != myvlatwo); + + // +=: not provided, emulate + //myvla += myvlatwo; + Q_FOREACH (const QString &s, myvlatwo) + myvla.push_back(s); + QCOMPARE(myvla, combined); + + // == + QVERIFY(myvla == combined); + + // <, >, <=, >= + QVERIFY(!(myvla < combined)); + QVERIFY(!(myvla > combined)); + QVERIFY( myvla <= combined); + QVERIFY( myvla >= combined); + combined.push_back("G"); + QVERIFY( myvla < combined); + QVERIFY(!(myvla > combined)); + QVERIFY( myvla <= combined); + QVERIFY(!(myvla >= combined)); + QVERIFY(combined > myvla); + QVERIFY(combined >= myvla); + + // [] + QCOMPARE(myvla[0], QLatin1String("A")); + QCOMPARE(myvla[1], QLatin1String("B")); + QCOMPARE(myvla[2], QLatin1String("C")); + QCOMPARE(myvla[3], QLatin1String("D")); + QCOMPARE(myvla[4], QLatin1String("E")); + QCOMPARE(myvla[5], QLatin1String("F")); +} + void tst_QVarLengthArray::indexOf() { QVarLengthArray myvec; -- cgit v1.2.3