diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c40b1a2a4..0b7968285 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,10 @@ set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Test Qt5::Widgets) file(GLOB_RECURSE SOURCES "src/*.cpp") include_directories("src/" "../lib/src/") +if(MSVC OR CMAKE_CXX_COMPILER MATCHES "cl\\.exe") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4005") # Suppress "macro redifinition" warnings +endif() + add_executable(${PROJECT_NAME} ${SOURCES}) add_test(${PROJECT_NAME} ${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} lib) diff --git a/tests/src/commands/sql-worker-test.cpp b/tests/src/commands/sql-worker-test.cpp index 64e6e9c72..a26e26be9 100644 --- a/tests/src/commands/sql-worker-test.cpp +++ b/tests/src/commands/sql-worker-test.cpp @@ -77,4 +77,4 @@ void SqlWorkerTest::testExecCreateAndInsert() } -static SqlWorkerTest instance; +QTEST_MAIN(SqlWorkerTest) diff --git a/tests/src/downloader/extension-rotator-test.cpp b/tests/src/downloader/extension-rotator-test.cpp index 82d526cc9..ef907d9eb 100644 --- a/tests/src/downloader/extension-rotator-test.cpp +++ b/tests/src/downloader/extension-rotator-test.cpp @@ -77,4 +77,4 @@ void ExtensionRotatorTest::testCopyConstructor() } -static ExtensionRotatorTest instance; +QTEST_MAIN(ExtensionRotatorTest) diff --git a/tests/src/downloader/file-downloader-test.cpp b/tests/src/downloader/file-downloader-test.cpp index 7fcabf74f..5b5eb69a5 100644 --- a/tests/src/downloader/file-downloader-test.cpp +++ b/tests/src/downloader/file-downloader-test.cpp @@ -76,4 +76,4 @@ void FileDownloaderTest::testFailedStart() } -static FileDownloaderTest instance; +QTEST_MAIN(FileDownloaderTest) diff --git a/tests/src/downloader/image-downloader-test.cpp b/tests/src/downloader/image-downloader-test.cpp index 8eec735e0..a04c2d82b 100644 --- a/tests/src/downloader/image-downloader-test.cpp +++ b/tests/src/downloader/image-downloader-test.cpp @@ -168,4 +168,4 @@ void ImageDownloaderTest::assertDownload(QSharedPointer img, ImageDownloa } -static ImageDownloaderTest instance; +QTEST_MAIN(ImageDownloaderTest) diff --git a/tests/src/functions-test.cpp b/tests/src/functions-test.cpp index b2914322a..e8070f491 100644 --- a/tests/src/functions-test.cpp +++ b/tests/src/functions-test.cpp @@ -299,4 +299,4 @@ void FunctionsTest::assertFixFilename(int platform, const QString &filename, con QCOMPARE(actual, expected); } -static FunctionsTest instance; +QTEST_MAIN(FunctionsTest) diff --git a/tests/src/integration/behoimi-test.cpp b/tests/src/integration/behoimi-test.cpp index e39f525e6..f76540702 100644 --- a/tests/src/integration/behoimi-test.cpp +++ b/tests/src/integration/behoimi-test.cpp @@ -109,4 +109,4 @@ void BehoimiTest::testJsonTags() } -static BehoimiTest instance; +QTEST_MAIN(BehoimiTest) diff --git a/tests/src/integration/booru-org-test.cpp b/tests/src/integration/booru-org-test.cpp index 88a65aa8e..f24272981 100644 --- a/tests/src/integration/booru-org-test.cpp +++ b/tests/src/integration/booru-org-test.cpp @@ -38,4 +38,4 @@ void BooruOrgTest::testPageTags() } -static BooruOrgTest instance; +QTEST_MAIN(BooruOrgTest) diff --git a/tests/src/integration/danbooru-test.cpp b/tests/src/integration/danbooru-test.cpp index aa25ccf42..3716dff7c 100644 --- a/tests/src/integration/danbooru-test.cpp +++ b/tests/src/integration/danbooru-test.cpp @@ -90,4 +90,4 @@ void DanbooruTest::testJsonTags() } -static DanbooruTest instance; +QTEST_MAIN(DanbooruTest) diff --git a/tests/src/integration/derpibooru-test.cpp b/tests/src/integration/derpibooru-test.cpp index a6bb4586c..9a286fc9b 100644 --- a/tests/src/integration/derpibooru-test.cpp +++ b/tests/src/integration/derpibooru-test.cpp @@ -65,4 +65,4 @@ void DerpibooruTest::testJsonTags() } -static DerpibooruTest instance; +QTEST_MAIN(DerpibooruTest) diff --git a/tests/src/integration/e621-test.cpp b/tests/src/integration/e621-test.cpp index 4abae1fee..b6b73176f 100644 --- a/tests/src/integration/e621-test.cpp +++ b/tests/src/integration/e621-test.cpp @@ -93,4 +93,4 @@ void E621Test::testJsonTags() } -static E621Test instance; +QTEST_MAIN(E621Test) diff --git a/tests/src/integration/gelbooru-test.cpp b/tests/src/integration/gelbooru-test.cpp index 065808144..7cc2f0311 100644 --- a/tests/src/integration/gelbooru-test.cpp +++ b/tests/src/integration/gelbooru-test.cpp @@ -68,4 +68,4 @@ void GelbooruTest::testHtmlTags() } -static GelbooruTest instance; +QTEST_MAIN(GelbooruTest) diff --git a/tests/src/integration/sankaku-test.cpp b/tests/src/integration/sankaku-test.cpp index 66df15d5b..ed371e7e0 100755 --- a/tests/src/integration/sankaku-test.cpp +++ b/tests/src/integration/sankaku-test.cpp @@ -44,4 +44,4 @@ void SankakuTest::testAnimatedUrls() } -static SankakuTest instance; +QTEST_MAIN(SankakuTest) diff --git a/tests/src/integration/zerochan-test.cpp b/tests/src/integration/zerochan-test.cpp index bda2cd8ae..d5346639a 100644 --- a/tests/src/integration/zerochan-test.cpp +++ b/tests/src/integration/zerochan-test.cpp @@ -42,4 +42,4 @@ void ZerochanTest::testRss() } -static ZerochanTest instance; +QTEST_MAIN(ZerochanTest) diff --git a/tests/src/loader/token-test.cpp b/tests/src/loader/token-test.cpp index bdfea9663..b06187e66 100644 --- a/tests/src/loader/token-test.cpp +++ b/tests/src/loader/token-test.cpp @@ -35,4 +35,4 @@ void TokenTest::testLazyWithoutCaching() } -static TokenTest instance; +QTEST_MAIN(TokenTest) diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 8ab283715..242d72b4a 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -12,33 +12,28 @@ int main(int argc, char *argv[]) QGuiApplication a(argc, argv); #endif + // A possible format to filter by test suite it to pass their names as arguments QStringList testSuites; - testSuites.reserve(argc - 1); for (int i = 1; i < argc; ++i) - testSuites.append(argv[i]); - - QMap results; - int failed = 0; + { + QString arg(argv[i]); + if (!arg.startsWith('-') && !arg.startsWith("test")) + testSuites.append(argv[i]); + } + // Used for networking and finding test resource files setTestModeEnabled(true); + // Run all selected test suites + int errorCode = 0; for (TestSuite *suite : TestSuite::getSuites()) { if (!testSuites.isEmpty() && !testSuites.contains(suite->metaObject()->className())) continue; - int result = QTest::qExec(suite); - results.insert(suite->metaObject()->className(), result); - if (result != 0) - { - failed++; - } - } - - for (auto it = results.begin(); it != results.end(); ++it) - { - std::cout << '[' << (it.value() != 0 ? "FAIL" : "OK") << "] " << it.key().toStdString() << std::endl; + errorCode |= QTest::qExec(suite, argc, argv); + std::cout << std::endl; } - return failed; + return errorCode; } diff --git a/tests/src/mixed-settings-test.cpp b/tests/src/mixed-settings-test.cpp index 1ff95e99f..820adef56 100644 --- a/tests/src/mixed-settings-test.cpp +++ b/tests/src/mixed-settings-test.cpp @@ -93,4 +93,4 @@ void MixedSettingsTest::testChildKeys() } -static MixedSettingsTest instance; +QTEST_MAIN(MixedSettingsTest) diff --git a/tests/src/models/favorite-test.cpp b/tests/src/models/favorite-test.cpp index 9c4f16591..6febc7968 100644 --- a/tests/src/models/favorite-test.cpp +++ b/tests/src/models/favorite-test.cpp @@ -272,4 +272,4 @@ void FavoriteTest::testSortByLastViewed() } -static FavoriteTest instance; +QTEST_MAIN(FavoriteTest) diff --git a/tests/src/models/filename-test.cpp b/tests/src/models/filename-test.cpp index 01615a9b8..5148d5445 100644 --- a/tests/src/models/filename-test.cpp +++ b/tests/src/models/filename-test.cpp @@ -740,4 +740,5 @@ void FilenameTest::assertExpand(const QString &format, const QString &expected) QCOMPARE(actual, expected); } -static FilenameTest instance; + +QTEST_MAIN(FilenameTest) diff --git a/tests/src/models/filtering/blacklist-test.cpp b/tests/src/models/filtering/blacklist-test.cpp index d53694d71..61486f6ee 100644 --- a/tests/src/models/filtering/blacklist-test.cpp +++ b/tests/src/models/filtering/blacklist-test.cpp @@ -54,4 +54,4 @@ void BlacklistTest::testMatch() } -static BlacklistTest instance; +QTEST_MAIN(BlacklistTest) diff --git a/tests/src/models/filtering/meta-filter-test.cpp b/tests/src/models/filtering/meta-filter-test.cpp index be0f127fd..aaf4fe909 100644 --- a/tests/src/models/filtering/meta-filter-test.cpp +++ b/tests/src/models/filtering/meta-filter-test.cpp @@ -135,4 +135,4 @@ void MetaFilterTest::testMatchString() } -static MetaFilterTest instance; +QTEST_MAIN(MetaFilterTest) diff --git a/tests/src/models/filtering/post-filter-test.cpp b/tests/src/models/filtering/post-filter-test.cpp index e5ae839f9..c063e96a8 100644 --- a/tests/src/models/filtering/post-filter-test.cpp +++ b/tests/src/models/filtering/post-filter-test.cpp @@ -106,4 +106,4 @@ void PostFilterTest::testFilterInvert() } -static PostFilterTest instance; +QTEST_MAIN(PostFilterTest) diff --git a/tests/src/models/filtering/tag-filter-test.cpp b/tests/src/models/filtering/tag-filter-test.cpp index d4b96d8ca..54cc10e93 100644 --- a/tests/src/models/filtering/tag-filter-test.cpp +++ b/tests/src/models/filtering/tag-filter-test.cpp @@ -46,4 +46,4 @@ void TagFilterTest::testMatchWildcard() } -static TagFilterTest instance; +QTEST_MAIN(TagFilterTest) diff --git a/tests/src/models/filtering/token-filter-test.cpp b/tests/src/models/filtering/token-filter-test.cpp index 060e19974..92603db29 100644 --- a/tests/src/models/filtering/token-filter-test.cpp +++ b/tests/src/models/filtering/token-filter-test.cpp @@ -69,4 +69,4 @@ void TokenFilterTest::testMatchStringList() } -static TokenFilterTest instance; +QTEST_MAIN(TokenFilterTest) diff --git a/tests/src/models/image-test.cpp b/tests/src/models/image-test.cpp index 0d95178a5..8f1b01511 100644 --- a/tests/src/models/image-test.cpp +++ b/tests/src/models/image-test.cpp @@ -372,4 +372,4 @@ void ImageTest::testSetUrl() } -static ImageTest instance; +QTEST_MAIN(ImageTest) diff --git a/tests/src/models/page-api-test.cpp b/tests/src/models/page-api-test.cpp index d2fb7e4a7..0144d3c36 100644 --- a/tests/src/models/page-api-test.cpp +++ b/tests/src/models/page-api-test.cpp @@ -66,4 +66,4 @@ void PageApiTest::testParseUrlAltPage() } -static PageApiTest instance; +QTEST_MAIN(PageApiTest) diff --git a/tests/src/models/page-test.cpp b/tests/src/models/page-test.cpp index 16bb2d873..53d1bfe05 100644 --- a/tests/src/models/page-test.cpp +++ b/tests/src/models/page-test.cpp @@ -46,4 +46,4 @@ void PageTest::testLoadTagsAbort() } -static PageTest instance; +QTEST_MAIN(PageTest) diff --git a/tests/src/models/pool-test.cpp b/tests/src/models/pool-test.cpp index d08cb7967..dae900278 100644 --- a/tests/src/models/pool-test.cpp +++ b/tests/src/models/pool-test.cpp @@ -7,25 +7,30 @@ void PoolTest::testGetId() Pool pool(123, "Test pool", 1, 2, 3); QCOMPARE(pool.id(), 123); } + void PoolTest::testGetName() { Pool pool(123, "Test pool", 1, 2, 3); QCOMPARE(pool.name(), QString("Test pool")); } + void PoolTest::testGetCurrent() { Pool pool(123, "Test pool", 1, 2, 3); QCOMPARE(pool.current(), 1); } + void PoolTest::testGetNext() { Pool pool(123, "Test pool", 1, 2, 3); QCOMPARE(pool.next(), 2); } + void PoolTest::testGetPrevious() { Pool pool(123, "Test pool", 1, 2, 3); QCOMPARE(pool.previous(), 3); } -static PoolTest instance; + +QTEST_MAIN(PoolTest) diff --git a/tests/src/models/profile-test.cpp b/tests/src/models/profile-test.cpp index 2f7f63c8d..126fd888d 100644 --- a/tests/src/models/profile-test.cpp +++ b/tests/src/models/profile-test.cpp @@ -216,4 +216,4 @@ void ProfileTest::testMd5ActionKeepDeleted() -static ProfileTest instance; +QTEST_MAIN(ProfileTest) diff --git a/tests/src/models/site-test.cpp b/tests/src/models/site-test.cpp index ff63b8dc0..6a411b6d0 100755 --- a/tests/src/models/site-test.cpp +++ b/tests/src/models/site-test.cpp @@ -227,4 +227,4 @@ void SiteTest::testLoginPost() } -static SiteTest instance; +QTEST_MAIN(SiteTest) diff --git a/tests/src/models/source-guesser-test.cpp b/tests/src/models/source-guesser-test.cpp index 190dad2a8..d557f886c 100644 --- a/tests/src/models/source-guesser-test.cpp +++ b/tests/src/models/source-guesser-test.cpp @@ -73,4 +73,4 @@ void SourceGuesserTest::testDanbooru2() } -static SourceGuesserTest instance; +QTEST_MAIN(SourceGuesserTest) diff --git a/tests/src/models/source-test.cpp b/tests/src/models/source-test.cpp index bab9b67d7..bff229e71 100644 --- a/tests/src/models/source-test.cpp +++ b/tests/src/models/source-test.cpp @@ -90,4 +90,4 @@ void SourceTest::testIgnoreEmptySites() } -static SourceTest instance; +QTEST_MAIN(SourceTest) diff --git a/tests/src/tags/tag-api-test.cpp b/tests/src/tags/tag-api-test.cpp index 06deb040b..eaea768bb 100644 --- a/tests/src/tags/tag-api-test.cpp +++ b/tests/src/tags/tag-api-test.cpp @@ -39,4 +39,4 @@ void TagApiTest::testBasic() } -static TagApiTest instance; +QTEST_MAIN(TagApiTest) diff --git a/tests/src/tags/tag-database-in-memory-test.cpp b/tests/src/tags/tag-database-in-memory-test.cpp index 54307816e..0b434aefc 100644 --- a/tests/src/tags/tag-database-in-memory-test.cpp +++ b/tests/src/tags/tag-database-in-memory-test.cpp @@ -113,4 +113,4 @@ void TagDatabaseInMemoryTest::saveData() } -static TagDatabaseInMemoryTest instance; +QTEST_MAIN(TagDatabaseInMemoryTest) diff --git a/tests/src/tags/tag-database-sqlite-test.cpp b/tests/src/tags/tag-database-sqlite-test.cpp index 15ad80b13..ea9c54f52 100644 --- a/tests/src/tags/tag-database-sqlite-test.cpp +++ b/tests/src/tags/tag-database-sqlite-test.cpp @@ -8,4 +8,4 @@ TagDatabaseSqliteTest::TagDatabaseSqliteTest() {} -static TagDatabaseSqliteTest instance; +QTEST_MAIN(TagDatabaseSqliteTest) diff --git a/tests/src/tags/tag-name-format-test.cpp b/tests/src/tags/tag-name-format-test.cpp index e58f6abff..2b8ca16c0 100644 --- a/tests/src/tags/tag-name-format-test.cpp +++ b/tests/src/tags/tag-name-format-test.cpp @@ -53,4 +53,4 @@ void TagNameFormatTest::testUnknown() } -static TagNameFormatTest instance; +QTEST_MAIN(TagNameFormatTest) diff --git a/tests/src/tags/tag-name-test.cpp b/tests/src/tags/tag-name-test.cpp index 7ee7e4905..902f2c4c4 100644 --- a/tests/src/tags/tag-name-test.cpp +++ b/tests/src/tags/tag-name-test.cpp @@ -45,4 +45,4 @@ void TagNameTest::testCompare() } -static TagNameTest instance; +QTEST_MAIN(TagNameTest) diff --git a/tests/src/tags/tag-stylist-test.cpp b/tests/src/tags/tag-stylist-test.cpp index 9a26ecf10..42f13e71a 100644 --- a/tests/src/tags/tag-stylist-test.cpp +++ b/tests/src/tags/tag-stylist-test.cpp @@ -143,4 +143,4 @@ void TagStylistTest::assertSort(const QString &sort, const QStringList &expected } -static TagStylistTest instance; +QTEST_MAIN(TagStylistTest) diff --git a/tests/src/tags/tag-test.cpp b/tests/src/tags/tag-test.cpp index bbb46a656..f224427c3 100644 --- a/tests/src/tags/tag-test.cpp +++ b/tests/src/tags/tag-test.cpp @@ -228,4 +228,4 @@ void TagTest::testGetType() } -static TagTest instance; +QTEST_MAIN(TagTest) diff --git a/tests/src/test-suite.h b/tests/src/test-suite.h index dd375d59a..3b32bf826 100644 --- a/tests/src/test-suite.h +++ b/tests/src/test-suite.h @@ -7,6 +7,9 @@ #include "models/profile.h" +#define QTEST_MAIN(CLASS_NAME) static CLASS_NAME instance; + + #ifdef _MSC_VER #include diff --git a/tests/src/updater/source-updater-test.cpp b/tests/src/updater/source-updater-test.cpp index d5a1546dc..2a669a54e 100644 --- a/tests/src/updater/source-updater-test.cpp +++ b/tests/src/updater/source-updater-test.cpp @@ -39,4 +39,4 @@ void SourceUpdaterTest::testChanged() #endif -static SourceUpdaterTest instance; +QTEST_MAIN(SourceUpdaterTest) diff --git a/tests/src/updater/updater-test.cpp b/tests/src/updater/updater-test.cpp index e984d9d49..9554115fe 100644 --- a/tests/src/updater/updater-test.cpp +++ b/tests/src/updater/updater-test.cpp @@ -55,4 +55,4 @@ void UpdaterTest::testCompareAlphaToOld() } -static UpdaterTest instance; +QTEST_MAIN(UpdaterTest)