tst_QMetaType: remove the IsInitialized check

All primitive types are initialized and have been since at least commit
33cd680ddb ("New QMetaType
representation").

Change-Id: I0e5f6bec596a4a78bd3bfffd16cb1fe22dc5c8f5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2022-01-17 09:45:45 -08:00
parent 26f02d0bb7
commit 541253fcd6
2 changed files with 11 additions and 28 deletions

View File

@ -741,12 +741,11 @@ static void testCreateHelper()
QMetaType info(ID);
void *actual1 = QMetaType::create(ID);
void *actual2 = info.create();
if (DefaultValueTraits<ID>::IsInitialized) {
Type *expected = DefaultValueFactory<ID>::create();
QCOMPARE(*static_cast<Type *>(actual1), *expected);
QCOMPARE(*static_cast<Type *>(actual2), *expected);
delete expected;
}
Type *expected = DefaultValueFactory<ID>::create();
QCOMPARE(*static_cast<Type *>(actual1), *expected);
QCOMPARE(*static_cast<Type *>(actual2), *expected);
delete expected;
QMetaType::destroy(ID, actual1);
info.destroy(actual2);
}
@ -755,9 +754,6 @@ template<>
void testCreateHelper<QMetaType::Void>()
{
void *actual = QMetaType::create(QMetaType::Void);
if (DefaultValueTraits<QMetaType::Void>::IsInitialized) {
QVERIFY(DefaultValueFactory<QMetaType::Void>::create());
}
QMetaType::destroy(QMetaType::Void, actual);
}
@ -1138,12 +1134,10 @@ static void testConstructHelper()
void *actual2 = info.construct(storage2, /*copy=*/0);
QCOMPARE(actual1, storage1);
QCOMPARE(actual2, storage2);
if (DefaultValueTraits<ID>::IsInitialized) {
Type *expected = DefaultValueFactory<ID>::create();
QCOMPARE(*static_cast<Type *>(actual1), *expected);
QCOMPARE(*static_cast<Type *>(actual2), *expected);
delete expected;
}
Type *expected = DefaultValueFactory<ID>::create();
QCOMPARE(*static_cast<Type *>(actual1), *expected);
QCOMPARE(*static_cast<Type *>(actual2), *expected);
delete expected;
QMetaType::destruct(ID, actual1);
qFreeAligned(storage1);
info.destruct(actual2);
@ -1163,9 +1157,6 @@ void testConstructHelper<QMetaType::Void>()
void *storage = 0;
void *actual = QMetaType::construct(QMetaType::Void, storage, /*copy=*/0);
QCOMPARE(actual, storage);
if (DefaultValueTraits<QMetaType::Void>::IsInitialized) {
QVERIFY(DefaultValueFactory<QMetaType::Void>::create());
}
QMetaType::destruct(QMetaType::Void, actual);
qFreeAligned(storage);

View File

@ -61,14 +61,14 @@ template <int ID>
struct DefaultValueFactory
{
typedef typename MetaEnumToType<ID>::Type Type;
static Type *create() { return new Type; }
static Type *create() { return new Type(); }
};
template <>
struct DefaultValueFactory<QMetaType::Void>
{
typedef MetaEnumToType<QMetaType::Void>::Type Type;
static Type *create() { return 0; }
static Type *create() { return nullptr; }
};
template <int ID>
@ -79,14 +79,6 @@ struct DefaultValueTraits
enum { IsInitialized = true };
};
#define DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS(MetaTypeName, MetaTypeId, RealType) \
template<> struct DefaultValueTraits<QMetaType::MetaTypeName> { \
enum { IsInitialized = false }; \
};
// Primitive types (int et al) aren't initialized
FOR_EACH_PRIMITIVE_METATYPE(DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS)
#undef DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS
template <int ID>
struct TestValueFactory {};