forked from longturn/freeciv21
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests attempting to load shipped rulesets
It's bad when they don't read, and we may not notice for a while. See longturn#380 (not a real autogames but a good starting point) and longturn#868.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
enable_testing(true) | ||
|
||
# Turn the list of rulesets into something C++ will understand | ||
list(JOIN RULESET_LIST "\", \"" ruleset_list_cpp) | ||
if (NOT ${ruleset_list_cpp} STREQUAL "") | ||
set(ruleset_list_cpp "\"${ruleset_list_cpp}\"") | ||
endif() | ||
|
||
# Create the test file. This is ugly because we need to replace variables | ||
# and use generator expressions. | ||
configure_file(rulesets.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/rulesets.cpp.in) | ||
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rulesets.cpp | ||
INPUT ${CMAKE_CURRENT_BINARY_DIR}/rulesets.cpp.in) | ||
|
||
add_executable(test_rulesets ${CMAKE_CURRENT_BINARY_DIR}/rulesets.cpp) | ||
add_test(NAME test_rulesets COMMAND test_rulesets) | ||
target_link_libraries(test_rulesets PRIVATE Qt5::Test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <QProcess> | ||
|
||
#include <QtTest> | ||
|
||
// Macro values replaced by cmake | ||
#define RULESETS "$<JOIN:${RULESET_LIST},", ">" | ||
#define SERVER_PATH "$<TARGET_FILE:freeciv21-server>" | ||
|
||
/** | ||
* Ruleset-related tests | ||
*/ | ||
class test_rulesets : public QObject { | ||
Q_OBJECT | ||
|
||
private slots: | ||
void load_data(); | ||
void load(); | ||
}; | ||
|
||
/** | ||
* Generates test data for load() | ||
*/ | ||
void test_rulesets::load_data() | ||
{ | ||
QTest::addColumn<QString>("name"); | ||
QTest::addColumn<bool>("exists"); | ||
|
||
const char *names[] = {"default", RULESETS}; | ||
for (auto &name : names) { | ||
QTest::newRow(name) << name << true; | ||
} | ||
|
||
// A ruleset that doesn't exist | ||
QTest::newRow("error") << "error" << false; | ||
} | ||
|
||
/** | ||
* Tries to spawn a server with a ruleset. | ||
*/ | ||
void test_rulesets::load() | ||
{ | ||
QFETCH(QString, name); | ||
QFETCH(bool, exists); | ||
|
||
QProcess p; | ||
p.start(SERVER_PATH, {QStringLiteral("-r"), name}); | ||
p.waitForStarted(); | ||
p.write("quit\n"); | ||
p.closeWriteChannel(); | ||
p.waitForFinished(5000); | ||
|
||
if (exists) { | ||
QCOMPARE(p.exitCode(), 0); | ||
} else { | ||
QCOMPARE(p.exitCode(), 1); | ||
} | ||
} | ||
|
||
QTEST_MAIN(test_rulesets) | ||
#include "rulesets.moc" |