diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-07-28 10:58:46 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-07-28 11:45:59 (GMT) |
commit | 7eba68adc4a7862d9474179592e5c8393a7acdbb (patch) | |
tree | 73014cabc8b10f46203844aeb40de574d97032dc /tests/auto/qsharedpointer | |
parent | a20f8dcbeafa34b50ef69d1c5db0f17b09731d2a (diff) | |
parent | 3bf3981c7026de9017887d08312391b54fe8afc6 (diff) | |
download | Qt-7eba68adc4a7862d9474179592e5c8393a7acdbb.zip Qt-7eba68adc4a7862d9474179592e5c8393a7acdbb.tar.gz Qt-7eba68adc4a7862d9474179592e5c8393a7acdbb.tar.bz2 |
Merge commit 'qt/master-stable'
Conflicts:
configure.exe
src/corelib/io/io.pri
src/corelib/io/qfilesystemwatcher.cpp
tests/auto/qfileinfo/tst_qfileinfo.cpp
tools/configure/configureapp.cpp
Diffstat (limited to 'tests/auto/qsharedpointer')
-rw-r--r-- | tests/auto/qsharedpointer/externaltests.cpp | 88 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/tst_qsharedpointer.cpp | 102 |
2 files changed, 176 insertions, 14 deletions
diff --git a/tests/auto/qsharedpointer/externaltests.cpp b/tests/auto/qsharedpointer/externaltests.cpp index 92682a5..6153c76 100644 --- a/tests/auto/qsharedpointer/externaltests.cpp +++ b/tests/auto/qsharedpointer/externaltests.cpp @@ -59,6 +59,11 @@ # error DEFAULT_MAKESPEC not defined #endif +#ifdef Q_OS_UNIX +# include <fcntl.h> +# include <unistd.h> +#endif + static QString makespec() { static const char default_makespec[] = DEFAULT_MAKESPEC; @@ -108,6 +113,27 @@ static bool removeRecursive(const QString &pathname) QT_BEGIN_NAMESPACE namespace QTest { + class QExternalProcess: public QProcess + { + protected: +#ifdef Q_OS_UNIX + void setupChildProcess() + { + // run in user code + QProcess::setupChildProcess(); + + if (processChannelMode() == ForwardedChannels) { + // reopen /dev/tty into stdin + int fd = ::open("/dev/tty", O_RDONLY); + if (fd == -1) + return; + ::dup2(fd, 0); + ::close(fd); + } + } +#endif + }; + class QExternalTestPrivate { public: @@ -338,6 +364,8 @@ namespace QTest { sourceCode.clear(); sourceCode.reserve(8192); + sourceCode += programHeader; + // Add Qt header includes if (qtModules & QExternalTest::QtCore) sourceCode += "#include <QtCore/QtCore>\n"; @@ -371,17 +399,11 @@ namespace QTest { "#include <stdlib.h>\n" "#include <stddef.h>\n"; - sourceCode += programHeader; - sourceCode += "\n" "void q_external_test_user_code()\n" "{\n" - " // HERE STARTS THE USER CODE\n"; - sourceCode += body; - sourceCode += - "\n" - " // HERE ENDS THE USER CODE\n" + "#include \"user_code.cpp\"\n" "}\n" "\n" "#ifdef Q_OS_WIN\n" @@ -446,6 +468,15 @@ namespace QTest { } sourceFile.write(sourceCode); + sourceFile.close(); + + sourceFile.setFileName(temporaryDir + QLatin1String("/user_code.cpp")); + if (!sourceFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { + std_err = sourceFile.errorString().toLocal8Bit(); + return false; + } + sourceFile.write(body); + return true; } @@ -556,6 +587,24 @@ namespace QTest { "embedded:test_run.commands += -qws\n" "QMAKE_EXTRA_TARGETS += test_run\n"); + // Use qmake to debug: + projectFile.write( + "\n" + "*-g++* {\n" + " unix:test_debug.commands = gdb --args ./$(QMAKE_TARGET)\n" + " else:test_debug.commands = gdb --args $(QMAKE_TARGET)\n" + " embedded:test_debug.commands += -qws\n" + " QMAKE_EXTRA_TARGETS += test_debug\n" + "}\n"); + + // Also use qmake to run the app with valgrind: + projectFile.write( + "\n" + "unix:test_valgrind.commands = valgrind ./$(QMAKE_TARGET)\n" + "else:test_valgrind.commands = valgrind $(QMAKE_TARGET)\n" + "embedded:test_valgrind.commands += -qws\n" + "QMAKE_EXTRA_TARGETS += test_valgrind\n"); + return true; } @@ -597,7 +646,7 @@ namespace QTest { { Q_ASSERT(!temporaryDir.isEmpty()); - QProcess make; + QExternalProcess make; make.setWorkingDirectory(temporaryDir); QStringList environment = QProcess::systemEnvironment(); @@ -605,10 +654,22 @@ namespace QTest { make.setEnvironment(environment); QStringList args; - if (target == Compile) + QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels; + if (target == Compile) { args << QLatin1String("test_compile"); - else if (target == Run) - args << QLatin1String("test_run"); + } else if (target == Run) { + QByteArray run = qgetenv("QTEST_EXTERNAL_RUN"); + if (run == "valgrind") + args << QLatin1String("test_valgrind"); + else if (run == "debug") + args << QLatin1String("test_debug"); + else + args << QLatin1String("test_run"); + if (!run.isEmpty()) + channelMode = QProcess::ForwardedChannels; + } + + make.setProcessChannelMode(channelMode); #if defined(Q_OS_WIN) && !defined(Q_CC_MINGW) make.start(QLatin1String("nmake.exe"), args); @@ -634,7 +695,10 @@ namespace QTest { return false; } - bool ok = make.waitForFinished(); + make.closeWriteChannel(); + bool ok = make.waitForFinished(channelMode == QProcess::ForwardedChannels ? -1 : 60000); + if (!ok) + make.terminate(); exitCode = make.exitCode(); std_out += make.readAllStandardOutput(); std_err += make.readAllStandardError(); diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp index 1c98eb3..4991549 100644 --- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp @@ -69,8 +69,9 @@ private slots: void dynamicCastVirtualBase(); void dynamicCastFailure(); #endif - void customDeleter(); void constCorrectness(); + void customDeleter(); + void creating(); void validConstructs(); void invalidConstructs_data(); void invalidConstructs(); @@ -108,6 +109,8 @@ public: { delete this; } + + virtual int classLevel() { return 1; } }; int Data::generationCounter = 0; int Data::destructorCounter = 0; @@ -336,6 +339,8 @@ public: { delete this; } + + virtual int classLevel() { return 2; } }; int DerivedData::derivedDestructorCounter = 0; @@ -343,15 +348,23 @@ class Stuffing { public: char buffer[16]; + Stuffing() { for (uint i = 0; i < sizeof buffer; ++i) buffer[i] = 16 - i; } virtual ~Stuffing() { } }; class DiffPtrDerivedData: public Stuffing, public Data { +public: + virtual int classLevel() { return 3; } }; class VirtualDerived: virtual public Data { +public: + int moreData; + + VirtualDerived() : moreData(0xc0ffee) { } + virtual int classLevel() { return 4; } }; void tst_QSharedPointer::downCast() @@ -997,6 +1010,82 @@ void tst_QSharedPointer::customDeleter() QCOMPARE(derivedDataDeleter.callCount, 1); } +void tst_QSharedPointer::creating() +{ + Data::generationCounter = Data::destructorCounter = 0; + { + QSharedPointer<Data> ptr = QSharedPointer<Data>::create(); + QVERIFY(ptr.data()); + QCOMPARE(Data::generationCounter, 1); + QCOMPARE(ptr->generation, 1); + QCOMPARE(Data::destructorCounter, 0); + + QCOMPARE(ptr->classLevel(), 1); + + ptr.clear(); + QCOMPARE(Data::destructorCounter, 1); + } + + Data::generationCounter = Data::destructorCounter = 0; + { + QSharedPointer<Data> ptr = QSharedPointer<Data>::create(); + QWeakPointer<Data> weakptr = ptr; + QtSharedPointer::ExternalRefCountData *d = ptr.d; + + ptr.clear(); + QVERIFY(ptr.isNull()); + QCOMPARE(Data::destructorCounter, 1); + + // valgrind will complain here if something happened to the pointer + QVERIFY(d->weakref == 1); + QVERIFY(d->strongref == 0); + } + + Data::generationCounter = Data::destructorCounter = 0; + DerivedData::derivedDestructorCounter = 0; + { + QSharedPointer<Data> ptr = QSharedPointer<DerivedData>::create(); + QCOMPARE(ptr->classLevel(), 2); + QCOMPARE(ptr.staticCast<DerivedData>()->moreData, 0); + ptr.clear(); + + QCOMPARE(Data::destructorCounter, 1); + QCOMPARE(DerivedData::derivedDestructorCounter, 1); + } + + { + QSharedPointer<Data> ptr = QSharedPointer<DiffPtrDerivedData>::create(); + QCOMPARE(ptr->classLevel(), 3); + QCOMPARE(ptr.staticCast<DiffPtrDerivedData>()->buffer[7]+0, 16-7); + QCOMPARE(ptr.staticCast<DiffPtrDerivedData>()->buffer[3]+0, 16-3); + QCOMPARE(ptr.staticCast<DiffPtrDerivedData>()->buffer[0]+0, 16); + } + + { + QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>::create(); + QCOMPARE(ptr->classLevel(), 4); + QCOMPARE(ptr->moreData, 0xc0ffee); + + QSharedPointer<Data> baseptr = ptr; + QCOMPARE(baseptr->classLevel(), 4); + } + + { + QSharedPointer<QObject> ptr = QSharedPointer<QObject>::create(); + QCOMPARE(ptr->metaObject(), &QObject::staticMetaObject); + + QPointer<QObject> qptr = ptr.data(); + ptr.clear(); + + QVERIFY(qptr.isNull()); + } + + { + QSharedPointer<QObject> ptr = QSharedPointer<OtherObject>::create(); + QCOMPARE(ptr->metaObject(), &OtherObject::staticMetaObject); + } +} + void tst_QSharedPointer::validConstructs() { { @@ -1048,6 +1137,9 @@ void tst_QSharedPointer::invalidConstructs_data() << "forwardDeclaredDestructorRunCount = 0;\n" "{ QSharedPointer<ForwardDeclared> ptr = QSharedPointer<ForwardDeclared>(forwardPointer()); }\n" "exit(forwardDeclaredDestructorRunCount);"; + QTest::newRow("creating-forward-declaration") + << &QTest::QExternalTest::tryCompileFail + << "QSharedPointer<ForwardDeclared>::create();"; // upcast without cast operator: QTest::newRow("upcast1") @@ -1080,10 +1172,16 @@ void tst_QSharedPointer::invalidConstructs_data() << "QSharedPointer<const Data> baseptr = QSharedPointer<const Data>(new Data);\n" "qSharedPointerDynamicCast<DerivedData>(baseptr);"; #endif - QTest::newRow("const-dropping-object-cast") + QTest::newRow("const-dropping-object-cast1") << &QTest::QExternalTest::tryCompileFail << "QSharedPointer<const QObject> baseptr = QSharedPointer<const QObject>(new QObject);\n" "qSharedPointerObjectCast<QCoreApplication>(baseptr);"; +#ifndef QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION + QTest::newRow("const-dropping-object-cast2") + << &QTest::QExternalTest::tryCompileFail + << "QSharedPointer<const QObject> baseptr = QSharedPointer<const QObject>(new QObject);\n" + "qobject_cast<QCoreApplication *>(baseptr);"; +#endif // arithmethics through automatic cast operators QTest::newRow("arithmethic1") |