From 5caa9b23fe3195c758f9b6f1a9ab5f7bf88ee45c Mon Sep 17 00:00:00 2001 From: Jeremie Guichard Date: Fri, 3 Mar 2017 13:33:25 +0700 Subject: 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 --- tests/testgitstorage.cpp | 11 +++++------ tests/testgitstorage.h | 2 ++ tests/testmerge.cpp | 7 +++++-- tests/testmerge.h | 2 ++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index 46e77142d..f2fe3f0e1 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -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) diff --git a/tests/testgitstorage.h b/tests/testgitstorage.h index 579aa33d3..d84a8e544 100644 --- a/tests/testgitstorage.h +++ b/tests/testgitstorage.h @@ -8,6 +8,8 @@ class TestGitStorage : public QObject Q_OBJECT private slots: void initTestCase(); + void cleanup(); + void testGitStorageLocal_data(); void testGitStorageLocal(); void testGitStorageCloud(); diff --git a/tests/testmerge.cpp b/tests/testmerge.cpp index 450aba2e9..8c2b3482d 100644 --- a/tests/testmerge.cpp +++ b/tests/testmerge.cpp @@ -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) diff --git a/tests/testmerge.h b/tests/testmerge.h index 771afc4db..2acb1dace 100644 --- a/tests/testmerge.h +++ b/tests/testmerge.h @@ -7,6 +7,8 @@ class TestMerge : public QObject{ Q_OBJECT private slots: void initTestCase(); + void cleanup(); + void testMergeEmpty(); void testMergeBackwards(); }; -- cgit v1.2.3-70-g09d2