int test_i0(void *state) { enum parser_error r = parser_parse(state, "I:0:10:3"); struct player_race *pr; eq(r, PARSE_ERROR_NONE); pr = parser_priv(state); require(pr); ptreq(pr->history, NULL); eq(pr->b_age, 10); eq(pr->m_age, 3); ok; }
static int test_d0(void *state) { errr r = parser_parse(state, "D:foo bar"); struct object_kind *k; eq(r, 0); k = parser_priv(state); require(k); require(k->text); require(streq(k->text, "foo bar")); r = parser_parse(state, "D: baz"); eq(r, 0); ptreq(k, parser_priv(state)); require(streq(k->text, "foo bar baz")); ok; }
int test_priv(void *state) { ptreq(parser_priv(state), 0); parser_setpriv(state, (void*)0x42); ptreq(parser_priv(state), (void*)0x42); ok; }
NOTEARDOWN /* Testing the linked list functions in obj-pile.c */ int test_obj_piles(void *state) { struct object *pile = NULL; struct object *o1 = object_new(); struct object *o2 = object_new(); struct object *o3 = object_new(); struct object *o4 = object_new(); pile_insert(&pile, o1); eq(pile_contains(pile, o1), TRUE); eq(pile_contains(pile, o2), FALSE); ptreq(pile, o1); ptreq(pile_last_item(pile), o1); pile_insert_end(&pile, o2); eq(pile_contains(pile, o1), TRUE); eq(pile_contains(pile, o2), TRUE); eq(pile_contains(pile, o3), FALSE); ptreq(pile, o1); ptreq(pile_last_item(pile), o2); pile_insert_end(&pile, o3); eq(pile_contains(pile, o1), TRUE); eq(pile_contains(pile, o2), TRUE); eq(pile_contains(pile, o3), TRUE); ptreq(pile, o1); ptreq(pile_last_item(pile)->prev, o2); ptreq(pile_last_item(pile), o3); /* Now let's try excision */ /* From the top */ pile_excise(&pile, o1); ptreq(pile, o2); eq(pile_contains(pile, o1), FALSE); /* Now put it back */ pile_insert(&pile, o1); /* From the end */ pile_excise(&pile, o3); ptreq(pile, o1); eq(pile_contains(pile, o3), FALSE); ptreq(pile_last_item(pile), o2); ptreq(pile_last_item(pile)->prev, o1); object_delete(o3); /* Now put it back, and add another */ o3 = object_new(); pile_insert_end(&pile, o3); pile_insert_end(&pile, o4); /* Try removing from the middle */ pile_excise(&pile, o3); ptreq(pile, o1); /* Now the list should look like o1 <-> o2 <-> o4, so check that */ ptreq(o1->prev, NULL); ptreq(o1->next, o2); ptreq(o2->prev, o1); ptreq(o2->next, o4); ptreq(o3->prev, NULL); ptreq(o3->next, NULL); ptreq(o4->prev, o2); ptreq(o4->next, NULL); /* Free up */ object_pile_free(pile); ok; }