summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-03-12 17:14:48 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-23 19:43:00 +0100
commitaccfdc85e5cb1816b3eda02ec8d37474259c247e (patch)
treee2c0369b07eaac3982f155adc8890532e6799e0a /tests/auto/corelib/kernel
parent98c3b8a44220096a4e2a3967a4e9742c3605a5cd (diff)
Fallback implementation of Q_ALIGNOF
For all practical purposes, the fallback introduced here returns the desired value. Having a fallback enables unconditional use of Q_ALIGNOF. For compilers that provide native support for it, Q_ALIGNOF is otherwise #defined in qcompilerdetection.h. Change-Id: Ie148ca8936cbbf8b80fe87771a14797c39a9d30c Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp34
1 files changed, 4 insertions, 30 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 72ad3080d6..9f4944b44b 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -868,41 +868,15 @@ void tst_QMetaType::construct_data()
create_data();
}
-#ifndef Q_ALIGNOF
-template<uint N>
-struct RoundToNextHighestPowerOfTwo
-{
-private:
- enum { V1 = N-1 };
- enum { V2 = V1 | (V1 >> 1) };
- enum { V3 = V2 | (V2 >> 2) };
- enum { V4 = V3 | (V3 >> 4) };
- enum { V5 = V4 | (V4 >> 8) };
- enum { V6 = V5 | (V5 >> 16) };
-public:
- enum { Value = V6 + 1 };
-};
-#endif
-
-template<class T>
-struct TypeAlignment
-{
-#ifdef Q_ALIGNOF
- enum { Value = Q_ALIGNOF(T) };
-#else
- enum { Value = RoundToNextHighestPowerOfTwo<sizeof(T)>::Value };
-#endif
-};
-
template<int ID>
static void testConstructHelper()
{
typedef typename MetaEnumToType<ID>::Type Type;
QMetaType info(ID);
int size = info.sizeOf();
- void *storage1 = qMallocAligned(size, TypeAlignment<Type>::Value);
+ void *storage1 = qMallocAligned(size, Q_ALIGNOF(Type));
void *actual1 = QMetaType::construct(ID, storage1, /*copy=*/0);
- void *storage2 = qMallocAligned(size, TypeAlignment<Type>::Value);
+ void *storage2 = qMallocAligned(size, Q_ALIGNOF(Type));
void *actual2 = info.construct(storage2, /*copy=*/0);
QCOMPARE(actual1, storage1);
QCOMPARE(actual2, storage2);
@@ -971,9 +945,9 @@ static void testConstructCopyHelper()
QMetaType info(ID);
int size = QMetaType::sizeOf(ID);
QCOMPARE(info.sizeOf(), size);
- void *storage1 = qMallocAligned(size, TypeAlignment<Type>::Value);
+ void *storage1 = qMallocAligned(size, Q_ALIGNOF(Type));
void *actual1 = QMetaType::construct(ID, storage1, expected);
- void *storage2 = qMallocAligned(size, TypeAlignment<Type>::Value);
+ void *storage2 = qMallocAligned(size, Q_ALIGNOF(Type));
void *actual2 = info.construct(storage2, expected);
QCOMPARE(actual1, storage1);
QCOMPARE(actual2, storage2);