summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobert Griebl <rgriebl@trolltech.com>2009-06-10 11:46:23 (GMT)
committerRobert Griebl <rgriebl@trolltech.com>2009-06-10 11:46:23 (GMT)
commit7604f8087f88171ef933d8ae08f501467e647338 (patch)
tree51d071f462ed48d0b25884d9f62b8ba11c5dff13 /tests
parent8c265860b41214daade7c8a28237c1e07ea71a3c (diff)
downloadQt-7604f8087f88171ef933d8ae08f501467e647338.zip
Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.gz
Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.bz2
Make Qt exception safer.
Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions, which also contains the full history. Rev-By: Harald Fernengel Rev-By: Ralf Engels
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/collections/tst_collections.cpp6
-rw-r--r--tests/auto/exceptionsafety/tst_exceptionsafety.cpp628
-rw-r--r--tests/auto/network-settings.h42
-rw-r--r--tests/auto/qbitarray/tst_qbitarray.cpp27
-rw-r--r--tests/auto/qeventloop/tst_qeventloop.cpp2
-rw-r--r--tests/auto/qfiledialog/tst_qfiledialog.cpp9
-rw-r--r--tests/auto/qfontdatabase/tst_qfontdatabase.cpp2
-rw-r--r--tests/auto/qglobal/tst_qglobal.cpp62
-rw-r--r--tests/auto/qitemdelegate/tst_qitemdelegate.cpp7
-rw-r--r--tests/auto/qscopedpointer/.gitignore1
-rw-r--r--tests/auto/qscopedpointer/qscopedpointer.pro3
-rw-r--r--tests/auto/qscopedpointer/tst_qscopedpointer.cpp282
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp4
-rw-r--r--tests/auto/qudpsocket/tst_qudpsocket.cpp2
15 files changed, 1047 insertions, 31 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 0092d49..178351b 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -231,6 +231,7 @@ SUBDIRS += _networkselftest \
qprogressbar \
qprogressdialog \
qpushbutton \
+ qscopedpointer \
qqueue \
qradiobutton \
qreadlocker \
diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp
index c05d8da..cbd72dc 100644
--- a/tests/auto/collections/tst_collections.cpp
+++ b/tests/auto/collections/tst_collections.cpp
@@ -1364,6 +1364,9 @@ void tst_Collections::byteArray()
ba1 = "FooFoo";
ba1.replace(char('F'), ba1);
QCOMPARE(ba1, QByteArray("FooFooooFooFoooo"));
+ ba1 = "FooFoo";
+ ba1.replace(char('o'), ba1);
+ QCOMPARE(ba1, QByteArray("FFooFooFooFooFFooFooFooFoo"));
ba1.replace(ba1, "xxx");
QCOMPARE(ba1, QByteArray("xxx"));
@@ -2354,6 +2357,9 @@ void tst_Collections::qstring()
str1 = "FooFoo";
str1.replace(char('F'), str1);
QCOMPARE(str1, QString("FooFooooFooFoooo"));
+ str1 = "FooFoo";
+ str1.replace(char('o'), str1);
+ QCOMPARE(str1, QString("FFooFooFooFooFFooFooFooFoo"));
str1 = "Foo";
str1.replace("Foo", str1);
diff --git a/tests/auto/exceptionsafety/tst_exceptionsafety.cpp b/tests/auto/exceptionsafety/tst_exceptionsafety.cpp
index 9c4f78d..8ed2913 100644
--- a/tests/auto/exceptionsafety/tst_exceptionsafety.cpp
+++ b/tests/auto/exceptionsafety/tst_exceptionsafety.cpp
@@ -52,9 +52,16 @@ class tst_ExceptionSafety: public QObject
Q_OBJECT
private slots:
void exceptionInSlot();
+ void exceptionVector();
+ void exceptionHash();
+ void exceptionMap();
+ void exceptionList();
+ void exceptionLinkedList();
+ void exceptionEventLoop();
+ void exceptionSignalSlot();
};
-class Emitter: public QObject
+class Emitter : public QObject
{
Q_OBJECT
public:
@@ -63,13 +70,111 @@ signals:
void testSignal();
};
-class ExceptionThrower: public QObject
+class ExceptionThrower : public QObject
{
Q_OBJECT
public slots:
void thrower() { throw 5; }
};
+class Receiver : public QObject
+{
+ Q_OBJECT
+public:
+ Receiver()
+ : received(0) {}
+ int received;
+
+public slots:
+ void receiver() { ++received; }
+};
+
+enum ThrowType { ThrowNot = 0, ThrowAtCreate = 1, ThrowAtCopy = 2, ThrowLater = 3, ThrowAtComparison = 4 };
+
+ThrowType throwType = ThrowNot; // global flag to indicate when an exception should be throw. Will be reset when the exception has been generated.
+
+int objCounter = 0;
+
+/*! Class that does not throw any exceptions. Used as baseclass for all the other ones.
+ */
+template <int T>
+class FlexibleThrower
+{
+ public:
+ FlexibleThrower() : _value(-1) {
+ if( throwType == ThrowAtCreate ) {
+ throwType = ThrowNot;
+ throw ThrowAtCreate;
+ }
+ objCounter++;
+ }
+
+ FlexibleThrower( short value ) : _value(value) {
+ if( throwType == ThrowAtCreate ) {
+ throwType = ThrowNot;
+ throw ThrowAtCreate;
+ }
+ objCounter++;
+ }
+
+ FlexibleThrower(FlexibleThrower const& other ) {
+ // qDebug("cc");
+
+ if( throwType == ThrowAtCopy ) {
+ throwType = ThrowNot;
+ throw ThrowAtCopy;
+
+ } else if( throwType == ThrowLater ) {
+ throwType = ThrowAtCopy;
+ }
+
+ objCounter++;
+ _value = other.value();
+ }
+
+ ~FlexibleThrower() { objCounter--; }
+
+ bool operator==(const FlexibleThrower<T> &t) const
+ {
+ // qDebug("vv == %d %d", value(), t.value());
+ if( throwType == ThrowAtComparison ) {
+ throwType = ThrowNot;
+ throw ThrowAtComparison;
+ }
+ return value()==t.value();
+ }
+
+ bool operator<(const FlexibleThrower<T> &t) const
+ {
+ // qDebug("vv < %d %d", value(), t.value());
+ if( throwType == ThrowAtComparison ) {
+ throwType = ThrowNot;
+ throw ThrowAtComparison;
+ }
+ return value()<t.value();
+ }
+
+ int value() const
+ { return (int)_value; }
+
+ short _value;
+ char dummy[T];
+};
+
+uint qHash(const FlexibleThrower<2>& t)
+{
+ // qDebug("ha");
+ if( throwType == ThrowAtComparison ) {
+ throwType = ThrowNot;
+ throw ThrowAtComparison;
+ }
+ return (uint)t.value();
+}
+
+typedef FlexibleThrower<2> FlexibleThrowerSmall;
+typedef QMap<FlexibleThrowerSmall,FlexibleThrowerSmall> MyMap;
+typedef QHash<FlexibleThrowerSmall,FlexibleThrowerSmall> MyHash;
+
// connect a signal to a slot that throws an exception
// run this through valgrind to make sure it doesn't corrupt
void tst_ExceptionSafety::exceptionInSlot()
@@ -86,6 +191,525 @@ void tst_ExceptionSafety::exceptionInSlot()
}
}
+void tst_ExceptionSafety::exceptionList() {
+
+ {
+ QList<FlexibleThrowerSmall> list;
+ QList<FlexibleThrowerSmall> list2;
+ QList<FlexibleThrowerSmall> list3;
+
+ for( int i = 0; i<10; i++ )
+ list.append( FlexibleThrowerSmall(i) );
+
+ try {
+ throwType = ThrowAtCopy;
+ list.append( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( list.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ list.prepend( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( list.at(0).value(), 0 );
+ QCOMPARE( list.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ list.insert( 8, FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( list.at(7).value(), 7 );
+ QCOMPARE( list.at(8).value(), 8 );
+ QCOMPARE( list.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ FlexibleThrowerSmall t = list.takeAt( 6 );
+ } catch (...) {
+ }
+ QCOMPARE( list.at(6).value(), 6 );
+ QCOMPARE( list.at(7).value(), 7 );
+ QCOMPARE( list.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ list3 = list;
+ } catch (...) {
+ }
+ QCOMPARE( list.at(0).value(), 0 );
+ QCOMPARE( list.at(7).value(), 7 );
+ QCOMPARE( list.size(), 10 );
+ QCOMPARE( list3.at(0).value(), 0 );
+ QCOMPARE( list3.at(7).value(), 7 );
+ QCOMPARE( list3.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ list3.append( FlexibleThrowerSmall(11) );
+ } catch (...) {
+ }
+ QCOMPARE( list.at(0).value(), 0 );
+ QCOMPARE( list.at(7).value(), 7 );
+ QCOMPARE( list.size(), 10 );
+ QCOMPARE( list3.at(0).value(), 0 );
+ QCOMPARE( list3.at(7).value(), 7 );
+ QCOMPARE( list3.size(), 10 );
+
+ try {
+ list2.clear();
+ list2.append( FlexibleThrowerSmall(11));
+ throwType = ThrowAtCopy;
+ list3 = list+list2;
+ } catch (...) {
+ }
+ QCOMPARE( list.at(0).value(), 0 );
+ QCOMPARE( list.at(7).value(), 7 );
+ QCOMPARE( list.size(), 10 );
+
+ // check that copy on write works atomar
+ list2.clear();
+ list2.append( FlexibleThrowerSmall(11));
+ list3 = list+list2;
+ try {
+ throwType = ThrowAtCreate;
+ list3[7]=FlexibleThrowerSmall(12);
+ } catch (...) {
+ }
+ QCOMPARE( list.at(7).value(), 7 );
+ QCOMPARE( list.size(), 10 );
+ QCOMPARE( list3.at(7).value(), 7 );
+ QCOMPARE( list3.size(), 11 );
+
+ }
+ QCOMPARE(objCounter, 0 ); // check that every object has been freed
+}
+
+void tst_ExceptionSafety::exceptionLinkedList() {
+
+ {
+ QLinkedList<FlexibleThrowerSmall> list;
+ QLinkedList<FlexibleThrowerSmall> list2;
+ QLinkedList<FlexibleThrowerSmall> list3;
+
+ for( int i = 0; i<10; i++ )
+ list.append( FlexibleThrowerSmall(i) );
+
+ try {
+ throwType = ThrowAtCopy;
+ list.append( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( list.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ list.prepend( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( list.first().value(), 0 );
+ QCOMPARE( list.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ list3 = list;
+ list3.append( FlexibleThrowerSmall(11) );
+ } catch (...) {
+ }
+ QCOMPARE( list.first().value(), 0 );
+ QCOMPARE( list.size(), 10 );
+ QCOMPARE( list3.size(), 10 );
+ }
+ QCOMPARE(objCounter, 0 ); // check that every object has been freed
+}
+
+void tst_ExceptionSafety::exceptionVector() {
+
+ {
+ QVector<FlexibleThrowerSmall> vector;
+ QVector<FlexibleThrowerSmall> vector2;
+ QVector<FlexibleThrowerSmall> vector3;
+
+ for (int i = 0; i<10; i++)
+ vector.append( FlexibleThrowerSmall(i) );
+
+ try {
+ throwType = ThrowAtCopy;
+ vector.append( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( vector.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ vector.prepend( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(0).value(), 0 );
+ QCOMPARE( vector.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ vector.insert( 8, FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.at(8).value(), 8 );
+ QCOMPARE( vector.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ vector3 = vector;
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(0).value(), 0 );
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.size(), 10 );
+ QCOMPARE( vector3.at(0).value(), 0 );
+ QCOMPARE( vector3.at(7).value(), 7 );
+ QCOMPARE( vector3.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ vector3.append( FlexibleThrowerSmall(11) );
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(0).value(), 0 );
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.size(), 10 );
+ QCOMPARE( vector3.at(0).value(), 0 );
+ QCOMPARE( vector3.at(7).value(), 7 );
+
+ try {
+ vector2.clear();
+ vector2.append( FlexibleThrowerSmall(11));
+ throwType = ThrowAtCopy;
+ vector3 = vector+vector2;
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(0).value(), 0 );
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.size(), 10 );
+
+ // check that copy on write works atomar
+ vector2.clear();
+ vector2.append( FlexibleThrowerSmall(11));
+ vector3 = vector+vector2;
+ try {
+ throwType = ThrowAtCreate;
+ vector3[7]=FlexibleThrowerSmall(12);
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.size(), 10 );
+ QCOMPARE( vector3.at(7).value(), 7 );
+ QCOMPARE( vector3.size(), 11 );
+
+ try {
+ throwType = ThrowAtCreate;
+ vector.resize(15);
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.size(), 10 );
+
+ try {
+ throwType = ThrowAtCreate;
+ vector.resize(15);
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(7).value(), 7 );
+ QCOMPARE( vector.size(), 10 );
+
+ try {
+ throwType = ThrowLater;
+ vector.fill(FlexibleThrowerSmall(1), 15);
+ } catch (...) {
+ }
+ QCOMPARE( vector.at(0).value(), 0 );
+ QCOMPARE( vector.size(), 10 );
+
+
+ }
+ QCOMPARE(objCounter, 0 ); // check that every object has been freed
+}
+
+
+void tst_ExceptionSafety::exceptionMap() {
+
+ {
+ MyMap map;
+ MyMap map2;
+ MyMap map3;
+
+ throwType = ThrowNot;
+ for (int i = 0; i<10; i++)
+ map[ FlexibleThrowerSmall(i) ] = FlexibleThrowerSmall(i);
+
+ return; // further test are deactivated until Map is fixed.
+
+ for( int i = ThrowAtCopy; i<=ThrowAtComparison; i++ ) {
+ try {
+ throwType = (ThrowType)i;
+ map[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
+ } catch(...) {
+ }
+ QCOMPARE( map.size(), 10 );
+ QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
+ }
+
+ map2 = map;
+ try {
+ throwType = ThrowLater;
+ map2[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
+ } catch(...) {
+ }
+ /* qDebug("%d %d", map.size(), map2.size() );
+ for( int i=0; i<map.size(); i++ )
+ qDebug( "Value at %d: %d",i, map.value(FlexibleThrowerSmall(i), FlexibleThrowerSmall()).value() );
+ QCOMPARE( map.value(FlexibleThrowerSmall(1), FlexibleThrowerSmall()), FlexibleThrowerSmall(1) );
+ qDebug( "Value at %d: %d",1, map[FlexibleThrowerSmall(1)].value() );
+ qDebug("%d %d", map.size(), map2.size() );
+ */
+ QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
+ QCOMPARE( map.size(), 10 );
+ QCOMPARE( map2[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
+ QCOMPARE( map2.size(), 10 );
+
+ }
+ QCOMPARE(objCounter, 0 ); // check that every object has been freed
+}
+
+void tst_ExceptionSafety::exceptionHash() {
+
+ {
+ MyHash hash;
+ MyHash hash2;
+ MyHash hash3;
+
+ for( int i = 0; i<10; i++ )
+ hash[ FlexibleThrowerSmall(i) ] = FlexibleThrowerSmall(i);
+
+ for( int i = ThrowAtCopy; i<=ThrowAtComparison; i++ ) {
+ try {
+ throwType = (ThrowType)i;
+ hash[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
+ } catch(...) {
+ }
+ QCOMPARE( hash.size(), 10 );
+ }
+
+ hash2 = hash;
+ try {
+ throwType = ThrowLater;
+ hash2[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
+ } catch(...) {
+ }
+ QCOMPARE( hash[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
+ QCOMPARE( hash.size(), 10 );
+ QCOMPARE( hash2[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
+ QCOMPARE( hash2.size(), 10 );
+
+ hash2.clear();
+ try {
+ throwType = ThrowLater;
+ hash2.reserve(30);
+ } catch(...) {
+ }
+ QCOMPARE( hash2.size(), 0 );
+
+ /*
+ try {
+ throwType = ThrowAtCopy;
+ hash.prepend( FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( hash.at(0).value(), 0 );
+ QCOMPARE( hash.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ hash.insert( 8, FlexibleThrowerSmall(10));
+ } catch (...) {
+ }
+ QCOMPARE( hash.at(7).value(), 7 );
+ QCOMPARE( hash.at(8).value(), 8 );
+ QCOMPARE( hash.size(), 10 );
+
+ qDebug("val");
+ try {
+ throwType = ThrowAtCopy;
+ hash3 = hash;
+ } catch (...) {
+ }
+ QCOMPARE( hash.at(0).value(), 0 );
+ QCOMPARE( hash.at(7).value(), 7 );
+ QCOMPARE( hash.size(), 10 );
+ QCOMPARE( hash3.at(0).value(), 0 );
+ QCOMPARE( hash3.at(7).value(), 7 );
+ QCOMPARE( hash3.size(), 10 );
+
+ try {
+ throwType = ThrowAtCopy;
+ hash3.append( FlexibleThrowerSmall(11) );
+ } catch (...) {
+ }
+ QCOMPARE( hash.at(0).value(), 0 );
+ QCOMPARE( hash.at(7).value(), 7 );
+ QCOMPARE( hash.size(), 10 );
+ QCOMPARE( hash3.at(0).value(), 0 );
+ QCOMPARE( hash3.at(7).value(), 7 );
+ QCOMPARE( hash3.at(11).value(), 11 );
+
+ try {
+ hash2.clear();
+ hash2.append( FlexibleThrowerSmall(11));
+ throwType = ThrowAtCopy;
+ hash3 = hash+hash2;
+ } catch (...) {
+ }
+ QCOMPARE( hash.at(0).value(), 0 );
+ QCOMPARE( hash.at(7).value(), 7 );
+ QCOMPARE( hash.size(), 10 );
+
+ // check that copy on write works atomar
+ hash2.clear();
+ hash2.append( FlexibleThrowerSmall(11));
+ hash3 = hash+hash2;
+ try {
+ throwType = ThrowAtCopy;
+ hash3[7]=FlexibleThrowerSmall(12);
+ } catch (...) {
+ }
+ QCOMPARE( hash.at(7).value(), 7 );
+ QCOMPARE( hash.size(), 10 );
+ QCOMPARE( hash3.at(7).value(), 7 );
+ QCOMPARE( hash3.size(), 11 );
+ */
+
+
+ }
+ QCOMPARE(objCounter, 0 ); // check that every object has been freed
+}
+
+enum
+{
+ ThrowEventId = QEvent::User + 42,
+ NoThrowEventId = QEvent::User + 43
+};
+
+class ThrowEvent : public QEvent
+{
+public:
+ ThrowEvent()
+ : QEvent(static_cast<QEvent::Type>(ThrowEventId))
+ {
+ }
+};
+
+class NoThrowEvent : public QEvent
+{
+public:
+ NoThrowEvent()
+ : QEvent(static_cast<QEvent::Type>(NoThrowEventId))
+ {}
+};
+
+class TestObject : public QObject
+{
+public:
+ TestObject()
+ : throwEventCount(0), noThrowEventCount(0) {}
+
+ int throwEventCount;
+ int noThrowEventCount;
+
+protected:
+ bool event(QEvent *event)
+ {
+ if (int(event->type()) == ThrowEventId) {
+ throw ++throwEventCount;
+ } else if (int(event->type()) == NoThrowEventId) {
+ ++noThrowEventCount;
+ }
+ return QObject::event(event);
+ }
+};
+
+void tst_ExceptionSafety::exceptionEventLoop()
+{
+ // send an event that throws
+ TestObject obj;
+ ThrowEvent throwEvent;
+ try {
+ qApp->sendEvent(&obj, &throwEvent);
+ } catch (int code) {
+ QCOMPARE(code, 1);
+ }
+ QCOMPARE(obj.throwEventCount, 1);
+
+ // post an event that throws
+ qApp->postEvent(&obj, new ThrowEvent);
+
+ try {
+ qApp->processEvents();
+ } catch (int code) {
+ QCOMPARE(code, 2);
+ }
+ QCOMPARE(obj.throwEventCount, 2);
+
+ // post a normal event, then a throwing event, then a normal event
+ // run this in valgrind to ensure that it doesn't leak.
+
+ qApp->postEvent(&obj, new NoThrowEvent);
+ qApp->postEvent(&obj, new ThrowEvent);
+ qApp->postEvent(&obj, new NoThrowEvent);
+
+ try {
+ qApp->processEvents();
+ } catch (int code) {
+ QCOMPARE(code, 3);
+ }
+ // here, we should have received on non-throwing event and one throwing one
+ QCOMPARE(obj.throwEventCount, 3);
+ QCOMPARE(obj.noThrowEventCount, 1);
+
+ // spin the event loop again
+ qApp->processEvents();
+
+ // now, we should have received the second non-throwing event
+ QCOMPARE(obj.noThrowEventCount, 2);
+}
+
+void tst_ExceptionSafety::exceptionSignalSlot()
+{
+ Emitter e;
+ ExceptionThrower thrower;
+ Receiver r1;
+ Receiver r2;
+
+ // connect a signal to a normal object, a thrower and a normal object again
+ connect(&e, SIGNAL(testSignal()), &r1, SLOT(receiver()));
+ connect(&e, SIGNAL(testSignal()), &thrower, SLOT(thrower()));
+ connect(&e, SIGNAL(testSignal()), &r2, SLOT(receiver()));
+
+ int code = 0;
+ try {
+ e.emitTestSignal();
+ } catch (int c) {
+ code = c;
+ }
+
+ // 5 is the magic number that's thrown by thrower
+ QCOMPARE(code, 5);
+
+ // assumption: slots are called in the connection order
+ QCOMPARE(r1.received, 1);
+ QCOMPARE(r2.received, 0);
+}
+
QTEST_MAIN(tst_ExceptionSafety)
#include "tst_exceptionsafety.moc"
#endif // QT_NO_EXCEPTIONS
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h
index 22d8886..0924c57 100644
--- a/tests/auto/network-settings.h
+++ b/tests/auto/network-settings.h
@@ -59,27 +59,28 @@
// network tests. WINPCAP connectivity uses Symbian OS IP stack,
// correspondingly as HW does. When using WINPCAP disable this define
//#define SYMBIAN_WINSOCK_CONNECTIVITY
-#endif
- class QtNetworkSettingsRecord {
- public:
- QtNetworkSettingsRecord() { }
+class QtNetworkSettingsRecord {
+public:
+ QtNetworkSettingsRecord() { }
+
+ QtNetworkSettingsRecord(const QString& recName, const QString& recVal)
+ : strRecordName(recName), strRecordValue(recVal) { }
- QtNetworkSettingsRecord(const QString& recName, const QString& recVal)
- : strRecordName(recName), strRecordValue(recVal) { }
+ QtNetworkSettingsRecord(const QtNetworkSettingsRecord & other)
+ : strRecordName(other.strRecordName), strRecordValue(other.strRecordValue) { }
- QtNetworkSettingsRecord(const QtNetworkSettingsRecord & other)
- : strRecordName(other.strRecordName), strRecordValue(other.strRecordValue) { }
+ ~QtNetworkSettingsRecord() { }
- ~QtNetworkSettingsRecord() { }
+ const QString& recordName() const { return strRecordName; }
+ const QString& recordValue() const { return strRecordValue; }
- const QString& recordName() const { return strRecordName; }
- const QString& recordValue() const { return strRecordValue; }
+private:
+ QString strRecordName;
+ QString strRecordValue;
+};
- private:
- QString strRecordName;
- QString strRecordValue;
- };
+#endif
class QtNetworkSettings
{
@@ -171,6 +172,7 @@ public:
static QByteArray expectedReplySSL()
{
+#ifdef Q_OS_SYMBIAN
loadTestSettings();
if(QtNetworkSettings::entries.contains("imap.expectedreplyssl")) {
@@ -180,12 +182,12 @@ public:
imapExpectedReplySsl.append('\r').append('\n');
}
return imapExpectedReplySsl.data();
- } else {
- QByteArray expected( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " );
- expected = expected.append(QtNetworkSettings::serverLocalName().toAscii());
- expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
- return expected;
}
+#endif
+ QByteArray expected( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " );
+ expected = expected.append(QtNetworkSettings::serverLocalName().toAscii());
+ expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
+ return expected;
}
static QByteArray expectedReplyFtp()
diff --git a/tests/auto/qbitarray/tst_qbitarray.cpp b/tests/auto/qbitarray/tst_qbitarray.cpp
index 12fbdc3..244183e 100644
--- a/tests/auto/qbitarray/tst_qbitarray.cpp
+++ b/tests/auto/qbitarray/tst_qbitarray.cpp
@@ -108,6 +108,8 @@ private slots:
void invertOnNull() const;
void operator_noteq_data();
void operator_noteq();
+
+ void resize();
};
Q_DECLARE_METATYPE(QBitArray)
@@ -628,5 +630,30 @@ void tst_QBitArray::operator_noteq()
QCOMPARE(b, res);
}
+void tst_QBitArray::resize()
+{
+ // -- check that a resize handles the bits correctly
+ QBitArray a = QStringToQBitArray(QString("11"));
+ a.resize(10);
+ QVERIFY(a.size() == 10);
+ QCOMPARE( a, QStringToQBitArray(QString("1100000000")) );
+
+ a.setBit(9);
+ a.resize(9);
+ // now the bit in a should have been gone:
+ QCOMPARE( a, QStringToQBitArray(QString("110000000")) );
+
+ // grow the array back and check the new bit
+ a.resize(10);
+ QCOMPARE( a, QStringToQBitArray(QString("1100000000")) );
+
+ // other test with and
+ a.resize(9);
+ QBitArray b = QStringToQBitArray(QString("1111111111"));
+ b &= a;
+ QCOMPARE( b, QStringToQBitArray(QString("1100000000")) );
+
+}
+
QTEST_APPLESS_MAIN(tst_QBitArray)
#include "tst_qbitarray.moc"
diff --git a/tests/auto/qeventloop/tst_qeventloop.cpp b/tests/auto/qeventloop/tst_qeventloop.cpp
index a4017b8..ed95402 100644
--- a/tests/auto/qeventloop/tst_qeventloop.cpp
+++ b/tests/auto/qeventloop/tst_qeventloop.cpp
@@ -243,8 +243,10 @@ public slots:
// Let all the events occur twice so we know they reactivated after
// each occurrence.
if (++timerCount >= 2) {
+#ifdef Q_OS_SYMBIAN
// This will hopefully run last, so stop the active scheduler.
CActiveScheduler::Stop();
+#endif
}
}
void zeroTimerSlot()
diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp
index b4fd0c5..5f0776f 100644
--- a/tests/auto/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp
@@ -465,10 +465,11 @@ void tst_QFiledialog::completer()
if (!tmp.exists(tempPath))
QVERIFY(tmp.mkdir("QFileDialogTestDir"));
QList<QTemporaryFile*> files;
+ QT_TRY {
for (int i = 0; i < 10; ++i) {
- QTemporaryFile *file = new QTemporaryFile(tempPath + "/rXXXXXX");
+ QScopedPointer<QTemporaryFile> file(new QTemporaryFile(tempPath + "/rXXXXXX"));
file->open();
- files.append(file);
+ files.append(file.take());
}
// ### flesh this out more
@@ -559,6 +560,10 @@ void tst_QFiledialog::completer()
// ### FIXME: This will fail on Symbian on some tests and some environments until the file engine and QFileSystemModel
// are fixed to properly capitalize paths, so that some folders are not duplicated in QFileSystemModel.
QTRY_COMPARE(cModel->rowCount(), expected);
+ } QT_CATCH(...) {
+ qDeleteAll(files);
+ QT_RETHROW;
+ }
qDeleteAll(files);
}
diff --git a/tests/auto/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/qfontdatabase/tst_qfontdatabase.cpp
index a006462..cb5790d 100644
--- a/tests/auto/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/qfontdatabase/tst_qfontdatabase.cpp
@@ -242,7 +242,7 @@ void tst_QFontDatabase::addAppFont()
QVERIFY(QFontDatabase::removeApplicationFont(id));
QCOMPARE(fontDbChangedSpy.count(), 2);
- QVERIFY(db.families() == oldFamilies);¨
+ QVERIFY(db.families() == oldFamilies);
#endif
}
diff --git a/tests/auto/qglobal/tst_qglobal.cpp b/tests/auto/qglobal/tst_qglobal.cpp
index 88fbcd2..b4d42e4 100644
--- a/tests/auto/qglobal/tst_qglobal.cpp
+++ b/tests/auto/qglobal/tst_qglobal.cpp
@@ -50,6 +50,7 @@ private slots:
void qInternalCallbacks();
void for_each();
void qassert();
+ void qtry();
};
void tst_QGlobal::qIsNull()
@@ -190,5 +191,66 @@ void tst_QGlobal::qassert()
QVERIFY(passed);
}
+void tst_QGlobal::qtry()
+{
+ int i = 0;
+ QT_TRY {
+ i = 1;
+ QT_THROW(42);
+ i = 2;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 1);
+ i = 7;
+ }
+#ifdef QT_NO_EXCEPTIONS
+ QCOMPARE(i, 2);
+#else
+ QCOMPARE(i, 7);
+#endif
+
+ // check propper if/else scoping
+ i = 0;
+ if (true)
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 4;
+ }
+ else
+ QCOMPARE(i, 0);
+ QCOMPARE(i, 4);
+
+ i = 0;
+ if (false)
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 2;
+ }
+ else
+ i = 8;
+ QCOMPARE(i, 8);
+
+ i = 0;
+ if (false)
+ i = 42;
+ else
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 4;
+ }
+ QCOMPARE(i, 4);
+}
+
QTEST_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"
diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
index 615ac01..955760a 100644
--- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
@@ -1115,13 +1115,16 @@ void tst_QItemDelegate::enterKey()
QList<QWidget*> lineEditors = qFindChildren<QWidget *>(view.viewport(), QString::fromLatin1("TheEditor"));
QCOMPARE(lineEditors.count(), 1);
- QWidget *editor = lineEditors.at(0);
+ QPointer<QWidget> editor = lineEditors.at(0);
QCOMPARE(editor->hasFocus(), true);
QTest::keyClick(editor, Qt::Key(key));
QApplication::processEvents();
- QCOMPARE(editor->hasFocus(), expectedFocus);
+ if (widget == 2 || widget == 3) {
+ QVERIFY(!editor.isNull());
+ QCOMPARE(editor->hasFocus(), expectedFocus);
+ }
}
diff --git a/tests/auto/qscopedpointer/.gitignore b/tests/auto/qscopedpointer/.gitignore
new file mode 100644
index 0000000..9f2324c
--- /dev/null
+++ b/tests/auto/qscopedpointer/.gitignore
@@ -0,0 +1 @@
+tst_qscopedpointer
diff --git a/tests/auto/qscopedpointer/qscopedpointer.pro b/tests/auto/qscopedpointer/qscopedpointer.pro
new file mode 100644
index 0000000..13d8425
--- /dev/null
+++ b/tests/auto/qscopedpointer/qscopedpointer.pro
@@ -0,0 +1,3 @@
+load(qttest_p4)
+SOURCES += tst_qscopedpointer.cpp
+QT -= gui
diff --git a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp
new file mode 100644
index 0000000..0e005c3
--- /dev/null
+++ b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp
@@ -0,0 +1,282 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/QScopedPointer>
+
+/*!
+ \class tst_QScopedPointer
+ \internal
+ \since 4.6
+ \brief Tests class QScopedPointer.
+
+ */
+class tst_QScopedPointer : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void defaultConstructor() const;
+ void dataOnDefaultConstructed() const;
+ void useSubClassInConstructor() const;
+ void dataOnValue() const;
+ void dataSignature() const;
+ void reset() const;
+ void dereferenceOperator() const;
+ void dereferenceOperatorSignature() const;
+ void pointerOperator() const;
+ void pointerOperatorSignature() const;
+ void negationOperator() const;
+ void negationOperatorSignature() const;
+ void operatorBool() const;
+ void operatorBoolSignature() const;
+ void isNull() const;
+ void isNullSignature() const;
+ void objectSize() const;
+ // TODO instansiate on const object
+};
+
+void tst_QScopedPointer::defaultConstructor() const
+{
+ /* Check that the members, one, is correctly initialized. */
+ QScopedPointer<int> p;
+ QCOMPARE(p.data(), static_cast<int *>(0));
+}
+
+void tst_QScopedPointer::dataOnDefaultConstructed() const
+{
+ QScopedPointer<int> p;
+
+ QCOMPARE(p.data(), static_cast<int *>(0));
+}
+
+class MyClass
+{
+};
+
+class MySubClass : public MyClass
+{
+};
+
+void tst_QScopedPointer::useSubClassInConstructor() const
+{
+ /* Use a syntax which users typically would do. */
+ QScopedPointer<MyClass> p(new MyClass());
+}
+
+void tst_QScopedPointer::dataOnValue() const
+{
+ int *const rawPointer = new int(5);
+ QScopedPointer<int> p(rawPointer);
+
+ QCOMPARE(p.data(), rawPointer);
+}
+
+void tst_QScopedPointer::dataSignature() const
+{
+ const QScopedPointer<int> p;
+ /* data() should be const. */
+ p.data();
+}
+
+void tst_QScopedPointer::reset() const
+{
+ /* Call reset() on a default constructed value. */
+ {
+ QScopedPointer<int> p;
+ p.reset();
+ QCOMPARE(p.data(), static_cast<int *>(0));
+ }
+
+ /* Call reset() on an active value. */
+ {
+ QScopedPointer<int> p(new int(3));
+ p.reset();
+ QCOMPARE(p.data(), static_cast<int *>(0));
+ }
+
+ /* Call reset() with a value, on an active value. */
+ {
+ QScopedPointer<int> p(new int(3));
+
+ int *const value = new int(9);
+ p.reset(value);
+ QCOMPARE(*p.data(), 9);
+ }
+
+ /* Call reset() with a value, on default constructed value. */
+ {
+ QScopedPointer<int> p;
+
+ int *const value = new int(9);
+ p.reset(value);
+ QCOMPARE(*p.data(), 9);
+ }
+}
+
+class AbstractClass
+{
+public:
+ virtual ~AbstractClass()
+ {
+ }
+
+ virtual int member() const = 0;
+};
+
+class SubClass : public AbstractClass
+{
+public:
+ virtual int member() const
+ {
+ return 5;
+ }
+};
+
+void tst_QScopedPointer::dereferenceOperator() const
+{
+ /* Dereference a basic value. */
+ {
+ QScopedPointer<int> p(new int(5));
+
+ const int value2 = *p;
+ QCOMPARE(value2, 5);
+ }
+
+ /* Dereference a pointer to an abstract class. This verifies
+ * that the operator returns a reference, when compiling
+ * with MSVC 2005. */
+ {
+ QScopedPointer<AbstractClass> p(new SubClass());
+
+ QCOMPARE((*p).member(), 5);
+ }
+}
+
+void tst_QScopedPointer::dereferenceOperatorSignature() const
+{
+ /* The operator should be const. */
+ {
+ const QScopedPointer<int> p(new int(5));
+ *p;
+ }
+
+ /* A reference should be returned, not a value. */
+ {
+ const QScopedPointer<int> p(new int(5));
+ Q_UNUSED(static_cast<int &>(*p));
+ }
+
+ /* Instantiated on a const object, the returned object is a const reference. */
+ {
+ const QScopedPointer<const int> p(new int(5));
+ Q_UNUSED(static_cast<const int &>(*p));
+ }
+}
+
+class AnyForm
+{
+public:
+ int value;
+};
+
+void tst_QScopedPointer::pointerOperator() const
+{
+ QScopedPointer<AnyForm> p(new AnyForm());
+ p->value = 5;
+
+ QCOMPARE(p->value, 5);
+}
+
+void tst_QScopedPointer::pointerOperatorSignature() const
+{
+ /* The operator should be const. */
+ const QScopedPointer<AnyForm> p(new AnyForm);
+ p->value = 5;
+
+ QVERIFY(p->value);
+}
+
+void tst_QScopedPointer::negationOperator() const
+{
+ /* Invoke on default constructed value. */
+ {
+ QScopedPointer<int> p;
+ QVERIFY(!p);
+ }
+
+ /* Invoke on a value. */
+ {
+ QScopedPointer<int> p(new int(2));
+ QCOMPARE(!p, false);
+ }
+}
+
+void tst_QScopedPointer::negationOperatorSignature() const
+{
+ /* The signature should be const. */
+ const QScopedPointer<int> p;
+ !p;
+
+ /* The return value should be bool. */
+ static_cast<bool>(!p);
+}
+
+void tst_QScopedPointer::operatorBool() const
+{
+ /* Invoke on default constructed value. */
+ {
+ QScopedPointer<int> p;
+ QCOMPARE(bool(p), false);
+ }
+
+ /* Invoke on active value. */
+ {
+ QScopedPointer<int> p(new int(3));
+ QVERIFY(p);
+ }
+}
+
+void tst_QScopedPointer::operatorBoolSignature() const
+{
+ /* The signature should be const and return bool. */
+ const QScopedPointer<int> p;
+
+ static_cast<bool>(p);
+}
+
+void tst_QScopedPointer::isNull() const
+{
+ /* Invoke on default constructed value. */
+ {
+ QScopedPointer<int> p;
+ QVERIFY(p.isNull());
+ }
+
+ /* Invoke on a set value. */
+ {
+ QScopedPointer<int> p(new int(69));
+ QVERIFY(!p.isNull());
+ }
+}
+
+void tst_QScopedPointer::isNullSignature() const
+{
+ const QScopedPointer<int> p(new int(69));
+
+ /* The signature should be const and return bool. */
+ static_cast<bool>(p.isNull());
+}
+
+void tst_QScopedPointer::objectSize() const
+{
+ /* The size of QScopedPointer should be the same as one pointer. */
+ QCOMPARE(sizeof(QScopedPointer<int>), sizeof(void *));
+}
+
+QTEST_MAIN(tst_QScopedPointer)
+#include "tst_qscopedpointer.moc"
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index f2ea2d9..cf16abb 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -81,10 +81,8 @@
#ifndef TEST_QNETWORK_PROXY
//#define TEST_QNETWORK_PROXY
#endif
-#if defined(TEST_QNETWORK_PROXY) || defined (Q_CC_RVCT)
// RVCT compiles also unused inline methods
# include <QNetworkProxy>
-#endif
#ifdef Q_OS_LINUX
#include <stdio.h>
@@ -1185,7 +1183,7 @@ void tst_QTcpSocket::readLine()
char buffer[1024];
int expectedReplySize = QtNetworkSettings::expectedReplyIMAP().size();
- ASSERT(expectedReplySize >= 3);
+ Q_ASSERT(expectedReplySize >= 3);
QCOMPARE(socket->readLine(buffer, sizeof(buffer)), qint64(expectedReplySize));
QCOMPARE((int) buffer[expectedReplySize-2], (int) '\r');
diff --git a/tests/auto/qudpsocket/tst_qudpsocket.cpp b/tests/auto/qudpsocket/tst_qudpsocket.cpp
index 621acbb..e9bf51b 100644
--- a/tests/auto/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/qudpsocket/tst_qudpsocket.cpp
@@ -853,4 +853,4 @@ void tst_QUdpSocket::zeroLengthDatagram()
}
QTEST_MAIN(tst_QUdpSocket)
-#include "test/tmp/tst_qudpsocket.moc"
+#include "tst_qudpsocket.moc"