Atrinik Server 2.5
tests/unit/server/check_arch.c
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00026 #include <global.h>
00027 #include <check.h>
00028 
00029 START_TEST(test_get_skill_archetype)
00030 {
00031     archetype *arch;
00032 
00033     arch = get_skill_archetype(lookup_skill_by_name("alchemy"));
00034     fail_if(arch == NULL, "Should be able to discover the alchemy skill.");
00035     fail_if(strcmp(arch->name, "skill_alchemy"), "Should have returned skill_alchemy but returned '%s'.", arch->name);
00036 
00037     arch = get_skill_archetype(-1);
00038     fail_if(arch != NULL, "Asking for skill with ID -1 should return NULL.");
00039 }
00040 END_TEST
00041 
00042 START_TEST(test_item_matched_string)
00043 {
00044     object *pl, *o1, *o2;
00045     int val;
00046 
00047     pl = get_archetype("raas");
00048     fail_if(pl == NULL, "Couldn't create raas.");
00049     pl->custom_attrset = (player *) calloc(1, sizeof(player));
00050     fail_if(CONTR(pl) == NULL, "Couldn't alloc CONTR.");
00051 
00052     o1 = get_archetype("cloak");
00053     fail_if(o1 == NULL, "Couldn't find cloak archetype");
00054     o1->title = add_string("of Moroch");
00055     CLEAR_FLAG(o1, FLAG_IDENTIFIED);
00056 
00057     val = item_matched_string(pl, o1, "all");
00058     fail_if(val != 1, "All didn't match cloak.");
00059     val = item_matched_string(pl, o1, "Moroch");
00060     fail_if(val != 0, "Unidentified cloak matched title with value %d.", val);
00061     val = item_matched_string(pl, o1, "random");
00062     fail_if(val != 0, "Unidentified cloak matched random value with value %d.", val);
00063 
00064     SET_FLAG(o1, FLAG_IDENTIFIED);
00065     val = item_matched_string(pl, o1, "Moroch");
00066     fail_if(val == 0, "Identified cloak didn't match title with value %d.", val);
00067 
00068     o2 = get_archetype("cloak");
00069     SET_FLAG(o2, FLAG_UNPAID);
00070     val = item_matched_string(pl, o2, "unpaid");
00071     fail_if(val != 2, "Unpaid cloak didn't match unpaid.");
00072     val = item_matched_string(pl, o2, "cloak");
00073     fail_if(val == 0, "Unpaid cloak didn't match cloak with %d.", val);
00074     val = item_matched_string(pl, o2, "wrong");
00075     fail_if(val != 0, "Unpaid cloak matched wrong name %d.", val);
00076 }
00077 END_TEST
00078 
00079 START_TEST(test_arch_to_object)
00080 {
00081     archetype *arch;
00082     object *obj;
00083 
00084     arch = find_archetype("empty_archetype");
00085     obj = arch_to_object(arch);
00086     fail_if(obj == NULL, "arch_to_object() with valid archetype should not return NULL.");
00087 }
00088 END_TEST
00089 
00090 START_TEST(test_create_singularity)
00091 {
00092     object *obj;
00093 
00094     obj = create_singularity("JO3584jke");
00095     fail_if(obj == NULL, "create_singularity() should not return NULL.");
00096     fail_if(strstr(obj->name, "JO3584jke") == 0, "create_singularity(\"JO3584jke\") should put JO3584jke somewhere in singularity name.");
00097 }
00098 END_TEST
00099 
00100 START_TEST(test_get_archetype)
00101 {
00102     object *obj;
00103 
00104     obj = get_archetype("empty_archetype");
00105     fail_if(obj == NULL, "create_archetype(\"empty_archetype\") should not return NULL.");
00106 }
00107 END_TEST
00108 
00109 START_TEST(test_find_archetype)
00110 {
00111     archetype *arch;
00112 
00113     arch = find_archetype("empty_archetype");
00114     fail_if(arch == NULL, "find_archetype(\"empty_archetype\") should not return NULL.");
00115     arch = find_archetype("AA938DFEPQ54FH");
00116     fail_if(arch != NULL, "find_archetype(\"AA938DFEPQ54FH\") should return NULL.");
00117 }
00118 END_TEST
00119 
00120 static Suite *arch_suite()
00121 {
00122     Suite *s = suite_create("arch");
00123     TCase *tc_core = tcase_create("Core");
00124 
00125     tcase_add_checked_fixture(tc_core, NULL, NULL);
00126 
00127     suite_add_tcase(s, tc_core);
00128     tcase_add_test(tc_core, test_get_skill_archetype);
00129     tcase_add_test(tc_core, test_item_matched_string);
00130     tcase_add_test(tc_core, test_arch_to_object);
00131     tcase_add_test(tc_core, test_create_singularity);
00132     tcase_add_test(tc_core, test_get_archetype);
00133     tcase_add_test(tc_core, test_find_archetype);
00134 
00135     return s;
00136 }
00137 
00138 void check_server_arch()
00139 {
00140     Suite *s = arch_suite();
00141     SRunner *sr = srunner_create(s);
00142 
00143     srunner_set_xml(sr, "unit/server/arch.xml");
00144     srunner_set_log(sr, "unit/server/arch.out");
00145     srunner_run_all(sr, CK_ENV);
00146     srunner_ntests_failed(sr);
00147     srunner_free(sr);
00148 }