summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-06-25 19:01:24 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-07-02 11:48:20 (GMT)
commit6f673e2cf55755a97aeb8971994ab9fc62fb794e (patch)
treef075a45e9fd6a18cfde96fd28069b719be743532 /tests/auto/qsharedpointer/tst_qsharedpointer.cpp
parentfb51a10ee0451274a430227566ae26efb2ac4474 (diff)
downloadQt-6f673e2cf55755a97aeb8971994ab9fc62fb794e.zip
Qt-6f673e2cf55755a97aeb8971994ab9fc62fb794e.tar.gz
Qt-6f673e2cf55755a97aeb8971994ab9fc62fb794e.tar.bz2
Experimental: allow QSharedPointer to be used with forward declarations that are declared in this file.
The one-definition rule allows the forward declaration appearing below to apply to code that was earlier. Therefore, if the compiler finds out how to delete the object, we can allow a QSharedPointer of a forward- declared-type. This means the actual problem is just a warning with g++. To catch the error, we need a separate .cpp file and I'd rather run this as an external test.
Diffstat (limited to 'tests/auto/qsharedpointer/tst_qsharedpointer.cpp')
-rw-r--r--tests/auto/qsharedpointer/tst_qsharedpointer.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
index d6321c7..dd53e3c 100644
--- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
@@ -225,16 +225,37 @@ void tst_QSharedPointer::basics()
}
class ForwardDeclared;
+ForwardDeclared *forwardPointer();
+void externalForwardDeclaration();
+extern int forwardDeclaredDestructorRunCount;
+
void tst_QSharedPointer::forwardDeclaration1()
{
- class Wrapper { QSharedPointer<ForwardDeclared> pointer; };
+ externalForwardDeclaration();
+
+ struct Wrapper { QSharedPointer<ForwardDeclared> pointer; };
+
+ forwardDeclaredDestructorRunCount = 0;
+ {
+ Wrapper w;
+ w.pointer = QSharedPointer<ForwardDeclared>(forwardPointer());
+ QVERIFY(!w.pointer.isNull());
+ }
+ QCOMPARE(forwardDeclaredDestructorRunCount, 1);
}
-class ForwardDeclared { };
+#include "forwarddeclared.h"
+
void tst_QSharedPointer::forwardDeclaration2()
{
- class Wrapper { QSharedPointer<ForwardDeclared> pointer; };
- Wrapper w;
+ forwardDeclaredDestructorRunCount = 0;
+ {
+ struct Wrapper { QSharedPointer<ForwardDeclared> pointer; };
+ Wrapper w1, w2;
+ w1.pointer = QSharedPointer<ForwardDeclared>(forwardPointer());
+ QVERIFY(!w1.pointer.isNull());
+ }
+ QCOMPARE(forwardDeclaredDestructorRunCount, 1);
}
void tst_QSharedPointer::memoryManagement()
@@ -1108,8 +1129,10 @@ void tst_QSharedPointer::invalidConstructs_data()
// use of forward-declared class
QTest::newRow("forward-declaration")
- << &QTest::QExternalTest::tryCompileFail
- << "QSharedPointer<ForwardDeclared> ptr;";
+ << &QTest::QExternalTest::tryRun
+ << "forwardDeclaredDestructorRunCount = 0;\n"
+ "{ QSharedPointer<ForwardDeclared> ptr = QSharedPointer<ForwardDeclared>(forwardPointer()); }\n"
+ "exit(forwardDeclaredDestructorRunCount);";
QTest::newRow("creating-forward-declaration")
<< &QTest::QExternalTest::tryCompileFail
<< "QSharedPointer<ForwardDeclared>::create();";
@@ -1216,6 +1239,7 @@ void tst_QSharedPointer::invalidConstructs()
QTest::QExternalTest test;
test.setDebugMode(true);
test.setQtModules(QTest::QExternalTest::QtCore);
+ test.setExtraProgramSources(QStringList() << SRCDIR "forwarddeclared.cpp");
test.setProgramHeader(
"#define QT_SHAREDPOINTER_TRACK_POINTERS\n"
"#include <QtCore/qsharedpointer.h>\n"
@@ -1223,7 +1247,11 @@ void tst_QSharedPointer::invalidConstructs()
"\n"
"struct Data { int i; };\n"
"struct DerivedData: public Data { int j; };\n"
- "struct ForwardDeclared;");
+ "\n"
+ "extern int forwardDeclaredDestructorRunCount;\n"
+ "struct ForwardDeclared;\n"
+ "ForwardDeclared *forwardPointer();\n"
+ );
QFETCH(QString, code);
static bool sane = true;