forked from github/server
testing all the error cases for PIRACY
This commit is contained in:
parent
678169d7d4
commit
dcf6c28b0e
5 changed files with 35 additions and 21 deletions
|
@ -4,7 +4,6 @@
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/messages.h>
|
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
|
@ -39,16 +38,14 @@ static void test_herbsearch(CuTest * tc)
|
||||||
|
|
||||||
herbsearch(u, INT_MAX);
|
herbsearch(u, INT_MAX);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error59"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error59"));
|
||||||
free_messagelist(f->msgs);
|
test_clear_messages(f);
|
||||||
f->msgs = 0;
|
|
||||||
|
|
||||||
set_level(u, SK_HERBALISM, 1);
|
set_level(u, SK_HERBALISM, 1);
|
||||||
CuAssertPtrEquals(tc, u2, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, u2, is_guarded(r, u, GUARD_PRODUCE));
|
||||||
herbsearch(u, INT_MAX);
|
herbsearch(u, INT_MAX);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||||
free_messagelist(f->msgs);
|
test_clear_messages(f);
|
||||||
f->msgs = 0;
|
|
||||||
|
|
||||||
guard(u2, GUARD_NONE);
|
guard(u2, GUARD_NONE);
|
||||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE));
|
CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE));
|
||||||
|
@ -57,8 +54,7 @@ static void test_herbsearch(CuTest * tc)
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||||
free_messagelist(f->msgs);
|
test_clear_messages(f);
|
||||||
f->msgs = 0;
|
|
||||||
|
|
||||||
rsetherbtype(r, itype);
|
rsetherbtype(r, itype);
|
||||||
CuAssertPtrEquals(tc, (void *)itype, (void *)rherbtype(r));
|
CuAssertPtrEquals(tc, (void *)itype, (void *)rherbtype(r));
|
||||||
|
@ -68,8 +64,7 @@ static void test_herbsearch(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||||
free_messagelist(f->msgs);
|
test_clear_messages(f);
|
||||||
f->msgs = 0;
|
|
||||||
|
|
||||||
rsetherbs(r, 100);
|
rsetherbs(r, 100);
|
||||||
CuAssertIntEquals(tc, 100, rherbs(r));
|
CuAssertIntEquals(tc, 100, rherbs(r));
|
||||||
|
@ -81,8 +76,7 @@ static void test_herbsearch(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||||
free_messagelist(f->msgs);
|
test_clear_messages(f);
|
||||||
f->msgs = 0;
|
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
#include <kernel/messages.h>
|
|
||||||
#include <kernel/order.h>
|
#include <kernel/order.h>
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
|
@ -214,8 +213,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
|
||||||
|
|
||||||
_snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no));
|
_snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no));
|
||||||
ord = create_order(K_GIVE, env.f1->locale, cmd);
|
ord = create_order(K_GIVE, env.f1->locale, cmd);
|
||||||
free_messagelist(env.f1->msgs);
|
test_clear_messages(env.f1);
|
||||||
env.f1->msgs = 0;
|
|
||||||
give_cmd(env.src, ord);
|
give_cmd(env.src, ord);
|
||||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "piracy.h"
|
#include "piracy.h"
|
||||||
|
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/ship.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/order.h>
|
#include <kernel/order.h>
|
||||||
|
|
||||||
|
@ -11,17 +12,32 @@
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static void test_piracy_cmd(CuTest * tc) {
|
static void test_piracy_cmd_errors(CuTest * tc) {
|
||||||
unit *u;
|
faction *f;
|
||||||
|
unit *u, *u2;
|
||||||
order *ord;
|
order *ord;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
u->faction->locale = get_or_create_locale("de");
|
f->locale = get_or_create_locale("de");
|
||||||
ord = create_order(K_PIRACY, u->faction->locale, "");
|
ord = create_order(K_PIRACY, f->locale, "");
|
||||||
assert(u);
|
assert(u);
|
||||||
piracy_cmd(u, ord);
|
piracy_cmd(u, ord);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error144"));
|
CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144"));
|
||||||
|
|
||||||
|
u_set_ship(u, test_create_ship(u->region, 0));
|
||||||
|
|
||||||
|
u2 = test_create_unit(u->faction, u->region);
|
||||||
|
u_set_ship(u2, u->ship);
|
||||||
|
|
||||||
|
test_clear_messages(f);
|
||||||
|
piracy_cmd(u2, ord);
|
||||||
|
CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146"));
|
||||||
|
|
||||||
|
test_clear_messages(f);
|
||||||
|
piracy_cmd(u, ord);
|
||||||
|
CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim"));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +45,6 @@ static void test_piracy_cmd(CuTest * tc) {
|
||||||
CuSuite *get_piracy_suite(void)
|
CuSuite *get_piracy_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_piracy_cmd);
|
SUITE_ADD_TEST(suite, test_piracy_cmd_errors);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,6 +279,11 @@ struct message * test_find_messagetype(struct message_list *msgs, const char *na
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_clear_messages(faction *f) {
|
||||||
|
free_messagelist(f->msgs);
|
||||||
|
f->msgs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void disabled_test(void *suite, void (*test)(CuTest *), const char *name) {
|
void disabled_test(void *suite, void (*test)(CuTest *), const char *name) {
|
||||||
(void)test;
|
(void)test;
|
||||||
fprintf(stderr, "%s: SKIP\n", name);
|
fprintf(stderr, "%s: SKIP\n", name);
|
||||||
|
|
|
@ -43,6 +43,7 @@ extern "C" {
|
||||||
const char * test_get_messagetype(const struct message *msg);
|
const char * test_get_messagetype(const struct message *msg);
|
||||||
struct message * test_find_messagetype(struct message_list *msgs, const char *name);
|
struct message * test_find_messagetype(struct message_list *msgs, const char *name);
|
||||||
struct message * test_get_last_message(struct message_list *mlist);
|
struct message * test_get_last_message(struct message_list *mlist);
|
||||||
|
void test_clear_messages(struct faction *f);
|
||||||
|
|
||||||
void disabled_test(void *suite, void (*)(struct CuTest *), const char *name);
|
void disabled_test(void *suite, void (*)(struct CuTest *), const char *name);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue