summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-03-02 11:03:12 +0100
committerOlivier Goffart <ogoffart@trolltech.com>2010-03-02 14:22:45 +0100
commit03daf059647c0a0222e8774b0a083f58c8e64934 (patch)
tree62f7bda5a497c508d98598a4ae4ef8d2fd0157c9 /tests/auto
parenta140e37fab6a1d028fd1b751a98774dacb4f1a89 (diff)
QMetaType: Now we can register typedefs.
Task-number: QTBUG-6833 Task-number: QTBUG-937 Reviewed-by: Brad Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qmetaobject/tst_qmetaobject.cpp20
-rw-r--r--tests/auto/qmetatype/tst_qmetatype.cpp14
-rw-r--r--tests/auto/qobject/tst_qobject.cpp16
3 files changed, 48 insertions, 2 deletions
diff --git a/tests/auto/qmetaobject/tst_qmetaobject.cpp b/tests/auto/qmetaobject/tst_qmetaobject.cpp
index bd54975243..bb4a0d2dd3 100644
--- a/tests/auto/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/qmetaobject/tst_qmetaobject.cpp
@@ -157,6 +157,7 @@ private slots:
void invokeQueuedMetaMember();
void invokeCustomTypes();
void invokeMetaConstructor();
+ void invokeTypedefTypes();
void qtMetaObjectInheritance();
void normalizedSignature_data();
void normalizedSignature();
@@ -598,6 +599,8 @@ struct MyType
int i1, i2, i3;
};
+typedef QString CustomString;
+
class QtTestCustomObject: public QObject
{
Q_OBJECT
@@ -607,6 +610,9 @@ public:
public slots:
void sl1(MyType myType);
+signals:
+ void sig_custom(const CustomString &string);
+
public:
int sum;
};
@@ -664,6 +670,20 @@ void tst_QMetaObject::invokeMetaConstructor()
}
}
+void tst_QMetaObject::invokeTypedefTypes()
+{
+ qRegisterMetaType<CustomString>("CustomString");
+ QtTestCustomObject obj;
+ QSignalSpy spy(&obj, SIGNAL(sig_custom(CustomString)));
+
+ QCOMPARE(spy.count(), 0);
+ CustomString arg("hello");
+ QVERIFY(QMetaObject::invokeMethod(&obj, "sig_custom", Q_ARG(CustomString, arg)));
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.at(0).count(), 1);
+ QCOMPARE(spy.at(0).at(0), QVariant(arg));
+}
+
void tst_QMetaObject::normalizedSignature_data()
{
QTest::addColumn<QString>("signature");
diff --git a/tests/auto/qmetatype/tst_qmetatype.cpp b/tests/auto/qmetatype/tst_qmetatype.cpp
index 943b05b3ca..f4e122f3c4 100644
--- a/tests/auto/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/qmetatype/tst_qmetatype.cpp
@@ -241,6 +241,9 @@ void tst_QMetaType::construct()
QMetaType::destroy(QMetaType::QSize, size);
}
+typedef QString CustomString;
+Q_DECLARE_METATYPE(CustomString) //this line is useless
+
void tst_QMetaType::typedefs()
{
QCOMPARE(QMetaType::type("long long"), int(QMetaType::LongLong));
@@ -256,6 +259,13 @@ void tst_QMetaType::typedefs()
// make sure the qreal typeId is the type id of the type it's defined to
QCOMPARE(QMetaType::type("qreal"), ::qMetaTypeId<qreal>());
+
+ qRegisterMetaType<CustomString>("CustomString");
+ QCOMPARE(QMetaType::type("CustomString"), ::qMetaTypeId<CustomString>());
+
+ typedef Whity<double> WhityDouble;
+ qRegisterMetaType<WhityDouble>("WhityDouble");
+ QCOMPARE(QMetaType::type("WhityDouble"), ::qMetaTypeId<WhityDouble>());
}
class IsRegisteredDummyType { };
@@ -286,9 +296,9 @@ void tst_QMetaType::isRegistered()
QCOMPARE(QMetaType::isRegistered(typeId), registered);
}
-class RegUnreg
+class RegUnreg
{
-public:
+public:
RegUnreg() {};
RegUnreg(const RegUnreg &) {};
~RegUnreg() {};
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index 3896d702cb..c8f846ed96 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -1112,6 +1112,8 @@ void tst_QObject::streamCustomTypes()
QCOMPARE(instanceCount, 0);
}
+typedef QString CustomString;
+
class PropertyObject : public QObject
{
Q_OBJECT
@@ -1125,6 +1127,7 @@ class PropertyObject : public QObject
Q_PROPERTY(CustomType* custom READ custom WRITE setCustom)
Q_PROPERTY(float myFloat READ myFloat WRITE setMyFloat)
Q_PROPERTY(qreal myQReal READ myQReal WRITE setMyQReal)
+ Q_PROPERTY(CustomString customString READ customString WRITE setCustomString )
public:
enum Alpha {
@@ -1163,6 +1166,9 @@ public:
void setMyQReal(qreal value) { m_qreal = value; }
qreal myQReal() const { return m_qreal; }
+ CustomString customString() const { return m_customString; }
+ void setCustomString(const QString &string) { m_customString = string; }
+
private:
Alpha m_alpha;
Priority m_priority;
@@ -1172,6 +1178,7 @@ private:
CustomType *m_custom;
float m_float;
qreal m_qreal;
+ CustomString m_customString;
};
Q_DECLARE_METATYPE(PropertyObject::Priority)
@@ -1626,6 +1633,15 @@ void tst_QObject::property()
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::Low);
object.setProperty("priority", var);
QCOMPARE(qVariantValue<PropertyObject::Priority>(object.property("priority")), PropertyObject::High);
+
+ qRegisterMetaType<CustomString>("CustomString");
+ QVERIFY(mo->indexOfProperty("customString") != -1);
+ QCOMPARE(object.property("customString").toString(), QString());
+ object.setCustomString("String1");
+ QCOMPARE(object.property("customString"), QVariant("String1"));
+ QVERIFY(object.setProperty("customString", "String2"));
+ QCOMPARE(object.property("customString"), QVariant("String2"));
+ QVERIFY(!object.setProperty("customString", QVariant()));
}
void tst_QObject::metamethod()