2018-07-07 17:29:22 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <platform.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "automate.h"
|
|
|
|
|
|
|
|
#include "kernel/faction.h"
|
|
|
|
#include "kernel/order.h"
|
|
|
|
#include "kernel/region.h"
|
|
|
|
#include "kernel/unit.h"
|
|
|
|
|
2018-10-28 21:28:05 +01:00
|
|
|
#include "util/message.h"
|
|
|
|
|
2018-07-07 17:29:22 +02:00
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
static void test_autostudy_init(CuTest *tc) {
|
|
|
|
scholar scholars[4];
|
2018-11-04 09:08:50 +01:00
|
|
|
unit *u1, *u2, *u3, *u4, *u5, *ulist;
|
2018-07-07 17:29:22 +02:00
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
2018-10-28 21:28:05 +01:00
|
|
|
mt_create_error(77);
|
|
|
|
mt_create_error(771);
|
|
|
|
|
2018-07-07 17:29:22 +02:00
|
|
|
r = test_create_plain(0, 0);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
2018-07-07 20:56:35 +02:00
|
|
|
test_create_unit(f, r);
|
2018-07-07 17:29:22 +02:00
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
2018-07-07 20:56:35 +02:00
|
|
|
set_level(u2, SK_ENTERTAINMENT, 2);
|
|
|
|
u3 = test_create_unit(f, r);
|
|
|
|
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
2018-11-04 09:08:50 +01:00
|
|
|
u4 = test_create_unit(f, r);
|
2018-10-28 21:28:05 +01:00
|
|
|
u4->thisorder = create_order(K_AUTOSTUDY, f->locale, "Dudelidu");
|
2018-11-04 09:08:50 +01:00
|
|
|
u5 = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
u5->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
2018-07-09 03:31:13 +02:00
|
|
|
scholars[3].u = NULL;
|
2018-11-04 09:08:50 +01:00
|
|
|
ulist = r->units;
|
|
|
|
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
|
2018-10-28 21:28:05 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77"));
|
2018-07-09 03:31:13 +02:00
|
|
|
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
|
|
|
CuAssertIntEquals(tc, 2, scholars[0].level);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
|
|
|
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[0].sk);
|
|
|
|
CuAssertPtrEquals(tc, u1, scholars[1].u);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[1].level);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[1].learn);
|
|
|
|
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[1].sk);
|
|
|
|
CuAssertPtrEquals(tc, u3, scholars[2].u);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[2].level);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[2].learn);
|
|
|
|
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].sk);
|
|
|
|
CuAssertPtrEquals(tc, NULL, scholars[3].u);
|
2018-11-04 09:08:50 +01:00
|
|
|
CuAssertPtrEquals(tc, u5, ulist);
|
|
|
|
CuAssertIntEquals(tc, 1, autostudy_init(scholars, 4, &ulist));
|
|
|
|
CuAssertPtrEquals(tc, u5, scholars[0].u);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[0].level);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
|
|
|
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[0].sk);
|
|
|
|
CuAssertPtrEquals(tc, NULL, scholars[1].u);
|
|
|
|
CuAssertPtrEquals(tc, NULL, ulist);
|
2018-07-07 17:29:22 +02:00
|
|
|
test_teardown();
|
|
|
|
}
|
|
|
|
|
2018-07-09 03:31:13 +02:00
|
|
|
static void test_autostudy_run(CuTest *tc) {
|
|
|
|
scholar scholars[4];
|
2018-11-04 09:08:50 +01:00
|
|
|
unit *u1, *u2, *u3, *ulist;
|
2018-07-09 03:31:13 +02:00
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
r = test_create_plain(0, 0);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
|
|
|
set_number(u1, 2);
|
2018-07-11 21:03:00 +02:00
|
|
|
set_level(u1, SK_ENTERTAINMENT, 2);
|
2018-07-09 03:31:13 +02:00
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
|
|
|
set_number(u2, 10);
|
|
|
|
u3 = test_create_unit(f, r);
|
|
|
|
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
2018-07-11 21:03:00 +02:00
|
|
|
set_number(u3, 15);
|
2018-07-09 03:31:13 +02:00
|
|
|
scholars[3].u = NULL;
|
2018-11-04 09:08:50 +01:00
|
|
|
ulist = r->units;
|
|
|
|
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
|
|
|
|
CuAssertPtrEquals(tc, NULL, ulist);
|
2018-07-09 03:31:13 +02:00
|
|
|
autostudy_run(scholars, 3);
|
2018-11-06 19:28:14 +01:00
|
|
|
CuAssertIntEquals(tc, 1, scholars[0].learn);
|
2018-07-09 03:31:13 +02:00
|
|
|
CuAssertIntEquals(tc, 20, scholars[1].learn);
|
2018-07-11 21:03:00 +02:00
|
|
|
CuAssertIntEquals(tc, 15, scholars[2].learn);
|
2018-07-14 15:56:44 +02:00
|
|
|
test_teardown();
|
2018-07-11 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_autostudy_run_noteachers(CuTest *tc) {
|
|
|
|
scholar scholars[4];
|
2018-11-04 09:08:50 +01:00
|
|
|
unit *u1, *u2, *u3, *ulist;
|
2018-07-11 21:03:00 +02:00
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
r = test_create_plain(0, 0);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_LUMBERJACK]);
|
|
|
|
set_number(u1, 2);
|
|
|
|
set_level(u1, SK_ENTERTAINMENT, 2);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
|
|
|
set_number(u2, 10);
|
|
|
|
u3 = test_create_unit(f, r);
|
|
|
|
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
|
|
|
set_number(u3, 15);
|
|
|
|
scholars[3].u = NULL;
|
2018-11-04 09:08:50 +01:00
|
|
|
ulist = r->units;
|
|
|
|
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
|
|
|
|
CuAssertPtrEquals(tc, NULL, ulist);
|
2018-07-11 21:03:00 +02:00
|
|
|
autostudy_run(scholars, 3);
|
|
|
|
CuAssertIntEquals(tc, 2, scholars[0].learn);
|
|
|
|
CuAssertIntEquals(tc, 10, scholars[1].learn);
|
|
|
|
CuAssertIntEquals(tc, 15, scholars[2].learn);
|
2018-07-14 15:56:44 +02:00
|
|
|
test_teardown();
|
2018-07-09 03:31:13 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 19:28:14 +01:00
|
|
|
/**
|
|
|
|
* Reproduce Bug 2514
|
|
|
|
*/
|
|
|
|
static void test_autostudy_run_skilldiff(CuTest *tc) {
|
|
|
|
scholar scholars[4];
|
|
|
|
unit *u1, *u2, *u3, *ulist;
|
|
|
|
faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
r = test_create_plain(0, 0);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
|
|
|
set_number(u1, 1);
|
|
|
|
set_level(u1, SK_PERCEPTION, 2);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
|
|
|
set_number(u2, 10);
|
|
|
|
set_level(u2, SK_PERCEPTION, 1);
|
|
|
|
u3 = test_create_unit(f, r);
|
|
|
|
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
|
|
|
set_number(u3, 10);
|
|
|
|
scholars[3].u = NULL;
|
|
|
|
ulist = r->units;
|
|
|
|
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
|
|
|
|
CuAssertPtrEquals(tc, NULL, ulist);
|
|
|
|
autostudy_run(scholars, 3);
|
|
|
|
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
|
|
|
CuAssertIntEquals(tc, 20, scholars[2].learn);
|
|
|
|
CuAssertIntEquals(tc, 10, scholars[1].learn);
|
|
|
|
test_teardown();
|
|
|
|
}
|
|
|
|
|
2018-07-07 17:29:22 +02:00
|
|
|
CuSuite *get_automate_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
2018-07-09 03:31:13 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_autostudy_init);
|
|
|
|
SUITE_ADD_TEST(suite, test_autostudy_run);
|
2018-07-11 21:03:00 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_autostudy_run_noteachers);
|
2018-11-06 19:28:14 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_autostudy_run_skilldiff);
|
2018-07-07 17:29:22 +02:00
|
|
|
return suite;
|
|
|
|
}
|