static void test_give_men_limit(CuTest * tc) { struct give env = { 0 }; message *msg; test_setup_ex(tc); env.f2 = test_create_faction(NULL); env.f1 = test_create_faction(NULL); setup_give(&env); config_set("rules.give.max_men", "1"); /* below the limit, give men, increase newbies counter */ contact_unit(env.dst, env.src); msg = give_men(1, env.src, env.dst, NULL); CuAssertStrEquals(tc, "give_person", test_get_messagetype(msg)); CuAssertIntEquals(tc, 2, env.dst->number); CuAssertIntEquals(tc, 0, env.src->number); CuAssertIntEquals(tc, 1, env.f2->newbies); msg_release(msg); /* beyond the limit, do nothing */ contact_unit(env.src, env.dst); msg = give_men(2, env.dst, env.src, NULL); CuAssertStrEquals(tc, "error129", test_get_messagetype(msg)); CuAssertIntEquals(tc, 2, env.dst->number); CuAssertIntEquals(tc, 0, env.src->number); CuAssertIntEquals(tc, 0, env.f1->newbies); msg_release(msg); test_teardown(); }
static void test_give_men_magicians(CuTest * tc) { struct give env = { 0 }; int p; message * msg; test_setup_ex(tc); mt_create_error(158); env.f2 = env.f1 = test_create_faction(NULL); setup_give(&env); set_level(env.src, SK_MAGIC, 1); CuAssertPtrNotNull(tc, msg = give_men(1, env.src, env.dst, NULL)); CuAssertStrEquals(tc, "error158", test_get_messagetype(msg)); CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); msg_release(msg); p = rpeasants(env.r); CuAssertPtrNotNull(tc, msg = disband_men(1, env.dst, NULL)); CuAssertStrEquals(tc, "give_person_peasants", test_get_messagetype(msg)); CuAssertIntEquals(tc, 0, env.dst->number); CuAssertIntEquals(tc, p+1, rpeasants(env.r)); msg_release(msg); test_teardown(); }
static void test_sabotage_other_fail(CuTest *tc) { unit *u, *u2; region *r; order *ord; message *msg; setup_sabotage(); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); assert(u && u2); u2->ship = test_create_ship(r, test_create_shiptype("boat")); assert(u2->ship); u->ship = u2->ship; ship_update_owner(u->ship); assert(ship_owner(u->ship) == u); ord = create_order(K_SABOTAGE, u->faction->locale, "SCHIFF"); assert(ord); CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord)); msg = test_get_last_message(u2->faction->msgs); CuAssertStrEquals(tc, "destroy_ship_1", test_get_messagetype(msg)); msg = test_get_last_message(u->faction->msgs); CuAssertStrEquals(tc, "destroy_ship_3", test_get_messagetype(msg)); CuAssertPtrNotNull(tc, r->ships); free_order(ord); test_cleanup(); }
static void test_bad_dreams(CuTest *tc) { curse_fixture fix; message *msg; setup_curse(&fix, "gbdream"); fix.c->effect = -1; msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); CuAssertStrEquals(tc, "curseinfo::baddream", test_get_messagetype(msg)); msg_release(msg); test_cleanup(); }
static void test_magicstreet_warning(CuTest *tc) { curse_fixture fix; message *msg; setup_curse(&fix, "magicstreet"); fix.c->duration = 1; msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0); CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", test_get_messagetype(msg)); msg_release(msg); test_cleanup(); }
static void test_give_men_not_to_self(CuTest * tc) { struct give env = { 0 }; message * msg; test_setup_ex(tc); env.f2 = env.f1 = test_create_faction(NULL); setup_give(&env); msg = give_men(1, env.src, env.src, NULL); CuAssertStrEquals(tc, "error10", test_get_messagetype(msg)); CuAssertIntEquals(tc, 1, env.src->number); msg_release(msg); test_teardown(); }
static void test_give_men_in_ocean(CuTest * tc) { struct give env = { 0 }; message * msg; test_setup_ex(tc); env.f1 = test_create_faction(NULL); env.f2 = 0; setup_give(&env); env.r->terrain = test_create_terrain("ocean", SEA_REGION); msg = disband_men(1, env.src, NULL); CuAssertStrEquals(tc, "give_person_ocean", test_get_messagetype(msg)); CuAssertIntEquals(tc, 0, env.src->number); msg_release(msg); test_teardown(); }
static void test_give_peasants(CuTest * tc) { struct give env = { 0 }; message * msg; test_setup_ex(tc); env.f1 = test_create_faction(NULL); env.f2 = 0; setup_give(&env); rsetpeasants(env.r, 0); msg = disband_men(1, env.src, NULL); CuAssertStrEquals(tc, "give_person_peasants", test_get_messagetype(msg)); CuAssertIntEquals(tc, 0, env.src->number); CuAssertIntEquals(tc, 1, rpeasants(env.r)); msg_release(msg); test_teardown(); }
static void test_give_men_other_faction(CuTest * tc) { struct give env = { 0 }; message * msg; test_setup_ex(tc); env.f1 = test_create_faction(NULL); env.f2 = test_create_faction(NULL); setup_give(&env); contact_unit(env.dst, env.src); msg = give_men(1, env.src, env.dst, NULL); CuAssertStrEquals(tc, "give_person", test_get_messagetype(msg)); CuAssertIntEquals(tc, 2, env.dst->number); CuAssertIntEquals(tc, 0, env.src->number); msg_release(msg); test_teardown(); }
static void test_give_men_requires_contact(CuTest * tc) { struct give env = { 0 }; message * msg; order *ord; test_setup_ex(tc); env.f1 = test_create_faction(NULL); env.f2 = test_create_faction(NULL); setup_give(&env); msg = give_men(1, env.src, env.dst, NULL); CuAssertStrEquals(tc, "feedback_no_contact", test_get_messagetype(msg)); CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.src->number); ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no)); test_clear_messages(env.f1); give_cmd(env.src, ord); CuAssertPtrEquals(tc, NULL, test_find_messagetype(env.f1->msgs, "give_person")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact")); msg_release(msg); free_order(ord); test_teardown(); }