1 /**
2 * @file
3 */
4
5 /*
6 Copyright (C) 2002-2013 UFO: Alien Invasion.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 See the GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 */
24
25
26 #include "test_character.h"
27 #include "test_shared.h"
28 #include "../client/cl_team.h"
29
30 /**
31 * The suite initialization function.
32 * Returns zero on success, non-zero otherwise.
33 */
InitSuite(void)34 static int InitSuite (void)
35 {
36 TEST_Init();
37
38 Com_ParseScripts(true);
39 return 0;
40 }
41
42 /**
43 * The suite cleanup function.
44 * Returns zero on success, non-zero otherwise.
45 */
CleanSuite(void)46 static int CleanSuite (void)
47 {
48 TEST_Shutdown();
49 return 0;
50 }
51
GetCharacter(const char * teamDefID="phalanx")52 static character_t* GetCharacter (const char* teamDefID = "phalanx")
53 {
54 static character_t chr;
55 CL_GenerateCharacter(&chr, teamDefID);
56 return &chr;
57 }
58
RunStrengthenImplant(character_t & chr,const implant_t & implant,const objDef_t & od)59 static void RunStrengthenImplant (character_t& chr, const implant_t& implant, const objDef_t& od)
60 {
61 Com_Printf("%s ", od.id);
62 /** @todo perform tests */
63 }
64
RunEffectForImplant(const fireDef_t & fd,character_t & chr,const implant_t & implant,const objDef_t & od,const itemEffect_t & effect)65 static void RunEffectForImplant (const fireDef_t& fd, character_t& chr, const implant_t& implant, const objDef_t& od, const itemEffect_t& effect)
66 {
67 Com_Printf("%s ", implant.def->id);
68 /** @todo perform tests */
69 }
70
RunImplant(const implantDef_t & implantDef)71 static void RunImplant (const implantDef_t& implantDef)
72 {
73 character_t* chr = GetCharacter();
74 const objDef_t* od = implantDef.item;
75 CU_ASSERT_PTR_NOT_NULL_FATAL(od);
76 const implant_t* implant = CHRSH_ApplyImplant(*chr, implantDef);
77 CU_ASSERT_PTR_NOT_NULL_FATAL(implant);
78 CU_ASSERT_PTR_NOT_NULL_FATAL(implant->def);
79 Com_Printf("implant: '%s': ", implant->def->id);
80 CU_ASSERT_EQUAL(implant->removedTime, 0);
81 CU_ASSERT_NOT_EQUAL(implant->installedTime, 0);
82 CU_ASSERT_PTR_NOT_NULL(implant->def);
83 CU_ASSERT_EQUAL(implant->installedTime, implantDef.installationTime);
84 for (int i = 0; i < implantDef.installationTime; i++) {
85 CHRSH_UpdateImplants(*chr);
86 }
87 CU_ASSERT_EQUAL(implant->installedTime, 0);
88
89 int effects = 0;
90 if (od->strengthenEffect != nullptr) {
91 RunStrengthenImplant(*chr, *implant, *od);
92 effects++;
93 }
94 for (int w = 0; w < MAX_WEAPONS_PER_OBJDEF; w++) {
95 for (int f = 0; f < od->numFiredefs[w]; f++) {
96 const fireDef_t& fd = od->fd[w][f];
97 const itemEffect_t* effect[] = { fd.activeEffect, fd.deactiveEffect, fd.overdoseEffect };
98 for (int e = 0; e < lengthof(effect); e++) {
99 if (effect[e] == nullptr)
100 continue;
101 RunEffectForImplant(fd, *chr, *implant, *od, *effect[e]);
102 effects++;
103 }
104 }
105 }
106 CU_ASSERT_TRUE_FATAL(effects >= 1);
107 Com_Printf("passed %i effects\n", effects);
108 }
109
testImplants(void)110 static void testImplants (void)
111 {
112 Com_Printf("\n");
113 for (int i = 0; i < csi.numImplants; i++) {
114 RunImplant(csi.implants[i]);
115 }
116 }
117
UFO_AddCharacterTests(void)118 int UFO_AddCharacterTests (void)
119 {
120 /* add a suite to the registry */
121 CU_pSuite DBufferSuite = CU_add_suite("CharacterTests", InitSuite, CleanSuite);
122 if (DBufferSuite == nullptr)
123 return CU_get_error();
124
125 /* add the tests to the suite */
126 if (CU_ADD_TEST(DBufferSuite, testImplants) == nullptr)
127 return CU_get_error();
128
129 return CUE_SUCCESS;
130 }
131