2015-01-12 22:53:21 +01:00
|
|
|
#include <platform.h>
|
2014-08-27 06:40:18 +02:00
|
|
|
#include "reports.h"
|
2016-09-17 15:56:32 +02:00
|
|
|
|
2018-07-13 22:45:17 +02:00
|
|
|
#include "guard.h"
|
2018-09-29 19:32:39 +02:00
|
|
|
#include "util/keyword.h"
|
2017-12-22 11:15:17 +01:00
|
|
|
#include "lighthouse.h"
|
2017-12-23 17:49:30 +01:00
|
|
|
#include "laws.h"
|
2015-08-18 17:08:02 +02:00
|
|
|
#include "move.h"
|
2017-12-22 11:15:17 +01:00
|
|
|
#include "spells.h"
|
2017-03-01 19:54:52 +01:00
|
|
|
#include "spy.h"
|
2015-08-18 18:57:04 +02:00
|
|
|
#include "travelthru.h"
|
2012-05-17 21:23:25 +02:00
|
|
|
|
2018-07-13 22:45:17 +02:00
|
|
|
#include "kernel/ally.h"
|
|
|
|
#include "kernel/calendar.h"
|
|
|
|
#include "kernel/config.h"
|
|
|
|
#include "kernel/building.h"
|
|
|
|
#include "kernel/faction.h"
|
|
|
|
#include "kernel/item.h"
|
|
|
|
#include "kernel/race.h"
|
|
|
|
#include "kernel/region.h"
|
|
|
|
#include "kernel/ship.h"
|
|
|
|
#include "kernel/terrain.h"
|
|
|
|
#include "kernel/unit.h"
|
|
|
|
#include "kernel/spell.h"
|
|
|
|
#include "kernel/spellbook.h"
|
|
|
|
#include "kernel/terrain.h"
|
|
|
|
|
2018-09-29 11:37:17 +02:00
|
|
|
#include "kernel/attrib.h"
|
2018-07-13 22:45:17 +02:00
|
|
|
#include "util/language.h"
|
|
|
|
#include "util/lists.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
|
|
|
|
#include "attributes/attributes.h"
|
|
|
|
#include "attributes/key.h"
|
|
|
|
#include "attributes/otherfaction.h"
|
2017-03-08 18:15:31 +01:00
|
|
|
|
2017-01-26 17:41:21 +01:00
|
|
|
#include <selist.h>
|
2015-05-19 08:26:44 +02:00
|
|
|
#include <stream.h>
|
|
|
|
#include <memstream.h>
|
2014-08-24 23:36:06 +02:00
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-05-17 21:23:25 +02:00
|
|
|
#include <tests.h>
|
|
|
|
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-05-17 21:23:25 +02:00
|
|
|
static void test_reorder_units(CuTest * tc)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
region *r;
|
|
|
|
building *b;
|
|
|
|
ship * s;
|
|
|
|
unit *u0, *u1, *u2, *u3, *u4;
|
|
|
|
struct faction * f;
|
|
|
|
|
2017-03-11 14:22:21 +01:00
|
|
|
test_setup();
|
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
b = test_create_building(r, NULL);
|
|
|
|
s = test_create_ship(r, NULL);
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
u0 = test_create_unit(f, r);
|
|
|
|
u_set_ship(u0, s);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u_set_ship(u1, s);
|
|
|
|
ship_set_owner(u1);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u3 = test_create_unit(f, r);
|
|
|
|
u_set_building(u3, b);
|
|
|
|
u4 = test_create_unit(f, r);
|
|
|
|
u_set_building(u4, b);
|
|
|
|
building_set_owner(u4);
|
|
|
|
|
|
|
|
reorder_units(r);
|
|
|
|
|
|
|
|
CuAssertPtrEquals(tc, u4, r->units);
|
|
|
|
CuAssertPtrEquals(tc, u3, u4->next);
|
|
|
|
CuAssertPtrEquals(tc, u2, u3->next);
|
|
|
|
CuAssertPtrEquals(tc, u1, u2->next);
|
|
|
|
CuAssertPtrEquals(tc, u0, u1->next);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, u0->next);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2012-05-17 21:23:25 +02:00
|
|
|
}
|
|
|
|
|
2012-05-29 08:31:46 +02:00
|
|
|
static void test_regionid(CuTest * tc) {
|
2015-01-30 20:37:14 +01:00
|
|
|
size_t len;
|
|
|
|
const struct terrain_type * plain;
|
|
|
|
struct region * r;
|
|
|
|
char buffer[64];
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2015-01-30 20:37:14 +01:00
|
|
|
plain = test_create_terrain("plain", 0);
|
|
|
|
r = test_create_region(0, 0, plain);
|
|
|
|
|
|
|
|
memset(buffer, 0x7d, sizeof(buffer));
|
|
|
|
len = f_regionid(r, 0, buffer, sizeof(buffer));
|
2015-05-15 20:35:36 +02:00
|
|
|
CuAssertIntEquals(tc, 11, (int)len);
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertStrEquals(tc, "plain (0,0)", buffer);
|
|
|
|
|
|
|
|
memset(buffer, 0x7d, sizeof(buffer));
|
|
|
|
len = f_regionid(r, 0, buffer, 11);
|
2015-05-15 20:35:36 +02:00
|
|
|
CuAssertIntEquals(tc, 10, (int)len);
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertStrEquals(tc, "plain (0,0", buffer);
|
|
|
|
CuAssertIntEquals(tc, 0x7d, buffer[11]);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2012-05-29 08:31:46 +02:00
|
|
|
}
|
|
|
|
|
2014-08-24 23:36:06 +02:00
|
|
|
static void test_seen_faction(CuTest *tc) {
|
|
|
|
faction *f1, *f2;
|
2015-10-13 22:11:45 +02:00
|
|
|
race *rc;
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2015-10-13 22:11:45 +02:00
|
|
|
rc = test_create_race("human");
|
2014-08-24 23:36:06 +02:00
|
|
|
f1 = test_create_faction(rc);
|
|
|
|
f2 = test_create_faction(rc);
|
|
|
|
add_seen_faction(f1, f2);
|
2017-01-26 17:41:21 +01:00
|
|
|
CuAssertPtrEquals(tc, f2, selist_get(f1->seen_factions, 0));
|
|
|
|
CuAssertIntEquals(tc, 1, selist_length(f1->seen_factions));
|
2014-08-24 23:36:06 +02:00
|
|
|
add_seen_faction(f1, f2);
|
2017-01-26 17:41:21 +01:00
|
|
|
CuAssertIntEquals(tc, 1, selist_length(f1->seen_factions));
|
2014-08-24 23:36:06 +02:00
|
|
|
add_seen_faction(f1, f1);
|
2017-01-26 17:41:21 +01:00
|
|
|
CuAssertIntEquals(tc, 2, selist_length(f1->seen_factions));
|
|
|
|
f2 = (faction *)selist_get(f1->seen_factions, 1);
|
|
|
|
f1 = (faction *)selist_get(f1->seen_factions, 0);
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertTrue(tc, f1->no < f2->no);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2014-08-24 23:36:06 +02:00
|
|
|
}
|
|
|
|
|
2015-05-20 18:05:25 +02:00
|
|
|
static void test_sparagraph(CuTest *tc) {
|
|
|
|
strlist *sp = 0;
|
2015-10-13 23:06:33 +02:00
|
|
|
|
2015-05-20 18:05:25 +02:00
|
|
|
split_paragraph(&sp, "Hello World", 0, 16, 0);
|
|
|
|
CuAssertPtrNotNull(tc, sp);
|
|
|
|
CuAssertStrEquals(tc, "Hello World", sp->s);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, sp->next);
|
2015-10-13 23:06:33 +02:00
|
|
|
freestrlist(sp);
|
|
|
|
|
2015-05-20 18:05:25 +02:00
|
|
|
split_paragraph(&sp, "Hello World", 4, 16, 0);
|
|
|
|
CuAssertPtrNotNull(tc, sp);
|
|
|
|
CuAssertStrEquals(tc, " Hello World", sp->s);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, sp->next);
|
2015-10-13 23:06:33 +02:00
|
|
|
freestrlist(sp);
|
|
|
|
|
2015-05-20 18:05:25 +02:00
|
|
|
split_paragraph(&sp, "Hello World", 4, 16, '*');
|
|
|
|
CuAssertPtrNotNull(tc, sp);
|
|
|
|
CuAssertStrEquals(tc, " * Hello World", sp->s);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, sp->next);
|
2015-10-13 23:06:33 +02:00
|
|
|
freestrlist(sp);
|
|
|
|
|
2015-05-20 18:05:25 +02:00
|
|
|
split_paragraph(&sp, "12345678 90 12345678", 0, 8, '*');
|
|
|
|
CuAssertPtrNotNull(tc, sp);
|
|
|
|
CuAssertStrEquals(tc, "12345678", sp->s);
|
|
|
|
CuAssertPtrNotNull(tc, sp->next);
|
|
|
|
CuAssertStrEquals(tc, "90", sp->next->s);
|
|
|
|
CuAssertPtrNotNull(tc, sp->next->next);
|
|
|
|
CuAssertStrEquals(tc, "12345678", sp->next->next->s);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, sp->next->next->next);
|
2015-10-13 22:21:05 +02:00
|
|
|
freestrlist(sp);
|
2015-05-20 18:05:25 +02:00
|
|
|
}
|
|
|
|
|
2017-09-04 20:08:34 +02:00
|
|
|
static void test_sparagraph_long(CuTest *tc) {
|
|
|
|
strlist *sp = 0;
|
|
|
|
|
|
|
|
split_paragraph(&sp, "HelloWorld HelloWorld", 0, 16, 0);
|
|
|
|
CuAssertPtrNotNull(tc, sp);
|
|
|
|
CuAssertStrEquals(tc, "HelloWorld", sp->s);
|
|
|
|
CuAssertStrEquals(tc, "HelloWorld", sp->next->s);
|
|
|
|
CuAssertPtrEquals(tc, NULL, sp->next->next);
|
|
|
|
freestrlist(sp);
|
|
|
|
|
|
|
|
split_paragraph(&sp, "HelloWorldHelloWorld", 0, 16, 0);
|
|
|
|
CuAssertPtrNotNull(tc, sp);
|
|
|
|
CuAssertStrEquals(tc, "HelloWorldHelloWorld", sp->s);
|
|
|
|
CuAssertPtrEquals(tc, NULL, sp->next);
|
|
|
|
freestrlist(sp);
|
|
|
|
}
|
|
|
|
|
2017-03-08 20:15:41 +01:00
|
|
|
static void test_bufunit_fstealth(CuTest *tc) {
|
2017-03-08 18:15:31 +01:00
|
|
|
faction *f1, *f2;
|
|
|
|
region *r;
|
2017-03-08 20:15:41 +01:00
|
|
|
unit *u;
|
2017-03-08 18:15:31 +01:00
|
|
|
ally *al;
|
2017-03-08 20:15:41 +01:00
|
|
|
char buf[256];
|
|
|
|
struct locale *lang;
|
2017-03-08 18:15:31 +01:00
|
|
|
|
|
|
|
test_setup();
|
2017-03-08 20:15:41 +01:00
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
locale_setstring(lang, "status_aggressive", "aggressive");
|
|
|
|
locale_setstring(lang, "anonymous", "anonymous");
|
2018-01-14 09:38:26 +01:00
|
|
|
f1 = test_create_faction(NULL);
|
2017-03-08 20:15:41 +01:00
|
|
|
f1->locale = lang;
|
2018-01-14 09:38:26 +01:00
|
|
|
f2 = test_create_faction(NULL);
|
2017-03-08 20:15:41 +01:00
|
|
|
f2->locale = lang;
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2017-03-08 18:15:31 +01:00
|
|
|
u = test_create_unit(f1, r);
|
2017-03-08 20:15:41 +01:00
|
|
|
faction_setname(f1, "UFO");
|
|
|
|
renumber_faction(f1, 1);
|
|
|
|
faction_setname(f2, "TWW");
|
|
|
|
renumber_faction(f2, 2);
|
2017-03-08 18:15:31 +01:00
|
|
|
unit_setname(u, "Hodor");
|
|
|
|
unit_setid(u, 1);
|
|
|
|
key_set(&u->attribs, 42, 42);
|
|
|
|
|
2017-03-08 20:15:41 +01:00
|
|
|
/* report to ourselves */
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f1, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 18:15:31 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressive.", buf);
|
|
|
|
|
2017-03-08 20:15:41 +01:00
|
|
|
/* ... also when we are anonymous */
|
|
|
|
u->flags |= UFL_ANON_FACTION;
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f1, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf);
|
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
|
|
|
|
|
|
|
/* we see that our unit is cloaked */
|
|
|
|
set_factionstealth(u, f2);
|
|
|
|
CuAssertPtrNotNull(tc, u->attribs);
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f1, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human, aggressive.", buf);
|
|
|
|
|
|
|
|
/* ... also when we are anonymous */
|
|
|
|
u->flags |= UFL_ANON_FACTION;
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f1, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf);
|
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
|
|
|
|
|
|
|
/* we can see that someone is presenting as us */
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human.", buf);
|
2017-03-08 18:15:31 +01:00
|
|
|
|
2017-03-08 20:15:41 +01:00
|
|
|
/* ... but not if they are anonymous */
|
|
|
|
u->flags |= UFL_ANON_FACTION;
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
|
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
|
|
|
|
|
|
|
/* we see the same thing as them when we are an ally */
|
2017-03-08 18:15:31 +01:00
|
|
|
al = ally_add(&f1->allies, f2);
|
|
|
|
al->status = HELP_FSTEALTH;
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf);
|
2017-03-08 18:15:31 +01:00
|
|
|
|
2017-03-08 20:15:41 +01:00
|
|
|
/* ... also when they are anonymous */
|
|
|
|
u->flags |= UFL_ANON_FACTION;
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
|
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
|
|
|
|
|
|
|
/* fstealth has no influence when we are allies, same results again */
|
|
|
|
set_factionstealth(u, NULL);
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:30:32 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buf);
|
2017-03-08 20:15:41 +01:00
|
|
|
|
|
|
|
u->flags |= UFL_ANON_FACTION;
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f2, u, seen_unit, buf, sizeof(buf));
|
2017-03-08 20:15:41 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
|
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
2017-03-08 18:15:31 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-03-08 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 20:15:41 +01:00
|
|
|
static void test_bufunit(CuTest *tc) {
|
2015-08-26 21:19:14 +02:00
|
|
|
unit *u;
|
|
|
|
faction *f;
|
|
|
|
race *rc;
|
|
|
|
struct locale *lang;
|
2017-03-08 20:15:41 +01:00
|
|
|
char buffer[256];
|
2015-08-26 21:19:14 +02:00
|
|
|
|
2017-03-08 18:15:31 +01:00
|
|
|
test_setup();
|
2015-08-26 21:19:14 +02:00
|
|
|
rc = rc_get_or_create("human");
|
|
|
|
rc->bonus[SK_ALCHEMY] = 1;
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
locale_setstring(lang, "nr_skills", "Talente");
|
|
|
|
locale_setstring(lang, "skill::sailing", "Segeln");
|
|
|
|
locale_setstring(lang, "skill::alchemy", "Alchemie");
|
2016-02-01 14:06:56 +01:00
|
|
|
locale_setstring(lang, "status_aggressive", "aggressiv");
|
2015-08-26 21:19:14 +02:00
|
|
|
init_skills(lang);
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
2015-08-26 21:19:14 +02:00
|
|
|
u->faction->locale = lang;
|
|
|
|
faction_setname(u->faction, "UFO");
|
|
|
|
renumber_faction(u->faction, 1);
|
|
|
|
unit_setname(u, "Hodor");
|
|
|
|
unit_setid(u, 1);
|
|
|
|
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(u->faction, u, 0, buffer, sizeof(buffer));
|
2016-02-01 14:06:56 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressiv.", buffer);
|
2015-08-26 21:19:14 +02:00
|
|
|
|
2017-09-15 21:52:20 +02:00
|
|
|
set_level(u, SK_ALCHEMY, 1);
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(u->faction, u, 0, buffer, sizeof(buffer));
|
2017-09-15 21:52:20 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressiv, Talente: Alchemie 2.", buffer);
|
2015-08-26 21:19:14 +02:00
|
|
|
|
2017-09-15 21:52:20 +02:00
|
|
|
set_level(u, SK_SAILING, 1);
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(u->faction, u, 0, buffer, sizeof(buffer));
|
2017-09-15 21:52:20 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressiv, Talente: Alchemie 2, Segeln 1.", buffer);
|
2015-08-26 21:19:14 +02:00
|
|
|
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2015-08-26 21:19:14 +02:00
|
|
|
f->locale = get_or_create_locale("de");
|
2018-02-24 19:46:34 +01:00
|
|
|
bufunit(f, u, 0, buffer, sizeof(buffer));
|
2015-08-26 21:19:14 +02:00
|
|
|
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buffer);
|
2017-03-08 20:15:41 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-26 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 18:31:09 +02:00
|
|
|
static void test_arg_resources(CuTest *tc) {
|
|
|
|
variant v1, v2;
|
|
|
|
arg_type *atype;
|
|
|
|
resource *res;
|
|
|
|
item_type *itype;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
itype = test_create_itemtype("stone");
|
|
|
|
v1.v = res = malloc(sizeof(resource)*2);
|
|
|
|
res[0].number = 10;
|
|
|
|
res[0].type = itype->rtype;
|
|
|
|
res[0].next = &res[1];
|
|
|
|
res[1].number = 5;
|
|
|
|
res[1].type = itype->rtype;
|
|
|
|
res[1].next = NULL;
|
|
|
|
|
|
|
|
register_reports();
|
2016-08-29 19:15:20 +02:00
|
|
|
atype = find_argtype("resources");
|
2016-08-29 18:31:09 +02:00
|
|
|
CuAssertPtrNotNull(tc, atype);
|
|
|
|
v2 = atype->copy(v1);
|
|
|
|
free(v1.v);
|
|
|
|
CuAssertPtrNotNull(tc, v2.v);
|
|
|
|
res = (resource *)v2.v;
|
|
|
|
CuAssertPtrEquals(tc, itype->rtype, (void *)res->type);
|
|
|
|
CuAssertIntEquals(tc, 10, res->number);
|
|
|
|
CuAssertPtrNotNull(tc, res = res->next);
|
|
|
|
CuAssertPtrEquals(tc, itype->rtype, (void *)res->type);
|
|
|
|
CuAssertIntEquals(tc, 5, res->number);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, res->next);
|
2016-08-29 18:31:09 +02:00
|
|
|
atype->release(v2);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-08-29 18:31:09 +02:00
|
|
|
}
|
|
|
|
|
2017-01-22 12:38:41 +01:00
|
|
|
static void test_newbie_password_message(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f;
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2017-01-22 12:38:41 +01:00
|
|
|
f->age = 5;
|
2017-01-22 18:51:20 +01:00
|
|
|
f->flags = 0;
|
2017-01-22 12:38:41 +01:00
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd"));
|
2017-01-22 12:38:41 +01:00
|
|
|
f->age=2;
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG);
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-01-22 12:38:41 +01:00
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:40 +02:00
|
|
|
static void test_prepare_travelthru(CuTest *tc) {
|
|
|
|
report_context ctx;
|
2016-09-16 21:17:54 +02:00
|
|
|
faction *f, *f2;
|
2016-09-16 17:25:40 +02:00
|
|
|
region *r1, *r2, *r3;
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
|
|
|
r1 = test_create_region(0, 0, NULL);
|
2016-09-16 17:25:40 +02:00
|
|
|
r2 = test_create_region(1, 0, 0);
|
2016-09-18 13:27:25 +02:00
|
|
|
r3 = test_create_region(3, 0, 0);
|
2016-09-16 21:26:17 +02:00
|
|
|
test_create_unit(f2, r1);
|
|
|
|
test_create_unit(f2, r3);
|
2016-09-16 17:25:40 +02:00
|
|
|
u = test_create_unit(f, r1);
|
|
|
|
travelthru_add(r2, u);
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, r3, ctx.last);
|
2016-09-16 21:17:54 +02:00
|
|
|
CuAssertPtrEquals(tc, f, ctx.f);
|
2016-09-16 17:25:40 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_travel, r2->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_none, r3->seen.mode);
|
2016-09-16 21:17:54 +02:00
|
|
|
finish_reports(&ctx);
|
|
|
|
CuAssertIntEquals(tc, seen_none, r2->seen.mode);
|
|
|
|
|
|
|
|
prepare_report(&ctx, f2);
|
2016-09-18 13:27:25 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_unit, r3->seen.mode);
|
2016-09-16 21:17:54 +02:00
|
|
|
CuAssertPtrEquals(tc, f2, ctx.f);
|
2016-09-16 21:26:17 +02:00
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2016-09-16 21:17:54 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-16 17:25:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 19:52:23 +01:00
|
|
|
static void test_get_addresses(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f, *f2, *f1;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2017-03-01 19:52:23 +01:00
|
|
|
test_create_unit(f, r);
|
|
|
|
test_create_unit(f1, r);
|
|
|
|
test_create_unit(f2, r);
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
|
|
|
get_addresses(&ctx);
|
|
|
|
CuAssertPtrNotNull(tc, ctx.addresses);
|
2017-03-01 20:37:49 +01:00
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f, NULL));
|
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f1, NULL));
|
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f2, NULL));
|
2017-03-01 19:52:23 +01:00
|
|
|
CuAssertIntEquals(tc, 3, selist_length(ctx.addresses));
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-03-01 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_get_addresses_fstealth(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f, *f2, *f1;
|
|
|
|
region *r;
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2017-03-01 19:54:52 +01:00
|
|
|
test_create_unit(f, r);
|
2017-03-01 21:10:50 +01:00
|
|
|
u = test_create_unit(f1, r);
|
|
|
|
set_factionstealth(u, f2);
|
2017-03-01 19:54:52 +01:00
|
|
|
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
|
|
|
get_addresses(&ctx);
|
|
|
|
CuAssertPtrNotNull(tc, ctx.addresses);
|
2017-03-01 20:37:49 +01:00
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f, NULL));
|
2017-03-01 21:10:50 +01:00
|
|
|
CuAssertTrue(tc, !selist_contains(ctx.addresses, f1, NULL));
|
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f2, NULL));
|
|
|
|
CuAssertIntEquals(tc, 2, selist_length(ctx.addresses));
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-03-01 21:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_get_addresses_travelthru(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f, *f2, *f1;
|
|
|
|
region *r1, *r2;
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
|
|
|
r1 = test_create_region(0, 0, NULL);
|
2017-03-01 21:10:50 +01:00
|
|
|
r2 = test_create_region(1, 0, 0);
|
|
|
|
u = test_create_unit(f, r2);
|
|
|
|
travelthru_add(r1, u);
|
|
|
|
u = test_create_unit(f1, r1);
|
|
|
|
set_factionstealth(u, f2);
|
|
|
|
u->building = test_create_building(u->region, test_create_buildingtype("tower"));
|
|
|
|
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
|
|
|
get_addresses(&ctx);
|
|
|
|
CuAssertPtrNotNull(tc, ctx.addresses);
|
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f, NULL));
|
|
|
|
CuAssertTrue(tc, !selist_contains(ctx.addresses, f1, NULL));
|
|
|
|
CuAssertTrue(tc, selist_contains(ctx.addresses, f2, NULL));
|
2017-03-01 20:37:49 +01:00
|
|
|
CuAssertIntEquals(tc, 2, selist_length(ctx.addresses));
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-03-01 19:52:23 +01:00
|
|
|
}
|
|
|
|
|
2016-09-17 15:56:32 +02:00
|
|
|
void test_prepare_lighthouse_capacity(CuTest *tc) {
|
2016-09-17 14:54:39 +02:00
|
|
|
building *b;
|
|
|
|
building_type *btype;
|
2016-09-17 15:56:32 +02:00
|
|
|
unit *u1, *u2;
|
2016-09-17 14:54:39 +02:00
|
|
|
region *r1, *r2;
|
|
|
|
faction *f;
|
|
|
|
const struct terrain_type *t_ocean, *t_plain;
|
2016-09-17 15:56:32 +02:00
|
|
|
report_context ctx;
|
2016-09-17 14:54:39 +02:00
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2016-09-17 14:54:39 +02:00
|
|
|
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
t_plain = test_create_terrain("plain", LAND_REGION);
|
|
|
|
btype = test_create_buildingtype("lighthouse");
|
|
|
|
btype->maxcapacity = 4;
|
2016-09-17 15:29:28 +02:00
|
|
|
r1 = test_create_region(0, 0, t_plain);
|
|
|
|
r2 = test_create_region(1, 0, t_ocean);
|
2016-09-17 14:54:39 +02:00
|
|
|
b = test_create_building(r1, btype);
|
2016-09-17 15:29:28 +02:00
|
|
|
b->flags |= BLD_MAINTAINED;
|
2016-09-17 14:54:39 +02:00
|
|
|
b->size = 10;
|
|
|
|
update_lighthouse(b);
|
2018-01-14 09:38:26 +01:00
|
|
|
u1 = test_create_unit(test_create_faction(NULL), r1);
|
2016-09-17 15:56:32 +02:00
|
|
|
u1->number = 4;
|
|
|
|
u1->building = b;
|
|
|
|
set_level(u1, SK_PERCEPTION, 3);
|
2018-07-18 20:49:17 +02:00
|
|
|
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u1));
|
2016-09-17 15:56:32 +02:00
|
|
|
CuAssertPtrEquals(tc, b, inside_building(u1));
|
|
|
|
u2 = test_create_unit(f, r1);
|
|
|
|
u2->building = b;
|
|
|
|
set_level(u2, SK_PERCEPTION, 3);
|
|
|
|
CuAssertPtrEquals(tc, NULL, inside_building(u2));
|
|
|
|
prepare_report(&ctx, u1->faction);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-18 13:27:25 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
|
2016-09-17 15:56:32 +02:00
|
|
|
finish_reports(&ctx);
|
2016-09-18 13:27:25 +02:00
|
|
|
|
2016-09-17 15:56:32 +02:00
|
|
|
prepare_report(&ctx, u2->faction);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-18 13:27:25 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
|
2016-09-17 15:56:32 +02:00
|
|
|
finish_reports(&ctx);
|
2016-09-18 13:27:25 +02:00
|
|
|
|
2017-07-17 17:22:01 +02:00
|
|
|
/* lighthouse capacity is # of units, not people: */
|
2017-07-17 17:08:27 +02:00
|
|
|
config_set_int("rules.lighthouse.unit_capacity", 1);
|
|
|
|
prepare_report(&ctx, u2->faction);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2017-07-17 17:08:27 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
|
|
|
|
finish_reports(&ctx);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-17 15:56:32 +02:00
|
|
|
}
|
|
|
|
|
2016-09-15 13:01:08 +02:00
|
|
|
static void test_prepare_lighthouse(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f;
|
2018-07-17 20:53:34 +02:00
|
|
|
region *r1, *r2, *r3, *r4;
|
2016-09-15 13:01:08 +02:00
|
|
|
unit *u;
|
|
|
|
building *b;
|
|
|
|
building_type *btype;
|
2016-09-17 13:20:02 +02:00
|
|
|
const struct terrain_type *t_ocean, *t_plain;
|
2016-09-15 13:01:08 +02:00
|
|
|
|
|
|
|
test_setup();
|
2016-09-17 13:20:02 +02:00
|
|
|
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
t_plain = test_create_terrain("plain", LAND_REGION);
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2016-09-17 13:20:02 +02:00
|
|
|
r1 = test_create_region(0, 0, t_plain);
|
|
|
|
r2 = test_create_region(1, 0, t_ocean);
|
|
|
|
r3 = test_create_region(2, 0, t_ocean);
|
2018-07-17 20:53:34 +02:00
|
|
|
r4 = test_create_region(0, 1, t_plain);
|
2016-09-15 13:01:08 +02:00
|
|
|
btype = test_create_buildingtype("lighthouse");
|
|
|
|
b = test_create_building(r1, btype);
|
2016-09-17 13:20:02 +02:00
|
|
|
b->flags |= BLD_MAINTAINED;
|
2016-09-15 13:01:08 +02:00
|
|
|
b->size = 10;
|
2016-09-17 13:20:02 +02:00
|
|
|
update_lighthouse(b);
|
2016-09-15 13:01:08 +02:00
|
|
|
u = test_create_unit(f, r1);
|
|
|
|
u->building = b;
|
2016-09-17 13:20:02 +02:00
|
|
|
set_level(u, SK_PERCEPTION, 3);
|
2016-09-15 13:01:08 +02:00
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2016-09-17 13:20:02 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-15 13:01:08 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
|
2016-09-17 13:20:02 +02:00
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode);
|
2018-07-17 20:53:34 +02:00
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r4->seen.mode);
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-15 13:01:08 +02:00
|
|
|
}
|
|
|
|
|
2017-05-21 21:33:29 +02:00
|
|
|
/**
|
|
|
|
* In E3, region owners get the view range benefit of
|
|
|
|
* any lighthouse in the region.
|
|
|
|
*/
|
|
|
|
static void test_prepare_lighthouse_owners(CuTest *tc)
|
|
|
|
{
|
2016-10-05 20:36:01 +02:00
|
|
|
report_context ctx;
|
|
|
|
faction *f;
|
|
|
|
region *r1, *r2, *r3;
|
|
|
|
unit *u;
|
|
|
|
building *b;
|
|
|
|
building_type *btype;
|
|
|
|
const struct terrain_type *t_ocean, *t_plain;
|
|
|
|
|
|
|
|
test_setup();
|
2017-05-22 19:50:18 +02:00
|
|
|
enable_skill(SK_PERCEPTION, false);
|
2016-10-05 20:36:01 +02:00
|
|
|
config_set("rules.region_owner_pay_building", "lighthouse");
|
|
|
|
config_set("rules.region_owners", "1");
|
|
|
|
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
t_plain = test_create_terrain("plain", LAND_REGION);
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2016-10-05 20:36:01 +02:00
|
|
|
r1 = test_create_region(0, 0, t_plain);
|
|
|
|
r2 = test_create_region(1, 0, t_ocean);
|
|
|
|
r3 = test_create_region(2, 0, t_ocean);
|
2017-05-22 19:50:18 +02:00
|
|
|
r3 = test_create_region(3, 0, t_ocean);
|
2016-10-05 20:36:01 +02:00
|
|
|
btype = test_create_buildingtype("lighthouse");
|
|
|
|
b = test_create_building(r1, btype);
|
|
|
|
b->flags |= BLD_MAINTAINED;
|
|
|
|
b->size = 10;
|
|
|
|
update_lighthouse(b);
|
|
|
|
u = test_create_unit(f, r1);
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), r1);
|
2016-10-05 20:36:01 +02:00
|
|
|
u->building = b;
|
|
|
|
region_set_owner(b->region, f, 0);
|
2018-07-18 20:49:17 +02:00
|
|
|
CuAssertIntEquals(tc, 2, lighthouse_view_distance(b, NULL));
|
2016-10-05 20:36:01 +02:00
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode);
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-10-05 20:36:01 +02:00
|
|
|
}
|
|
|
|
|
2016-09-14 21:46:57 +02:00
|
|
|
static void test_prepare_report(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-09-14 21:46:57 +02:00
|
|
|
|
|
|
|
prepare_report(&ctx, f);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-14 21:46:57 +02:00
|
|
|
CuAssertIntEquals(tc, seen_none, r->seen.mode);
|
|
|
|
finish_reports(&ctx);
|
|
|
|
|
2016-09-15 10:02:49 +02:00
|
|
|
test_create_unit(f, r);
|
2016-09-14 21:46:57 +02:00
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r, ctx.first);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-14 21:46:57 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r->seen.mode);
|
|
|
|
finish_reports(&ctx);
|
|
|
|
CuAssertIntEquals(tc, seen_none, r->seen.mode);
|
2016-09-17 15:56:32 +02:00
|
|
|
|
2016-09-18 13:27:25 +02:00
|
|
|
r = test_create_region(2, 0, 0);
|
2016-09-15 10:02:49 +02:00
|
|
|
CuAssertPtrEquals(tc, r, regions->next);
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, regions, ctx.first);
|
|
|
|
CuAssertPtrEquals(tc, r, ctx.last);
|
2016-09-17 13:20:02 +02:00
|
|
|
CuAssertIntEquals(tc, seen_none, r->seen.mode);
|
2017-03-30 23:13:55 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-14 21:46:57 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 13:08:53 +02:00
|
|
|
static void test_seen_neighbours(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f;
|
|
|
|
region *r1, *r2;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r1 = test_create_region(0, 0, NULL);
|
2016-09-18 13:08:53 +02:00
|
|
|
r2 = test_create_region(1, 0, 0);
|
|
|
|
|
|
|
|
test_create_unit(f, r1);
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-18 13:08:53 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
|
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-18 13:08:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_seen_travelthru(CuTest *tc) {
|
|
|
|
report_context ctx;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
region *r1, *r2, *r3;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r1 = test_create_region(0, 0, NULL);
|
2016-09-18 13:08:53 +02:00
|
|
|
r2 = test_create_region(1, 0, 0);
|
|
|
|
r3 = test_create_region(2, 0, 0);
|
|
|
|
|
|
|
|
u = test_create_unit(f, r1);
|
2016-09-20 15:53:55 +02:00
|
|
|
CuAssertPtrEquals(tc, r1, f->first);
|
|
|
|
CuAssertPtrEquals(tc, r1, f->last);
|
2016-09-18 13:08:53 +02:00
|
|
|
travelthru_add(r2, u);
|
2016-09-20 15:53:55 +02:00
|
|
|
CuAssertPtrEquals(tc, r1, f->first);
|
|
|
|
CuAssertPtrEquals(tc, r3, f->last);
|
2016-09-18 13:08:53 +02:00
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-18 13:08:53 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_travel, r2->seen.mode);
|
|
|
|
CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode);
|
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-18 13:08:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 11:20:33 +02:00
|
|
|
static void test_region_distance_max(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
region *result[64];
|
|
|
|
int x, y;
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-09-24 11:20:33 +02:00
|
|
|
for (x=-3;x<=3;++x) {
|
|
|
|
for (y = -3; y <= 3; ++y) {
|
|
|
|
if (x != 0 || y != 0) {
|
|
|
|
test_create_region(x, y, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CuAssertIntEquals(tc, 1, get_regions_distance_arr(r, 0, result, 64));
|
|
|
|
CuAssertIntEquals(tc, 7, get_regions_distance_arr(r, 1, result, 64));
|
|
|
|
CuAssertIntEquals(tc, 19, get_regions_distance_arr(r, 2, result, 64));
|
|
|
|
CuAssertIntEquals(tc, 37, get_regions_distance_arr(r, 3, result, 64));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-24 11:20:33 +02:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:51:33 +02:00
|
|
|
static void test_region_distance(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
region *result[8];
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-09-23 19:51:33 +02:00
|
|
|
CuAssertIntEquals(tc, 1, get_regions_distance_arr(r, 0, result, 8));
|
|
|
|
CuAssertPtrEquals(tc, r, result[0]);
|
|
|
|
CuAssertIntEquals(tc, 1, get_regions_distance_arr(r, 1, result, 8));
|
|
|
|
test_create_region(1, 0, 0);
|
|
|
|
test_create_region(0, 1, 0);
|
|
|
|
CuAssertIntEquals(tc, 1, get_regions_distance_arr(r, 0, result, 8));
|
|
|
|
CuAssertIntEquals(tc, 3, get_regions_distance_arr(r, 1, result, 8));
|
|
|
|
CuAssertIntEquals(tc, 3, get_regions_distance_arr(r, 2, result, 8));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-23 19:51:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_region_distance_ql(CuTest *tc) {
|
|
|
|
region *r;
|
2017-03-11 16:08:14 +01:00
|
|
|
selist *ql;
|
2016-09-23 19:51:33 +02:00
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-09-23 19:51:33 +02:00
|
|
|
ql = get_regions_distance(r, 0);
|
2017-03-11 16:08:14 +01:00
|
|
|
CuAssertIntEquals(tc, 1, selist_length(ql));
|
|
|
|
CuAssertPtrEquals(tc, r, selist_get(ql, 0));
|
|
|
|
selist_free(ql);
|
2016-09-23 19:51:33 +02:00
|
|
|
test_create_region(1, 0, 0);
|
|
|
|
test_create_region(0, 1, 0);
|
|
|
|
ql = get_regions_distance(r, 1);
|
2017-03-11 16:08:14 +01:00
|
|
|
CuAssertIntEquals(tc, 3, selist_length(ql));
|
|
|
|
selist_free(ql);
|
2016-09-23 19:51:33 +02:00
|
|
|
ql = get_regions_distance(r, 2);
|
2017-03-11 16:08:14 +01:00
|
|
|
CuAssertIntEquals(tc, 3, selist_length(ql));
|
|
|
|
selist_free(ql);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-23 19:51:33 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 20:31:31 +02:00
|
|
|
static void test_report_far_vision(CuTest *tc) {
|
|
|
|
faction *f;
|
|
|
|
region *r1, *r2;
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r1 = test_create_region(0, 0, NULL);
|
2017-05-21 23:47:54 +02:00
|
|
|
test_create_unit(f, r1);
|
2016-09-24 20:31:31 +02:00
|
|
|
r2 = test_create_region(10, 0, 0);
|
2017-05-24 08:18:55 +02:00
|
|
|
set_observer(r2, f, 10, 2);
|
2016-09-24 21:09:15 +02:00
|
|
|
CuAssertPtrEquals(tc, r1, f->first);
|
|
|
|
CuAssertPtrEquals(tc, r2, f->last);
|
2016-09-24 20:31:31 +02:00
|
|
|
report_context ctx;
|
|
|
|
prepare_report(&ctx, f);
|
|
|
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
2016-09-24 20:31:31 +02:00
|
|
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
2016-09-25 13:01:51 +02:00
|
|
|
CuAssertIntEquals(tc, seen_spell, r2->seen.mode);
|
2016-09-24 20:31:31 +02:00
|
|
|
finish_reports(&ctx);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-24 20:31:31 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 20:09:39 +02:00
|
|
|
static void test_stealth_modifier(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
r = test_create_region(0, 0, NULL);
|
|
|
|
CuAssertIntEquals(tc, 0, stealth_modifier(r, f, seen_unit));
|
|
|
|
CuAssertIntEquals(tc, -1, stealth_modifier(r, f, seen_travel));
|
|
|
|
CuAssertIntEquals(tc, -2, stealth_modifier(r, f, seen_lighthouse));
|
|
|
|
CuAssertIntEquals(tc, -1, stealth_modifier(r, f, seen_spell));
|
|
|
|
|
|
|
|
set_observer(r, f, 10, 1);
|
|
|
|
CuAssertIntEquals(tc, 10, stealth_modifier(r, f, seen_spell));
|
|
|
|
CuAssertIntEquals(tc, -1, stealth_modifier(r, NULL, seen_spell));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-10 20:09:39 +02:00
|
|
|
}
|
|
|
|
|
2017-12-22 11:15:17 +01:00
|
|
|
static void test_insect_warnings(CuTest *tc) {
|
|
|
|
faction *f;
|
|
|
|
gamedate gd;
|
|
|
|
|
|
|
|
test_setup();
|
2018-08-02 14:31:00 +02:00
|
|
|
test_create_calendar();
|
2018-01-14 17:08:46 +01:00
|
|
|
test_inject_messagetypes();
|
2017-12-22 11:15:17 +01:00
|
|
|
f = test_create_faction(test_create_race("insect"));
|
|
|
|
|
2018-08-02 13:53:41 +02:00
|
|
|
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
|
|
|
|
report_warnings(f, gd.turn);
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectfall"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
|
|
|
|
test_clear_messages(f);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1082, &gd)->season);
|
|
|
|
report_warnings(f, gd.turn);
|
2017-12-22 11:15:17 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectfall"));
|
2018-08-02 13:53:41 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectwinter"));
|
|
|
|
test_clear_messages(f);
|
2017-12-22 11:15:17 +01:00
|
|
|
|
2018-08-02 13:53:41 +02:00
|
|
|
CuAssertIntEquals(tc, SEASON_WINTER, get_gamedate(1084, &gd)->season);
|
|
|
|
report_warnings(f, gd.turn);
|
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectfall"));
|
2017-12-22 11:15:17 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
|
2018-08-02 13:53:41 +02:00
|
|
|
test_clear_messages(f);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-12-22 11:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_newbie_warning(CuTest *tc) {
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 17:08:46 +01:00
|
|
|
test_inject_messagetypes();
|
2018-08-02 13:53:41 +02:00
|
|
|
f = test_create_faction(NULL);
|
2017-12-22 11:15:17 +01:00
|
|
|
config_set_int("NewbieImmunity", 3);
|
|
|
|
|
|
|
|
f->age = 2;
|
2018-08-02 13:53:41 +02:00
|
|
|
report_warnings(f, 0);
|
2017-12-22 11:15:17 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "newbieimmunity"));
|
|
|
|
test_clear_messages(f);
|
|
|
|
|
|
|
|
f->age = 3;
|
2018-08-02 13:53:41 +02:00
|
|
|
report_warnings(f, 0);
|
2017-12-22 11:15:17 +01:00
|
|
|
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "newbieimmunity"));
|
|
|
|
test_clear_messages(f);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-12-22 11:15:17 +01:00
|
|
|
}
|
|
|
|
|
2018-03-11 14:40:38 +01:00
|
|
|
static void test_visible_unit(CuTest *tc) {
|
2018-07-13 22:45:17 +02:00
|
|
|
unit *u;
|
2017-12-23 17:49:30 +01:00
|
|
|
faction *f;
|
2018-03-11 14:40:38 +01:00
|
|
|
ship *sh;
|
2018-07-13 22:45:17 +02:00
|
|
|
building *b;
|
|
|
|
race *rc;
|
2017-12-23 17:49:30 +01:00
|
|
|
|
|
|
|
test_setup();
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2018-07-13 22:45:17 +02:00
|
|
|
rc = test_create_race("smurf");
|
|
|
|
rc->flags |= RCF_UNARMEDGUARD;
|
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
|
|
|
|
|
|
|
CuAssertTrue(tc, cansee(f, u->region, u, 0));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, 0, seen_unit));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, 0, seen_spell));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, 0, seen_battle));
|
|
|
|
CuAssertTrue(tc, !visible_unit(u, f, 0, seen_travel));
|
|
|
|
CuAssertTrue(tc, !visible_unit(u, f, 0, seen_none));
|
|
|
|
CuAssertTrue(tc, !visible_unit(u, f, 0, seen_neighbour));
|
|
|
|
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, 0, seen_lighthouse));
|
|
|
|
CuAssertTrue(tc, !visible_unit(u, f, -2, seen_lighthouse));
|
|
|
|
|
|
|
|
u->ship = sh = test_create_ship(u->region, NULL);
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse));
|
|
|
|
u->ship = NULL;
|
|
|
|
|
|
|
|
setguard(u, true);
|
|
|
|
CuAssertTrue(tc, is_guard(u));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse));
|
|
|
|
setguard(u, false);
|
|
|
|
|
|
|
|
u->building = b = test_create_building(u->region, NULL);
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse));
|
|
|
|
u->building = NULL;
|
|
|
|
|
|
|
|
set_level(u, SK_STEALTH, 1);
|
|
|
|
CuAssertTrue(tc, !cansee(f, u->region, u, 0));
|
|
|
|
CuAssertTrue(tc, cansee(f, u->region, u, 1));
|
|
|
|
|
|
|
|
u->ship = sh;
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel));
|
|
|
|
u->ship = NULL;
|
|
|
|
|
|
|
|
u->building = b;
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel));
|
|
|
|
u->building = NULL;
|
|
|
|
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, 1, seen_spell));
|
|
|
|
CuAssertTrue(tc, visible_unit(u, f, 1, seen_battle));
|
2017-12-23 17:49:30 +01:00
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-12-23 17:49:30 +01:00
|
|
|
}
|
|
|
|
|
2012-05-17 21:23:25 +02:00
|
|
|
CuSuite *get_reports_suite(void)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
2016-09-23 19:51:33 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_region_distance);
|
2016-09-24 11:20:33 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_region_distance_max);
|
2016-09-23 19:51:33 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_region_distance_ql);
|
2018-10-24 09:27:48 +02:00
|
|
|
DISABLE_TEST(suite, test_newbie_password_message);
|
2016-09-14 21:46:57 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_prepare_report);
|
2016-09-18 13:08:53 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_seen_neighbours);
|
|
|
|
SUITE_ADD_TEST(suite, test_seen_travelthru);
|
2016-09-15 13:01:08 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_prepare_lighthouse);
|
2016-10-05 20:36:01 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_prepare_lighthouse_owners);
|
2016-09-17 15:56:32 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_prepare_lighthouse_capacity);
|
2016-09-16 17:25:40 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_prepare_travelthru);
|
2017-03-01 19:52:23 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_get_addresses);
|
2017-03-01 19:54:52 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_get_addresses_fstealth);
|
2017-03-01 21:10:50 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_get_addresses_travelthru);
|
2016-09-24 20:31:31 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_report_far_vision);
|
2015-01-30 20:37:14 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_reorder_units);
|
|
|
|
SUITE_ADD_TEST(suite, test_seen_faction);
|
2017-10-10 20:09:39 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_stealth_modifier);
|
2015-01-30 20:37:14 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_regionid);
|
2015-05-20 18:05:25 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_sparagraph);
|
2017-09-04 20:08:34 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_sparagraph_long);
|
2017-03-08 20:15:41 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_bufunit);
|
|
|
|
SUITE_ADD_TEST(suite, test_bufunit_fstealth);
|
2016-08-29 18:31:09 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_arg_resources);
|
2017-12-22 11:15:17 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_insect_warnings);
|
|
|
|
SUITE_ADD_TEST(suite, test_newbie_warning);
|
2018-03-11 14:40:38 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_visible_unit);
|
2015-01-30 20:37:14 +01:00
|
|
|
return suite;
|
2012-05-17 21:23:25 +02:00
|
|
|
}
|