Use QTest cleanup method for proper test shutdown

In case of QCOMPARE failure, code following the comparison
is not executed, this results in application state not being
properly resorted and often gives several test failures,
when only one test really fails.
Using QTest cleanup method allows restoring proper state,
before next test is executed.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
This commit is contained in:
Jeremie Guichard 2017-03-03 13:33:25 +07:00 committed by Dirk Hohndel
parent 16a321d43b
commit 5caa9b23fe
4 changed files with 14 additions and 8 deletions

View file

@ -59,6 +59,11 @@ void TestGitStorage::initTestCase()
QCOMPARE(localCacheDirectory.removeRecursively(), true);
}
void TestGitStorage::cleanup()
{
clear_dive_file_data();
}
void TestGitStorage::testGitStorageLocal_data()
{
// test different path we may encounter (since storage depends on user name)
@ -92,7 +97,6 @@ void TestGitStorage::testGitStorageLocal()
QString readin = orgS.readAll();
QString written = outS.readAll();
QCOMPARE(readin, written);
clear_dive_file_data();
}
void TestGitStorage::testGitStorageCloud()
@ -115,7 +119,6 @@ void TestGitStorage::testGitStorageCloud()
QString readin = orgS.readAll();
QString written = outS.readAll();
QCOMPARE(readin, written);
clear_dive_file_data();
}
void TestGitStorage::testGitStorageCloudOfflineSync()
@ -165,7 +168,6 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
readin = orgS2.readAll();
written = outS2.readAll();
QCOMPARE(readin, written);
clear_dive_file_data();
}
void TestGitStorage::testGitStorageCloudMerge()
@ -213,7 +215,6 @@ void TestGitStorage::testGitStorageCloudMerge()
QString readin = orgS.readAll();
QString written = outS.readAll();
QCOMPARE(readin, written);
clear_dive_file_data();
}
void TestGitStorage::testGitStorageCloudMerge2()
@ -268,7 +269,6 @@ void TestGitStorage::testGitStorageCloudMerge2()
QString readin = orgS.readAll();
QString written = outS.readAll();
QCOMPARE(readin, written);
clear_dive_file_data();
}
void TestGitStorage::testGitStorageCloudMerge3()
@ -334,7 +334,6 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test
// checks is that there are no parsing errors with the merge
clear_dive_file_data();
}
QTEST_GUILESS_MAIN(TestGitStorage)

View file

@ -8,6 +8,8 @@ class TestGitStorage : public QObject
Q_OBJECT
private slots:
void initTestCase();
void cleanup();
void testGitStorageLocal_data();
void testGitStorageLocal();
void testGitStorageCloud();

View file

@ -10,6 +10,11 @@ void TestMerge::initTestCase()
Q_INIT_RESOURCE(subsurface);
}
void TestMerge::cleanup()
{
clear_dive_file_data();
}
void TestMerge::testMergeEmpty()
{
/*
@ -31,7 +36,6 @@ void TestMerge::testMergeEmpty()
while(readin.size() && written.size()){
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
}
clear_dive_file_data();
}
void TestMerge::testMergeBackwards()
@ -55,7 +59,6 @@ void TestMerge::testMergeBackwards()
while(readin.size() && written.size()){
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
}
clear_dive_file_data();
}
QTEST_GUILESS_MAIN(TestMerge)

View file

@ -7,6 +7,8 @@ class TestMerge : public QObject{
Q_OBJECT
private slots:
void initTestCase();
void cleanup();
void testMergeEmpty();
void testMergeBackwards();
};