31 #include <QtCore/private/qmetaobjectbuilder_p.h>
54 static_assert(QTypeTraits::has_operator_equal_v<bool>);
55 static_assert(QTypeTraits::has_operator_less_than_v<bool>);
56 static_assert(QTypeTraits::has_operator_equal_v<int>);
57 static_assert(QTypeTraits::has_operator_less_than_v<int>);
58 static_assert(QTypeTraits::has_operator_equal_v<double>);
59 static_assert(QTypeTraits::has_operator_less_than_v<double>);
62 static_assert(!QTypeTraits::has_operator_equal_v<NoOperators>);
63 static_assert(!QTypeTraits::has_operator_less_than_v<NoOperators>);
66 static_assert(QTypeTraits::has_operator_equal_v<QString>);
67 static_assert(QTypeTraits::has_operator_less_than_v<QString>);
68 static_assert(QTypeTraits::has_operator_equal_v<QVariant>);
69 static_assert(!QTypeTraits::has_operator_less_than_v<QVariant>);
72 static_assert(QTypeTraits::has_operator_equal_v<QStringList>);
73 static_assert(QTypeTraits::has_operator_less_than_v<QStringList>);
135 static_assert(QTypeTraits::has_operator_equal_v<Nested>);
136 static_assert(!QTypeTraits::has_operator_less_than_v<Nested>);
142 static_assert(QTypeTraits::has_operator_equal_v<Nested2>);
143 static_assert(!QTypeTraits::has_operator_less_than_v<Nested2>);
155 virtual void *
constructor(
int typeId,
void *where,
const void *copy) = 0;
164 void *
constructor(
int typeId,
void *where,
const void *copy)
override
167 ret->m_typeId = typeId;
183 prop.metaType().construct(_a[0], prop.constData());
188 prop =
QVariant(prop.metaType(), _a[0]);
210 void *
constructor(
int typeId,
void *where,
const void *copy)
override
213 ret->m_typeId = typeId;
246 static std::vector<std::shared_ptr<QtPrivate::QMetaTypeInterface>> s_metaTypeInterfaces;
253 reinterpret_cast<BaseGenericType*
>(_o)->staticMetacallFunction(_c, _id, _a);
256 static void GadgetTypedDestructor(
int typeId,
void *ptr)
262 static void *GadgetTypedConstructor(
int type,
void *where,
const void *copy)
264 auto it = s_managedTypes.find(
type);
265 if (
it == s_managedTypes.end())
267 return it->first->constructor(
type, where, copy);
319 gadgetBuilder.
setFlags(metaObjectflags);
320 auto dynamicGadgetProperties = std::make_shared<GenericGadgetType>();
321 for (
const auto &
prop : gadgetProperties) {
323 dynamicGadgetProperties->properties.push_back(
QVariant(
QMetaType(propertyType)));
326 dynamicPropery.setReadable(
true);
330 meta->d.superdata =
nullptr;
337 auto typeInfo = s_metaTypeInterfaces.emplace_back(
new TypeInfo {
341 return reinterpret_cast<const TypeInfo *
>(
self)->
mo;
358 dynamicGadgetProperties->m_metatype = gadgetMetaType;
361 s_managedTypes[gadgetTypeId] =
qMakePair(dynamicGadgetProperties, std::shared_ptr<QMetaObject>{meta, [](
QMetaObject *ptr){ ::free(ptr); }});
364 void tst_QMetaType::defined()
416 for (
int i = 0;
i < 1000; ++
i) {
419 int tp = qRegisterMetaType<Bar>(nm);
420 #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
424 if (!
info.isValid()) {
426 qWarning() <<
"Wrong typeInfo returned for" << tp;
428 if (!
info.isRegistered()) {
434 qWarning() <<
"Wrong typeInfo returned for" << tp;
446 void *buf3 =
info.create(tp, 0);
447 void *buf4 =
info.create(tp, buf1);
454 info.construct(space, 0);
455 info.destruct(space);
456 info.construct(space, buf1);
457 info.destruct(space);
461 qWarning() <<
"Null buffer returned by QMetaType::create(tp, 0)";
465 qWarning() <<
"Null buffer returned by QMetaType::create(tp, buf)";
469 qWarning() <<
"Null buffer returned by info.create(tp, 0)";
473 qWarning() <<
"Null buffer returned by infocreate(tp, buf)";
487 void tst_QMetaType::threadSafety()
514 #define ADD_TESTSPACE(F) TestSpace::F
517 void tst_QMetaType::namespaces()
521 QCOMPARE(qvariant_cast<TestSpace::Foo>(
v).
d, 11.12);
523 int qungTfuId = qRegisterMetaType<ADD_TESTSPACE(QungTfu)>();
527 void tst_QMetaType::id()
530 QCOMPARE(
QMetaType(::qMetaTypeId<TestSpace::Foo>()).
id(), ::qMetaTypeId<TestSpace::Foo>());
531 QCOMPARE(QMetaType::fromType<TestSpace::Foo>().
id(), ::qMetaTypeId<TestSpace::Foo>());
534 void tst_QMetaType::qMetaTypeId()
543 QVERIFY(::qMetaTypeId<signed char>() != ::qMetaTypeId<char>());
547 void tst_QMetaType::properties()
549 qRegisterMetaType<QList<QVariant> >(
"QList<QVariant>");
566 void tst_QMetaType::normalizedTypes()
568 int WhityIntId = ::qMetaTypeId<Whity<int> >();
569 int WhityDoubleId = ::qMetaTypeId<Whity<double> >();
588 #define TYPENAME_DATA(MetaTypeName, MetaTypeId, RealType)\
589 QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << #RealType;
591 void tst_QMetaType::typeName_data()
593 QTest::addColumn<int>(
"aType");
594 QTest::addColumn<QString>(
"aTypeName");
629 void tst_QMetaType::typeName()
635 QSKIP(
"The test doesn't link against QtWidgets.");
642 QCOMPARE(rawname ==
nullptr, aTypeName.isNull());
651 void tst_QMetaType::type_data()
653 QTest::addColumn<int>(
"aType");
654 QTest::addColumn<QByteArray>(
"aTypeName");
656 #define TST_QMETATYPE_TYPE_DATA(MetaTypeName, MetaTypeId, RealType)\
657 QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << QByteArray( #RealType );
658 #define TST_QMETATYPE_TYPE_DATA_ALIAS(MetaTypeName, MetaTypeId, AliasType, RealTypeString)\
659 QTest::newRow(RealTypeString) << int(QMetaType::MetaTypeName) << QByteArray( #AliasType );
666 #undef TST_QMETATYPE_TYPE_DATA
667 #undef TST_METATYPE_TYPE_DATA_ALIAS
670 void tst_QMetaType::type()
676 QSKIP(
"The test doesn't link against QtWidgets.");
683 void tst_QMetaType::type_fromSubString_data()
685 QTest::addColumn<int>(
"offset");
686 QTest::addColumn<int>(
"size");
687 QTest::addColumn<int>(
"expectedType");
694 QTest::newRow(
"QMetaType::Type") << 7 << 15 << ::qMetaTypeId<QMetaType::Type>();
698 void tst_QMetaType::type_fromSubString()
700 static const char *
types =
"intboolQMetaType::Typedoublexxx";
703 QFETCH(
int, expectedType);
709 template <
typename T>
710 struct static_assert_trigger {
712 enum {
value =
true };
716 #define CHECK_BUILTIN(MetaTypeName, MetaTypeId, RealType) static_assert_trigger< RealType >::value &&
727 void tst_QMetaType::create_data()
729 QTest::addColumn<int>(
"type");
730 #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
731 QTest::newRow(QMetaType::typeName(QMetaType::MetaTypeName)) << int(QMetaType::MetaTypeName);
733 #undef ADD_METATYPE_TEST_ROW
737 static void testCreateHelper()
742 void *actual2 =
info.create();
750 info.destroy(actual2);
754 void testCreateHelper<QMetaType::Void>()
766 void tst_QMetaType::create()
768 struct TypeTestFunctionGetter
773 #define RETURN_CREATE_FUNCTION(MetaTypeName, MetaTypeId, RealType) \
774 case QMetaType::MetaTypeName: \
775 return testCreateHelper<QMetaType::MetaTypeName>;
777 #undef RETURN_CREATE_FUNCTION
788 static void testCreateCopyHelper()
794 void *actual2 =
info.create(expected);
798 info.destroy(actual2);
803 void testCreateCopyHelper<QMetaType::Void>()
812 void tst_QMetaType::createCopy_data()
817 void tst_QMetaType::createCopy()
819 struct TypeTestFunctionGetter
824 #define RETURN_CREATE_COPY_FUNCTION(MetaTypeName, MetaTypeId, RealType) \
825 case QMetaType::MetaTypeName: \
826 return testCreateCopyHelper<QMetaType::MetaTypeName>;
828 #undef RETURN_CREATE_COPY_FUNCTION
843 void tst_QMetaType::sizeOf_data()
845 QTest::addColumn<int>(
"type");
846 QTest::addColumn<size_t>(
"size");
849 #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
850 QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << getSize<RealType>;
852 #undef ADD_METATYPE_TEST_ROW
863 void tst_QMetaType::sizeOf()
870 void tst_QMetaType::sizeOfStaticLess_data()
875 void tst_QMetaType::sizeOfStaticLess()
882 template <
typename T>
885 if constexpr (std::is_same_v<T, void>)
891 void tst_QMetaType::alignOf_data()
893 QTest::addColumn<int>(
"type");
894 QTest::addColumn<size_t>(
"size");
897 #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
898 QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << size_t(getAlignOf<RealType>());
900 #undef ADD_METATYPE_TEST_ROW
911 void tst_QMetaType::alignOf()
949 #if defined(Q_CC_GNU) && Q_CC_GNU < 501
979 void tst_QMetaType::flags_data()
981 QTest::addColumn<int>(
"type");
982 QTest::addColumn<bool>(
"isMovable");
983 QTest::addColumn<bool>(
"isComplex");
984 QTest::addColumn<bool>(
"isPointerToQObject");
985 QTest::addColumn<bool>(
"isEnum");
986 QTest::addColumn<bool>(
"isQmlList");
988 #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
989 QTest::newRow(#RealType) << MetaTypeId \
990 << bool(QTypeInfo<RealType>::isRelocatable) \
991 << bool(QTypeInfo<RealType>::isComplex) \
992 << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \
993 << bool(std::is_enum<RealType>::value) \
998 #undef ADD_METATYPE_TEST_ROW
999 QTest::newRow(
"TestSpace::Foo") << ::qMetaTypeId<TestSpace::Foo>() <<
false <<
true <<
false <<
false <<
false;
1000 QTest::newRow(
"Whity<double>") << ::qMetaTypeId<Whity<double> >() <<
true <<
true <<
false <<
false <<
false;
1001 QTest::newRow(
"CustomMovable") << ::qMetaTypeId<CustomMovable>() <<
true <<
true <<
false <<
false <<
false;
1002 QTest::newRow(
"CustomObject*") << ::qMetaTypeId<CustomObject*>() <<
true <<
false <<
true <<
false <<
false;
1003 QTest::newRow(
"CustomMultiInheritanceObject*") << ::qMetaTypeId<CustomMultiInheritanceObject*>() <<
true <<
false <<
true <<
false <<
false;
1004 QTest::newRow(
"QPair<C,C>") << ::qMetaTypeId<QPair<C,C> >() <<
false <<
true <<
false <<
false <<
false;
1005 QTest::newRow(
"QPair<C,M>") << ::qMetaTypeId<QPair<C,M> >() <<
false <<
true <<
false <<
false <<
false;
1006 QTest::newRow(
"QPair<C,P>") << ::qMetaTypeId<QPair<C,P> >() <<
false <<
true <<
false <<
false <<
false;
1007 QTest::newRow(
"QPair<M,C>") << ::qMetaTypeId<QPair<M,C> >() <<
false <<
true <<
false <<
false <<
false;
1008 QTest::newRow(
"QPair<M,M>") << ::qMetaTypeId<QPair<M,M> >() <<
true <<
true <<
false <<
false <<
false;
1009 QTest::newRow(
"QPair<M,P>") << ::qMetaTypeId<QPair<M,P> >() <<
true <<
true <<
false <<
false <<
false;
1010 QTest::newRow(
"QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() <<
false <<
true <<
false <<
false <<
false;
1011 QTest::newRow(
"QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() <<
true <<
true <<
false <<
false <<
false;
1012 QTest::newRow(
"QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() <<
true <<
false <<
false <<
false <<
false;
1013 QTest::newRow(
"FlagsDataEnum") << ::qMetaTypeId<FlagsDataEnum>() <<
true <<
false <<
false <<
true <<
false;
1016 QTest::newRow(
"-1") << -1 <<
false <<
false <<
false <<
false <<
false;
1017 QTest::newRow(
"-124125534") << -124125534 <<
false <<
false <<
false <<
false <<
false;
1018 QTest::newRow(
"124125534") << 124125534 <<
false <<
false <<
false <<
false <<
false;
1021 void tst_QMetaType::flags()
1026 QFETCH(
bool, isPointerToQObject);
1038 void tst_QMetaType::flagsStaticLess_data()
1043 void tst_QMetaType::flagsStaticLess()
1055 void tst_QMetaType::flagsBinaryCompatibility6_0_data()
1076 QTest::addColumn<quint32>(
"id");
1077 QTest::addColumn<quint32>(
"flags");
1085 for (
int i = 0;
i <
buffer.size();
i+=2) {
1095 void tst_QMetaType::flagsBinaryCompatibility6_0()
1100 const auto currentFlags = QMetaType::typeFlags(
id);
1101 auto expectedFlags = QMetaType::TypeFlags(
flags);
1114 void tst_QMetaType::construct_data()
1120 static void testConstructHelper()
1128 void *actual2 =
info.construct(storage2, 0);
1139 info.destruct(actual2);
1150 void testConstructHelper<QMetaType::Void>()
1166 void tst_QMetaType::construct()
1168 struct TypeTestFunctionGetter
1173 #define RETURN_CONSTRUCT_FUNCTION(MetaTypeName, MetaTypeId, RealType) \
1174 case QMetaType::MetaTypeName: \
1175 return testConstructHelper<QMetaType::MetaTypeName>;
1177 #undef RETURN_CONSTRUCT_FUNCTION
1187 void tst_QMetaType::typedConstruct()
1191 auto metaObject = QMetaType::metaObjectForType(gadget.
userType());
1192 QVERIFY(metaObject !=
nullptr);
1193 QCOMPARE(metaObject->methodCount(), 0);
1194 QCOMPARE(metaObject->propertyCount(), properties.size());
1195 for (
int i = 0;
i < metaObject->propertyCount(); ++
i) {
1196 auto prop = metaObject->property(
i);
1199 prop.writeOnGadget(gadget.
data(), properties[
i].testData);
1205 auto metaObject = QMetaType::metaObjectForType(gadget.
userType());
1206 QVERIFY(metaObject !=
nullptr);
1207 QCOMPARE(metaObject->methodCount(), 0);
1208 QCOMPARE(metaObject->propertyCount(), properties.size());
1209 for (
int i = 0;
i < metaObject->propertyCount(); ++
i) {
1210 auto prop = metaObject->property(
i);
1219 {
"int",
"int_prop", 34526},
1220 {
"float",
"float_prop", 1.23f},
1221 {
"QString",
"string_prop",
QString{
"Test QString"}}
1223 registerGadget(
"DynamicGadget1", dynamicGadget1);
1226 testMetaObjectWriteOnGadget(testGadget1, dynamicGadget1);
1227 testMetaObjectReadOnGadget(testGadget1, dynamicGadget1);
1231 {
"int",
"int_prop", 512},
1232 {
"double",
"double_prop", 4.56},
1233 {
"QString",
"string_prop",
QString{
"Another String"}},
1234 {
"DynamicGadget1",
"dynamicGadget1_prop", testGadget1}
1236 registerGadget(
"DynamicGadget2", dynamicGadget2);
1238 testMetaObjectWriteOnGadget(testGadget2, dynamicGadget2);
1239 testMetaObjectReadOnGadget(testGadget2, dynamicGadget2);
1240 auto g2mo = QMetaType::metaObjectForType(testGadget2.userType());
1241 auto dynamicGadget1_prop = g2mo->property(g2mo->indexOfProperty(
"dynamicGadget1_prop"));
1242 testMetaObjectReadOnGadget(dynamicGadget1_prop.readOnGadget(testGadget2.constData()), dynamicGadget1);
1246 const QByteArray myPodTesData =
"My POD test data";
1247 const char podTypeName[] =
"DynamicPOD";
1248 auto dynamicGadgetProperties = std::make_shared<GenericPODType>();
1249 dynamicGadgetProperties->podData = myPodTesData;
1252 auto typeInfo = s_metaTypeInterfaces.emplace_back(
new TypeInfo {
1254 [](
const TypeInfo *
self,
void *where) { GadgetTypedConstructor(
self->typeId, where,
nullptr); },
1255 [](
const TypeInfo *
self,
void *where,
const void *copy) { GadgetTypedConstructor(
self->typeId, where, copy); },
1256 [](
const TypeInfo *
self,
void *where,
void *copy) { GadgetTypedConstructor(
self->typeId, where, copy); },
1257 [](
const TypeInfo *
self,
void *ptr) { GadgetTypedDestructor(
self->typeId, ptr); },
1266 dynamicGadgetProperties->m_metatype = metatype;
1267 int podTypeId = metatype.id();
1269 s_managedTypes[podTypeId] =
qMakePair(dynamicGadgetProperties, std::shared_ptr<QMetaObject>{});
1283 static void testConstructCopyHelper()
1293 void *actual2 =
info.construct(storage2, expected);
1300 info.destruct(actual2);
1310 void testConstructCopyHelper<QMetaType::Void>()
1324 void tst_QMetaType::constructCopy_data()
1329 void tst_QMetaType::constructCopy()
1331 struct TypeTestFunctionGetter
1336 #define RETURN_CONSTRUCT_COPY_FUNCTION(MetaTypeName, MetaTypeId, RealType) \
1337 case QMetaType::MetaTypeName: \
1338 return testConstructCopyHelper<QMetaType::MetaTypeName>;
1340 #undef RETURN_CONSTRUCT_COPY_FUNCTION
1350 void tst_QMetaType::selfCompare_data()
1352 qRegisterMetaType<QPartialOrdering>();
1353 QTest::addColumn<int>(
"type");
1354 QTest::addColumn<QPartialOrdering>(
"order");
1364 #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
1365 QTest::newRow(QMetaType::typeName(QMetaType::MetaTypeName)) << int(QMetaType::MetaTypeName) << orderingFor(QMetaType::MetaTypeName);
1367 #undef ADD_METATYPE_TEST_ROW
1370 void tst_QMetaType::selfCompare()
1376 void *
v1 =
t.create(
nullptr);
1377 void *
v2 =
t.create(
nullptr);
1386 if (
t.iface() &&
t.iface()->lessThan)
1394 #define ADD_METATYPE_CASE(MetaTypeName, MetaTypeId, RealType) \
1395 case QMetaType::MetaTypeName:
1397 #undef ADD_METATYPE_CASE
1405 void tst_QMetaType::typedefs()
1425 qRegisterMetaType<WhityDouble>(
"WhityDouble");
1429 void tst_QMetaType::registerType()
1436 int fooId = qRegisterMetaType<TestSpace::Foo>(
"TestSpace::Foo");
1438 QCOMPARE(qRegisterMetaType<TestSpace::Foo>(
"TestSpace::Foo"), fooId);
1440 int movableId = qRegisterMetaType<CustomMovable>(
"CustomMovable");
1442 QCOMPARE(qRegisterMetaType<CustomMovable>(
"CustomMovable"), movableId);
1456 QCOMPARE(qRegisterMetaType<MyMovable>(
"MyMovable"), movableId);
1457 QCOMPARE(qRegisterMetaType<MyMovable>(
"MyMovable"), movableId);
1461 QCOMPARE(qRegisterMetaType<MyFoo>(
"MyFoo"), fooId);
1462 QCOMPARE(qRegisterMetaType<MyFoo>(
"MyFoo"), fooId);
1469 void tst_QMetaType::isRegistered_data()
1471 QTest::addColumn<int>(
"typeId");
1472 QTest::addColumn<bool>(
"registered");
1475 QTest::newRow(
"QMetaType::Void") << int(QMetaType::Void) <<
true;
1478 int dummyTypeId = qRegisterMetaType<IsRegisteredDummyType>(
"IsRegisteredDummyType");
1480 QTest::newRow(
"IsRegisteredDummyType") << dummyTypeId <<
true;
1485 QTest::newRow(
"IsRegisteredDummyType + 1") << (dummyTypeId + 1) <<
false;
1489 void tst_QMetaType::isRegistered()
1492 QFETCH(
bool, registered);
1505 void tst_QMetaType::isEnum()
1507 int type0 = qRegisterMetaType<int>(
"int");
1510 int type1 = qRegisterMetaType<isEnumTest_Enum0>(
"isEnumTest_Enum0");
1513 int type2 = qRegisterMetaType<isEnumTest_Struct0>(
"isEnumTest_Struct0");
1516 int type3 = qRegisterMetaType<isEnumTest_Enum0 *>(
"isEnumTest_Enum0 *");
1519 int type4 = qRegisterMetaType<isEnumTest_Struct0::A>(
"isEnumTest_Struct0::A");
1522 int type5 = ::qMetaTypeId<isEnumTest_Struct1>();
1525 int type6 = ::qMetaTypeId<isEnumTest_Enum1>();
1529 void tst_QMetaType::isRegisteredStaticLess_data()
1531 isRegistered_data();
1534 void tst_QMetaType::isRegisteredStaticLess()
1537 QFETCH(
bool, registered);
1578 m_hash.insert(4, 2);
1608 void tst_QMetaType::automaticTemplateRegistration_1()
1610 #define TEST_SEQUENTIAL_CONTAINER(CONTAINER, VALUE_TYPE) \
1612 CONTAINER<VALUE_TYPE> innerContainer; \
1613 innerContainer.push_back(42); \
1614 QVERIFY(*QVariant::fromValue(innerContainer).value<CONTAINER<VALUE_TYPE> >().begin() == 42); \
1615 QList<CONTAINER<VALUE_TYPE> > outerContainer; \
1616 outerContainer << innerContainer; \
1617 QVERIFY(*QVariant::fromValue(outerContainer).value<QList<CONTAINER<VALUE_TYPE> > >().first().begin() == 42); \
1625 std::vector<bool> vecbool;
1626 vecbool.push_back(
true);
1627 vecbool.push_back(
false);
1628 vecbool.push_back(
true);
1631 vectorList << vecbool;
1637 unsignedList << 123;
1640 vectorList << unsignedList;
1654 sharedPointerList << QSharedPointer<QObject>(
testObject);
1657 vectorList << sharedPointerList;
1667 qRegisterMetaType<QHash<int, int> >(
"IntIntHash");
1671 qRegisterMetaType<int>(
"NaturalNumber");
1677 intUIntHash.
insert(4, 2);
1683 intComparableHash.
insert(4,
m);
1693 IntIntMap intIntMap;
1705 intComparableMap.
insert(4,
m);
1714 typedef std::map<int, int> IntIntMap;
1715 IntIntMap intIntMap;
1720 typedef std::map<int, uint> StdIntUIntMap;
1721 StdIntUIntMap intUIntMap;
1726 typedef std::map<int, CustomObject*> StdMapIntCustomObject ;
1727 StdMapIntCustomObject intComparableMap;
1729 intComparableMap[4] =
o;
1733 typedef std::map<QString, QVariant> StdMapStringVariant;
1734 StdMapStringVariant variantMap;
1740 IntIntPair intIntPair =
qMakePair(4, 2);
1756 typedef std::pair<int, int> IntIntPair;
1757 IntIntPair intIntPair = std::make_pair(4, 2);
1762 typedef std::pair<int, uint> StdIntUIntPair;
1763 StdIntUIntPair intUIntPair = std::make_pair<int, uint>(4, 2);
1768 typedef std::pair<int, CustomQObject*> StdIntComparablePair;
1770 StdIntComparablePair intComparablePair = std::make_pair(4,
o);
1776 QVERIFY(qRegisterMetaType<IntUnregisteredTypeHash>(
"IntUnregisteredTypeHash") > 0);
1780 QVERIFY(qRegisterMetaType<UnregisteredTypeList>(
"UnregisteredTypeList") > 0);
1800 #define TEST_OWNING_SMARTPOINTER(SMARTPOINTER, ELEMENT_TYPE, FLAG_TEST, FROMVARIANTFUNCTION) \
1802 SMARTPOINTER < ELEMENT_TYPE > sp(new ELEMENT_TYPE); \
1803 sp.data()->setObjectName("Test name"); \
1804 QVariant v = QVariant::fromValue(sp); \
1805 QCOMPARE(v.typeName(), #SMARTPOINTER "<" #ELEMENT_TYPE ">"); \
1806 QVERIFY(QMetaType::typeFlags(::qMetaTypeId<SMARTPOINTER < ELEMENT_TYPE > >()) & QMetaType::FLAG_TEST); \
1807 SMARTPOINTER < QObject > extractedPtr = FROMVARIANTFUNCTION<QObject>(v); \
1808 QCOMPARE(extractedPtr.data()->objectName(), sp.data()->objectName()); \
1815 #undef TEST_OWNING_SMARTPOINTER
1817 #define TEST_NONOWNING_SMARTPOINTER(SMARTPOINTER, ELEMENT_TYPE, FLAG_TEST, FROMVARIANTFUNCTION) \
1819 ELEMENT_TYPE elem; \
1820 SMARTPOINTER < ELEMENT_TYPE > sp(&elem); \
1821 sp.data()->setObjectName("Test name"); \
1822 QVariant v = QVariant::fromValue(sp); \
1823 QCOMPARE(v.typeName(), #SMARTPOINTER "<" #ELEMENT_TYPE ">"); \
1824 QVERIFY(QMetaType::typeFlags(::qMetaTypeId<SMARTPOINTER < ELEMENT_TYPE > >()) & QMetaType::FLAG_TEST); \
1825 SMARTPOINTER < QObject > extractedPtr = FROMVARIANTFUNCTION<QObject>(v); \
1826 QCOMPARE(extractedPtr.data()->objectName(), sp.data()->objectName()); \
1833 #undef TEST_NONOWNING_SMARTPOINTER
1836 #define TEST_WEAK_SMARTPOINTER(ELEMENT_TYPE, FLAG_TEST) \
1838 ELEMENT_TYPE elem; \
1839 QSharedPointer < ELEMENT_TYPE > shared(new ELEMENT_TYPE); \
1840 QWeakPointer < ELEMENT_TYPE > sp(shared); \
1841 sp.toStrongRef()->setObjectName("Test name"); \
1842 QVariant v = QVariant::fromValue(sp); \
1843 QCOMPARE(v.typeName(), "QWeakPointer<" #ELEMENT_TYPE ">"); \
1844 QVERIFY(QMetaType::typeFlags(::qMetaTypeId<QWeakPointer < ELEMENT_TYPE > >()) & QMetaType::FLAG_TEST); \
1851 #undef TEST_WEAK_SMARTPOINTER
1854 template <
typename T>
1862 #define DECLARE_NONSTREAMABLE(Type) \
1863 template<> struct StreamingTraits<Type> { enum { isStreamable = 0 }; };
1872 #define DECLARE_WIDGETS_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \
1873 DECLARE_NONSTREAMABLE(RealType)
1875 #undef DECLARE_WIDGETS_CLASS_NONSTREAMABLE
1877 #undef DECLARE_NONSTREAMABLE
1879 void tst_QMetaType::saveAndLoadBuiltin_data()
1881 QTest::addColumn<int>(
"type");
1882 QTest::addColumn<bool>(
"isStreamable");
1884 #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
1885 QTest::newRow(#RealType) << MetaTypeId << bool(StreamingTraits<RealType>::isStreamable);
1887 #undef ADD_METATYPE_TEST_ROW
1890 void tst_QMetaType::saveAndLoadBuiltin()
1893 QFETCH(
bool, isStreamable);
1907 if (
type != QMetaType::Nullptr)
1913 stream.device()->seek(0);
1922 if (
type != QMetaType::Nullptr)
1949 void tst_QMetaType::saveAndLoadCustom()
1954 int id = ::qMetaTypeId<CustomStreamableType>();
1967 stream.device()->seek(0);
2000 void tst_QMetaType::metaObject_data()
2002 QTest::addColumn<int>(
"type");
2003 QTest::addColumn<const QMetaObject*>(
"result");
2004 QTest::addColumn<bool>(
"isGadget");
2005 QTest::addColumn<bool>(
"isGadgetPtr");
2006 QTest::addColumn<bool>(
"isQObjectPtr");
2008 QTest::newRow(
"QObject") << int(QMetaType::QObjectStar) << &QObject::staticMetaObject <<
false <<
false <<
true;
2009 QTest::newRow(
"QFile*") << ::qMetaTypeId<QFile*>() << &QFile::staticMetaObject <<
false <<
false <<
true;
2010 QTest::newRow(
"MyObject*") << ::qMetaTypeId<MyObject*>() << &MyObject::staticMetaObject <<
false <<
false <<
true;
2012 QTest::newRow(
"QEasingCurve") << ::qMetaTypeId<QEasingCurve>() << &QEasingCurve::staticMetaObject <<
true <<
false <<
false;
2013 QTest::newRow(
"MyGadget") << ::qMetaTypeId<MyGadget>() << &MyGadget::staticMetaObject <<
true <<
false <<
false;
2014 QTest::newRow(
"MyGadget*") << ::qMetaTypeId<MyGadget*>() << &MyGadget::staticMetaObject <<
false <<
true <<
false;
2015 QTest::newRow(
"MyEnum") << ::qMetaTypeId<MyGadget::MyEnum>() << &MyGadget::staticMetaObject <<
false <<
false <<
false;
2016 QTest::newRow(
"Qt::ScrollBarPolicy") << ::qMetaTypeId<Qt::ScrollBarPolicy>() << &Qt::staticMetaObject <<
false <<
false <<
false;
2017 QTest::newRow(
"MyQObjectFromGadget*") << ::qMetaTypeId<MyQObjectFromGadget*>() << &MyQObjectFromGadget::staticMetaObject <<
false <<
false <<
true;
2024 void tst_QMetaType::metaObject()
2029 QFETCH(
bool, isGadgetPtr);
2030 QFETCH(
bool, isQObjectPtr);
2040 #define METATYPE_ID_FUNCTION(Type, MetaTypeId, Name) \
2041 case ::qMetaTypeId< Name >(): metaType = MetaTypeIdStruct<MetaTypeId>::Value; break;
2043 #define REGISTER_METATYPE_FUNCTION(Type, MetaTypeId, Name) \
2044 case qRegisterMetaType< Name >(): metaType = RegisterMetaTypeStruct<MetaTypeId>::Value; break;
2056 #define METATYPE_ID_STRUCT(Type, MetaTypeId, Name) \
2058 struct MetaTypeIdStruct< ::qMetaTypeId< Name >()> \
2060 enum { Value = ::qMetaTypeId< Name >() }; \
2063 #define REGISTER_METATYPE_STRUCT(Type, MetaTypeId, Name) \
2065 struct RegisterMetaTypeStruct<qRegisterMetaType< Name >()> \
2067 enum { Value = qRegisterMetaType< Name >() }; \
2073 template<int i = ::qMetaTypeId<int>()>
2079 template<int i = qRegisterMetaType<int>()>
2085 void tst_QMetaType::constexprMetaTypeIds()
2115 #include "tst_qmetatype.moc"
small capitals from c petite p scientific i
[1]
CustomGadget_NonDefaultConstructible(int)
CustomMultiInheritanceObject(QObject *parent=nullptr)
CustomObject(QObject *parent=nullptr)
CustomQObject(QObject *parent=nullptr)
MyObject(QObject *parent=nullptr)
MyQObjectFromGadget(QObject *parent=nullptr)
The QByteArray class provides an array of bytes.
const char * constData() const noexcept
static QByteArray number(int, int base=10)
static QByteArray fromRawData(const char *data, qsizetype size)
The QDataStream class provides serialization of binary data to a QIODevice.
operator>>(QDataStream &ds, qfloat16 &f)
operator<<(QDataStream &ds, qfloat16 f)
The QFile class provides an interface for reading from and writing to files.
bool open(OpenMode flags) override
T value(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
QList< T > toList() const noexcept
iterator insert(const Key &key, const T &value)
The QModelIndex class is used to locate data in a data model.
The QObject class is the base class of all Qt objects.
Q_INVOKABLE QObject(QObject *parent=nullptr)
QVariant property(const char *name) const
bool setProperty(const char *name, const QVariant &value)
static const QPartialOrdering Equivalent
static const QPartialOrdering Unordered
The QPersistentModelIndex class is used to locate data in a data model.
The QPointer class is a template class that provides guarded pointers to QObject.
The QSharedPointer class holds a strong reference to a shared pointer.
The QString class provides a Unicode character string.
static QString fromLatin1(QByteArrayView ba)
The QTemporaryFile class is an I/O device that operates on temporary files.
static Qt::HANDLE currentThreadId() noexcept Q_DECL_PURE_FUNCTION
The QVariant class acts like a union for the most common Qt data types.
static auto fromValue(const T &value) -> std::enable_if_t< std::is_copy_constructible_v< T >, QVariant >
QMetaType metaType() const
const void * constData() const
backing_store_ptr info
[4]
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
constexpr bool has_operator_equal_v
constexpr bool has_operator_less_than_v
#define Q_DECL_UNUSED_MEMBER
std::pair< T1, T2 > QPair
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
QList< QVariant > QVariantList
QT_BEGIN_NAMESPACE void * qMallocAligned(size_t size, size_t alignment)
void qFreeAligned(void *ptr)
GLint GLfloat GLfloat GLfloat v2
GLenum GLsizei GLsizei GLint * values
[16]
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei GLenum GLenum * types
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLfixed GLfixed GLint GLint order
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
QPointer< T > qPointerFromVariant(const QVariant &variant)
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
QSharedPointer< typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< T * >::Value, T >::type > qSharedPointerFromVariant(const QVariant &variant)
#define QStringLiteral(str)
#define QTEST_MAIN(TestObject)
#define QSKIP(statement,...)
#define QFETCH(Type, name)
#define QVERIFY(statement)
#define QFINDTESTDATA(basepath)
#define QVERIFY2(statement, description)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
QTextStream out(stdout)
[7]
http get(QUrl::toPercentEncoding("/index.html"))
virtual void loadOperator(QDataStream &in)=0
virtual void saveOperator(QDataStream &out) const =0
virtual ~BaseGenericType()
virtual void staticMetacallFunction(QMetaObject::Call _c, int _id, void **_a)=0
virtual void * constructor(int typeId, void *where, const void *copy)=0
bool operator==(const CustomComparable &other) const
CustomComparable(int i_=0)
void saveOperator(QDataStream &out) const override
void * constructor(int typeId, void *where, const void *copy) override
void loadOperator(QDataStream &in) override
QList< QVariant > properties
void staticMetacallFunction(QMetaObject::Call _c, int _id, void **_a) override
void staticMetacallFunction(QMetaObject::Call _c, int _id, void **_a) override
void saveOperator(QDataStream &out) const override
void * constructor(int typeId, void *where, const void *copy) override
void loadOperator(QDataStream &in) override
const QByteArray testData("test")
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent