summaryrefslogtreecommitdiffstats
path: root/tests/auto/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-06-25 13:49:53 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-06-25 13:49:53 (GMT)
commitdb8f05e257019694f5e8076845626008f2adc3dd (patch)
tree05d3959403cf15ac5f702091439e028af01f343b /tests/auto/qobject/tst_qobject.cpp
parent8aafaa65a1d16f8b982279f5aceedf1e281ddb5a (diff)
parent796a5a2c7d8c91a46ac761dde18b7da2ec6c177b (diff)
downloadQt-db8f05e257019694f5e8076845626008f2adc3dd.zip
Qt-db8f05e257019694f5e8076845626008f2adc3dd.tar.gz
Qt-db8f05e257019694f5e8076845626008f2adc3dd.tar.bz2
Merge commit 'qt/master-stable' into 4.6-stable
Bring Qt 4.6 into the Qt-S60 repo. Conflicts: configure.exe mkspecs/features/qttest_p4.prf qmake/generators/makefile.cpp src/corelib/io/qdir.cpp src/corelib/io/qprocess.h src/corelib/kernel/qcoreevent.h src/corelib/kernel/qobject.cpp src/corelib/kernel/qsharedmemory_unix.cpp src/corelib/thread/qthread_p.h src/corelib/tools/qvector.h src/gui/dialogs/qdialog.cpp src/gui/dialogs/qfiledialog.cpp src/gui/dialogs/qfiledialog_p.h src/gui/dialogs/qmessagebox.cpp src/gui/graphicsview/qgraphicsitem.cpp src/gui/graphicsview/qgraphicsview.cpp src/gui/image/qpixmapcache.cpp src/gui/kernel/qapplication.cpp src/gui/kernel/qapplication_p.h src/gui/kernel/qwidget.cpp src/gui/kernel/qwidget_p.h src/gui/painting/qdrawhelper.cpp src/gui/painting/qpaintengine_raster.cpp src/gui/text/qfontengine_qpf.cpp src/gui/widgets/qmenubar.cpp src/network/socket/qlocalserver.cpp src/testlib/qtestcase.cpp src/testlib/testlib.pro tests/auto/qimagereader/tst_qimagereader.cpp tests/auto/qitemdelegate/tst_qitemdelegate.cpp tests/auto/qnetworkreply/tst_qnetworkreply.cpp tests/auto/qpixmap/qpixmap.pro
Diffstat (limited to 'tests/auto/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/qobject/tst_qobject.cpp108
1 files changed, 104 insertions, 4 deletions
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index ada4fcb..b7bc732 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -106,6 +106,7 @@ private slots:
void childDeletesItsSibling();
void dynamicProperties();
void floatProperty();
+ void qrealProperty();
void property();
void recursiveSignalEmission();
void blockingQueuedConnection();
@@ -116,6 +117,7 @@ private slots:
void dumpObjectInfo();
void connectToSender();
void qobjectConstCast();
+ void uniqConnection();
protected:
};
@@ -204,12 +206,20 @@ public:
sequence_slot3 = 0;
sequence_slot2 = 0;
sequence_slot1 = 0;
+ count_slot1 = 0;
+ count_slot2 = 0;
+ count_slot3 = 0;
+ count_slot4 = 0;
}
int sequence_slot1;
int sequence_slot2;
int sequence_slot3;
int sequence_slot4;
+ int count_slot1;
+ int count_slot2;
+ int count_slot3;
+ int count_slot4;
bool called(int slot) {
switch (slot) {
@@ -224,10 +234,10 @@ public:
static int sequence;
public slots:
- void slot1() { sequence_slot1 = ++sequence; }
- void slot2() { sequence_slot2 = ++sequence; }
- void slot3() { sequence_slot3 = ++sequence; }
- void slot4() { sequence_slot4 = ++sequence; }
+ void slot1() { sequence_slot1 = ++sequence; count_slot1++; }
+ void slot2() { sequence_slot2 = ++sequence; count_slot2++; }
+ void slot3() { sequence_slot3 = ++sequence; count_slot3++; }
+ void slot4() { sequence_slot4 = ++sequence; count_slot4++; }
};
@@ -1104,6 +1114,7 @@ class PropertyObject : public QObject
Q_PROPERTY(QVariant variant READ variant WRITE setVariant)
Q_PROPERTY(CustomType* custom READ custom WRITE setCustom)
Q_PROPERTY(float myFloat READ myFloat WRITE setMyFloat)
+ Q_PROPERTY(qreal myQReal READ myQReal WRITE setMyQReal)
public:
enum Alpha {
@@ -1139,6 +1150,9 @@ public:
void setMyFloat(float value) { m_float = value; }
inline float myFloat() const { return m_float; }
+ void setMyQReal(qreal value) { m_qreal = value; }
+ qreal myQReal() const { return m_qreal; }
+
private:
Alpha m_alpha;
Priority m_priority;
@@ -1147,6 +1161,7 @@ private:
QVariant m_variant;
CustomType *m_custom;
float m_float;
+ qreal m_qreal;
};
Q_DECLARE_METATYPE(PropertyObject::Priority)
@@ -2349,6 +2364,27 @@ void tst_QObject::floatProperty()
QVERIFY(qVariantValue<float>(v) == 128.0f);
}
+void tst_QObject::qrealProperty()
+{
+ PropertyObject obj;
+ const int idx = obj.metaObject()->indexOfProperty("myQReal");
+ QVERIFY(idx > 0);
+ QMetaProperty prop = obj.metaObject()->property(idx);
+ QVERIFY(prop.isValid());
+ QVERIFY(prop.type() == uint(QMetaType::type("qreal")));
+ QVERIFY(!prop.write(&obj, QVariant("Hello")));
+
+ QVERIFY(prop.write(&obj, qVariantFromValue(128.0f)));
+ QVariant v = prop.read(&obj);
+ QCOMPARE(v.userType(), qMetaTypeId<qreal>());
+ QVERIFY(qVariantValue<qreal>(v) == 128.0);
+
+ QVERIFY(prop.write(&obj, qVariantFromValue(double(127))));
+ v = prop.read(&obj);
+ QCOMPARE(v.userType(), qMetaTypeId<qreal>());
+ QVERIFY(qVariantValue<qreal>(v) == 127.0);
+}
+
class DynamicPropertyObject : public PropertyObject
{
public:
@@ -2796,5 +2832,69 @@ void tst_QObject::qobjectConstCast()
QVERIFY(qobject_cast<const FooObject *>(cptr));
}
+void tst_QObject::uniqConnection()
+{
+ SenderObject *s = new SenderObject;
+ ReceiverObject *r1 = new ReceiverObject;
+ ReceiverObject *r2 = new ReceiverObject;
+ r1->reset();
+ r2->reset();
+ ReceiverObject::sequence = 0;
+
+ QVERIFY( connect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal1() ), r2, SLOT( slot1() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal1() ), r1, SLOT( slot3() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal3() ), r1, SLOT( slot3() ) , Qt::UniqueConnection) );
+
+ s->emitSignal1();
+ s->emitSignal2();
+ s->emitSignal3();
+ s->emitSignal4();
+
+ QCOMPARE( r1->count_slot1, 1 );
+ QCOMPARE( r1->count_slot2, 0 );
+ QCOMPARE( r1->count_slot3, 2 );
+ QCOMPARE( r1->count_slot4, 0 );
+ QCOMPARE( r2->count_slot1, 1 );
+ QCOMPARE( r2->count_slot2, 0 );
+ QCOMPARE( r2->count_slot3, 0 );
+ QCOMPARE( r2->count_slot4, 0 );
+ QCOMPARE( r1->sequence_slot1, 1 );
+ QCOMPARE( r2->sequence_slot1, 2 );
+ QCOMPARE( r1->sequence_slot3, 4 );
+
+ r1->reset();
+ r2->reset();
+ ReceiverObject::sequence = 0;
+
+ QVERIFY( connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal4() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY(!connect( s, SIGNAL( signal4() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal1() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY(!connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) , Qt::UniqueConnection) );
+
+ s->emitSignal4();
+ QCOMPARE( r1->count_slot4, 1 );
+ QCOMPARE( r2->count_slot4, 1 );
+ QCOMPARE( r1->sequence_slot4, 1 );
+ QCOMPARE( r2->sequence_slot4, 2 );
+
+ r1->reset();
+ r2->reset();
+ ReceiverObject::sequence = 0;
+
+ connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) );
+
+ s->emitSignal4();
+ QCOMPARE( r1->count_slot4, 2 );
+ QCOMPARE( r2->count_slot4, 1 );
+ QCOMPARE( r1->sequence_slot4, 3 );
+ QCOMPARE( r2->sequence_slot4, 2 );
+
+ delete s;
+ delete r1;
+ delete r2;
+}
+
QTEST_MAIN(tst_QObject)
#include "tst_qobject.moc"