summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2016-06-16 17:38:44 +0300
committerSean Harmer <sean.harmer@kdab.com>2016-06-20 14:33:55 +0000
commit4862fea330cffdc4f9fb2972e76287487444e8b4 (patch)
tree5686cfedbac9cc2162f4638414cde6c018d0f744
parentd44aa5a1b285100aa1b656ccf34b69f154b965a3 (diff)
Make QHandle tests pass on big endian systems
QHandle uses an union internally so the value of handle is composed of values of three other integer fields, as defined in Data structure. The value is different on big endian and little endian systems. This commit introduces a new GET_EXPECTED_HANDLE macro which determines what the handle should be equal to based on values of those integer fields and the system endianness. Note that the values of those fields are verified too in the tests. Change-Id: I1f1e37a7469995879ff94e8fc2d6b974c1d4359b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--tests/auto/core/handle/tst_handle.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/tests/auto/core/handle/tst_handle.cpp b/tests/auto/core/handle/tst_handle.cpp
index 5eb92e53b..9ed3a17d6 100644
--- a/tests/auto/core/handle/tst_handle.cpp
+++ b/tests/auto/core/handle/tst_handle.cpp
@@ -41,6 +41,12 @@
#define private public
#include <Qt3DCore/private/qhandle_p.h>
+#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+#define GET_EXPECTED_HANDLE(qHandle) ((qHandle.index() << (qHandle.CounterBits + 2)) + (qHandle.counter() << 2))
+#else /* Q_LITTLE_ENDIAN */
+#define GET_EXPECTED_HANDLE(qHandle) (qHandle.index() + (qHandle.counter() << qHandle.IndexBits))
+#endif
+
class tst_Handle : public QObject
{
Q_OBJECT
@@ -88,14 +94,14 @@ void tst_Handle::construction()
QVERIFY(h.index() == 0);
QVERIFY(h.counter() == 1);
qDebug() << h;
- QVERIFY(h.handle() == 65536);
+ QVERIFY(h.handle() == GET_EXPECTED_HANDLE(h));
Handle h2(1, 1);
QVERIFY(h2.isNull() == false);
QVERIFY(h2.index() == 1);
QVERIFY(h2.counter() == 1);
qDebug() << h2;
- QVERIFY(h2.handle() == 65537);
+ QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
}
void tst_Handle::copyConstruction()
@@ -105,7 +111,7 @@ void tst_Handle::copyConstruction()
QVERIFY(h2.isNull() == false);
QVERIFY(h2.index() == 0);
QVERIFY(h2.counter() == 1);
- QVERIFY(h2.handle() == 65536);
+ QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
}
void tst_Handle::assignment()
@@ -115,7 +121,7 @@ void tst_Handle::assignment()
QVERIFY(h2.isNull() == false);
QVERIFY(h2.index() == 0);
QVERIFY(h2.counter() == 1);
- QVERIFY(h2.handle() == 65536);
+ QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
}
void tst_Handle::equality()
@@ -125,7 +131,7 @@ void tst_Handle::equality()
QVERIFY(h1.isNull() == false);
QVERIFY(h1.index() == 2);
QVERIFY(h1.counter() == 1);
- QVERIFY(h1.handle() == 65538);
+ QVERIFY(h1.handle() == GET_EXPECTED_HANDLE(h1));
QVERIFY(h1 == h2);
}
@@ -136,7 +142,7 @@ void tst_Handle::inequality()
QVERIFY(h1.isNull() == false);
QVERIFY(h1.index() == 2);
QVERIFY(h1.counter() == 1);
- QVERIFY(h1.handle() == 65538);
+ QVERIFY(h1.handle() == GET_EXPECTED_HANDLE(h1));
QVERIFY(h1 != h2);
Handle h3(2, 2);
@@ -161,13 +167,13 @@ void tst_Handle::bigHandle()
QVERIFY(h1.isNull() == false);
QVERIFY(h1.index() == 0);
QVERIFY(h1.counter() == 1);
- QVERIFY(h1.handle() == 4194304);
+ QVERIFY(h1.handle() == GET_EXPECTED_HANDLE(h1));
BigHandle h2(1, 1);
QVERIFY(h2.isNull() == false);
QVERIFY(h2.index() == 1);
QVERIFY(h2.counter() == 1);
- QVERIFY(h2.handle() == 4194305);
+ QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
QVERIFY(BigHandle::maxIndex() == (1 << 22) - 1);
QVERIFY(BigHandle::maxCounter() == (1 << (32 - 22 - 2)) - 1);