forked from github/server
make the summary test pass without a leak
This commit is contained in:
parent
a62a14956f
commit
b56d1220b7
2 changed files with 42 additions and 26 deletions
|
@ -79,28 +79,34 @@ int update_nmrs(void)
|
||||||
int i, newplayers = 0;
|
int i, newplayers = 0;
|
||||||
faction *f;
|
faction *f;
|
||||||
int turn = global.data_turn;
|
int turn = global.data_turn;
|
||||||
|
int timeout = NMRTimeout();
|
||||||
|
|
||||||
if (nmrs == NULL)
|
if (timeout>0) {
|
||||||
nmrs = malloc(sizeof(int) * (NMRTimeout() + 1));
|
if (nmrs == NULL) {
|
||||||
for (i = 0; i <= NMRTimeout(); ++i) {
|
nmrs = malloc(sizeof(int) * (timeout + 1));
|
||||||
nmrs[i] = 0;
|
}
|
||||||
|
for (i = 0; i <= timeout; ++i) {
|
||||||
|
nmrs[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (fval(f, FFL_ISNEW)) {
|
if (fval(f, FFL_ISNEW)) {
|
||||||
++newplayers;
|
++newplayers;
|
||||||
}
|
}
|
||||||
else if (!fval(f, FFL_NOIDLEOUT|FFL_CURSED)) {
|
else if (!fval(f, FFL_NOIDLEOUT|FFL_CURSED)) {
|
||||||
int nmr = turn - f->lastorders + 1;
|
int nmr = turn - f->lastorders + 1;
|
||||||
if (nmr < 0 || nmr > NMRTimeout()) {
|
if (timeout>0) {
|
||||||
log_error("faction %s has %d NMR", factionid(f), nmr);
|
if (nmr < 0 || nmr > timeout) {
|
||||||
nmr = _max(0, nmr);
|
log_error("faction %s has %d NMR", factionid(f), nmr);
|
||||||
nmr = _min(nmr, NMRTimeout());
|
nmr = _max(0, nmr);
|
||||||
|
nmr = _min(nmr, timeout);
|
||||||
|
}
|
||||||
|
if (nmr > 0) {
|
||||||
|
log_debug("faction %s has %d NMR", factionid(f), nmr);
|
||||||
|
}
|
||||||
|
++nmrs[nmr];
|
||||||
}
|
}
|
||||||
if (nmr > 0) {
|
|
||||||
log_debug("faction %s has %d NMR", factionid(f), nmr);
|
|
||||||
}
|
|
||||||
++nmrs[nmr];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newplayers;
|
return newplayers;
|
||||||
|
@ -187,6 +193,7 @@ void report_summary(summary * s, summary * o, bool full)
|
||||||
int i, newplayers = 0;
|
int i, newplayers = 0;
|
||||||
faction *f;
|
faction *f;
|
||||||
char zText[MAX_PATH];
|
char zText[MAX_PATH];
|
||||||
|
int timeout = NMRTimeout();
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
join_path(basepath(), "parteien.full", zText, sizeof(zText));
|
join_path(basepath(), "parteien.full", zText, sizeof(zText));
|
||||||
|
@ -303,12 +310,14 @@ void report_summary(summary * s, summary * o, bool full)
|
||||||
|
|
||||||
newplayers = update_nmrs();
|
newplayers = update_nmrs();
|
||||||
|
|
||||||
for (i = 0; i <= NMRTimeout(); ++i) {
|
if (nmrs) {
|
||||||
if (i == NMRTimeout()) {
|
for (i = 0; i <= timeout; ++i) {
|
||||||
fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]);
|
if (i == timeout) {
|
||||||
}
|
fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]);
|
||||||
else {
|
}
|
||||||
fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]);
|
else {
|
||||||
|
fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (age) {
|
if (age) {
|
||||||
|
@ -322,18 +331,18 @@ void report_summary(summary * s, summary * o, bool full)
|
||||||
fprintf(F, "Neue Spieler:\t %d\n", newplayers);
|
fprintf(F, "Neue Spieler:\t %d\n", newplayers);
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
if (factions)
|
if (factions) {
|
||||||
fprintf(F, "\nParteien:\n\n");
|
fprintf(F, "\nParteien:\n\n");
|
||||||
|
for (f = factions; f; f = f->next) {
|
||||||
for (f = factions; f; f = f->next) {
|
out_faction(F, f);
|
||||||
out_faction(F, f);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NMRTimeout() && full) {
|
if (timeout>0 && full) {
|
||||||
fprintf(F, "\n\nFactions with NMRs:\n");
|
fprintf(F, "\n\nFactions with NMRs:\n");
|
||||||
for (i = NMRTimeout(); i > 0; --i) {
|
for (i = timeout; i > 0; --i) {
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (i == NMRTimeout()) {
|
if (i == timeout) {
|
||||||
if (turn - f->lastorders >= i) {
|
if (turn - f->lastorders >= i) {
|
||||||
out_faction(F, f);
|
out_faction(F, f);
|
||||||
}
|
}
|
||||||
|
@ -359,6 +368,11 @@ void report_summary(summary * s, summary * o, bool full)
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_summary(summary *sum) {
|
void free_summary(summary *sum) {
|
||||||
|
while (sum->languages) {
|
||||||
|
struct language *next = sum->languages->next;
|
||||||
|
free(sum->languages);
|
||||||
|
sum->languages = next;
|
||||||
|
}
|
||||||
free(sum);
|
free(sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ static void test_summary(CuTest * tc)
|
||||||
{
|
{
|
||||||
struct summary *sum;
|
struct summary *sum;
|
||||||
test_setup();
|
test_setup();
|
||||||
|
test_create_faction(0);
|
||||||
|
test_create_faction(0);
|
||||||
sum = make_summary();
|
sum = make_summary();
|
||||||
report_summary(sum, sum, true);
|
report_summary(sum, sum, true);
|
||||||
CuAssertIntEquals(tc, 0, remove("parteien.full"));
|
CuAssertIntEquals(tc, 0, remove("parteien.full"));
|
||||||
|
|
Loading…
Reference in a new issue