Skip to content

Commit

Permalink
Use macro to allow Qt Creator to detect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Aug 3, 2018
1 parent fba64bb commit 85f9d22
Show file tree
Hide file tree
Showing 42 changed files with 64 additions and 56 deletions.
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/src/commands/sql-worker-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ void SqlWorkerTest::testExecCreateAndInsert()
}


static SqlWorkerTest instance;
QTEST_MAIN(SqlWorkerTest)
2 changes: 1 addition & 1 deletion tests/src/downloader/extension-rotator-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ void ExtensionRotatorTest::testCopyConstructor()
}


static ExtensionRotatorTest instance;
QTEST_MAIN(ExtensionRotatorTest)
2 changes: 1 addition & 1 deletion tests/src/downloader/file-downloader-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ void FileDownloaderTest::testFailedStart()
}


static FileDownloaderTest instance;
QTEST_MAIN(FileDownloaderTest)
2 changes: 1 addition & 1 deletion tests/src/downloader/image-downloader-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ void ImageDownloaderTest::assertDownload(QSharedPointer<Image> img, ImageDownloa
}


static ImageDownloaderTest instance;
QTEST_MAIN(ImageDownloaderTest)
2 changes: 1 addition & 1 deletion tests/src/functions-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,4 @@ void FunctionsTest::assertFixFilename(int platform, const QString &filename, con
QCOMPARE(actual, expected);
}

static FunctionsTest instance;
QTEST_MAIN(FunctionsTest)
2 changes: 1 addition & 1 deletion tests/src/integration/behoimi-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ void BehoimiTest::testJsonTags()
}


static BehoimiTest instance;
QTEST_MAIN(BehoimiTest)
2 changes: 1 addition & 1 deletion tests/src/integration/booru-org-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ void BooruOrgTest::testPageTags()
}


static BooruOrgTest instance;
QTEST_MAIN(BooruOrgTest)
2 changes: 1 addition & 1 deletion tests/src/integration/danbooru-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ void DanbooruTest::testJsonTags()
}


static DanbooruTest instance;
QTEST_MAIN(DanbooruTest)
2 changes: 1 addition & 1 deletion tests/src/integration/derpibooru-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ void DerpibooruTest::testJsonTags()
}


static DerpibooruTest instance;
QTEST_MAIN(DerpibooruTest)
2 changes: 1 addition & 1 deletion tests/src/integration/e621-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ void E621Test::testJsonTags()
}


static E621Test instance;
QTEST_MAIN(E621Test)
2 changes: 1 addition & 1 deletion tests/src/integration/gelbooru-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ void GelbooruTest::testHtmlTags()
}


static GelbooruTest instance;
QTEST_MAIN(GelbooruTest)
2 changes: 1 addition & 1 deletion tests/src/integration/sankaku-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ void SankakuTest::testAnimatedUrls()
}


static SankakuTest instance;
QTEST_MAIN(SankakuTest)
2 changes: 1 addition & 1 deletion tests/src/integration/zerochan-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ void ZerochanTest::testRss()
}


static ZerochanTest instance;
QTEST_MAIN(ZerochanTest)
2 changes: 1 addition & 1 deletion tests/src/loader/token-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ void TokenTest::testLazyWithoutCaching()
}


static TokenTest instance;
QTEST_MAIN(TokenTest)
29 changes: 12 additions & 17 deletions tests/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, int> 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;
}
2 changes: 1 addition & 1 deletion tests/src/mixed-settings-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ void MixedSettingsTest::testChildKeys()
}


static MixedSettingsTest instance;
QTEST_MAIN(MixedSettingsTest)
2 changes: 1 addition & 1 deletion tests/src/models/favorite-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ void FavoriteTest::testSortByLastViewed()
}


static FavoriteTest instance;
QTEST_MAIN(FavoriteTest)
3 changes: 2 additions & 1 deletion tests/src/models/filename-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,4 +740,5 @@ void FilenameTest::assertExpand(const QString &format, const QString &expected)
QCOMPARE(actual, expected);
}

static FilenameTest instance;

QTEST_MAIN(FilenameTest)
2 changes: 1 addition & 1 deletion tests/src/models/filtering/blacklist-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ void BlacklistTest::testMatch()
}


