2014-07-06 05:14:11 +02:00
|
|
|
#include <platform.h>
|
2015-01-12 08:18:41 +01:00
|
|
|
#include <eressea.h>
|
2014-07-06 05:14:11 +02:00
|
|
|
#include <kernel/config.h>
|
2017-11-18 12:54:48 +01:00
|
|
|
#include <kernel/database.h>
|
2014-02-18 05:45:00 +01:00
|
|
|
#include <CuTest.h>
|
|
|
|
#include <stdio.h>
|
2015-10-14 18:34:41 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2014-02-18 05:45:00 +01:00
|
|
|
#include <util/log.h>
|
2017-12-28 18:29:40 +01:00
|
|
|
#include <util/strings.h>
|
2017-02-24 17:51:35 +01:00
|
|
|
#include <util/variant.h>
|
2014-02-18 05:45:00 +01:00
|
|
|
|
2014-08-25 00:35:49 +02:00
|
|
|
#pragma warning(disable: 4210)
|
2014-12-12 12:17:41 +01:00
|
|
|
|
2015-10-14 18:34:41 +02:00
|
|
|
typedef struct suite {
|
|
|
|
struct suite *next;
|
|
|
|
CuSuite *csuite;
|
|
|
|
char *name;
|
|
|
|
} suite;
|
|
|
|
|
|
|
|
static suite *suites;
|
|
|
|
|
2015-10-14 18:38:10 +02:00
|
|
|
static void add_suite(CuSuite *(*csuite)(void), const char *name, int argc, char *argv[]) {
|
2015-10-14 18:34:41 +02:00
|
|
|
suite *s = 0;
|
2015-10-14 18:40:37 +02:00
|
|
|
if (argc > 0) {
|
2015-10-14 18:34:41 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i != argc; ++i) {
|
|
|
|
if (strcmp(argv[i], name) == 0) {
|
|
|
|
s = malloc(sizeof(suite));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s = malloc(sizeof(suite));
|
|
|
|
}
|
|
|
|
if (s) {
|
|
|
|
s->next = suites;
|
2017-12-28 18:29:40 +01:00
|
|
|
s->name = str_strdup(name);
|
2015-10-14 18:34:41 +02:00
|
|
|
s->csuite = csuite();
|
|
|
|
suites = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 12:17:41 +01:00
|
|
|
void RunTests(CuSuite * suite, const char *name) {
|
|
|
|
CuString *output = CuStringNew();
|
|
|
|
|
|
|
|
CuSuiteRun(suite);
|
|
|
|
CuSuiteDetails(suite, output);
|
|
|
|
if (suite->failCount) CuSuiteSummary(suite, output);
|
|
|
|
printf("%s: %s", name, output->buffer);
|
|
|
|
CuStringDelete(output);
|
|
|
|
}
|
|
|
|
|
2015-10-14 18:34:41 +02:00
|
|
|
bool list = false;
|
|
|
|
|
|
|
|
#define ADD_SUITE(name) \
|
2017-02-18 21:15:14 +01:00
|
|
|
do { \
|
|
|
|
CuSuite *get_##name##_suite(void); \
|
|
|
|
if (list) printf("%s\n", #name); \
|
|
|
|
if (!list || argc>0) add_suite(get_##name##_suite, #name, argc, argv); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-08-14 05:06:36 +02:00
|
|
|
|
2015-10-14 18:34:41 +02:00
|
|
|
int RunAllTests(int argc, char *argv[])
|
2014-02-18 05:45:00 +01:00
|
|
|
{
|
2015-10-14 18:34:41 +02:00
|
|
|
/* self-test */
|
|
|
|
ADD_SUITE(tests);
|
|
|
|
ADD_SUITE(json);
|
|
|
|
ADD_SUITE(jsonconf);
|
|
|
|
ADD_SUITE(direction);
|
|
|
|
ADD_SUITE(skill);
|
|
|
|
ADD_SUITE(keyword);
|
2017-01-06 20:54:57 +01:00
|
|
|
ADD_SUITE(message);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(order);
|
|
|
|
ADD_SUITE(race);
|
|
|
|
/* util */
|
|
|
|
ADD_SUITE(config);
|
|
|
|
ADD_SUITE(attrib);
|
|
|
|
ADD_SUITE(base36);
|
|
|
|
ADD_SUITE(functions);
|
2016-02-13 12:51:50 +01:00
|
|
|
ADD_SUITE(gamedata);
|
2016-09-04 21:27:36 +02:00
|
|
|
ADD_SUITE(language);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(parser);
|
2016-01-13 12:37:07 +01:00
|
|
|
ADD_SUITE(password);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(umlaut);
|
|
|
|
ADD_SUITE(unicode);
|
|
|
|
ADD_SUITE(strings);
|
2016-05-01 13:36:00 +02:00
|
|
|
ADD_SUITE(log);
|
2017-02-24 17:51:35 +01:00
|
|
|
ADD_SUITE(variant);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(rng);
|
|
|
|
/* items */
|
|
|
|
ADD_SUITE(xerewards);
|
|
|
|
/* kernel */
|
2018-01-17 18:04:04 +01:00
|
|
|
ADD_SUITE(academy);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(alliance);
|
2018-01-17 18:04:04 +01:00
|
|
|
ADD_SUITE(ally);
|
|
|
|
ADD_SUITE(building);
|
2016-04-08 19:45:27 +02:00
|
|
|
ADD_SUITE(command);
|
2017-11-09 19:55:28 +01:00
|
|
|
ADD_SUITE(db);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(faction);
|
|
|
|
ADD_SUITE(group);
|
|
|
|
ADD_SUITE(build);
|
|
|
|
ADD_SUITE(curse);
|
|
|
|
ADD_SUITE(equipment);
|
2017-10-05 22:13:39 +02:00
|
|
|
ADD_SUITE(familiar);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(item);
|
|
|
|
ADD_SUITE(magic);
|
2018-01-17 18:04:04 +01:00
|
|
|
ADD_SUITE(magicresistance);
|
|
|
|
ADD_SUITE(messages);
|
|
|
|
ADD_SUITE(plane);
|
|
|
|
ADD_SUITE(pool);
|
2016-09-16 21:17:54 +02:00
|
|
|
ADD_SUITE(reports);
|
2016-10-24 13:47:38 +02:00
|
|
|
ADD_SUITE(region);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(save);
|
|
|
|
ADD_SUITE(ship);
|
2018-01-17 18:04:04 +01:00
|
|
|
ADD_SUITE(skills);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(spellbook);
|
|
|
|
ADD_SUITE(spell);
|
|
|
|
ADD_SUITE(spells);
|
2018-01-17 18:04:04 +01:00
|
|
|
ADD_SUITE(unit);
|
2015-10-14 18:34:41 +02:00
|
|
|
/* gamecode */
|
2018-07-07 17:29:22 +02:00
|
|
|
ADD_SUITE(alchemy);
|
|
|
|
ADD_SUITE(automate);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(battle);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(calendar);
|
|
|
|
ADD_SUITE(creport);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(donations);
|
|
|
|
ADD_SUITE(economy);
|
2015-11-02 17:54:23 +01:00
|
|
|
ADD_SUITE(flyingship);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(give);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(guard);
|
|
|
|
ADD_SUITE(key);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(laws);
|
2016-09-17 12:34:02 +02:00
|
|
|
ADD_SUITE(lighthouse);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(market);
|
2015-11-17 02:07:46 +01:00
|
|
|
ADD_SUITE(monsters);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(move);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(names);
|
2017-10-14 08:43:01 +02:00
|
|
|
ADD_SUITE(orderdb);
|
2017-10-07 20:17:04 +02:00
|
|
|
ADD_SUITE(orderfile);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(otherfaction);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(piracy);
|
2016-11-16 20:03:34 +01:00
|
|
|
ADD_SUITE(prefix);
|
|
|
|
ADD_SUITE(renumber);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(report);
|
|
|
|
ADD_SUITE(shock);
|
|
|
|
ADD_SUITE(spy);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(stealth);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(study);
|
|
|
|
ADD_SUITE(summary);
|
|
|
|
ADD_SUITE(travelthru);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(upkeep);
|
2017-05-07 13:35:59 +02:00
|
|
|
ADD_SUITE(volcano);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(vortex);
|
|
|
|
ADD_SUITE(wormhole);
|
2014-02-18 05:45:00 +01:00
|
|
|
|
2015-10-14 18:34:41 +02:00
|
|
|
if (suites) {
|
2015-10-14 20:04:03 +02:00
|
|
|
CuSuite *summary = CuSuiteNew();
|
2015-10-14 18:34:41 +02:00
|
|
|
int fail_count;
|
2015-10-14 20:04:03 +02:00
|
|
|
game_init();
|
2015-10-14 18:34:41 +02:00
|
|
|
while (suites) {
|
|
|
|
suite *s = suites->next;
|
|
|
|
RunTests(suites->csuite, suites->name);
|
|
|
|
summary->failCount += suites->csuite->failCount;
|
|
|
|
summary->count += suites->csuite->count;
|
|
|
|
CuSuiteDelete(suites->csuite);
|
|
|
|
free(suites->name);
|
|
|
|
free(suites);
|
|
|
|
suites = s;
|
|
|
|
}
|
|
|
|
printf("\ntest summary: %d tests, %d failed\n", summary->count, summary->failCount);
|
|
|
|
fail_count = summary->failCount;
|
|
|
|
CuSuiteDelete(summary);
|
|
|
|
game_done();
|
|
|
|
return fail_count;
|
|
|
|
}
|
|
|
|
return 0;
|
2014-02-18 05:45:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
2015-10-14 18:34:41 +02:00
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
if (argc > 0 && strcmp("--list", argv[0]) == 0) {
|
|
|
|
list = true;
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
}
|
|
|
|
return RunAllTests(argc, argv);
|
2014-02-18 05:45:00 +01:00
|
|
|
}
|