/* Just make sure elements get free properly */ void bigring_str_test(int size, bigring_free_entry_f fef) { bigring_t* br = bigring_create(size, fef); int i; char* p; char buf[16]; free_count__ = 0; for(i = 0; i < size*2; i++) { bigring_push(br, aim_fstrdup("%d", i)); } /* * At this point: * free_count should be size (or zero if using default free function) * next entry should be "size" * ringcount should be size */ if(fef == free_entry__) { if(free_count__ != size) { AIM_LOG_ERROR("Free count is %d, should be %d", free_count__, size); } } if(fef == bigring_aim_free_entry) { if(free_count__ != 0) { AIM_LOG_ERROR("free_count is %d, should be zero", free_count__); } } ASSERT_COUNT(bigring_count(br), size, bigring_size(br)); p = bigring_shift(br); ASSERT_COUNT(bigring_count(br), size-1, bigring_size(br)); aim_snprintf(buf, sizeof(buf), "%d", size); if(strcmp(p, buf)) { AIM_LOG_ERROR("Next is '%s', should be '%s'", p, buf); abort(); } AIM_FREE(p); /* * Verify the rest of the entries are free. * Note - we removed the current entry, so we need * to increment free_count__ to account for it or * the verification will be off by one. */ free_count__++; bigring_destroy(br); }
static void bigring_int_test(int size, int count) { bigring_t* br = bigring_create(size, NULL); intptr_t c; intptr_t start; intptr_t max; int i; i = bigring_size(br); if(i != size) { AIM_LOG_ERROR("size not correct -- should be %d, is %d\n", size, i); abort(); } for(c = 0; c < count; c++) { #define ASSERT_COUNT(_bc, _vc, _size) \ do { \ if(_bc != ((_vc < _size) ? _vc : _size)) { \ AIM_LOG_ERROR("size = %d, count is %d, should be %d", _size, _bc, _vc); \ abort(); \ } \ } while(0) ASSERT_COUNT(bigring_count(br), c, bigring_size(br)); bigring_push(br, (void*)c); } /** Make sure the entries are correct (module size) */ start = (count <= size) ? 0 : count - size; max = (count <= size) ? count : size; for(i = 0, c = max-1; i < max; i++, start++, c--) { intptr_t v = (intptr_t)bigring_shift(br); if(v != start) { AIM_LOG_ERROR("entry mismatch @%d - expected %p, got %p", i, start, v); abort(); } /* Count should have decremented */ ASSERT_COUNT(bigring_count(br), c, bigring_size(br)); } /* Make sure additional shifts return null */ if(bigring_count(br) != 0) { AIM_LOG_ERROR("count is %d but should be zero", bigring_count(br)); abort(); } c = (intptr_t)bigring_shift(br); if(c != 0) { AIM_LOG_ERROR("shift returned %p when it should have returned null", c); abort(); } /** Add an entry, pop and entry */ c = 1; bigring_push(br, (void*)c); ASSERT_COUNT(bigring_count(br), 1, bigring_size(br)); c = (intptr_t)bigring_shift(br); if(c != 1) { AIM_LOG_ERROR("shift returned %p when it should have returned 1", c); abort(); } ASSERT_COUNT(bigring_count(br), 0, bigring_size(br)); /* Repopulate and iterate instead of shifting */ for(c = 0; c < count; c++) { #define ASSERT_COUNT(_bc, _vc, _size) \ do { \ if(_bc != ((_vc < _size) ? _vc : _size)) { \ AIM_LOG_ERROR("size = %d, count is %d, should be %d", _size, _bc, _vc); \ abort(); \ } \ } while(0) ASSERT_COUNT(bigring_count(br), c, bigring_size(br)); bigring_push(br, (void*)c); } { int j; /* Iterate twice */ for(j = 0; j < 2; j++) { int iter = -42; bigring_lock(br); bigring_iter_start(br, &iter); /** Make sure the entries are correct (module size) */ start = (count <= size) ? 0 : count - size; max = (count <= size) ? count : size; for(i = 0; i < max; i++, start++) { intptr_t v = (intptr_t)bigring_iter_next(br, &iter); if(v != start) { AIM_LOG_ERROR("entry mismatch @%d - expected %p, got %p", i, start, v); } ASSERT_COUNT(bigring_count_locked(br), max, bigring_size(br)); } c = (intptr_t)bigring_iter_next(br, &iter); if(c != 0) { AIM_LOG_MSG("bigring_iter_next() returned %d when it should have returned NULL", c); } c = (intptr_t)bigring_iter_next(br, &iter); if(c != 0) { AIM_LOG_MSG("bigring_iter_next() returned %d when it should have returned NULL", c); } bigring_unlock(br); } } bigring_destroy(br); }
/* * item_create() * Creates a new item */ item_t *item_create(int type) { item_t *item = NULL; switch(type) { case IT_RING: item = collectible_create(); break; case IT_BOUNCINGRING: item = bouncingcollectible_create(); break; case IT_LIFEBOX: item = lifebox_create(); break; case IT_RINGBOX: item = collectiblebox_create(); break; case IT_STARBOX: item = starbox_create(); break; case IT_SPEEDBOX: item = speedbox_create(); break; case IT_GLASSESBOX: item = glassesbox_create(); break; case IT_SHIELDBOX: item = shieldbox_create(); break; case IT_FIRESHIELDBOX: item = fireshieldbox_create(); break; case IT_THUNDERSHIELDBOX: item = thundershieldbox_create(); break; case IT_WATERSHIELDBOX: item = watershieldbox_create(); break; case IT_ACIDSHIELDBOX: item = acidshieldbox_create(); break; case IT_WINDSHIELDBOX: item = windshieldbox_create(); break; case IT_TRAPBOX: item = trapbox_create(); break; case IT_EMPTYBOX: item = emptybox_create(); break; case IT_CRUSHEDBOX: item = crushedbox_create(); break; case IT_ICON: item = icon_create(); break; case IT_EXPLOSION: item = explosion_create(); break; case IT_FLYINGTEXT: item = flyingtext_create(); break; case IT_ANIMAL: item = animal_create(); break; case IT_LOOPRIGHT: item = loopright_create(); break; case IT_LOOPMIDDLE: item = looptop_create(); break; case IT_LOOPLEFT: item = loopleft_create(); break; case IT_LOOPNONE: item = loopnone_create(); break; case IT_LOOPFLOOR: item = loopfloor_create(); break; case IT_LOOPFLOORNONE: item = loopfloornone_create(); break; case IT_LOOPFLOORTOP: item = loopfloortop_create(); break; case IT_YELLOWSPRING: item = yellowspring_create(); break; case IT_BYELLOWSPRING: item = byellowspring_create(); break; case IT_TRYELLOWSPRING: item = tryellowspring_create(); break; case IT_RYELLOWSPRING: item = ryellowspring_create(); break; case IT_BRYELLOWSPRING: item = bryellowspring_create(); break; case IT_BLYELLOWSPRING: item = blyellowspring_create(); break; case IT_LYELLOWSPRING: item = lyellowspring_create(); break; case IT_TLYELLOWSPRING: item = tlyellowspring_create(); break; case IT_REDSPRING: item = redspring_create(); break; case IT_BREDSPRING: item = bredspring_create(); break; case IT_TRREDSPRING: item = trredspring_create(); break; case IT_RREDSPRING: item = rredspring_create(); break; case IT_BRREDSPRING: item = brredspring_create(); break; case IT_BLREDSPRING: item = blredspring_create(); break; case IT_LREDSPRING: item = lredspring_create(); break; case IT_TLREDSPRING: item = tlredspring_create(); break; case IT_BLUESPRING: item = bluespring_create(); break; case IT_BBLUESPRING: item = bbluespring_create(); break; case IT_TRBLUESPRING: item = trbluespring_create(); break; case IT_RBLUESPRING: item = rbluespring_create(); break; case IT_BRBLUESPRING: item = brbluespring_create(); break; case IT_BLBLUESPRING: item = blbluespring_create(); break; case IT_LBLUESPRING: item = lbluespring_create(); break; case IT_TLBLUESPRING: item = tlbluespring_create(); break; case IT_BLUERING: item = supercollectible_create(); break; case IT_SWITCH: item = switch_create(); break; case IT_DOOR: item = door_create(); break; case IT_TELEPORTER: item = teleporter_create(); break; case IT_BIGRING: item = bigring_create(); break; case IT_CHECKPOINT: item = checkpointorb_create(); break; case IT_GOAL: item = goalsign_create(); break; case IT_ENDSIGN: item = endsign_create(); break; case IT_ENDLEVEL: item = animalprison_create(); break; case IT_BUMPER: item = bumper_create(); break; case IT_DANGER: item = horizontaldanger_create(); break; case IT_VDANGER: item = verticaldanger_create(); break; case IT_FIREDANGER: item = horizontalfiredanger_create(); break; case IT_VFIREDANGER: item = verticalfiredanger_create(); break; case IT_SPIKES: item = floorspikes_create(); break; case IT_CEILSPIKES: item = ceilingspikes_create(); break; case IT_LWSPIKES: item = leftwallspikes_create(); break; case IT_RWSPIKES: item = rightwallspikes_create(); break; case IT_PERSPIKES: item = periodic_floorspikes_create(); break; case IT_PERCEILSPIKES: item = periodic_ceilingspikes_create(); break; case IT_PERLWSPIKES: item = periodic_leftwallspikes_create(); break; case IT_PERRWSPIKES: item = periodic_rightwallspikes_create(); break; case IT_DNADOOR: item = surge_dnadoor_create(); break; case IT_DNADOORNEON: item = neon_dnadoor_create(); break; case IT_DNADOORCHARGE: item = charge_dnadoor_create(); break; case IT_HDNADOOR: item = surge_horizontal_dnadoor_create(); break; case IT_HDNADOORNEON: item = neon_horizontal_dnadoor_create(); break; case IT_HDNADOORCHARGE: item = charge_horizontal_dnadoor_create(); break; case IT_LOOPGREEN: item = loopgreen_create(); break; case IT_LOOPYELLOW: item = loopyellow_create(); break; } if(item != NULL) { item->type = type; item->state = IS_IDLE; item->init(item); } return item; }