summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qchar
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-10-15 23:02:43 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-12-10 01:26:51 +0100
commitcb93117d06dc1f32a39a8fe9608c7a68566d6781 (patch)
tree2e49fc7742bf73ea49f2fbe3ab3f7774fe8f2429 /tests/auto/corelib/tools/qchar
parentc9db6e52bc9bd9731159fcb4e95fca5cba01bc9c (diff)
QChar: prepare relational operators for constexpr'ification
Make sure the relational operators are in a constexpr'able form by removing the use of the const/non-const-overloaded unicode() function, which in the relational operators is resolved to the non-const version, which isn't constexpr'able. Replaced with direct member access for op== and op< (required making them friends) and reformulating the other operators in terms of these two. Since I managed to introduce a bug while doing this change, add a simple test for QChar operators, too. Change-Id: I69f3da849e71abc2a17152f797694950914adebc Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qchar')
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index a4350ea2fe..55c911a5fc 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -47,6 +47,8 @@ public slots:
void init();
void cleanup();
private slots:
+ void operators_data();
+ void operators();
void toUpper();
void toLower();
void toTitle();
@@ -99,6 +101,33 @@ void tst_QChar::cleanup()
#endif
}
+void tst_QChar::operators_data()
+{
+ QTest::addColumn<QChar>("lhs");
+ QTest::addColumn<QChar>("rhs");
+
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j)
+ QTest::newRow(qPrintable(QString().sprintf("'\\%d' (op) '\\%d'", i, j)))
+ << QChar(ushort(i)) << QChar(ushort(j));
+ }
+}
+
+void tst_QChar::operators()
+{
+ QFETCH(QChar, lhs);
+ QFETCH(QChar, rhs);
+
+#define CHECK(op) QCOMPARE((lhs op rhs), (lhs.unicode() op rhs.unicode()))
+ CHECK(==);
+ CHECK(!=);
+ CHECK(< );
+ CHECK(> );
+ CHECK(<=);
+ CHECK(>=);
+#undef CHECK
+}
+
void tst_QChar::toUpper()
{
QVERIFY(QChar('a').toUpper() == 'A');