summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-09-08 10:10:12 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-01 13:02:47 +0000
commit048447346bc1b78992be3ce4bf3292fc272f7e1a (patch)
treefeb3a31098cba1ee7c6d090ac85e51778494c7ba /tests
parentf4a33e345eb658996e171daa6478fdc2ef62ff17 (diff)
QPointerUniqueId: make fit for release
- Declare as Q_MOVABLE_TYPE - Prevent QList<QPointerUniqueId> from being instantiated (use QVector instead) - Add equality relational operators - Add qHash() overload - Replace non-default ctor with named ctor. - Add Q_DECL_NOTHROW. - Add Q_DECL_CONSTEXPR. - Rename numeric() -> numericId(). - Update docs. The extension vector for this class calls for additional properties to be added later, but these are not user- settable. It thus suffices to rely on the only data member, a qint64, which can be reinterpreted to an index into an array or hash with actual objects. This allows to make the class a Trivial Type (ie. no overhead over an int) while still supporting later extension. Cf. QSslEllipticCurve as another example of such a class. The extension has to maintain the following invariants, encoded into user code by way of being used in inline functions: - m_numericId == -1 <=> !isValid() This is trivial to support. An extension could not and still cannot reinterpret the qint64 member as a d-pointer, but a d-pointer is only necessary for user-settable properties where updating a central private data structure would cause too much contention. Add a test. Since this type is used in other modules, keep the existing functions, but mark them as deprecated with the expectation that these compat functions be removed before 5.8.0 final. Task-number: QTBUG-54616 Change-Id: Ia3ede0ecaeeef4cd3ffa94a72b1050bd409713a5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index e6fd67e3a8..02814b48e9 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -194,6 +194,7 @@ public:
private slots:
void cleanup();
+ void qPointerUniqueId();
void touchDisabledByDefault();
void touchEventAcceptedByDefault();
void touchBeginPropagatesWhenIgnored();
@@ -224,6 +225,44 @@ void tst_QTouchEvent::cleanup()
QVERIFY(QGuiApplication::topLevelWindows().isEmpty());
}
+void tst_QTouchEvent::qPointerUniqueId()
+{
+ QPointerUniqueId id1, id2;
+
+ QCOMPARE(id1.numericId(), Q_INT64_C(-1));
+ QVERIFY(!id1.isValid());
+
+ QVERIFY( id1 == id2);
+ QVERIFY(!(id1 != id2));
+
+ QSet<QPointerUniqueId> set; // compile test
+ set.insert(id1);
+ set.insert(id2);
+ QCOMPARE(set.size(), 1);
+
+
+ const auto id3 = QPointerUniqueId::fromNumericId(-1);
+ QCOMPARE(id3.numericId(), Q_INT64_C(-1));
+ QVERIFY(!id3.isValid());
+
+ QVERIFY( id1 == id3);
+ QVERIFY(!(id1 != id3));
+
+ set.insert(id3);
+ QCOMPARE(set.size(), 1);
+
+
+ const auto id4 = QPointerUniqueId::fromNumericId(4);
+ QCOMPARE(id4.numericId(), Q_INT64_C(4));
+ QVERIFY(id4.isValid());
+
+ QVERIFY( id1 != id4);
+ QVERIFY(!(id1 == id4));
+
+ set.insert(id4);
+ QCOMPARE(set.size(), 2);
+}
+
void tst_QTouchEvent::touchDisabledByDefault()
{
// QWidget