| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include <global.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#include <check.h> |
| 36 |
#include <loader.h> |
| 37 |
#include <toolkit_common.h> |
| 38 |
|
| 39 |
#include "stringbuffer.h" |
| 40 |
|
| 41 |
static void setup(void) { |
| 42 |
cctk_setdatadir(BUILD_ROOT "lib"); |
| 43 |
cctk_setlog(LOGDIR "/unit/common/object.out"); |
| 44 |
printf("set log to %s\n", LOGDIR"/unit/common/object.out"); |
| 45 |
cctk_init_std_archetypes(); |
| 46 |
} |
| 47 |
|
| 48 |
static void teardown(void) { |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
START_TEST(test_object_can_merge) { |
| 103 |
object *ob1; |
| 104 |
object *ob2; |
| 105 |
|
| 106 |
ob1 = cctk_create_game_object(NULL); |
| 107 |
ob2 = cctk_create_game_object(NULL); |
| 108 |
fail_unless(object_can_merge(ob1, ob2), "Should be able to merge 2 same object"); |
| 109 |
ob2->name = add_string("Not same name"); |
| 110 |
fail_unless(!object_can_merge(ob1, ob2), "Should not be able to merge 2 object with different names"); |
| 111 |
ob2 = cctk_create_game_object(NULL); |
| 112 |
ob2->type++; |
| 113 |
fail_unless(!object_can_merge(ob1, ob2), "Should not be able to merge 2 object with different types"); |
| 114 |
ob2 = cctk_create_game_object(NULL); |
| 115 |
ob1->nrof = (1UL<<31)-1; |
| 116 |
ob2->nrof = 1; |
| 117 |
fail_unless(!object_can_merge(ob1, ob2), "Should not be able to merge 2 object if result nrof goes to 1<<31 or higher"); |
| 118 |
|
| 119 |
} |
| 120 |
END_TEST |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
START_TEST(test_object_sum_weight) { |
| 126 |
object *ob1; |
| 127 |
object *ob2; |
| 128 |
object *ob3; |
| 129 |
object *ob4; |
| 130 |
unsigned long sum; |
| 131 |
|
| 132 |
ob1 = cctk_create_game_object(NULL); |
| 133 |
ob2 = cctk_create_game_object(NULL); |
| 134 |
ob3 = cctk_create_game_object(NULL); |
| 135 |
ob4 = cctk_create_game_object(NULL); |
| 136 |
ob1->weight = 10; |
| 137 |
ob1->type = CONTAINER; |
| 138 |
ob1->stats.Str = 40; |
| 139 |
ob2->weight = 6; |
| 140 |
ob2->nrof = 10; |
| 141 |
ob3->weight = 7; |
| 142 |
ob4->weight = 8; |
| 143 |
object_insert_in_ob(ob2, ob1); |
| 144 |
object_insert_in_ob(ob3, ob1); |
| 145 |
object_insert_in_ob(ob4, ob1); |
| 146 |
sum = object_sum_weight(ob1); |
| 147 |
fail_unless(sum == 45, "Sum of object's inventory should be 45 ((6*10+7+8)*.6) but was %lu.", sum); |
| 148 |
} |
| 149 |
END_TEST |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
START_TEST(test_object_get_env_recursive) { |
| 155 |
object *ob1; |
| 156 |
object *ob2; |
| 157 |
object *ob3; |
| 158 |
object *ob4; |
| 159 |
object *result; |
| 160 |
|
| 161 |
ob1 = cctk_create_game_object(NULL); |
| 162 |
ob2 = cctk_create_game_object(NULL); |
| 163 |
ob3 = cctk_create_game_object(NULL); |
| 164 |
ob4 = cctk_create_game_object(NULL); |
| 165 |
object_insert_in_ob(ob2, ob1); |
| 166 |
object_insert_in_ob(ob3, ob2); |
| 167 |
object_insert_in_ob(ob4, ob3); |
| 168 |
result = object_get_env_recursive(ob4); |
| 169 |
fail_unless(result == ob1, "Getting top level container for ob4(%p) should bring ob1(%p) but brought %p.", ob4, ob1, result); |
| 170 |
} |
| 171 |
END_TEST |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
START_TEST(test_object_get_player_container) { |
| 177 |
object *ob1; |
| 178 |
object *ob2; |
| 179 |
object *ob3; |
| 180 |
object *ob4; |
| 181 |
object *result; |
| 182 |
|
| 183 |
ob1 = cctk_create_game_object(NULL); |
| 184 |
ob2 = cctk_create_game_object(NULL); |
| 185 |
ob3 = cctk_create_game_object(NULL); |
| 186 |
ob4 = cctk_create_game_object(NULL); |
| 187 |
object_insert_in_ob(ob2, ob1); |
| 188 |
object_insert_in_ob(ob3, ob2); |
| 189 |
object_insert_in_ob(ob4, ob3); |
| 190 |
result = object_get_player_container(ob4); |
| 191 |
fail_unless(result == NULL, "Getting containing player for ob4(%p) should bring NULL but brought %p while not contained in a player.", ob4, result); |
| 192 |
ob1->type = PLAYER; |
| 193 |
result = object_get_player_container(ob4); |
| 194 |
fail_unless(result == ob1, "Getting containing player for ob4(%p) should bring ob1(%p) but brought %p while ob1 is player.", ob4, ob1, result); |
| 195 |
} |
| 196 |
END_TEST |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
START_TEST(test_object_dump) { |
| 202 |
object *ob1; |
| 203 |
object *ob2; |
| 204 |
object *ob3; |
| 205 |
StringBuffer *sb; |
| 206 |
char *result; |
| 207 |
|
| 208 |
ob1 = cctk_create_game_object(NULL); |
| 209 |
ob2 = cctk_create_game_object(NULL); |
| 210 |
ob3 = cctk_create_game_object(NULL); |
| 211 |
object_insert_in_ob(ob2, ob1); |
| 212 |
object_insert_in_ob(ob3, ob2); |
| 213 |
sb = stringbuffer_new(); |
| 214 |
object_dump(ob1, sb); |
| 215 |
result = stringbuffer_finish(sb); |
| 216 |
fail_unless(strstr(result, "arch") != NULL, "The object dump should contain 'arch' but was %s", sb); |
| 217 |
free(result); |
| 218 |
} |
| 219 |
END_TEST |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
START_TEST(test_object_dump_all) { |
| 225 |
cctk_create_game_object(NULL); |
| 226 |
cctk_create_game_object(NULL); |
| 227 |
cctk_create_game_object(NULL); |
| 228 |
object_dump_all(); |
| 229 |
} |
| 230 |
END_TEST |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
START_TEST(test_object_find_by_tag_global) { |
| 236 |
object *ob1; |
| 237 |
object *result; |
| 238 |
|
| 239 |
cctk_create_game_object(NULL); |
| 240 |
cctk_create_game_object(NULL); |
| 241 |
ob1 = cctk_create_game_object(NULL); |
| 242 |
result = object_find_by_tag_global(ob1->count); |
| 243 |
fail_unless(result == ob1, "Should find ob1(%p) while search for item %d but got %p", ob1, ob1->count, result); |
| 244 |
} |
| 245 |
END_TEST |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
START_TEST(test_object_find_by_name_global) { |
| 251 |
object *ob1; |
| 252 |
object *result; |
| 253 |
|
| 254 |
ob1 = cctk_create_game_object(NULL); |
| 255 |
ob1->name = add_string("This is a name"); |
| 256 |
ob1 = cctk_create_game_object(NULL); |
| 257 |
ob1->name = add_string("This is another name"); |
| 258 |
ob1 = cctk_create_game_object(NULL); |
| 259 |
ob1->name = add_string("This is the key name"); |
| 260 |
result = object_find_by_name_global(add_string("This is the key name")); |
| 261 |
fail_unless(result == ob1, "Searching for object with name 'This is the key name' returned %p(%s) instead of ob1(%p)", result, result ? result->name : "null", ob1); |
| 262 |
} |
| 263 |
END_TEST |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
START_TEST(test_object_free_all_data) { |
| 269 |
|
| 270 |
} |
| 271 |
END_TEST |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
START_TEST(test_object_get_owner) { |
| 277 |
object *ob1; |
| 278 |
object *ob2; |
| 279 |
|
| 280 |
ob1 = cctk_create_game_object(NULL); |
| 281 |
ob2 = cctk_create_game_object(NULL); |
| 282 |
object_set_owner(ob2, ob1); |
| 283 |
CLEAR_FLAG(ob1, FLAG_REMOVED); |
| 284 |
CLEAR_FLAG(ob2, FLAG_REMOVED); |
| 285 |
fail_unless(object_get_owner(ob2) == ob1, "Owner of ob2(%p) shoud be ob1(%p) but was %p", ob2, ob1, object_get_owner(ob2)); |
| 286 |
} |
| 287 |
END_TEST |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
START_TEST(test_object_clear_owner) { |
| 293 |
object *ob1; |
| 294 |
object *ob2; |
| 295 |
|
| 296 |
ob1 = cctk_create_game_object(NULL); |
| 297 |
ob2 = cctk_create_game_object(NULL); |
| 298 |
object_set_owner(ob2, ob1); |
| 299 |
fail_unless(ob2->owner != NULL, "Prior to testing object_clear_owner, owner of ob2 was wrongly initialized"); |
| 300 |
object_clear_owner(ob2); |
| 301 |
fail_unless(ob2->owner == NULL, "After object_clear_owner ob2 still had an owner"); |
| 302 |
} |
| 303 |
END_TEST |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
START_TEST(test_object_set_owner) { |
| 309 |
object *ob1; |
| 310 |
object *ob2; |
| 311 |
|
| 312 |
ob1 = cctk_create_game_object(NULL); |
| 313 |
ob2 = cctk_create_game_object(NULL); |
| 314 |
object_set_owner(ob2, ob1); |
| 315 |
fail_unless(ob2->owner == ob1, "After object_set_owner ob2(%p) owner should be ob1(%p) but was (%p)", ob2, ob1, ob2->owner); |
| 316 |
} |
| 317 |
END_TEST |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
START_TEST(test_object_copy_owner) { |
| 323 |
object *ob1; |
| 324 |
object *ob2; |
| 325 |
object *ob3; |
| 326 |
|
| 327 |
ob1 = cctk_create_game_object(NULL); |
| 328 |
ob2 = cctk_create_game_object(NULL); |
| 329 |
ob3 = cctk_create_game_object(NULL); |
| 330 |
object_set_owner(ob2, ob1); |
| 331 |
object_copy_owner(ob3, ob2); |
| 332 |
fail_unless(object_get_owner(ob2) == object_get_owner(ob3), "After object_copy_owner, ob3 and ob2 should have same owner (ob1=%p) but got %p and %p", object_get_owner(ob3), object_get_owner(ob2)); |
| 333 |
} |
| 334 |
END_TEST |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
START_TEST(test_object_reset) { |
| 340 |
object *ob1; |
| 341 |
|
| 342 |
ob1 = cctk_create_game_object(NULL); |
| 343 |
object_reset(ob1); |
| 344 |
fail_unless(ob1->name == NULL, "Field name of ob1 was not NULLified by object_reset"); |
| 345 |
fail_unless(ob1->name_pl == NULL, "Field name_pl of ob1 was not NULLified by object_reset"); |
| 346 |
fail_unless(ob1->title == NULL, "Field title of ob1 was not NULLified by object_reset"); |
| 347 |
fail_unless(ob1->race == NULL, "Field race of ob1 was not NULLified by object_reset"); |
| 348 |
fail_unless(ob1->slaying == NULL, "Field slaying of ob1 was not NULLified by object_reset"); |
| 349 |
fail_unless(ob1->skill == NULL, "Field skill of ob1 was not NULLified by object_reset"); |
| 350 |
fail_unless(ob1->msg == NULL, "Field msg of ob1 was not NULLified by object_reset"); |
| 351 |
fail_unless(ob1->materialname == NULL, "Field materialname of ob1 was not NULLified by object_reset"); |
| 352 |
fail_unless(ob1->lore == NULL, "Field lore of ob1 was not NULLified by object_reset"); |
| 353 |
} |
| 354 |
END_TEST |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
START_TEST(test_object_clear) { |
| 360 |
object *ob1; |
| 361 |
const char *reference; |
| 362 |
|
| 363 |
ob1 = cctk_create_game_object(NULL); |
| 364 |
cctk_set_object_strings(ob1, "This is a test String"); |
| 365 |
reference = add_string("This is a test String"); |
| 366 |
object_clear(ob1); |
| 367 |
fail_unless(ob1->name == NULL, "Field name of ob1 was not cleaned by object_clear"); |
| 368 |
fail_unless(ob1->name_pl == NULL, "Field name_pl of ob1 was not cleaned by object_clear"); |
| 369 |
fail_unless(ob1->title == NULL, "Field title of ob1 was not cleaned by object_clear"); |
| 370 |
fail_unless(ob1->race == NULL, "Field race of ob1 was not cleaned by object_clear"); |
| 371 |
fail_unless(ob1->slaying == NULL, "Field slaying of ob1 was not cleaned by object_clear"); |
| 372 |
fail_unless(ob1->skill == NULL, "Field skill of ob1 was not cleaned by object_clear"); |
| 373 |
fail_unless(ob1->msg == NULL, "Field msg of ob1 was not cleaned by object_clear"); |
| 374 |
fail_unless(ob1->materialname == NULL, "Field materialname of ob1 was not cleaned by object_clear"); |
| 375 |
fail_unless(ob1->lore == NULL, "Field lore of ob1 was not cleaned by object_clear"); |
| 376 |
fail_unless(query_refcount(reference) == 1, "The number of references to string should drop back to 1 but was %d", query_refcount(reference)); |
| 377 |
} |
| 378 |
END_TEST |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
START_TEST(test_object_copy) { |
| 384 |
object *ob1; |
| 385 |
object *ob2; |
| 386 |
const char *reference; |
| 387 |
|
| 388 |
ob1 = cctk_create_game_object(NULL); |
| 389 |
ob2 = cctk_create_game_object(NULL); |
| 390 |
cctk_set_object_strings(ob1, "test String1"); |
| 391 |
cctk_set_object_strings(ob2, "test String2"); |
| 392 |
reference = add_string("test String2"); |
| 393 |
object_copy(ob1, ob2); |
| 394 |
fail_unless(ob1->name == ob2->name, "Field name of ob1 should match ob2"); |
| 395 |
fail_unless(ob1->name_pl == ob2->name_pl, "Field name_pl of ob1 should match ob2"); |
| 396 |
fail_unless(ob1->title == ob2->title, "Field title of ob1 should match ob2"); |
| 397 |
fail_unless(ob1->race == ob2->race, "Field race of ob1 should match ob2"); |
| 398 |
fail_unless(ob1->slaying == ob2->slaying, "Field slaying of ob1 should match ob2"); |
| 399 |
fail_unless(ob1->skill == ob2->skill, "Field skill of ob1 should match ob2"); |
| 400 |
fail_unless(ob1->msg == ob2->msg, "Field msg of ob1 should match ob2"); |
| 401 |
fail_unless(ob1->materialname == ob2->materialname, "Field materialname of ob1 should match ob2"); |
| 402 |
fail_unless(ob1->lore == ob2->lore, "Field lore of ob1 should match ob2"); |
| 403 |
fail_unless(query_refcount(reference) == 1, "refcount of marker string is not dropped to 1 after copy object, some string field were not cleaned. refcount: %d", query_refcount(reference)); |
| 404 |
} |
| 405 |
END_TEST |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
START_TEST(test_object_new) { |
| 412 |
object *ob; |
| 413 |
long int i; |
| 414 |
|
| 415 |
ob = object_new(); |
| 416 |
fail_unless(ob != NULL, "Should get an object after calling object_new()"); |
| 417 |
fail_unless(ob->name == NULL, "Field name has not been nullified by object_new()"); |
| 418 |
fail_unless(ob->name_pl == NULL, "Field name_pl has not been nullified by object_new()"); |
| 419 |
fail_unless(ob->title == NULL, "Field title has not been nullified by object_new()"); |
| 420 |
fail_unless(ob->race == NULL, "Field race has not been nullified by object_new()"); |
| 421 |
fail_unless(ob->slaying == NULL, "Field slaying has not been nullified by object_new()"); |
| 422 |
fail_unless(ob->skill == NULL, "Field skill has not been nullified by object_new()"); |
| 423 |
fail_unless(ob->lore == NULL, "Field lore has not been nullified by object_new()"); |
| 424 |
fail_unless(ob->msg == NULL, "Field msg has not been nullified by object_new()"); |
| 425 |
fail_unless(ob->materialname == NULL, "Field materialname has not been nullified by object_new()"); |
| 426 |
fail_unless(ob->prev == NULL, "Field prev has not been nullified by object_new()"); |
| 427 |
fail_unless(ob->active_next == NULL, "Field active_next has not been nullified by object_new()"); |
| 428 |
fail_unless(ob->active_prev == NULL, "Field active_prev has not been nullified by object_new()"); |
| 429 |
|
| 430 |
|
| 431 |
for (i = 0; i < 1L<<17; i++) { |
| 432 |
ob = object_new(); |
| 433 |
fail_unless(ob != NULL, "Should get an object after calling object_new() (iteration %l)", i); |
| 434 |
if (!(i&((1<<13)-1))) |
| 435 |
LOG(llevDebug, "%ldk items created with object_new\n", i>>10); |
| 436 |
} |
| 437 |
} |
| 438 |
END_TEST |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
START_TEST(test_object_update_turn_face) { |
| 444 |
object *ob1; |
| 445 |
const Face *face1; |
| 446 |
const Face *face2; |
| 447 |
|
| 448 |
ob1 = cctk_create_game_object("arrow"); |
| 449 |
ob1->direction = 1; |
| 450 |
object_update_turn_face(ob1); |
| 451 |
face1 = ob1->face; |
| 452 |
ob1->direction = 0; |
| 453 |
object_update_turn_face(ob1); |
| 454 |
face2 = ob1->face; |
| 455 |
fail_unless(face2 != face1, "2 opposite direction should provide different faces after object_update_turn_face"); |
| 456 |
} |
| 457 |
END_TEST |
| 458 |
|
| 459 |
#define IS_OBJECT_ACTIVE(op) (op->active_next || op->active_prev || op == active_objects) |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
START_TEST(test_object_update_speed) { |
| 464 |
object *ob1; |
| 465 |
object *ob2; |
| 466 |
object *ob3; |
| 467 |
object *ob4; |
| 468 |
|
| 469 |
ob1 = cctk_create_game_object(NULL); |
| 470 |
ob2 = cctk_create_game_object(NULL); |
| 471 |
ob3 = cctk_create_game_object(NULL); |
| 472 |
ob4 = cctk_create_game_object(NULL); |
| 473 |
ob1->speed = MIN_ACTIVE_SPEED; |
| 474 |
object_update_speed(ob1); |
| 475 |
fail_unless(!IS_OBJECT_ACTIVE(ob1), "Object with absolute speed <=MIN_ACTIVE_SPEED(%f) should not be made active (speed=%f)", MIN_ACTIVE_SPEED, ob1->speed); |
| 476 |
ob1->speed = -MIN_ACTIVE_SPEED; |
| 477 |
object_update_speed(ob1); |
| 478 |
fail_unless(!IS_OBJECT_ACTIVE(ob1), "Object with absolute speed <=MIN_ACTIVE_SPEED(%f) should not be made active (speed=%f)", MIN_ACTIVE_SPEED, ob1->speed); |
| 479 |
ob1->speed = MIN_ACTIVE_SPEED*2; |
| 480 |
object_update_speed(ob1); |
| 481 |
fail_unless(IS_OBJECT_ACTIVE(ob1), "Object with absolute speed >MIN_ACTIVE_SPEED(%f) should be made active (speed=%f)", MIN_ACTIVE_SPEED, ob1->speed); |
| 482 |
ob2->speed = -MIN_ACTIVE_SPEED*2; |
| 483 |
object_update_speed(ob2); |
| 484 |
fail_unless(IS_OBJECT_ACTIVE(ob2), "Object with absolute speed >MIN_ACTIVE_SPEED(%f) should be made active (speed=%f)", MIN_ACTIVE_SPEED, ob2->speed); |
| 485 |
ob4->speed = ob3->speed = ob2->speed; |
| 486 |
object_update_speed(ob3); |
| 487 |
object_update_speed(ob4); |
| 488 |
fail_unless(IS_OBJECT_ACTIVE(ob3), "Object with absolute speed >MIN_ACTIVE_SPEED(%f) should be made active (speed=%f)", MIN_ACTIVE_SPEED, ob3->speed); |
| 489 |
fail_unless(IS_OBJECT_ACTIVE(ob4), "Object with absolute speed >MIN_ACTIVE_SPEED(%f) should be made active (speed=%f)", MIN_ACTIVE_SPEED, ob4->speed); |
| 490 |
ob1->speed = 0.0; |
| 491 |
ob2->speed = 0.0; |
| 492 |
ob3->speed = 0.0; |
| 493 |
ob4->speed = 0.0; |
| 494 |
object_update_speed(ob1); |
| 495 |
object_update_speed(ob2); |
| 496 |
object_update_speed(ob3); |
| 497 |
object_update_speed(ob4); |
| 498 |
fail_unless(!IS_OBJECT_ACTIVE(ob1), "Object with absolute speed 0.0 should be inactivated", ob1->speed); |
| 499 |
fail_unless(!IS_OBJECT_ACTIVE(ob2), "Object with absolute speed 0.0 should be inactivated", ob2->speed); |
| 500 |
fail_unless(!IS_OBJECT_ACTIVE(ob3), "Object with absolute speed 0.0 should be inactivated", ob3->speed); |
| 501 |
fail_unless(!IS_OBJECT_ACTIVE(ob4), "Object with absolute speed 0.0 should be inactivated", ob4->speed); |
| 502 |
} |
| 503 |
END_TEST |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
START_TEST(test_object_remove_from_active_list) { |
| 509 |
object *ob1; |
| 510 |
|
| 511 |
ob1 = cctk_create_game_object(NULL); |
| 512 |
ob1->speed = MIN_ACTIVE_SPEED*2; |
| 513 |
object_update_speed(ob1); |
| 514 |
fail_unless(IS_OBJECT_ACTIVE(ob1), "Object with absolute speed >MIN_ACTIVE_SPEED(%f) should be made active (speed=%f)", MIN_ACTIVE_SPEED, ob1->speed); |
| 515 |
object_remove_from_active_list(ob1); |
| 516 |
fail_unless(!IS_OBJECT_ACTIVE(ob1), "After call to object_remove_from_active_list, object should be made inactive"); |
| 517 |
} |
| 518 |
END_TEST |
| 519 |
#undef IS_OBJECT_ACTIVE |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
START_TEST(test_object_update) { |
| 525 |
|
| 526 |
} |
| 527 |
END_TEST |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
START_TEST(test_object_free_drop_inventory) { |
| 533 |
object *ob1; |
| 534 |
object *ob2; |
| 535 |
|
| 536 |
ob1 = cctk_create_game_object(NULL); |
| 537 |
ob2 = cctk_create_game_object(NULL); |
| 538 |
object_insert_in_ob(ob2, ob1); |
| 539 |
object_free_drop_inventory(ob1); |
| 540 |
fail_unless(QUERY_FLAG(ob1, FLAG_FREED), "Freeing ob1 should mark it freed"); |
| 541 |
fail_unless(QUERY_FLAG(ob2, FLAG_FREED), "Freeing ob1 should mark it's content freed"); |
| 542 |
} |
| 543 |
END_TEST |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
START_TEST(test_object_count_free) { |
| 549 |
int free1, free2; |
| 550 |
|
| 551 |
cctk_create_game_object(NULL); |
| 552 |
free1 = object_count_free(); |
| 553 |
cctk_create_game_object(NULL); |
| 554 |
free2 = object_count_free(); |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
#ifdef MEMORY_DEBUG |
| 559 |
fail_unless(((free2 == 0) && (free1 == 0)), "after creating an object, the object_count_free() should return 0 (compiled with MEMORY_DEBUG)", free1-1, free2); |
| 560 |
#else |
| 561 |
fail_unless((free2 == free1-1), "after creating an object, the object_count_free() should return one less (%d) but returned %d", free1-1, free2); |
| 562 |
#endif |
| 563 |
} |
| 564 |
END_TEST |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
START_TEST(test_object_count_used) { |
| 570 |
int used1, used2; |
| 571 |
|
| 572 |
cctk_create_game_object(NULL); |
| 573 |
used1 = object_count_used(); |
| 574 |
cctk_create_game_object(NULL); |
| 575 |
used2 = object_count_used(); |
| 576 |
fail_unless((used2 == used1+1), "after creating an object, the object_count_used() should return one more (%d) but returned %d", used1-1, used2); |
| 577 |
} |
| 578 |
END_TEST |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
START_TEST(test_object_count_active) { |
| 584 |
object *ob1; |
| 585 |
int active1, active2; |
| 586 |
|
| 587 |
ob1 = cctk_create_game_object(NULL); |
| 588 |
ob1->speed = MIN_ACTIVE_SPEED*2; |
| 589 |
object_update_speed(ob1); |
| 590 |
active1 = object_count_active(); |
| 591 |
ob1 = cctk_create_game_object(NULL); |
| 592 |
ob1->speed = MIN_ACTIVE_SPEED*2; |
| 593 |
object_update_speed(ob1); |
| 594 |
active2 = object_count_active(); |
| 595 |
fail_unless((active2 == active1+1), "after activating an additional object, object_count_active should return one less %d but returned %d", active1-1, active2); |
| 596 |
} |
| 597 |
END_TEST |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
START_TEST(test_object_sub_weight) { |
| 603 |
object *ob1; |
| 604 |
object *ob2; |
| 605 |
object *ob3; |
| 606 |
object *ob4; |
| 607 |
unsigned long sum; |
| 608 |
|
| 609 |
ob1 = cctk_create_game_object(NULL); |
| 610 |
ob2 = cctk_create_game_object(NULL); |
| 611 |
ob3 = cctk_create_game_object(NULL); |
| 612 |
ob4 = cctk_create_game_object(NULL); |
| 613 |
ob1->weight = 10; |
| 614 |
ob1->type = CONTAINER; |
| 615 |
ob2->type = CONTAINER; |
| 616 |
ob3->type = CONTAINER; |
| 617 |
ob1->stats.Str = 40; |
| 618 |
ob2->weight = 10; |
| 619 |
ob3->weight = 10; |
| 620 |
ob4->weight = 10; |
| 621 |
object_insert_in_ob(ob2, ob1); |
| 622 |
object_insert_in_ob(ob3, ob2); |
| 623 |
object_insert_in_ob(ob4, ob3); |
| 624 |
sum = object_sum_weight(ob1); |
| 625 |
fail_unless(sum == 18, "Sum of object's inventory should be 18 (30*0.6+10) but was %lu.", sum); |
| 626 |
object_sub_weight(ob4, 10); |
| 627 |
fail_unless(ob1->carrying == 12, "after call to object_sub_weight, carrying of ob1 should be 22 but was %d", ob1->carrying); |
| 628 |
} |
| 629 |
END_TEST |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
START_TEST(test_object_remove) { |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
} |
| 641 |
END_TEST |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
START_TEST(test_object_merge) { |
| 647 |
object *ob1; |
| 648 |
object *ob2; |
| 649 |
object *ob3; |
| 650 |
object *ob4; |
| 651 |
|
| 652 |
ob1 = cctk_create_game_object(NULL); |
| 653 |
ob2 = cctk_create_game_object(NULL); |
| 654 |
ob3 = cctk_create_game_object(NULL); |
| 655 |
ob4 = cctk_create_game_object(NULL); |
| 656 |
cctk_create_game_object(NULL); |
| 657 |
ob1->below = ob2; |
| 658 |
ob2->below = ob3; |
| 659 |
ob3->below = ob4; |
| 660 |
ob2->above = ob1; |
| 661 |
ob3->above = ob2; |
| 662 |
ob4->above = ob3; |
| 663 |
ob1->name = add_string("test"); |
| 664 |
ob2->name = add_string("test2"); |
| 665 |
ob3->name = add_string("test3"); |
| 666 |
} |
| 667 |
END_TEST |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
START_TEST(test_object_insert_in_map_at) { |
| 673 |
mapstruct *map; |
| 674 |
object *first = NULL; |
| 675 |
object *got = NULL; |
| 676 |
|
| 677 |
map = get_empty_map(5, 5); |
| 678 |
fail_unless(map != NULL, "get_empty_map returned NULL."); |
| 679 |
|
| 680 |
|
| 681 |
first = cctk_create_game_object("barrel"); |
| 682 |
fail_unless(first != NULL, "create barrel failed"); |
| 683 |
|
| 684 |
got = object_insert_in_map_at(first, map, NULL, 0, 0, 0); |
| 685 |
fail_unless(got == first, "item shouldn't be destroyed"); |
| 686 |
|
| 687 |
first = cctk_create_game_object("dragon"); |
| 688 |
fail_unless(first != NULL, "create dragon failed"); |
| 689 |
fail_unless(first->more != NULL, "no other body part"); |
| 690 |
|
| 691 |
got = object_insert_in_map_at(first, map, NULL, 0, 1, 1); |
| 692 |
fail_unless(got == first, "item shouldn't be destroyed"); |
| 693 |
|
| 694 |
fail_unless(GET_MAP_OB(map, 1, 1) == first, "item isn't on 1,1"); |
| 695 |
fail_unless(GET_MAP_OB(map, 2, 1) != NULL, "no item on 2,1"); |
| 696 |
fail_unless(GET_MAP_OB(map, 2, 1)->head == first, "head of 2,1 isn't 1,1"); |
| 697 |
} |
| 698 |
END_TEST |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
START_TEST(test_object_insert_in_map) { |
| 704 |
mapstruct *map; |
| 705 |
object *first = NULL; |
| 706 |
object *second = NULL; |
| 707 |
object *third = NULL; |
| 708 |
object *floor = NULL; |
| 709 |
object *got = NULL; |
| 710 |
|
| 711 |
map = get_empty_map(5, 5); |
| 712 |
fail_unless(map != NULL, "get_empty_map returned NULL."); |
| 713 |
|
| 714 |
|
| 715 |
floor = cctk_create_game_object("woodfloor"); |
| 716 |
fail_unless(floor != NULL, "create woodfloor failed"); |
| 717 |
floor->x = 3; |
| 718 |
floor->y = 3; |
| 719 |
|
| 720 |
got = object_insert_in_map(floor, map, NULL, 0); |
| 721 |
fail_unless(got == floor, "woodfloor shouldn't disappear"); |
| 722 |
fail_unless(floor == GET_MAP_OB(map, 3, 3), "woodfloor should be first object"); |
| 723 |
|
| 724 |
first = cctk_create_game_object("barrel"); |
| 725 |
fail_unless(first != NULL, "create barrel failed"); |
| 726 |
first->x = 3; |
| 727 |
first->y = 3; |
| 728 |
|
| 729 |
got = object_insert_in_map(first, map, NULL, 0); |
| 730 |
fail_unless(got == first, "barrel shouldn't disappear"); |
| 731 |
fail_unless(floor == GET_MAP_OB(map, 3, 3), "woodfloor should still be first object"); |
| 732 |
fail_unless(floor->above == first, "barrel should be above floor"); |
| 733 |
|
| 734 |
second = cctk_create_game_object("gem"); |
| 735 |
fail_unless(second != NULL, "create gem failed"); |
| 736 |
second->nrof = 1; |
| 737 |
second->x = 3; |
| 738 |
second->y = 3; |
| 739 |
|
| 740 |
got = object_insert_in_map(second, map, NULL, INS_ABOVE_FLOOR_ONLY); |
| 741 |
fail_unless(got == second, "gem shouldn't disappear"); |
| 742 |
fail_unless(floor == GET_MAP_OB(map, 3, 3), "woodfloor should still be first object"); |
| 743 |
fail_unless(floor->above == second, "gem should be above floor"); |
| 744 |
fail_unless(second->above == first, "barrel should be above gem"); |
| 745 |
|
| 746 |
third = cctk_create_game_object("bed_1"); |
| 747 |
fail_unless(third != NULL, "create bed_1 failed"); |
| 748 |
third->nrof = 1; |
| 749 |
third->x = 3; |
| 750 |
third->y = 3; |
| 751 |
|
| 752 |
got = object_insert_in_map(third, map, first, INS_BELOW_ORIGINATOR); |
| 753 |
fail_unless(got == third, "bed_1 shouldn't disappear"); |
| 754 |
fail_unless(floor == GET_MAP_OB(map, 3, 3), "woodfloor should still be first object"); |
| 755 |
fail_unless(third->above == first, "bed should be below barrel"); |
| 756 |
fail_unless(third->below == second, "bed should be above gem"); |
| 757 |
|
| 758 |
|
| 759 |
third = cctk_create_game_object("gem"); |
| 760 |
fail_unless(third != NULL, "create gem failed"); |
| 761 |
third->nrof = 1; |
| 762 |
third->x = 3; |
| 763 |
third->y = 3; |
| 764 |
|
| 765 |
got = object_insert_in_map(third, map, NULL, 0); |
| 766 |
fail_unless(got == third, "gem shouldn't disappear"); |
| 767 |
fail_unless(QUERY_FLAG(second, FLAG_FREED), "first gem should have been removed."); |
| 768 |
fail_unless(third->nrof == 2, "second gem should have nrof 2"); |
| 769 |
|
| 770 |
second = cctk_create_game_object("gem"); |
| 771 |
fail_unless(second != NULL, "create gem failed"); |
| 772 |
second->nrof = 1; |
| 773 |
second->x = 3; |
| 774 |
second->y = 3; |
| 775 |
second->value = 1; |
| 776 |
|
| 777 |
got = object_insert_in_map(second, map, NULL, 0); |
| 778 |
fail_unless(got == second, "modified gem shouldn't disappear"); |
| 779 |
fail_unless(second->nrof == 1, "modified gem should have nrof 1"); |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
} |
| 805 |
END_TEST |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
START_TEST(test_object_replace_insert_in_map) { |
| 812 |
mapstruct *map; |
| 813 |
object *first = NULL, *second = NULL, *third = NULL; |
| 814 |
tag_t tag_first, tag_second, tag_third; |
| 815 |
object *got = NULL; |
| 816 |
|
| 817 |
map = get_empty_map(5, 5); |
| 818 |
fail_unless(map != NULL, "get_empty_map returned NULL."); |
| 819 |
|
| 820 |
|
| 821 |
first = cctk_create_game_object("barrel"); |
| 822 |
fail_unless(first != NULL, "create barrel failed"); |
| 823 |
tag_first = first->count; |
| 824 |
|
| 825 |
got = object_insert_in_map_at(first, map, NULL, 0, 0, 0); |
| 826 |
fail_unless(got == first, "item shouldn't be destroyed"); |
| 827 |
|
| 828 |
second = cctk_create_game_object("table"); |
| 829 |
fail_unless(second != NULL, "create table failed"); |
| 830 |
|
| 831 |
got = object_insert_in_map_at(second, map, NULL, 0, 0, 0); |
| 832 |
fail_unless(got == second, "second item shouldn't be destroyed"); |
| 833 |
tag_second = second->count; |
| 834 |
|
| 835 |
third = cctk_create_game_object("barrel"); |
| 836 |
fail_unless(third != NULL, "create 2nd barrel failed"); |
| 837 |
got = object_insert_in_map_at(third, map, NULL, 0, 0, 0); |
| 838 |
fail_unless(got == third, "second barrel shouldn't be destroyed"); |
| 839 |
tag_third = third->count; |
| 840 |
|
| 841 |
fail_unless(GET_MAP_OB(map, 0, 0) == first, "item at 0,0 isn't barrel"); |
| 842 |
fail_unless(GET_MAP_OB(map, 0, 0)->above == second, "second item at 0,0 isn't table"); |
| 843 |
fail_unless(GET_MAP_OB(map, 0, 0)->above->above == third, "third item at 0,0 isn't barrel"); |
| 844 |
|
| 845 |
object_replace_insert_in_map("barrel", second); |
| 846 |
|
| 847 |
fail_unless(GET_MAP_OB(map, 0, 0) != first, "item at 0, 0 is still first?"); |
| 848 |
fail_unless(object_was_destroyed(first, tag_first), "1st barrel should be destroyed"); |
| 849 |
fail_unless(!object_was_destroyed(second, tag_second), "table shouldn't be destroyed"); |
| 850 |
fail_unless(object_was_destroyed(third, tag_third), "2nd barrel should be destroyed"); |
| 851 |
|
| 852 |
fail_unless(GET_MAP_OB(map, 0, 0) != NULL, "no item at 0,0 after object_replace_insert_in_map"); |
| 853 |
fail_unless(GET_MAP_OB(map, 0, 0) != second, "second at bottom at 0,0 after object_replace_insert_in_map"); |
| 854 |
fail_unless(GET_MAP_OB(map, 0, 0)->above == second, "table isn't above new barrel"); |
| 855 |
fail_unless(strcmp(GET_MAP_OB(map, 0, 0)->arch->name, "barrel") == 0, "item at 0,0 is not a barrel after object_replace_insert_in_map"); |
| 856 |
} |
| 857 |
END_TEST |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
START_TEST(test_object_split) { |
| 863 |
object *first = NULL; |
| 864 |
object *second = NULL; |
| 865 |
char err[50]; |
| 866 |
|
| 867 |
first = cctk_create_game_object("gem"); |
| 868 |
fail_unless(first != NULL, "create gem failed"); |
| 869 |
first->nrof = 5; |
| 870 |
|
| 871 |
second = object_split(first, 2, err, sizeof(err)); |
| 872 |
fail_unless(second != NULL, "should return an item"); |
| 873 |
fail_unless(second->nrof == 2, "2 expected to split"); |
| 874 |
fail_unless(first->nrof == 3, "3 should be left"); |
| 875 |
|
| 876 |
second = object_split(first, 3, err, sizeof(err)); |
| 877 |
fail_unless(second != NULL, "should return an item"); |
| 878 |
fail_unless(QUERY_FLAG(first, FLAG_FREED), "first should be freed"); |
| 879 |
|
| 880 |
first = object_split(second, 10, err, sizeof(err)); |
| 881 |
fail_unless(first == NULL, "should return NULL"); |
| 882 |
fail_unless(second->nrof == 3, "3 should be left"); |
| 883 |
} |
| 884 |
END_TEST |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
START_TEST(test_object_decrease_nrof) { |
| 890 |
object *first = NULL; |
| 891 |
object *second = NULL; |
| 892 |
|
| 893 |
first = cctk_create_game_object("gem"); |
| 894 |
fail_unless(first != NULL, "create gem failed"); |
| 895 |
first->nrof = 5; |
| 896 |
|
| 897 |
second = object_decrease_nrof(first, 3); |
| 898 |
fail_unless(second == first, "gem shouldn't be destroyed"); |
| 899 |
|
| 900 |
second = object_decrease_nrof(first, 2); |
| 901 |
fail_unless(second == NULL, "object_decrease_nrof should return NULL"); |
| 902 |
fail_unless(QUERY_FLAG(first, FLAG_FREED), "gem should have been freed"); |
| 903 |
} |
| 904 |
END_TEST |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
START_TEST(test_object_add_weight) { |
| 910 |
|
| 911 |
} |
| 912 |
END_TEST |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
START_TEST(test_object_insert_in_ob) { |
| 918 |
object *container = NULL; |
| 919 |
object *item = NULL; |
| 920 |
|
| 921 |
item = cctk_create_game_object("gem"); |
| 922 |
fail_unless(item != NULL, "create gem failed"); |
| 923 |
item->weight = 50; |
| 924 |
|
| 925 |
|
| 926 |
container = cctk_create_game_object("bookshelf"); |
| 927 |
fail_unless(container != NULL, "create bookshelf failed"); |
| 928 |
|
| 929 |
object_insert_in_ob(item, container); |
| 930 |
fail_unless(container->inv == item, "item not inserted"); |
| 931 |
fail_unless(container->carrying == 50, "container should carry 50 and not %d", container->carrying); |
| 932 |
|
| 933 |
object_remove(item); |
| 934 |
fail_unless(container->carrying == 0, "container should carry 0 and not %d", container->carrying); |
| 935 |
|
| 936 |
|
| 937 |
container = cctk_create_game_object("sack"); |
| 938 |
fail_unless(container != NULL, "create sack failed"); |
| 939 |
|
| 940 |
object_insert_in_ob(item, container); |
| 941 |
fail_unless(container->inv == item, "item not inserted"); |
| 942 |
fail_unless(container->carrying == 45, "container should carry 45 and not %d", container->carrying); |
| 943 |
} |
| 944 |
END_TEST |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
START_TEST(test_object_check_move_on) { |
| 950 |
|
| 951 |
} |
| 952 |
END_TEST |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
START_TEST(test_map_find_by_archetype) { |
| 958 |
|
| 959 |
} |
| 960 |
END_TEST |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
START_TEST(test_map_find_by_type) { |
| 966 |
|
| 967 |
} |
| 968 |
END_TEST |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
START_TEST(test_object_present_in_ob) { |
| 974 |
|
| 975 |
} |
| 976 |
END_TEST |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
START_TEST(test_object_present_in_ob_by_name) { |
| 982 |
|
| 983 |
} |
| 984 |
END_TEST |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
START_TEST(test_arch_present_in_ob) { |
| 990 |
|
| 991 |
} |
| 992 |
END_TEST |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
START_TEST(test_object_set_flag_inv) { |
| 998 |
|
| 999 |
} |
| 1000 |
END_TEST |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
START_TEST(test_object_unset_flag_inv) { |
| 1006 |
|
| 1007 |
} |
| 1008 |
END_TEST |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
START_TEST(test_object_set_cheat) { |
| 1014 |
|
| 1015 |
} |
| 1016 |
END_TEST |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
START_TEST(test_object_find_free_spot) { |
| 1022 |
|
| 1023 |
} |
| 1024 |
END_TEST |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
START_TEST(test_object_find_first_free_spot) { |
| 1030 |
|
| 1031 |
} |
| 1032 |
END_TEST |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
START_TEST(test_get_search_arr) { |
| 1038 |
|
| 1039 |
} |
| 1040 |
END_TEST |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
START_TEST(test_map_find_dir) { |
| 1046 |
|
| 1047 |
} |
| 1048 |
END_TEST |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
START_TEST(test_object_distance) { |
| 1054 |
|
| 1055 |
} |
| 1056 |
END_TEST |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
START_TEST(test_find_dir_2) { |
| 1062 |
|
| 1063 |
} |
| 1064 |
END_TEST |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
START_TEST(test_absdir) { |
| 1070 |
|
| 1071 |
} |
| 1072 |
END_TEST |
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
START_TEST(test_dirdiff) { |
| 1078 |
|
| 1079 |
} |
| 1080 |
END_TEST |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
START_TEST(test_can_see_monsterP) { |
| 1086 |
|
| 1087 |
} |
| 1088 |
END_TEST |
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
START_TEST(test_object_can_pick) { |
| 1094 |
|
| 1095 |
} |
| 1096 |
END_TEST |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
START_TEST(test_object_create_clone) { |
| 1102 |
|
| 1103 |
} |
| 1104 |
END_TEST |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
START_TEST(test_object_was_destroyed) { |
| 1110 |
|
| 1111 |
} |
| 1112 |
END_TEST |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
START_TEST(test_object_find_by_type_subtype) { |
| 1118 |
|
| 1119 |
} |
| 1120 |
END_TEST |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
START_TEST(test_object_get_key_value) { |
| 1126 |
|
| 1127 |
} |
| 1128 |
END_TEST |
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
START_TEST(test_object_get_value) { |
| 1134 |
|
| 1135 |
} |
| 1136 |
END_TEST |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
START_TEST(test_object_set_value) { |
| 1142 |
|
| 1143 |
} |
| 1144 |
END_TEST |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
START_TEST(test_object_matches_string) { |
| 1150 |
object *pl; |
| 1151 |
object *o1, *o2; |
| 1152 |
int val; |
| 1153 |
|
| 1154 |
pl = cctk_create_game_object("kobold"); |
| 1155 |
fail_unless(pl != NULL, "couldn't create kobold"); |
| 1156 |
pl->contr = (player *)calloc(1, sizeof(player)); |
| 1157 |
fail_unless(pl->contr != NULL, "couldn't alloc contr"); |
| 1158 |
|
| 1159 |
o1 = cctk_create_game_object("cloak"); |
| 1160 |
fail_unless(o1 != NULL, "couldn't find cloak archetype"); |
| 1161 |
o1->title = add_string("of Gorokh"); |
| 1162 |
CLEAR_FLAG(o1, FLAG_IDENTIFIED); |
| 1163 |
|
| 1164 |
val = object_matches_string(pl, o1, "all"); |
| 1165 |
fail_unless(val == 1, "all didn't match cloak"); |
| 1166 |
val = object_matches_string(pl, o1, "Gorokh"); |
| 1167 |
fail_unless(val == 0, "unidentified cloak matched title with value %d", val); |
| 1168 |
val = object_matches_string(pl, o1, "random"); |
| 1169 |
fail_unless(val == 0, "unidentified cloak matched random value with value %d", val); |
| 1170 |
|
| 1171 |
SET_FLAG(o1, FLAG_IDENTIFIED); |
| 1172 |
val = object_matches_string(pl, o1, "Gorokh"); |
| 1173 |
fail_unless(val != 0, "identified cloak didn't match title with value %d", val); |
| 1174 |
|
| 1175 |
o2 = cctk_create_game_object("cloak"); |
| 1176 |
SET_FLAG(o2, FLAG_UNPAID); |
| 1177 |
val = object_matches_string(pl, o2, "unpaid"); |
| 1178 |
fail_unless(val == 2, "unpaid cloak didn't match unpaid"); |
| 1179 |
val = object_matches_string(pl, o2, "cloak"); |
| 1180 |
fail_unless(val != 0, "unpaid cloak didn't match cloak with %d", val); |
| 1181 |
val = object_matches_string(pl, o2, "wrong"); |
| 1182 |
fail_unless(val == 0, "unpaid cloak matched wrong name %d", val); |
| 1183 |
} |
| 1184 |
END_TEST |
| 1185 |
|
| 1186 |
static Suite *object_suite(void) { |
| 1187 |
Suite *s = suite_create("object"); |
| 1188 |
TCase *tc_core = tcase_create("Core"); |
| 1189 |
|
| 1190 |
|
| 1191 |
tcase_add_unchecked_fixture(tc_core, setup, teardown); |
| 1192 |
|
| 1193 |
suite_add_tcase(s, tc_core); |
| 1194 |
tcase_add_test(tc_core, test_object_can_merge); |
| 1195 |
tcase_add_test(tc_core, test_object_sum_weight); |
| 1196 |
tcase_add_test(tc_core, test_object_get_env_recursive); |
| 1197 |
tcase_add_test(tc_core, test_object_get_player_container); |
| 1198 |
tcase_add_test(tc_core, test_object_dump); |
| 1199 |
tcase_add_test(tc_core, test_object_dump_all); |
| 1200 |
tcase_add_test(tc_core, test_object_find_by_tag_global); |
| 1201 |
tcase_add_test(tc_core, test_object_find_by_name_global); |
| 1202 |
tcase_add_test(tc_core, test_object_free_all_data); |
| 1203 |
tcase_add_test(tc_core, test_object_get_owner); |
| 1204 |
tcase_add_test(tc_core, test_object_clear_owner); |
| 1205 |
tcase_add_test(tc_core, test_object_set_owner); |
| 1206 |
tcase_add_test(tc_core, test_object_copy_owner); |
| 1207 |
tcase_add_test(tc_core, test_object_reset); |
| 1208 |
tcase_add_test(tc_core, test_object_clear); |
| 1209 |
tcase_add_test(tc_core, test_object_copy); |
| 1210 |
tcase_add_test(tc_core, test_object_new); |
| 1211 |
tcase_add_test(tc_core, test_object_update_turn_face); |
| 1212 |
tcase_add_test(tc_core, test_object_update_speed); |
| 1213 |
tcase_add_test(tc_core, test_object_remove_from_active_list); |
| 1214 |
tcase_add_test(tc_core, test_object_update); |
| 1215 |
tcase_add_test(tc_core, test_object_free_drop_inventory); |
| 1216 |
tcase_add_test(tc_core, test_object_count_free); |
| 1217 |
tcase_add_test(tc_core, test_object_count_used); |
| 1218 |
tcase_add_test(tc_core, test_object_count_active); |
| 1219 |
tcase_add_test(tc_core, test_object_sub_weight); |
| 1220 |
tcase_add_test(tc_core, test_object_remove); |
| 1221 |
tcase_add_test(tc_core, test_object_merge); |
| 1222 |
tcase_add_test(tc_core, test_object_insert_in_map_at); |
| 1223 |
tcase_add_test(tc_core, test_object_insert_in_map); |
| 1224 |
tcase_add_test(tc_core, test_object_replace_insert_in_map); |
| 1225 |
tcase_add_test(tc_core, test_object_split); |
| 1226 |
tcase_add_test(tc_core, test_object_decrease_nrof); |
| 1227 |
tcase_add_test(tc_core, test_object_add_weight); |
| 1228 |
tcase_add_test(tc_core, test_object_insert_in_ob); |
| 1229 |
tcase_add_test(tc_core, test_object_check_move_on); |
| 1230 |
tcase_add_test(tc_core, test_map_find_by_archetype); |
| 1231 |
tcase_add_test(tc_core, test_map_find_by_type); |
| 1232 |
tcase_add_test(tc_core, test_object_present_in_ob); |
| 1233 |
tcase_add_test(tc_core, test_object_present_in_ob_by_name); |
| 1234 |
tcase_add_test(tc_core, test_arch_present_in_ob); |
| 1235 |
tcase_add_test(tc_core, test_object_set_flag_inv); |
| 1236 |
tcase_add_test(tc_core, test_object_unset_flag_inv); |
| 1237 |
tcase_add_test(tc_core, test_object_set_cheat); |
| 1238 |
tcase_add_test(tc_core, test_object_find_free_spot); |
| 1239 |
tcase_add_test(tc_core, test_object_find_first_free_spot); |
| 1240 |
tcase_add_test(tc_core, test_get_search_arr); |
| 1241 |
tcase_add_test(tc_core, test_map_find_dir); |
| 1242 |
tcase_add_test(tc_core, test_object_distance); |
| 1243 |
tcase_add_test(tc_core, test_find_dir_2); |
| 1244 |
tcase_add_test(tc_core, test_absdir); |
| 1245 |
tcase_add_test(tc_core, test_dirdiff); |
| 1246 |
tcase_add_test(tc_core, test_can_see_monsterP); |
| 1247 |
tcase_add_test(tc_core, test_object_can_pick); |
| 1248 |
tcase_add_test(tc_core, test_object_create_clone); |
| 1249 |
tcase_add_test(tc_core, test_object_was_destroyed); |
| 1250 |
tcase_add_test(tc_core, test_object_find_by_type_subtype); |
| 1251 |
tcase_add_test(tc_core, test_object_get_key_value); |
| 1252 |
tcase_add_test(tc_core, test_object_get_value); |
| 1253 |
tcase_add_test(tc_core, test_object_set_value); |
| 1254 |
tcase_add_test(tc_core, test_object_matches_string); |
| 1255 |
|
| 1256 |
return s; |
| 1257 |
} |
| 1258 |
|
| 1259 |
int main(void) { |
| 1260 |
int nf; |
| 1261 |
SRunner *sr; |
| 1262 |
Suite *s = object_suite(); |
| 1263 |
|
| 1264 |
sr = srunner_create(s); |
| 1265 |
srunner_set_xml(sr, LOGDIR "/unit/common/object.xml"); |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
srunner_run_all(sr, CK_ENV); |
| 1270 |
nf = srunner_ntests_failed(sr); |
| 1271 |
srunner_free(sr); |
| 1272 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 1273 |
} |