static void test_piracy_cmd(CuTest * tc) { faction *f; region *r; unit *u, *u2; terrain_type *t_ocean; ship_type *st_boat; test_setup(); setup_piracy(); t_ocean = get_or_create_terrain("ocean"); st_boat = st_get_or_create("boat"); u2 = test_create_unit(test_create_faction(NULL), test_create_region(1, 0, t_ocean)); assert(u2); u_set_ship(u2, test_create_ship(u2->region, st_boat)); u = test_create_unit(f = test_create_faction(NULL), r = test_create_region(0, 0, t_ocean)); assert(f && u); set_level(u, SK_SAILING, st_boat->sumskill); u_set_ship(u, test_create_ship(u->region, st_boat)); f->locale = get_or_create_locale("de"); u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no)); piracy_cmd(u); CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertTrue(tc, u->region != r); CuAssertPtrEquals(tc, u2->region, u->region); CuAssertPtrEquals(tc, u2->region, u->ship->region); CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); /* FIXME: this is testing implementation, not interface */ CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim")); CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail")); test_teardown(); }
static void test_shipspeed_max_range(CuTest *tc) { ship *sh; ship_type *stype; region *r; struct faction *f; unit *cap, *crew; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); config_set("movement.shipspeed.skillbonus", "5"); r = sh->region; f = test_create_faction(NULL); assert(r && f); stype = st_get_or_create(sh->type->_name); set_level(cap, SK_SAILING, stype->cptskill + 4); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 4); CuAssertIntEquals_Msg(tc, "skill bonus requires at least movement.shipspeed.skillbonus points", 2, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill + 5); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 5); CuAssertIntEquals_Msg(tc, "skill bonus from movement.shipspeed.skillbonus", 3, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill + 15); scale_number(crew, 15); set_level(crew, SK_SAILING, stype->sumskill - stype->cptskill); CuAssertIntEquals_Msg(tc, "skill-bonus cannot exceed max_range", 4, shipspeed(sh, cap)); test_teardown(); }
static void json_ships(cJSON *json) { cJSON *child; if (json->type != cJSON_Object) { log_error("ships is not a json object: %d", json->type); return; } for (child = json->child; child; child = child->next) { json_ship(child, st_get_or_create(child->string)); } }
static void test_register_ship(CuTest * tc) { ship_type *stype; test_cleanup(); stype = st_get_or_create("herp"); CuAssertPtrNotNull(tc, stype); CuAssertPtrEquals(tc, stype, (void *)st_find("herp")); }
static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const char *p_shiptype, unit **victim, int v_r_flags, const char *v_shiptype) { terrain_type *vterrain; ship_type *st_boat = NULL; race *rc; faction *f; setup_piracy(); vterrain = get_or_create_terrain("terrain1"); fset(vterrain, v_r_flags); *victim = test_create_unit(test_create_faction(NULL), test_create_region(1, 0, vterrain)); assert(*victim); if (v_shiptype) { st_boat = st_get_or_create(v_shiptype); u_set_ship(*victim, test_create_ship((*victim)->region, st_boat)); free(st_boat->coasts); st_boat->coasts = (struct terrain_type **)calloc(2, sizeof(struct terrain_type *)); st_boat->coasts[0] = vterrain; st_boat->coasts[1] = 0; } *pirate = create_unit(test_create_region(0, 0, get_or_create_terrain("terrain2")), f = test_create_faction(NULL), 1, rc = rc_get_or_create("pirate"), 0, 0, 0); fset(rc, p_rc_flags); assert(f && *pirate); if (p_shiptype) { st_boat = st_get_or_create(p_shiptype); u_set_ship(*pirate, test_create_ship((*pirate)->region, st_boat)); free(st_boat->coasts); st_boat->coasts = (struct terrain_type **)calloc(2, sizeof(struct terrain_type *)); st_boat->coasts[0] = vterrain; st_boat->coasts[1] = 0; } f->locale = get_or_create_locale("de"); (*pirate)->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36((*victim)->faction->no)); }
static void test_piracy_cmd_errors(CuTest * tc) { race *r; faction *f; unit *u, *u2; ship_type *st_boat; test_setup(); setup_piracy(); st_boat = st_get_or_create("boat"); r = test_create_race("pirates"); u = test_create_unit(f = test_create_faction(r), test_create_region(0, 0, get_or_create_terrain("ocean"))); f->locale = test_create_locale(); u->thisorder = create_order(K_PIRACY, f->locale, ""); assert(u && u->thisorder); piracy_cmd(u); CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144")); test_clear_messages(f); fset(r, RCF_SWIM); piracy_cmd(u); CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error144")); CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error146")); freset(r, RCF_SWIM); fset(r, RCF_FLY); CuAssertPtrEquals_Msg(tc, "flyers are pirates", 0, test_find_messagetype(f->msgs, "error144")); freset(r, RCF_FLY); test_clear_messages(f); u_set_ship(u, test_create_ship(u->region, st_boat)); u2 = test_create_unit(u->faction, u->region); u2->thisorder = create_order(K_PIRACY, f->locale, ""); u_set_ship(u2, u->ship); test_clear_messages(f); piracy_cmd(u2); CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146")); test_clear_messages(f); piracy_cmd(u); CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim")); CuAssertPtrNotNull(tc, u->thisorder); test_teardown(); }
static void test_stype_defaults(CuTest *tc) { ship_type *stype; test_setup(); stype = st_get_or_create("hodor"); CuAssertPtrNotNull(tc, stype); CuAssertStrEquals(tc, "hodor", stype->_name); CuAssertPtrEquals(tc, NULL, stype->construction); CuAssertPtrEquals(tc, NULL, stype->coasts); CuAssertDblEquals(tc, 0.0, stype->damage, 0.0); CuAssertDblEquals(tc, 1.0, stype->storm, 0.0); CuAssertDblEquals(tc, 1.0, stype->tac_bonus, 0.01); CuAssertIntEquals(tc, 0, stype->cabins); CuAssertIntEquals(tc, 0, stype->cargo); CuAssertIntEquals(tc, 0, stype->combat); CuAssertIntEquals(tc, 0, stype->fishing); CuAssertIntEquals(tc, 0, stype->range); CuAssertIntEquals(tc, 0, stype->cptskill); CuAssertIntEquals(tc, 0, stype->minskill); CuAssertIntEquals(tc, 0, stype->sumskill); CuAssertIntEquals(tc, 0, stype->at_bonus); CuAssertIntEquals(tc, 0, stype->df_bonus); CuAssertIntEquals(tc, 0, stype->flags); test_teardown(); }