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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 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 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
|
/*
* static char *rcsid_check_object_c =
* "$Id: check_object.c 6683 2007-06-20 20:07:39Z ryo_saeba $";
*/
/*
CrossFire, A Multiplayer game for X-windows
Copyright (C) 2002 Mark Wedel & Crossfire Development Team
Copyright (C) 1992 Frank Tore Johansen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The authors can be reached via e-mail at crossfire-devel@real-time.com
*/
/*
* This is the unit tests file for common/object.c
*/
#include <global.h>
#include <stdlib.h>
#include <check.h>
#include <loader.h>
#include <toolkit_common.h>
void setup(void) {
cctk_setdatadir(SOURCE_ROOT "lib");
cctk_setlog(LOGDIR "/unit/common/object.out");
printf("set log to %s\n",LOGDIR "/unit/common/object.out");
cctk_init_std_archetypes();
}
void teardown(void)
{
/* put any cleanup steps here, they will be run after each testcase */
}
/*
* Things to check
* update_turn_face
* update_ob_speed
* remove_from_active_list
* update_object
* free_object
* count_free
* count_used
* count_active
* sub_weight
* remove_ob
* merge_ob
* insert_ob_in_map_at
* insert_ob_in_map
* replace_insert_ob_in_map
* get_split_ob
* decrease_ob_nr
* add_weight
* insert_ob_in_ob
* check_move_on
* present_arch
* present
* present_in_ob
* present_in_ob_by_name
* present_arch_in_ob
* flag_inv
* unflag_inv
* set_cheat
* find_free_spot
* find_first_free_spot
* get_search_arr
* find_dir
* distance
* find_dir_2
* absdir
* dirdiff
* can_see_monsterP
* can_pick
* object_create_clone
* was_destroyed
* find_obj_by_type_subtype
* get_ob_key_link
* get_ob_key_value
* set_ob_key_value
* item_matched_string
*/
/** This is the test to check the behaviour of the method
* int can_merge(object *ob1, object *ob2);
*/
START_TEST (test_can_merge)
{
object *ob1;
object *ob2;
ob1=cctk_create_game_object(NULL);
ob2=cctk_create_game_object(NULL);
fail_unless(can_merge(ob1,ob2),"Should be able to merge 2 same object");
ob2->name=add_string("Not same name");
fail_unless(!can_merge(ob1,ob2),"Should not be able to merge 2 object with different names");
ob2=cctk_create_game_object(NULL);
ob2->type++;
fail_unless(!can_merge(ob1,ob2),"Should not be able to merge 2 object with different types");
ob2=cctk_create_game_object(NULL);
ob1->nrof=(1UL<<31)-1;
ob2->nrof=1;
fail_unless(!can_merge(ob1,ob2),"Should not be able to merge 2 object if result nrof goes to 1<<31 or higher");
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* signed long sum_weight(object *op);
*/
START_TEST (test_sum_weight)
{
object *ob1;
object *ob2;
object *ob3;
object *ob4;
unsigned long sum;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
ob4 = cctk_create_game_object(NULL);
ob1->weight=10; /*This should not be taken into account by sum_weight*/
ob1->type=CONTAINER;
ob1->stats.Str=40; /*40% reduction of weight*/
ob2->weight=6;
ob2->nrof=10;
ob3->weight=7;
ob4->weight=8;
insert_ob_in_ob(ob2,ob1);
insert_ob_in_ob(ob3,ob1);
insert_ob_in_ob(ob4,ob1);
sum=sum_weight(ob1);
fail_unless(sum==45,"Sum of object's inventory should be 45 ((6*10+7+8)*.6) but was %lu.",sum);
}
END_TEST
/** This is the test to check the behaviour of the method
* object *object_get_env_recursive(object *op);
*/
START_TEST (test_object_get_env_recursive)
{
object *ob1;
object *ob2;
object *ob3;
object *ob4;
object *result;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
ob4 = cctk_create_game_object(NULL);
insert_ob_in_ob(ob2,ob1);
insert_ob_in_ob(ob3,ob2);
insert_ob_in_ob(ob4,ob3);
result=object_get_env_recursive(ob4);
fail_unless(result==ob1,"Getting top level container for ob4(%p) should bring ob1(%p) but brought %p.",ob4,ob1,result);
}
END_TEST
/** This is the test to check the behaviour of the method
* object *get_player_container(object *op);
*/
START_TEST (test_get_player_container)
{
object *ob1;
object *ob2;
object *ob3;
object *ob4;
object *result;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
ob4 = cctk_create_game_object(NULL);
insert_ob_in_ob(ob2,ob1);
insert_ob_in_ob(ob3,ob2);
insert_ob_in_ob(ob4,ob3);
result=get_player_container(ob4);
fail_unless(result==NULL,"Getting containing player for ob4(%p) should bring NULL but brought %p while not contained in a player.",ob4,result);
ob1->type=PLAYER;
result=get_player_container(ob4);
fail_unless(result==ob1,"Getting containing player for ob4(%p) should bring ob1(%p) but brought %p while ob1 is player.",ob4,ob1,result);
}
END_TEST
/** This is the test to check the behaviour of the method
* void dump_object(object *op);
*/
START_TEST (test_dump_object)
{
object *ob1;
object *ob2;
object *ob3;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
insert_ob_in_ob(ob2,ob1);
insert_ob_in_ob(ob3,ob2);
strcpy(errmsg,"----");
dump_object(ob1);
fail_unless(strstr(errmsg,"arch")!=NULL,"The object dump should contain 'arch' but was %s",errmsg);
}
END_TEST
/** This is the test to check the behaviour of the method
* void dump_all_objects(void);
*/
START_TEST (test_dump_all_objects)
{
object *ob1;
object *ob2;
object *ob3;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
dump_all_objects(); /*Should not crash, that all i can test*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *find_object(tag_t i);
*/
START_TEST (test_find_object)
{
object *ob1;
object *result;
ob1 = cctk_create_game_object(NULL);
ob1 = cctk_create_game_object(NULL);
ob1 = cctk_create_game_object(NULL);
result=find_object(ob1->count);
fail_unless(result==ob1,"Should find ob1(%p) while search for item %d but got %p",ob1,ob1->count,result);
}
END_TEST
/** This is the test to check the behaviour of the method
* object *find_object_name(const char *str);
*/
START_TEST (test_find_object_name)
{
object *ob1;
object *result;
ob1 = cctk_create_game_object(NULL);
ob1->name=add_string("This is a name");
ob1 = cctk_create_game_object(NULL);
ob1->name=add_string("This is another name");
ob1 = cctk_create_game_object(NULL);
ob1->name=add_string("This is the key name");
result=find_object_name(add_string("This is the key name"));
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);
}
END_TEST
/** This is the test to check the behaviour of the method
* void free_all_object_data(void);
*/
START_TEST (test_free_all_object_data)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *get_owner(object *op);
*/
START_TEST (test_get_owner)
{
object *ob1;
object *ob2;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
set_owner(ob2,ob1);
CLEAR_FLAG(ob1, FLAG_REMOVED);
CLEAR_FLAG(ob2, FLAG_REMOVED);
fail_unless(get_owner(ob2)==ob1,"Owner of ob2(%p) shoud be ob1(%p) but was %p",ob2,ob1,get_owner(ob2));
}
END_TEST
/** This is the test to check the behaviour of the method
* void clear_owner(object *op);
*/
START_TEST (test_clear_owner)
{
object *ob1;
object *ob2;
int refcount;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
set_owner(ob2,ob1);
refcount = ob1->refcount;
fail_unless(ob2->owner!=NULL,"Prior to testing clear_owner, owner of ob2 was wrongly initialized");
clear_owner(ob2);
fail_unless(ob2->owner==NULL,"After clear_owner ob2 still had an owner");
fail_unless(ob1->refcount<refcount,"After clear_owner of ob2, ob1 refcont should be decreased. Before clear_ower:%d , after %d",refcount,ob1->refcount);
}
END_TEST
/** This is the test to check the behaviour of the method
* void set_owner(object *op, object *owner);
*/
START_TEST (test_set_owner)
{
object *ob1;
object *ob2;
int refcount;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
refcount = ob1->refcount;
set_owner(ob2,ob1);
fail_unless(ob2->owner==ob1,"After set_owner ob2(%p) owner should be ob1(%p) but was (%p)",ob2,ob1,ob2->owner);
}
END_TEST
/** This is the test to check the behaviour of the method
* void copy_owner(object *op, object *clone);
*/
START_TEST (test_copy_owner)
{
object *ob1;
object *ob2;
object *ob3;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
set_owner(ob2,ob1);
copy_owner(ob3,ob2);
fail_unless(get_owner(ob2)==get_owner(ob3),"After copy_owner, ob3 and ob2 should have same owner (ob1=%p) but got %p and %p",
get_owner(ob3),get_owner(ob2));
}
END_TEST
/** This is the test to check the behaviour of the method
* void reset_object(object *op);
*/
START_TEST (test_reset_object)
{
object *ob1;
object *result;
ob1 = cctk_create_game_object(NULL);
reset_object(ob1);
fail_unless(ob1->name == NULL,"Field name of ob1 was not NULLified by reset_object");
fail_unless(ob1->name_pl == NULL,"Field name_pl of ob1 was not NULLified by reset_object");
fail_unless(ob1->title == NULL,"Field title of ob1 was not NULLified by reset_object");
fail_unless(ob1->race == NULL,"Field race of ob1 was not NULLified by reset_object");
fail_unless(ob1->slaying == NULL,"Field slaying of ob1 was not NULLified by reset_object");
fail_unless(ob1->skill == NULL,"Field skill of ob1 was not NULLified by reset_object");
fail_unless(ob1->msg == NULL,"Field msg of ob1 was not NULLified by reset_object");
fail_unless(ob1->materialname == NULL,"Field materialname of ob1 was not NULLified by reset_object");
fail_unless(ob1->lore == NULL,"Field lore of ob1 was not NULLified by reset_object");
}
END_TEST
/** This is the test to check the behaviour of the method
* void clear_object(object *op);
*/
START_TEST (test_clear_object)
{
object *ob1;
const char* reference;
ob1 = cctk_create_game_object(NULL);
cctk_set_object_strings(ob1,"This is a test String");
reference=add_string("This is a test String");
clear_object(ob1);
fail_unless(ob1->name == NULL,"Field name of ob1 was not cleaned by clear_object");
fail_unless(ob1->name_pl == NULL,"Field name_pl of ob1 was not cleaned by clear_object");
fail_unless(ob1->title == NULL,"Field title of ob1 was not cleaned by clear_object");
fail_unless(ob1->race == NULL,"Field race of ob1 was not cleaned by clear_object");
fail_unless(ob1->slaying == NULL,"Field slaying of ob1 was not cleaned by clear_object");
fail_unless(ob1->skill == NULL,"Field skill of ob1 was not cleaned by clear_object");
fail_unless(ob1->msg == NULL,"Field msg of ob1 was not cleaned by clear_object");
fail_unless(ob1->materialname == NULL,"Field materialname of ob1 was not cleaned by clear_object");
fail_unless(ob1->lore == NULL,"Field lore of ob1 was not cleaned by clear_object");
fail_unless(query_refcount(reference)==1,
"The number of references to string should drop back to 1 but was %d",query_refcount(reference));
}
END_TEST
/** This is the test to check the behaviour of the method
* void copy_object(object *op2, object *op);
*/
START_TEST (test_copy_object)
{
object *ob1;
object *ob2;
const char* reference;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
cctk_set_object_strings(ob1,"test String1");
cctk_set_object_strings(ob2,"test String2");
reference=add_string("test String2");
copy_object(ob1,ob2);
fail_unless(ob1->name==ob2->name,"Field name of ob1 should match ob2");
fail_unless(ob1->name_pl==ob2->name_pl,"Field name_pl of ob1 should match ob2");
fail_unless(ob1->title==ob2->title,"Field title of ob1 should match ob2");
fail_unless(ob1->race==ob2->race,"Field race of ob1 should match ob2");
fail_unless(ob1->slaying==ob2->slaying,"Field slaying of ob1 should match ob2");
fail_unless(ob1->skill==ob2->skill,"Field skill of ob1 should match ob2");
fail_unless(ob1->msg==ob2->msg,"Field msg of ob1 should match ob2");
fail_unless(ob1->materialname==ob2->materialname,"Field materialname of ob1 should match ob2");
fail_unless(ob1->lore==ob2->lore,"Field lore of ob1 should match ob2");
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));
}
END_TEST
/**
* This is the test to check the behaviour of the method
* object *get_object(void);
*/
START_TEST (test_get_object)
{
object* ob;
long int i;
ob=get_object();
fail_unless(ob!=NULL,"Should get an object after calling get_object()");
fail_unless(ob->name==NULL,"Field name has not been nullified by get_object()");
fail_unless(ob->name_pl==NULL,"Field name_pl has not been nullified by get_object()");
fail_unless(ob->title==NULL,"Field title has not been nullified by get_object()");
fail_unless(ob->race==NULL,"Field race has not been nullified by get_object()");
fail_unless(ob->slaying==NULL,"Field slaying has not been nullified by get_object()");
fail_unless(ob->skill==NULL,"Field skill has not been nullified by get_object()");
fail_unless(ob->lore==NULL,"Field lore has not been nullified by get_object()");
fail_unless(ob->msg==NULL,"Field msg has not been nullified by get_object()");
fail_unless(ob->materialname==NULL,"Field materialname has not been nullified by get_object()");
fail_unless(ob->prev==NULL,"Field prev has not been nullified by get_object()");
fail_unless(ob->active_next==NULL,"Field active_next has not been nullified by get_object()");
fail_unless(ob->active_prev==NULL,"Field active_prev has not been nullified by get_object()");
/* did you really thing i'll go with only one object? */
/* let's go for about 2M allocations in a row, let's test roughness */
for(i=0;i<1U<<17;i++){
ob=get_object();
fail_unless(ob!=NULL,"Should get an object after calling get_object() (iteration %l)",i);
if (!(i&((1<<13)-1)))
LOG(llevDebug,"%ldk items created with get_object\n",i>>10);
}
}
END_TEST
/** This is the test to check the behaviour of the method
* void update_turn_face(object *op);
*/
START_TEST (test_update_turn_face)
{
object *ob1;
New_Face *face1;
New_Face *face2;
const char* reference;
ob1 = cctk_create_game_object("xan");
ob1->direction=1;
update_turn_face(ob1);
face1=ob1->face;
ob1->direction=5;
update_turn_face(ob1);
face2=ob1->face;
fail_unless(face2!=face1,"2 opposite direction should provide different faces after update_turn_face");
}
END_TEST
#define IS_OBJECT_ACTIVE(op) (op->active_next || op->active_prev || op==active_objects)
/** This is the test to check the behaviour of the method
* void update_ob_speed(object *op);
*/
START_TEST (test_update_ob_speed)
{
object *ob1;
object *ob2;
object *ob3;
object *ob4;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
ob4 = cctk_create_game_object(NULL);
ob1->speed=MIN_ACTIVE_SPEED;
update_ob_speed(ob1);
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);
ob1->speed=-MIN_ACTIVE_SPEED;
update_ob_speed(ob1);
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);
ob1->speed=MIN_ACTIVE_SPEED*2;
update_ob_speed(ob1);
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);
ob2->speed=-MIN_ACTIVE_SPEED*2;
update_ob_speed(ob2);
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);
ob4->speed=ob3->speed=ob2->speed;
update_ob_speed(ob3);
update_ob_speed(ob4);
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);
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);
ob1->speed=0.0;
ob2->speed=0.0;
ob3->speed=0.0;
ob4->speed=0.0;
update_ob_speed(ob1);
update_ob_speed(ob2);
update_ob_speed(ob3);
update_ob_speed(ob4);
fail_unless(!IS_OBJECT_ACTIVE(ob1),"Object with absolute speed 0.0 should be inactivated",ob1->speed);
fail_unless(!IS_OBJECT_ACTIVE(ob2),"Object with absolute speed 0.0 should be inactivated",ob2->speed);
fail_unless(!IS_OBJECT_ACTIVE(ob3),"Object with absolute speed 0.0 should be inactivated",ob3->speed);
fail_unless(!IS_OBJECT_ACTIVE(ob4),"Object with absolute speed 0.0 should be inactivated",ob4->speed);
}
END_TEST
/** This is the test to check the behaviour of the method
* void remove_from_active_list(object *op);
*/
START_TEST (test_remove_from_active_list)
{
object *ob1;
ob1 = cctk_create_game_object(NULL);
ob1->speed=MIN_ACTIVE_SPEED*2;
update_ob_speed(ob1);
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);
remove_from_active_list(ob1);
fail_unless(!IS_OBJECT_ACTIVE(ob1),"After call to remove_from_active_list, object should be made inactive");
}
END_TEST
#undef IS_OBJECT_ACTIVE
/** This is the test to check the behaviour of the method
* void update_object(object *op, int action);
*/
START_TEST (test_update_object)
{
/*TESTME (this one need a map loading, left for later*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void free_object(object *ob);
*/
START_TEST (test_free_object)
{
object *ob1;
object *ob2;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
insert_ob_in_ob(ob2,ob1);
free_object(ob1);
fail_unless(QUERY_FLAG(ob1,FLAG_FREED),"Freeing ob1 should mark it freed");
fail_unless(QUERY_FLAG(ob2,FLAG_FREED),"Freeing ob1 should mark it's content freed");
}
END_TEST
/** This is the test to check the behaviour of the method
* int count_free(void);
*/
START_TEST (test_count_free)
{
object *ob1;
int free1,free2;
ob1 = cctk_create_game_object(NULL);
free1 = count_free();
ob1 = cctk_create_game_object(NULL);
free2 = count_free();
fail_unless((free2==free1-1),"after creating an object, the count_free() should return one less (%d) but returned %d",free1-1,free2);
}
END_TEST
/** This is the test to check the behaviour of the method
* int count_used(void);
*/
START_TEST (test_count_used)
{
object *ob1;
int used1,used2;
ob1 = cctk_create_game_object(NULL);
used1 = count_used();
ob1 = cctk_create_game_object(NULL);
used2 = count_used();
fail_unless((used2==used1+1),"after creating an object, the count_used() should return one more (%d) but returned %d",used1-1,used2);
}
END_TEST
/** This is the test to check the behaviour of the method
* int count_active(void);
*/
START_TEST (test_count_active)
{
object *ob1;
int active1,active2;
ob1 = cctk_create_game_object(NULL);
ob1->speed=MIN_ACTIVE_SPEED*2;
update_ob_speed(ob1);
active1=count_active();
ob1 = cctk_create_game_object(NULL);
ob1->speed=MIN_ACTIVE_SPEED*2;
update_ob_speed(ob1);
active2=count_active();
fail_unless((active2==active1+1),"after activating an additional object, count_active should return one less %d but returned %d",active1-1,active2);
}
END_TEST
/** This is the test to check the behaviour of the method
* void sub_weight(object *op, signed long weight);
*/
START_TEST (test_sub_weight)
{
object *ob1;
object *ob2;
object *ob3;
object *ob4;
unsigned long sum;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
ob4 = cctk_create_game_object(NULL);
ob1->weight=10; /*This should not be taken into account by sum_weight*/
ob1->type=CONTAINER;
ob2->type=CONTAINER;
ob3->type=CONTAINER;
ob1->stats.Str=40; /*40% reduction of weight*/
ob2->weight=10;
ob3->weight=10;
ob4->weight=10;
insert_ob_in_ob(ob2,ob1);
insert_ob_in_ob(ob3,ob2);
insert_ob_in_ob(ob4,ob3);
sum=sum_weight(ob1);
fail_unless(sum==18,"Sum of object's inventory should be 18 (30*0.6+10) but was %lu.",sum);
sub_weight(ob4,10);
fail_unless(ob1->carrying==12,"after call to sub_weight, carrying of ob1 should be 22 but was %d",ob1->carrying);
}
END_TEST
/** This is the test to check the behaviour of the method
* void remove_ob(object *op);
*/
START_TEST (test_remove_ob)
{
/*TESTME test those
ob with more
player inv
remove from map
*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *merge_ob(object *op, object *top);
*/
START_TEST (test_merge_ob)
{
object *ob1;
object *ob2;
object *ob3;
object *ob4;
object *op;
ob1 = cctk_create_game_object(NULL);
ob2 = cctk_create_game_object(NULL);
ob3 = cctk_create_game_object(NULL);
ob4 = cctk_create_game_object(NULL);
op = cctk_create_game_object(NULL);
ob1->below=ob2;
ob2->below=ob3;
ob3->below=ob4;
ob2->above=ob1;
ob3->above=ob2;
ob4->above=ob3;
ob1->name=add_string("test");
ob2->name=add_string("test2");
ob3->name=add_string("test3");
}
END_TEST
/** This is the test to check the behaviour of the method
* object *insert_ob_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y);
*/
START_TEST (test_insert_ob_in_map_at)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag);
void replace_insert_ob_in_map(const char *arch_string, object *op);
*/
START_TEST (test_insert_ob_in_map)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void replace_insert_ob_in_map(const char *arch_string, object *op);
*/
START_TEST (test_replace_insert_ob_in_map)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *get_split_ob(object *orig_ob, uint32 nr);
*/
START_TEST (test_get_split_ob)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *decrease_ob_nr(object *op, uint32 i);
*/
START_TEST (test_decrease_ob_nr)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void add_weight(object *op, signed long weight);
*/
START_TEST (test_add_weight)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *insert_ob_in_ob(object *op, object *where);
*/
START_TEST (test_insert_ob_in_ob)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int check_move_on(object *op, object *originator);
*/
START_TEST (test_check_move_on)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *present_arch(const archetype *at, mapstruct *m, int x, int y);
*/
START_TEST (test_present_arch)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *present(unsigned char type, mapstruct *m, int x, int y);
*/
START_TEST (test_present)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *present_in_ob(unsigned char type, const object *op);
*/
START_TEST (test_present_in_ob)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *present_in_ob_by_name(int type, const char *str, const object *op);
*/
START_TEST (test_present_in_ob_by_name)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *present_arch_in_ob(const archetype *at, const object *op);
*/
START_TEST (test_present_arch_in_ob)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void flag_inv(object *op, int flag);
void unflag_inv(object *op, int flag);
*/
START_TEST (test_flag_inv)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void unflag_inv(object *op, int flag);
*/
START_TEST (test_unflag_inv)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void set_cheat(object *op);
*/
START_TEST (test_set_cheat)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop);
*/
START_TEST (test_find_free_spot)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int find_first_free_spot(const object *ob, mapstruct *m, int x, int y);
*/
START_TEST (test_find_first_free_spot)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* void get_search_arr(int *search_arr);
*/
START_TEST (test_get_search_arr)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int find_dir(mapstruct *m, int x, int y, object *exclude);
*/
START_TEST (test_find_dir)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int distance(const object *ob1, const object *ob2);
*/
START_TEST (test_distance)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int find_dir_2(int x, int y);
*/
START_TEST (test_find_dir_2)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int absdir(int d);
*/
START_TEST (test_absdir)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int dirdiff(int dir1, int dir2);
*/
START_TEST (test_dirdiff)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int can_see_monsterP(mapstruct *m, int x, int y, int dir);
*/
START_TEST (test_can_see_monsterP)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int can_pick(const object *who, const object *item);
*/
START_TEST (test_can_pick)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *object_create_clone(object *asrc);
*/
START_TEST (test_object_create_clone)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int was_destroyed(const object *op, tag_t old_tag);
*/
START_TEST (test_was_destroyed)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* object *find_obj_by_type_subtype(const object *who, int type, int subtype);
*/
START_TEST (test_find_obj_by_type_subtype)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* key_value *get_ob_key_link(const object *ob, const char *key);
*/
START_TEST (test_get_ob_key_link)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* const char *get_ob_key_value(const object *op, const char *const key);
*/
START_TEST (test_get_ob_key_value)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int set_ob_key_value(object *op, const char *key, const char *value, int add_key);
*/
START_TEST (test_set_ob_key_value)
{
/*TESTME*/
}
END_TEST
/** This is the test to check the behaviour of the method
* int item_matched_string(object *pl, object *op, const char *name);
*/
START_TEST (test_item_matched_string)
{
object *pl;
object *o1, *o2, *o3, *o4;
int val;
pl = cctk_create_game_object("kobold");
fail_unless(pl != NULL, "couldn't create kobold");
pl->contr = (player*)calloc(1, sizeof(player));
fail_unless(pl->contr != NULL, "couldn't alloc contr");
o1 = cctk_create_game_object("cloak");
fail_unless(o1 != NULL, "couldn't find cloak archetype");
o1->title = add_string("of Gorokh");
CLEAR_FLAG(o1, FLAG_IDENTIFIED);
val = item_matched_string(pl, o1, "all");
fail_unless(val == 1, "all didn't match cloak");
val = item_matched_string(pl, o1, "Gorokh");
fail_unless(val == 0, "unidentified cloak matched title with value %d", val);
val = item_matched_string(pl, o1, "random");
fail_unless(val == 0, "unidentified cloak matched random value with value %d", val);
SET_FLAG(o1, FLAG_IDENTIFIED);
val = item_matched_string(pl, o1, "Gorokh");
fail_unless(val != 0, "identified cloak didn't match title with value %d", val);
o2 = cctk_create_game_object("cloak");
SET_FLAG(o2, FLAG_UNPAID);
val = item_matched_string(pl, o2, "unpaid");
fail_unless(val == 2, "unpaid cloak didn't match unpaid");
val = item_matched_string(pl, o2, "cloak");
fail_unless(val != 0, "unpaid cloak didn't match cloak with %d", val);
val = item_matched_string(pl, o2, "wrong");
fail_unless(val == 0, "unpaid cloak matched wrong name %d", val);
}
END_TEST
Suite *object_suite(void)
{
Suite *s = suite_create("object");
TCase *tc_core = tcase_create("Core");
/*setup and teardown will be called before each test in testcase 'tc_core' */
tcase_add_unchecked_fixture(tc_core,setup,teardown);
suite_add_tcase (s, tc_core);
tcase_add_test(tc_core, test_can_merge);
tcase_add_test(tc_core, test_sum_weight);
tcase_add_test(tc_core, test_object_get_env_recursive);
tcase_add_test(tc_core, test_get_player_container);
tcase_add_test(tc_core, test_dump_object);
tcase_add_test(tc_core, test_dump_all_objects);
tcase_add_test(tc_core, test_find_object);
tcase_add_test(tc_core, test_find_object_name);
tcase_add_test(tc_core, test_free_all_object_data);
tcase_add_test(tc_core, test_get_owner);
tcase_add_test(tc_core, test_clear_owner);
tcase_add_test(tc_core, test_set_owner);
tcase_add_test(tc_core, test_copy_owner);
tcase_add_test(tc_core, test_reset_object);
tcase_add_test(tc_core, test_clear_object);
tcase_add_test(tc_core, test_copy_object);
tcase_add_test(tc_core, test_get_object);
tcase_add_test(tc_core, test_update_turn_face);
tcase_add_test(tc_core, test_update_ob_speed);
tcase_add_test(tc_core, test_remove_from_active_list);
tcase_add_test(tc_core, test_update_object);
tcase_add_test(tc_core, test_free_object);
tcase_add_test(tc_core, test_count_free);
tcase_add_test(tc_core, test_count_used);
tcase_add_test(tc_core, test_count_active);
tcase_add_test(tc_core, test_sub_weight);
tcase_add_test(tc_core, test_remove_ob);
tcase_add_test(tc_core, test_merge_ob);
tcase_add_test(tc_core, test_insert_ob_in_map_at);
tcase_add_test(tc_core, test_insert_ob_in_map);
tcase_add_test(tc_core, test_replace_insert_ob_in_map);
tcase_add_test(tc_core, test_get_split_ob);
tcase_add_test(tc_core, test_decrease_ob_nr);
tcase_add_test(tc_core, test_add_weight);
tcase_add_test(tc_core, test_insert_ob_in_ob);
tcase_add_test(tc_core, test_check_move_on);
tcase_add_test(tc_core, test_present_arch);
tcase_add_test(tc_core, test_present);
tcase_add_test(tc_core, test_present_in_ob);
tcase_add_test(tc_core, test_present_in_ob_by_name);
tcase_add_test(tc_core, test_present_arch_in_ob);
tcase_add_test(tc_core, test_flag_inv);
tcase_add_test(tc_core, test_unflag_inv);
tcase_add_test(tc_core, test_set_cheat);
tcase_add_test(tc_core, test_find_free_spot);
tcase_add_test(tc_core, test_find_first_free_spot);
tcase_add_test(tc_core, test_get_search_arr);
tcase_add_test(tc_core, test_find_dir);
tcase_add_test(tc_core, test_distance);
tcase_add_test(tc_core, test_find_dir_2);
tcase_add_test(tc_core, test_absdir);
tcase_add_test(tc_core, test_dirdiff);
tcase_add_test(tc_core, test_can_see_monsterP);
tcase_add_test(tc_core, test_can_pick);
tcase_add_test(tc_core, test_object_create_clone);
tcase_add_test(tc_core, test_was_destroyed);
tcase_add_test(tc_core, test_find_obj_by_type_subtype);
tcase_add_test(tc_core, test_get_ob_key_link);
tcase_add_test(tc_core, test_get_ob_key_value);
tcase_add_test(tc_core, test_set_ob_key_value);
tcase_add_test(tc_core, test_item_matched_string);
return s;
}
int main(void)
{
int nf;
SRunner *sr;
Suite *s = object_suite();
sr = srunner_create(s);
srunner_set_xml(sr,LOGDIR "/unit/common/object.xml");
srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
nf = srunner_ntests_failed(sr);
srunner_free(sr);
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
|