static BlacklistTest instance;
QTEST_MAIN(BlacklistTest)
2 changes: 1 addition & 1 deletion tests/src/models/filtering/meta-filter-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ void MetaFilterTest::testMatchString()
}


static MetaFilterTest instance;
QTEST_MAIN(MetaFilterTest)
2 changes: 1 addition & 1 deletion tests/src/models/filtering/post-filter-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ void PostFilterTest::testFilterInvert()
}


static PostFilterTest instance;
QTEST_MAIN(PostFilterTest)
2 changes: 1 addition & 1 deletion tests/src/models/filtering/tag-filter-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ void TagFilterTest::testMatchWildcard()
}


static TagFilterTest instance;
QTEST_MAIN(TagFilterTest)
2 changes: 1 addition & 1 deletion tests/src/models/filtering/token-filter-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ void TokenFilterTest::testMatchStringList()
}


static TokenFilterTest instance;
QTEST_MAIN(TokenFilterTest)
2 changes: 1 addition & 1 deletion tests/src/models/image-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,4 @@ void ImageTest::testSetUrl()
}


static ImageTest instance;
QTEST_MAIN(ImageTest)
2 changes: 1 addition & 1 deletion tests/src/models/page-api-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ void PageApiTest::testParseUrlAltPage()
}


static PageApiTest instance;
QTEST_MAIN(PageApiTest)
2 changes: 1 addition & 1 deletion tests/src/models/page-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ void PageTest::testLoadTagsAbort()
}


static PageTest instance;
QTEST_MAIN(PageTest)
7 changes: 6 additions & 1 deletion tests/src/models/pool-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/src/models/profile-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ void ProfileTest::testMd5ActionKeepDeleted()



static ProfileTest instance;
QTEST_MAIN(ProfileTest)
2 changes: 1 addition & 1 deletion tests/src/models/site-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ void SiteTest::testLoginPost()
}


static SiteTest instance;
QTEST_MAIN(SiteTest)
2 changes: 1 addition & 1 deletion tests/src/models/source-guesser-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ void SourceGuesserTest::testDanbooru2()
}


static SourceGuesserTest instance;
QTEST_MAIN(SourceGuesserTest)
2 changes: 1 addition & 1 deletion tests/src/models/source-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ void SourceTest::testIgnoreEmptySites()
}


static SourceTest instance;
QTEST_MAIN(SourceTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-api-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ void TagApiTest::testBasic()
}


static TagApiTest instance;
QTEST_MAIN(TagApiTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-database-in-memory-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ void TagDatabaseInMemoryTest::saveData()
}


static TagDatabaseInMemoryTest instance;
QTEST_MAIN(TagDatabaseInMemoryTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-database-sqlite-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ TagDatabaseSqliteTest::TagDatabaseSqliteTest()
{}


static TagDatabaseSqliteTest instance;
QTEST_MAIN(TagDatabaseSqliteTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-name-format-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ void TagNameFormatTest::testUnknown()
}


static TagNameFormatTest instance;
QTEST_MAIN(TagNameFormatTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-name-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ void TagNameTest::testCompare()
}


static TagNameTest instance;
QTEST_MAIN(TagNameTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-stylist-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ void TagStylistTest::assertSort(const QString &sort, const QStringList &expected
}


static TagStylistTest instance;
QTEST_MAIN(TagStylistTest)
2 changes: 1 addition & 1 deletion tests/src/tags/tag-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ void TagTest::testGetType()
}


static TagTest instance;
QTEST_MAIN(TagTest)
3 changes: 3 additions & 0 deletions tests/src/test-suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "models/profile.h"


#define QTEST_MAIN(CLASS_NAME) static CLASS_NAME instance;


#ifdef _MSC_VER
#include <crtdbg.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/src/updater/source-updater-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ void SourceUpdaterTest::testChanged()
#endif


static SourceUpdaterTest instance;
QTEST_MAIN(SourceUpdaterTest)
2 changes: 1 addition & 1 deletion tests/src/updater/updater-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ void UpdaterTest::testCompareAlphaToOld()
}


static UpdaterTest instance;
QTEST_MAIN(UpdaterTest)

0 comments on commit 85f9d22

Please sign in to comment.