bool doInit () { lego_init(5,10); if((mtl = mt_new(NULL, NULL, LMT_PORT)) == NULL) { printf("Error initializing left motor.\n"); return false; } if((mtr = mt_new(NULL, NULL, RMT_PORT)) == NULL) { printf("Error initializing right motor.\n"); return false; } if(!ag_new(&push, PSH_PORT, PUSH)) { printf("Error initializing push sensor.\n"); return false; } if(!ag_new(&lright, LR_PORT, LIGHT)) { printf("Error initializing right light sensor.\n"); return false; } if(!ag_new(&lleft, LL_PORT, LIGHT)) { printf("Error initializing left light sensor.\n"); return false; } return true; }
static void test_merge_split(CuTest *tc) { message_list *mlist = 0, *append = 0; struct mlist **split; /* TODO: why is this a double asterisk? */ message_type *mtype; message *msg; test_setup(); mtype = mt_create(mt_new("custom", NULL), NULL, 0); add_message(&mlist, msg = msg_message(mtype->name, "")); msg_release(msg); add_message(&append, msg = msg_message(mtype->name, "")); msg_release(msg); CuAssertPtrEquals(tc, NULL, mlist->begin->next); CuAssertPtrEquals(tc, &mlist->begin->next, mlist->end); split = merge_messages(mlist, append); CuAssertPtrNotNull(tc, split); CuAssertPtrEquals(tc, &mlist->begin->next, split); CuAssertPtrEquals(tc, append->end, mlist->end); CuAssertPtrNotNull(tc, mlist->begin->next); CuAssertPtrEquals(tc, append->begin, mlist->begin->next); split_messages(mlist, split); CuAssertPtrEquals(tc, NULL, mlist->begin->next); free_messagelist(*split); free_messagelist(mlist->begin); free(mlist); free_messagelist(append->begin); free(append); test_teardown(); }
static void setup_piracy(void) { struct locale *lang; ship_type *st_boat; config_set("rules.ship.storms", "0"); lang = get_or_create_locale("de"); locale_setstring(lang, directions[D_EAST], "OSTEN"); init_directions(lang); test_create_terrain("ocean", SEA_REGION); st_boat = test_create_shiptype("boat"); st_boat->cargo = 1000; mt_create_error(144); mt_create_error(146); mt_create_va(mt_new("piratenovictim", NULL), "ship:ship", "unit:unit", "region:region", MT_NEW_END); mt_create_va(mt_new("piratesawvictim", NULL), "ship:ship", "unit:unit", "region:region", "dir:int", MT_NEW_END); mt_create_va(mt_new("shipsail", NULL), "ship:ship", "from:region", "to:region", MT_NEW_END); mt_create_va(mt_new("shipfly", NULL), "ship:ship", "from:region", "to:region", MT_NEW_END); mt_create_va(mt_new("shipnoshore", NULL), "ship:ship", "region:region", MT_NEW_END); mt_create_va(mt_new("travel", NULL), "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END); }
message_type *mt_new_va(const char *name, ...) { const char *args[16]; int i = 0; va_list marker; va_start(marker, name); for (;;) { const char *c = va_arg(marker, const char *); args[i++] = c; if (c == NULL) break; } va_end(marker); return mt_new(name, args); }
void test_message(CuTest *tc) { message *msg; message_type *mtype; test_setup(); mtype = mt_create(mt_new("custom", NULL), NULL, 0); CuAssertPtrEquals(tc, mtype, (void *)mt_find("custom")); CuAssertIntEquals(tc, 0, mtype->nparameters); CuAssertPtrEquals(tc, NULL, (void *)mtype->pnames); CuAssertPtrEquals(tc, NULL, (void *)mtype->types); msg = msg_message("custom", ""); CuAssertPtrNotNull(tc, msg); CuAssertIntEquals(tc, 1, msg->refcount); CuAssertPtrEquals(tc, NULL, msg->parameters); CuAssertPtrEquals(tc, mtype, (void *)msg->type); CuAssertPtrEquals(tc, msg, msg_addref(msg)); CuAssertIntEquals(tc, 2, msg->refcount); msg_release(msg); CuAssertIntEquals(tc, 1, msg->refcount); msg_release(msg); test_teardown(); }
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); }