Esempio n. 1
0
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();
}
Esempio n. 2
0
static void test_plane(CuTest *tc) {
    struct region *r;
    plane *pl;

    test_setup();
    r = test_create_region(0, 0, NULL);
    CuAssertPtrEquals(tc, NULL, findplane(0, 0));
    CuAssertPtrEquals(tc, NULL, getplane(r));
    CuAssertIntEquals(tc, 0, getplaneid(r));
    CuAssertPtrEquals(tc, NULL, getplanebyid(0));
    CuAssertIntEquals(tc, 0, plane_center_x(0));
    CuAssertIntEquals(tc, 0, plane_center_y(0));
    CuAssertIntEquals(tc, 0, plane_width(0));
    CuAssertIntEquals(tc, 0, plane_height(0));
    CuAssertPtrEquals(tc, NULL, get_homeplane());

    pl = create_new_plane(1, "Hell", 4, 8, 40, 80, 15);
    r = test_create_region(4, 40, 0);
    CuAssertIntEquals(tc, 15, pl->flags);
    CuAssertIntEquals(tc, 4, pl->minx);
    CuAssertIntEquals(tc, 8, pl->maxx);
    CuAssertIntEquals(tc, 40, pl->miny);
    CuAssertIntEquals(tc, 80, pl->maxy);
    CuAssertPtrEquals(tc, NULL, pl->attribs);
    CuAssertStrEquals(tc, "Hell", pl->name);
    CuAssertPtrEquals(tc, pl, findplane(4, 40));
    CuAssertPtrEquals(tc, pl, getplane(r));
    CuAssertPtrEquals(tc, pl, getplanebyid(1));
    CuAssertIntEquals(tc, 1, getplaneid(r));
    CuAssertIntEquals(tc, 6, plane_center_x(pl));
    CuAssertIntEquals(tc, 60, plane_center_y(pl));
    CuAssertIntEquals(tc, 5, plane_width(pl));
    CuAssertIntEquals(tc, 41, plane_height(pl));
    test_teardown();
}
Esempio n. 3
0
static void test_piracy_cmd_land_to_land(CuTest * tc) {
    unit *u;
    region *r;
    faction *f;
    int target;
    const terrain_type *t_plain;
    const ship_type *stype;

    test_setup();
    setup_piracy();
    t_plain = get_or_create_terrain("plain");
    stype = test_create_shiptype("boat");

    /* create a target: */
    r = test_create_region(0, 0, t_plain);
    f = test_create_faction(NULL);
    u = test_create_unit(f, r);
    u->ship = test_create_ship(r, stype);
    target = f->no;

    /* create a pirate: */
    r = test_create_region(1, 0, t_plain);
    f = test_create_faction(NULL);
    u = test_create_unit(f, r);
    u->ship = test_create_ship(r, stype);
    set_level(u, SK_SAILING, u->ship->type->sumskill);
    u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(target));

    piracy_cmd(u);
    CuAssertPtrEquals(tc, NULL, u->thisorder);
    CuAssertPtrEquals(tc, r, u->region);

    test_teardown();
}
Esempio n. 4
0
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();
}
Esempio n. 5
0
static void test_cmp_current_owner(CuTest *tc) {
    region *r;
    building *b1, *b2;
    building_type *btype;
    unit *u1, *u2;

    test_setup();
    config_set("rules.region_owners", "1");
    r = test_create_region(0, 0, NULL);
    btype = test_create_buildingtype("watch");
    btype->stages->construction->maxsize = 1;
    btype->taxes = 200;
    b1 = test_create_building(r, btype);
    btype = test_create_buildingtype("castle");
    btype->stages->construction->maxsize = 1;
    btype->taxes = 100;
    b2 = test_create_building(r, btype);
    b1->size = 1;
    CuAssertIntEquals(tc, 1, buildingeffsize(b1, false));
    b2->size = 1;
    CuAssertIntEquals(tc, 1, buildingeffsize(b2, false));
    u1 = test_create_unit(test_create_faction(NULL), r);
    u_set_building(u1, b1);
    u2 = test_create_unit(test_create_faction(NULL), r);
    u_set_building(u2, b2);
    region_set_owner(r, u1->faction, turn);
    CuAssertPtrEquals(tc, b1, largestbuilding(r, cmp_current_owner, false));
    CuAssertTrue(tc, cmp_current_owner(b2, b1) < 0);
    CuAssertTrue(tc, cmp_current_owner(b1, b2) > 0);
    CuAssertTrue(tc, cmp_current_owner(b1, b1) == 0);
    test_teardown();
}
Esempio n. 6
0
static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, region **_r) {
    char buf[1024];
    stream out = { 0 };
    int err;
    region *r;
    cJSON *json, *attr;

    r = test_create_region(0, 0, terrain);

    mstream_init(&out);
    err = json_export(&out, EXPORT_REGIONS);
    CuAssertIntEquals(tc, 0, err);
    out.api->rewind(out.handle);
    out.api->read(out.handle, buf, sizeof(buf));
    mstream_done(&out);

    json = cJSON_Parse(buf);
    CuAssertPtrNotNull(tc, json);
    CuAssertIntEquals(tc, cJSON_Object, json->type);
    CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "factions"));
    CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "units"));
    CuAssertPtrNotNull(tc, json = cJSON_GetObjectItem(json, "regions"));
    CuAssertIntEquals(tc, cJSON_Object, json->type);
    json = json->child;
    CuAssertIntEquals(tc, r->uid, atoi(json->string));
    CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "x"));
    CuAssertIntEquals(tc, r->x, attr->valueint);
    CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "y"));
    CuAssertIntEquals(tc, r->y, attr->valueint);
    CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "type"));
    CuAssertStrEquals(tc, terrain->_name, attr->valuestring);

    if (_r) *_r = r;
    return json;
}
Esempio n. 7
0
static void test_group(CuTest * tc)
{
    unit *u;
    region *r;
    faction *f;
    group *g;

    test_cleanup();
    r = test_create_region(0, 0, 0);
    f = test_create_faction(0);
    assert(r && f);
    u = test_create_unit(f, r);
    assert(u);
    CuAssertPtrNotNull(tc, (g = join_group(u, "hodor")));
    CuAssertPtrEquals(tc, g, get_group(u));
    CuAssertStrEquals(tc, "hodor", g->name);
    CuAssertIntEquals(tc, 1, g->members);
    set_group(u, 0);
    CuAssertIntEquals(tc, 0, g->members);
    CuAssertPtrEquals(tc, 0, get_group(u));
    set_group(u, g);
    CuAssertIntEquals(tc, 1, g->members);
    CuAssertPtrEquals(tc, g, get_group(u));
    test_cleanup();
}
Esempio n. 8
0
static void test_building_effsize(CuTest *tc) {
    building *b;
    building_type *btype;
    building_stage *stage;
    construction *cons;

    test_setup();
    btype = test_create_buildingtype("castle");
    stage = btype->stages;
    assert(stage && stage->construction);
    cons = stage->construction;
    cons->maxsize = 5;

    stage->next = calloc(1, sizeof(building_stage));
    stage = stage->next;
    cons = stage->construction = calloc(1, sizeof(construction));
    cons->maxsize = 5;

    stage->next = calloc(1, sizeof(building_stage));
    stage = stage->next;
    cons = stage->construction = calloc(1, sizeof(construction));
    cons->maxsize = -1;

    b = test_create_building(test_create_region(0,0,0), btype);
    b->size = 1;
    CuAssertIntEquals(tc, 0, buildingeffsize(b, false));
    b->size = 5;
    CuAssertIntEquals(tc, 1, buildingeffsize(b, false));
    b->size = 10;
    CuAssertIntEquals(tc, 2, buildingeffsize(b, false));
    b->size = 20;
    CuAssertIntEquals(tc, 2, buildingeffsize(b, false));
    test_teardown();
}
Esempio n. 9
0
static void test_active_building(CuTest *tc) {
    building *b;
    region *r;
    unit *u;
    building_type *btype;

    test_setup();

    btype = test_create_buildingtype("castle");
    assert(btype && btype->maxsize == -1);
    b = test_create_building(r = test_create_region(0, 0, NULL), btype);
    u = test_create_unit(test_create_faction(NULL), r);
    CuAssertIntEquals(tc, false, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));

    b->flags |= BLD_MAINTAINED;
    CuAssertIntEquals(tc, true, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));
    u_set_building(u, b);
    CuAssertIntEquals(tc, true, building_is_active(b));
    CuAssertPtrNotNull(tc, active_building(u, btype) );
    btype->maxsize = 10;
    b->size = btype->maxsize;
    CuAssertIntEquals(tc, true, building_is_active(b));
    CuAssertPtrNotNull(tc, active_building(u, btype) );
    b->size = 9;
    CuAssertIntEquals(tc, false, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));
    btype->maxsize = -1;
    b->flags &= ~BLD_MAINTAINED;
    CuAssertIntEquals(tc, false, building_is_active(b));
    CuAssertPtrEquals(tc, NULL, active_building(u, btype));
    test_teardown();
}
Esempio n. 10
0
static void test_shipspeed_speedy(CuTest *tc) {
    ship_type *stype;
    ship *sh;
    unit *cap, *crw;
    test_setup();
    stype = test_create_shiptype("dragonship");
    stype->range = 5;
    stype->range_max = -1;
    stype->flags |= SFL_SPEEDY;
    cap = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    crw = test_create_unit(cap->faction, cap->region);
    sh = test_create_ship(cap->region, stype);
    cap->ship = sh;
    crw->ship = sh;
    set_level(cap, SK_SAILING, stype->cptskill);
    set_level(crw, SK_SAILING, stype->sumskill - stype->cptskill);
    CuAssertPtrEquals(tc, cap, ship_owner(sh));
    CuAssertIntEquals(tc, 5, shipspeed(sh, cap));

    set_level(cap, SK_SAILING, stype->cptskill * 3 - 1);
    CuAssertIntEquals(tc, 5, shipspeed(sh, cap));
    set_level(cap, SK_SAILING, stype->cptskill * 3);
    CuAssertIntEquals(tc, 6, shipspeed(sh, cap));

    set_level(cap, SK_SAILING, stype->cptskill * 3 * 3 - 1);
    CuAssertIntEquals(tc, 6, shipspeed(sh, cap));
    set_level(cap, SK_SAILING, stype->cptskill * 3 * 3);
    CuAssertIntEquals(tc, 7, shipspeed(sh, cap));

    test_teardown();
}
Esempio n. 11
0
static void test_getunit(CuTest *tc) {
    unit *u, *u2;
    order *ord;
    attrib *a;
    struct region *r;
    struct locale *lang;
    struct terrain_type *t_plain;

    test_cleanup();
    lang = get_or_create_locale("de");
    test_translate_param(lang, P_TEMP, "TEMP");
    /* note that the english order is FIGHT, not COMBAT, so this is a poor example */
    t_plain = test_create_terrain("plain", LAND_REGION);
    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, t_plain));
    a = a_add(&u->attribs, a_new(&at_alias));
    a->data.i = atoi36("42"); /* this unit is also TEMP 42 */
    r = test_create_region(1, 0, t_plain);

    ord = create_order(K_GIVE, lang, itoa36(u->no));
    init_order(ord);
    CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, u, u2);
    init_order(ord);
    CuAssertIntEquals(tc, GET_NOTFOUND, getunit(r, u->faction, &u2));
    CuAssertPtrEquals(tc, NULL, u2);
    free_order(ord);

    ord = create_order(K_GIVE, lang, itoa36(u->no + 1));
    init_order(ord);
    CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, NULL, u2);
    free_order(ord);

    ord = create_order(K_GIVE, lang, "0");
    init_order(ord);
    CuAssertIntEquals(tc, GET_PEASANTS, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, NULL, u2);
    free_order(ord);

    ord = create_order(K_GIVE, lang, "TEMP 42");
    init_order(ord);
    CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2));
    CuAssertPtrEquals(tc, u, u2);
    free_order(ord);

    test_cleanup();
}
Esempio n. 12
0
static void test_move_to_vortex(CuTest *tc) {
    region *r1, *r2, *r = 0;
    terrain_type *t_plain;
    unit *u;
    struct locale *lang;

    test_cleanup();
    lang = get_or_create_locale("en");
    locale_setstring(lang, "vortex", "wirbel");
    init_locale(lang);
    t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
    r1 = test_create_region(0, 0, t_plain);
    r2 = test_create_region(5, 0, t_plain);
    CuAssertPtrNotNull(tc, create_special_direction(r1, r2, 10, "", "vortex", true));
    u = test_create_unit(test_create_faction(rc_get_or_create("hodor")), r1);
    CuAssertIntEquals(tc, E_MOVE_NOREGION, movewhere(u, "barf", r1, &r));
    CuAssertIntEquals(tc, E_MOVE_OK, movewhere(u, "wirbel", r1, &r));
    CuAssertPtrEquals(tc, r2, r);
}
Esempio n. 13
0
static void test_income(CuTest *tc)
{
    race *rc;
    unit *u;
    test_setup();
    rc = test_create_race("nerd");
    u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
    CuAssertIntEquals(tc, 20, income(u));
    u->number = 5;
    CuAssertIntEquals(tc, 100, income(u));
    test_cleanup();
}
Esempio n. 14
0
static void test_safe_building(CuTest *tc) {
    building_type *btype;
    unit *u1, *u2;

    test_setup();
    btype = test_create_buildingtype("castle");
    u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    u2 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
    u1->building = test_create_building(u1->region, btype);
    CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
    btype->flags |= BTF_FORTIFICATION;
    CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
    u2->building = u1->building;
    CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
    u1->number = 2;
    CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
    u1->building->size = 3;
    CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
    test_teardown();
}
Esempio n. 15
0
static void setup_give(struct give *env) {
    struct terrain_type *ter = test_create_terrain("plain", LAND_REGION);
    race *rc;

    assert(env->f1);
    rc = test_create_race(env->f1->race ? env->f1->race->_name : "humon");
    rc->ec_flags |= ECF_GIVEPERSON;

    env->r = test_create_region(0, 0, ter);
    env->src = test_create_unit(env->f1, env->r);
    env->itype = it_get_or_create(rt_get_or_create("money"));
    env->itype->flags |= ITF_HERB;
    if (env->f2) {
        ally_set(&env->f2->allies, env->f1, HELP_GIVE);
        env->dst = test_create_unit(env->f2, env->r);
    }
    else {
        env->dst = NULL;
    }
    if (env->lang) {
        locale_setstring(env->lang, env->itype->rtype->_name, "SILBER");
        init_locale(env->lang);
        env->f1->locale = env->lang;
    }

    config_set("rules.give.max_men", "-1");
    /* success messages: */
    mt_create_va(mt_new("receive_person", NULL), "unit:unit", "target:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_person", NULL), "unit:unit", "target:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_person_peasants", NULL), "unit:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_person_ocean", NULL), "unit:unit", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("receive", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END);
    mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END);
    /* error messages: */
    mt_create_error(120);
    mt_create_error(128);
    mt_create_error(129);
    mt_create_error(96);
    mt_create_error(10);
    mt_create_feedback("feedback_give_forbidden");
    mt_create_feedback("peasants_give_invalid");
    mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
    mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
    mt_create_va(mt_new("feedback_no_contact", NULL), "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END);
    mt_create_va(mt_new("giverestriction", NULL), "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END);
    mt_create_va(mt_new("error_unit_size", NULL), "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END);
    mt_create_va(mt_new("nogive_reserved", NULL), "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END);
    mt_create_va(mt_new("race_notake", NULL), "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END);
    mt_create_va(mt_new("race_noregroup", NULL), "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END);
}
Esempio n. 16
0
/** creates a small world and some stuff in it.
 * two terrains: 'plain' and 'ocean'
 * one race: 'human'
 * one ship_type: 'boat'
 * one building_type: 'castle'
 * in 0.0 and 1.0 is an island of two plains, around it is ocean.
 */
void test_create_world(void)
{
  terrain_type *t_plain, *t_ocean;
  region *island[2];
  int i;
  const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" };

  make_locale("de");
  init_resources();
  assert(!olditemtype[I_HORSE]);

  olditemtype[I_HORSE] = test_create_itemtype(names+0);
  olditemtype[I_IRON] = test_create_itemtype(names+4);
  olditemtype[I_STONE] = test_create_itemtype(names+6);

  t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
  t_plain->size = 1000;
  t_ocean = test_create_terrain("ocean", SEA_REGION | SAIL_INTO | SWIM_INTO);
  t_ocean->size = 0;

  island[0] = test_create_region(0, 0, t_plain);
  island[1] = test_create_region(1, 0, t_plain);
  for (i = 0; i != 2; ++i) {
    int j;
    region *r = island[i];
    for (j = 0; j != MAXDIRECTIONS; ++j) {
      region *rn = r_connect(r, (direction_t)j);
      if (!rn) {
        rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean);
      }
    }
  }

  test_create_race("human");

  test_create_buildingtype("castle");
  test_create_shiptype(names+2);
}
Esempio n. 17
0
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));
}
Esempio n. 18
0
static ship *setup_ship(void) {
    region *r;
    ship_type *stype;

    set_param(&global.parameters, "movement.shipspeed.skillbonus", "0");
    r = test_create_region(0, 0, test_create_terrain("ocean", 0));
    stype = test_create_shiptype("longboat");
    stype->cptskill = 1;
    stype->sumskill = 10;
    stype->minskill = 1;
    stype->range = 2;
    stype->range_max = 4;
    return test_create_ship(r, stype);
}
Esempio n. 19
0
static void test_otherfaction(CuTest *tc) {
    unit *u;
    faction *f;

    test_setup();
    u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    f = test_create_faction(NULL);
    config_set("stealth.faction.other", "1");
    CuAssertIntEquals(tc, true, rule_stealth_other());
    CuAssertPtrEquals(tc, u->faction, visible_faction(f, u));
    a_add(&u->attribs, make_otherfaction(f));
    CuAssertPtrEquals(tc, f, visible_faction(f, u));
    test_teardown();
}
Esempio n. 20
0
static void test_spawn_seaserpent(CuTest *tc) {
    region *r;
    unit *u;
    faction *f;
    race *rc;
    test_cleanup();
    rc = test_create_race("seaserpent");
    rc->flags |= RCF_NPC;
    r = test_create_region(0, 0, 0);
    f = test_create_faction(0);
    u = spawn_seaserpent(r, f);
    CuAssertPtrNotNull(tc, u);
    CuAssertPtrEquals(tc, 0, u->_name);
    test_cleanup();
}
Esempio n. 21
0
static void create_monsters(faction **player, faction **monsters, unit **u, unit **m) {
    race* rc;
    region *r;

    test_cleanup();

    test_create_horse();
    default_locale = test_create_locale();
    *player = test_create_faction(NULL);
    *monsters = get_or_create_monsters();
    assert(rc_find((*monsters)->race->_name));
    rc = rc_get_or_create((*monsters)->race->_name);
    fset(rc, RCF_UNARMEDGUARD|RCF_NPC|RCF_DRAGON);
    fset(*monsters, FFL_NOIDLEOUT);
    assert(fval(*monsters, FFL_NPC) && fval((*monsters)->race, RCF_UNARMEDGUARD) && fval((*monsters)->race, RCF_NPC) && fval(*monsters, FFL_NOIDLEOUT));

    test_create_region(-1, 0, test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO));
    test_create_region(1, 0, 0);
    r = test_create_region(0, 0, 0);

    *u = test_create_unit(*player, r);
    unit_setid(*u, 1);
    *m = test_create_unit(*monsters, r);
}
Esempio n. 22
0
void test_missing_feedback(CuTest *tc) {
    message *msg;
    unit *u;

    test_setup();
    u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    u->thisorder = create_order(K_ENTERTAIN, u->faction->locale, NULL);
    message_handle_missing(MESSAGE_MISSING_REPLACE);
    msg = msg_error(u, NULL, 77);
    CuAssertPtrNotNull(tc, msg);
    CuAssertPtrNotNull(tc, msg->type);
    CuAssertStrEquals(tc, msg->type->name, "missing_feedback");
    CuAssertStrEquals(tc, "error77", (const char *)msg->parameters[3].v);
    msg_release(msg);
    test_teardown();
}
Esempio n. 23
0
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();
}
Esempio n. 24
0
static void test_noerror(CuTest *tc) {
    unit *u;
    struct locale *lang;
    message *msg;

    test_setup();
    lang = test_create_locale();
    u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    u->thisorder = parse_order("!@move", lang);
    CuAssertIntEquals(tc, K_MOVE | CMD_QUIET | CMD_PERSIST,  u->thisorder->command);
    CuAssertTrue(tc, !is_persistent(u->thisorder));
    CuAssertPtrEquals(tc, NULL, msg = msg_error(u, u->thisorder, 100));
    assert(!msg);
    CuAssertPtrEquals(tc, NULL, msg = msg_feedback(u, u->thisorder, "error_unit_not_found", NULL));
    assert(!msg);
    test_teardown();
}
Esempio n. 25
0
static void test_largestbuilding(CuTest *tc) {
    region *r;
    building *b1, *b2;
    test_setup();
    r = test_create_region(0, 0, NULL);
    CuAssertPtrEquals(tc, NULL, largestbuilding(r, cmp_size, false));
    b1 = test_create_building(r, NULL);
    b2 = test_create_building(r, NULL);
    b1->size = 1;
    b2->size = 1;
    CuAssertPtrEquals(tc, b1, largestbuilding(r, cmp_size, false));
    b1->size = 2;
    CuAssertPtrEquals(tc, b1, largestbuilding(r, cmp_size, false));
    b2->size = 3;
    CuAssertPtrEquals(tc, b2, largestbuilding(r, cmp_size, false));
    test_teardown();
}
Esempio n. 26
0
static void test_group_readwrite_dead_faction(CuTest *tc) {
    gamedata data;
    storage store;
    faction *f, *f2;
    unit * u;
    group *g;
    ally *al;
    int fno;

    test_cleanup();
    f = test_create_faction(0);
    fno = f->no;
    CuAssertPtrEquals(tc, f, factions);
    CuAssertPtrEquals(tc, 0, f->next);
    f2 = test_create_faction(0);
    CuAssertPtrEquals(tc, f2, factions->next);
    u = test_create_unit(f2, test_create_region(0, 0, 0));
    CuAssertPtrNotNull(tc, u);
    g = join_group(u, "group");
    CuAssertPtrNotNull(tc, g);
    al = ally_add(&g->allies, f);
    CuAssertPtrNotNull(tc, al);

    CuAssertPtrEquals(tc, f, factions);
    destroyfaction(&factions);
    CuAssertTrue(tc, !f->_alive);
    CuAssertPtrEquals(tc, f2, factions);
    mstream_init(&data.strm);
    gamedata_init(&data, &store, RELEASE_VERSION);
    write_game(&data);
    free_gamedata();
    f = f2 = NULL;
    data.strm.api->rewind(data.strm.handle);
    read_game(&data);
    mstream_done(&data.strm);
    gamedata_done(&data);
    CuAssertPtrEquals(tc, 0, findfaction(fno));
    f2 = factions;
    CuAssertPtrNotNull(tc, f2);
    u = f2->units;
    CuAssertPtrNotNull(tc, u);
    g = get_group(u);
    CuAssertPtrNotNull(tc, g);
    CuAssertPtrEquals(tc, 0, g->allies);
    test_cleanup();
}
Esempio n. 27
0
static void test_cr_mallorn(CuTest *tc) {
    stream strm;
    char line[1024];
    faction *f;
    region *r;
    
    setup_resources();

    f = test_create_faction(NULL);
    r = test_create_region(0, 0, NULL);
    r->land->horses = 1;
    r->land->peasants = 200;
    r->land->money = 300;
    r->flags |= RF_MALLORN;
    rsettrees(r, 0, 1);
    rsettrees(r, 1, 2);
    rsettrees(r, 2, 3);

    mstream_init(&strm);
    cr_output_resources(&strm, f, r, false);
    strm.api->rewind(strm.handle);
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "3;Baeume", line);
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "2;Schoesslinge", line);
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "1;Mallorn", line);

    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "\"Mallornschoesslinge\";type", line);
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "2;number", line);

    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "\"Mallorn\";type", line);
    CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
    CuAssertStrEquals(tc, "3;number", line);

    mstream_done(&strm);
    test_teardown();
}
Esempio n. 28
0
static void test_shock_low(CuTest *tc) {
    unit *u;
    trigger *tt;
    test_cleanup();

    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
    create_mage(u, M_GRAY);
    set_level(u, SK_MAGIC, 5);
    set_spellpoints(u, 1);
    u->hp = 1;
    tt = trigger_shock(u);
    tt->type->handle(tt, u);
    CuAssertIntEquals(tc, 1, u->hp);
    CuAssertIntEquals(tc, 1, get_spellpoints(u));
    t_free(tt);
    free(tt);
    test_cleanup();
}
Esempio n. 29
0
static void test_read_unitid(CuTest *tc) {
    unit *u;
    order *ord;
    attrib *a;
    struct locale *lang;
    struct terrain_type *t_plain;

    test_cleanup();
    lang = get_or_create_locale("de");
    test_translate_param(lang, P_TEMP, "TEMP");
    /* note that the english order is FIGHT, not COMBAT, so this is a poor example */
    t_plain = test_create_terrain("plain", LAND_REGION);
    u = test_create_unit(test_create_faction(0), test_create_region(0, 0, t_plain));
    a = a_add(&u->attribs, a_new(&at_alias));
    a->data.i = atoi36("42"); /* this unit is also TEMP 42 */

    ord = create_order(K_GIVE, lang, "TEMP 42");
    init_order(ord);
    CuAssertIntEquals(tc, u->no, read_unitid(u->faction, u->region));
    free_order(ord);

    ord = create_order(K_GIVE, lang, "8");
    init_order(ord);
    CuAssertIntEquals(tc, 8, read_unitid(u->faction, u->region));
    free_order(ord);

    ord = create_order(K_GIVE, lang, "");
    init_order(ord);
    CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region));
    free_order(ord);

    ord = create_order(K_GIVE, lang, "TEMP");
    init_order(ord);
    CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region));
    free_order(ord);

    // bug https://bugs.eressea.de/view.php?id=1685
    ord = create_order(K_GIVE, lang, "##");
    init_order(ord);
    CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region));
    free_order(ord);

    test_cleanup();
}
Esempio n. 30
0
static void test_recruit(CuTest *tc) {
    unit *u;
    faction *f;

    test_setup();
    f = test_create_faction(0);
    u = test_create_unit(f, test_create_region(0, 0, 0));
    CuAssertIntEquals(tc, 1, u->number);
    add_recruits(u, 1, 1);
    CuAssertIntEquals(tc, 2, u->number);
    CuAssertPtrEquals(tc, u, f->units);
    CuAssertPtrEquals(tc, NULL, u->nextF);
    CuAssertPtrEquals(tc, NULL, u->prevF);
    CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "recruit"));
    add_recruits(u, 1, 2);
    CuAssertIntEquals(tc, 3, u->number);
    CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "recruit"));
    test_cleanup();
}