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>
|
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>
|
|
|
|
|
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;
|
|
|
|
s->name = _strdup(name);
|
|
|
|
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) \
|
2014-12-12 12:17:41 +01:00
|
|
|
CuSuite *get_##name##_suite(void); \
|
2015-10-14 18:34:41 +02:00
|
|
|
if (list) printf("%s\n", #name); \
|
|
|
|
if (!list || argc>0) add_suite(get_##name##_suite, #name, argc, argv)
|
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(callback);
|
|
|
|
ADD_SUITE(seen);
|
|
|
|
ADD_SUITE(json);
|
|
|
|
ADD_SUITE(jsonconf);
|
|
|
|
ADD_SUITE(direction);
|
|
|
|
ADD_SUITE(skill);
|
|
|
|
ADD_SUITE(keyword);
|
|
|
|
ADD_SUITE(order);
|
|
|
|
ADD_SUITE(race);
|
|
|
|
/* util */
|
|
|
|
ADD_SUITE(config);
|
|
|
|
ADD_SUITE(attrib);
|
|
|
|
ADD_SUITE(base36);
|
|
|
|
ADD_SUITE(bsdstring);
|
|
|
|
ADD_SUITE(functions);
|
2016-02-13 12:51:50 +01:00
|
|
|
ADD_SUITE(gamedata);
|
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);
|
|
|
|
ADD_SUITE(rng);
|
|
|
|
/* items */
|
|
|
|
ADD_SUITE(xerewards);
|
|
|
|
/* kernel */
|
|
|
|
ADD_SUITE(alliance);
|
2016-04-08 19:45:27 +02:00
|
|
|
ADD_SUITE(command);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(unit);
|
|
|
|
ADD_SUITE(faction);
|
|
|
|
ADD_SUITE(group);
|
|
|
|
ADD_SUITE(build);
|
|
|
|
ADD_SUITE(pool);
|
|
|
|
ADD_SUITE(curse);
|
|
|
|
ADD_SUITE(equipment);
|
|
|
|
ADD_SUITE(item);
|
|
|
|
ADD_SUITE(magic);
|
|
|
|
ADD_SUITE(alchemy);
|
|
|
|
ADD_SUITE(reports);
|
|
|
|
ADD_SUITE(save);
|
|
|
|
ADD_SUITE(ship);
|
|
|
|
ADD_SUITE(spellbook);
|
|
|
|
ADD_SUITE(building);
|
|
|
|
ADD_SUITE(spell);
|
|
|
|
ADD_SUITE(spells);
|
|
|
|
ADD_SUITE(magicresistance);
|
|
|
|
ADD_SUITE(ally);
|
|
|
|
ADD_SUITE(messages);
|
|
|
|
/* gamecode */
|
|
|
|
ADD_SUITE(prefix);
|
|
|
|
ADD_SUITE(battle);
|
|
|
|
ADD_SUITE(donations);
|
|
|
|
ADD_SUITE(travelthru);
|
|
|
|
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);
|
|
|
|
ADD_SUITE(laws);
|
|
|
|
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);
|
|
|
|
ADD_SUITE(piracy);
|
2016-02-09 06:43:19 +01:00
|
|
|
ADD_SUITE(key);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(stealth);
|
2015-11-09 13:36:52 +01:00
|
|
|
ADD_SUITE(otherfaction);
|
2015-10-14 18:34:41 +02:00
|
|
|
ADD_SUITE(upkeep);
|
|
|
|
ADD_SUITE(vortex);
|
|
|
|
ADD_SUITE(wormhole);
|
|
|
|
ADD_SUITE(spy);
|
|
|
|
ADD_SUITE(study);
|
2015-11-09 19:43:51 +01:00
|
|
|
ADD_SUITE(shock);
|
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) {
|
2016-01-31 19:54:49 +01:00
|
|
|
log_to_file(LOG_CPERROR, stderr);
|
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
|
|
|
}
|