summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2016-09-06 16:58:58 (GMT)
committerRalf Habacker <ralf.habacker@freenet.de>2016-09-06 16:59:24 (GMT)
commit6d5686f264ddfda0e6bf030e16902569e7dc02df (patch)
tree76da8d75746eee969c4bfdd1a90e8b39103bca0d
parentbadc01d753ca0cb46b51a3fd2ed07d265cf9bfed (diff)
Fix crash in TEST_UMLObject::test_fullyQualifiedName() caused by creating uml model related objects on stack.
Because QCOMPARE() returns the function immediatly on error we need to delete related objects on ourself on exit. This is performed by adding objects to delete with cleanupOnExit(). CCBUG:368282
-rw-r--r--unittests/TEST_umlobject.cpp27
-rw-r--r--unittests/testbase.cpp8
-rw-r--r--unittests/testbase.h4
3 files changed, 27 insertions, 12 deletions
diff --git a/unittests/TEST_umlobject.cpp b/unittests/TEST_umlobject.cpp
index 1bcd6a4..6a4d70d 100644
--- a/unittests/TEST_umlobject.cpp
+++ b/unittests/TEST_umlobject.cpp
@@ -82,20 +82,23 @@ void TEST_UMLObject::test_equal()
void TEST_UMLObject::test_fullyQualifiedName()
{
- UMLObject a("Test A");
- QCOMPARE(a.fullyQualifiedName(), QLatin1String("Test A"));
-
- UMLPackage topParent("Top Parent");
- UMLPackage parent("Test Parent");
- parent.setUMLPackage(&topParent);
- a.setUMLPackage(&parent);
- QCOMPARE(a.umlPackage()->fullyQualifiedName(), a.package());
- QCOMPARE(a.fullyQualifiedName(), QLatin1String("Top Parent::Test Parent::Test A"));
- QCOMPARE(a.fullyQualifiedName(QLatin1String("-")), QLatin1String("Top Parent-Test Parent-Test A"));
+ UMLObject* a = new UMLObject("Test A");
+ cleanupOnExit(a);
+ QCOMPARE(a->fullyQualifiedName(), QLatin1String("Test A"));
+
+ UMLPackage* topParent = new UMLPackage("Top Parent");
+ cleanupOnExit(topParent);
+ UMLPackage* parent = new UMLPackage("Test Parent");
+ cleanupOnExit(parent);
+ parent->setUMLPackage(topParent);
+ a->setUMLPackage(parent);
+ QCOMPARE(a->umlPackage()->fullyQualifiedName(), a->package());
+ QCOMPARE(a->fullyQualifiedName(), QLatin1String("Top Parent::Test Parent::Test A"));
+ QCOMPARE(a->fullyQualifiedName(QLatin1String("-")), QLatin1String("Top Parent-Test Parent-Test A"));
UMLFolder *f = UMLApp::app()->document()->rootFolder(Uml::ModelType::Logical);
- parent.setUMLPackage(f);
- QCOMPARE(a.fullyQualifiedName(QLatin1String("::"), true), QLatin1String("Logical View::Test Parent::Test A"));
+ parent->setUMLPackage(f);
+ QCOMPARE(a->fullyQualifiedName(QLatin1String("::"), true), QLatin1String("Logical View::Test Parent::Test A"));
}
void TEST_UMLObject::test_isAbstract()
diff --git a/unittests/testbase.cpp b/unittests/testbase.cpp
index e0d6ec3..0ad4679 100644
--- a/unittests/testbase.cpp
+++ b/unittests/testbase.cpp
@@ -53,6 +53,14 @@ void TestBase::initTestCase()
void TestBase::cleanupTestCase()
{
delete UMLApp::app();
+ foreach(QObject *p, m_objectsToDelete) {
+ delete p;
+ }
+}
+
+void TestBase::cleanupOnExit(QObject *p)
+{
+ m_objectsToDelete.append(p);
}
void TestCodeGeneratorBase::initTestCase()
diff --git a/unittests/testbase.h b/unittests/testbase.h
index 60734e3..5dcd084 100644
--- a/unittests/testbase.h
+++ b/unittests/testbase.h
@@ -42,6 +42,10 @@ public:
protected slots:
virtual void initTestCase();
virtual void cleanupTestCase();
+ virtual void cleanupOnExit(QObject *p);
+
+protected:
+ QList<QPointer<QObject>> m_objectsToDelete;
};
/**