-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.test.c
73 lines (61 loc) · 1.65 KB
/
server.test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <atlantis.h>
#include <region.h>
#include <faction.h>
#include <game.h>
#include <ship.h>
#include <building.h>
#include <unit.h>
#include <rtl.h>
#include "json.h"
#include <stream.h>
#include <memstream.h>
#include <filestream.h>
#include <quicklist.h>
#include <CuTest.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cJSON.h>
static void test_json_report(CuTest * tc) {
region * r;
faction * f;
cJSON * json;
cleargame(true);
turn = 0;
r = create_region(0, 1, 1, create_terrain("plain"));
f = addplayer(r, 0, 0);
update_world(0, 0, 1, 1);
json = json_report(f);
CuAssertIntEquals(tc, turn, cJSON_GetObjectItem(json, "turn")->valueint);
free(json);
}
static void test_json_write(CuTest * tc) {
char buf[256];
cJSON * json = cJSON_CreateObject();
stream strm;
mstream_init(&strm);
cJSON_AddNumberToObject(json, "turn", 1);
json_write(json, &strm);
strm.api->rewind(strm.handle);
strm.api->readln(strm.handle, buf, sizeof(buf));
CuAssertStrEquals(tc, "{", buf);
strm.api->readln(strm.handle, buf, sizeof(buf));
CuAssertStrEquals(tc, "\t\"turn\":\t1", buf);
strm.api->readln(strm.handle, buf, sizeof(buf));
CuAssertStrEquals(tc, "}", buf);
cJSON_Delete(json);
mstream_done(&strm);
}
int main(void)
{
CuString *output = CuStringNew();
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_json_report);
SUITE_ADD_TEST(suite, test_json_write);
CuSuiteRun(suite);
CuSuiteSummary(suite, output);
CuSuiteDetails(suite, output);
printf("%s\n", output->buffer);
return suite->failCount;
}