1 /**
2 * @file
3 * @brief Test cases for code below client/renderer
4 */
5
6 /*
7 Copyright (C) 2002-2013 UFO: Alien Invasion.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 See the GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 */
25
26 #include "test_shared.h"
27 #include "test_renderer.h"
28 #include "../client/cl_video.h"
29 #include "../client/renderer/r_image.h"
30 #include "../client/renderer/r_model.h"
31
32 /**
33 * The suite initialization function.
34 * Returns zero on success, non-zero otherwise.
35 */
UFO_InitSuiteRenderer(void)36 static int UFO_InitSuiteRenderer (void)
37 {
38 TEST_Init();
39 return 0;
40 }
41
42 /**
43 * The suite cleanup function.
44 * Returns zero on success, non-zero otherwise.
45 */
UFO_CleanSuiteRenderer(void)46 static int UFO_CleanSuiteRenderer (void)
47 {
48 TEST_Shutdown();
49 return 0;
50 }
51
testLoadAllAnimationFiles(void)52 static void testLoadAllAnimationFiles (void)
53 {
54 const char* pattern = "models/**.anm";
55 const char* filename;
56 mAliasModel_t mod;
57
58 OBJZERO(mod);
59 /* set a very high value to work around the error check in the loading function */
60 mod.num_frames = 100000;
61
62 while ((filename = FS_NextFileFromFileList(pattern)) != nullptr) {
63 vid_modelPool = Mem_CreatePool("Vid Model Pool");
64 Com_Printf("load anim file: %s\n", filename);
65 R_ModLoadAnims(&mod, filename);
66 Mem_DeletePool(vid_modelPool);
67 }
68
69 FS_NextFileFromFileList(nullptr);
70 }
71
testCharacterAnimationFiles(void)72 static void testCharacterAnimationFiles (void)
73 {
74 const char* pattern = "models/**.anm";
75 const char* filename;
76 mAliasModel_t mod;
77 const char* bloodspider[] = { "death1", "death2", "death3", "dead1",
78 "dead2", "dead3", "stand0", "stand1", "stand2", "stand3", "walk0",
79 "walk1", "walk2", "walk3", "cstand0", "cstand1", "cstand2",
80 "cstand3", "cwalk0", "cwalk1", "cwalk2", "cwalk3", "stand_menu",
81 "panic0", nullptr };
82 const char* hovernet[] = { "death1", "dead1", "death2","dead2", "death3",
83 "dead3", "stand0", "walk0", "cstand0", "cwalk0", "stand1", "walk1",
84 "cstand1", "cwalk1", "stand2", "walk2", "cstand2", "cwalk2",
85 "stand3", "walk3", "cstand3", "cwalk3", "move_rifle", "shoot_rifle",
86 "cmove_rifle", "cshoot_rifle", "stand_menu", "panic0", nullptr };
87 const char* soldiers[] = { "death1", "death2", "death3", "dead1", "dead2",
88 "dead3", "stand0", "stand1", "stand2", "stand3", "walk0", "walk1",
89 "walk2", "walk3", "cstand0", "cstand1", "cstand2", "cstand3",
90 "cwalk0", "cwalk1", "cwalk2", "cwalk3", "stand_menu", "panic0",
91 "move_rifle", "shoot_rifle", "cmove_rifle", "cshoot_rifle",
92 "move_biggun", "shoot_biggun", "cmove_biggun", "cshoot_biggun",
93 "move_melee", "shoot_melee", "cmove_melee", "cshoot_melee",
94 "stand_still", "move_pistol", "shoot_pistol", "cmove_pistol",
95 "cshoot_pistol", "move_pistol_d", "shoot_pistol_d",
96 "cmove_pistol_d", "cshoot_pistol_d", "move_grenade",
97 "shoot_grenade", "cmove_grenade", "cshoot_grenade", "move_item",
98 "shoot_item", "cmove_item", "cshoot_item", "move_rpg", "shoot_rpg",
99 "cmove_rpg", "cshoot_rpg", nullptr };
100 const char* civilians[] = { "death1", "dead1", "death2", "dead2", "death3",
101 "dead3", "stand0", "walk0", "panic0", "stand1", "stand2",
102 "stand_menu", "stand_still", nullptr };
103
104 FS_BuildFileList(pattern);
105
106 vid_modelPool = Mem_CreatePool("Vid Model Pool");
107
108 while ((filename = FS_NextFileFromFileList(pattern)) != nullptr) {
109 const char** animList;
110 if (Q_strstart(filename, "models/soldiers/"))
111 animList = soldiers;
112 else if (Q_strstart(filename, "models/civilians/"))
113 animList = civilians;
114 else if (Q_strstart(filename, "models/aliens/bloodspider"))
115 animList = bloodspider;
116 else if (Q_strstart(filename, "models/aliens/hovernet"))
117 animList = hovernet;
118 else if (Q_strstart(filename, "models/aliens/"))
119 animList = soldiers;
120 else
121 animList = nullptr;
122
123 /** @todo remove this hack - but ugvs are just not ready yet */
124 if (Q_strstart(filename, "models/soldiers/ugv_"))
125 continue;
126 /** @todo remove this hack - alientank is just not ready yet */
127 if (Q_strstart(filename, "models/aliens/alientank/"))
128 continue;
129
130 if (animList != nullptr) {
131 OBJZERO(mod);
132 /* set a very high value to work around the error check in the loading function */
133 mod.num_frames = 100000;
134
135 Com_Printf("load character anim file: %s\n", filename);
136 R_ModLoadAnims(&mod, filename);
137
138 while (*animList != nullptr) {
139 int i;
140 for (i = 0; i < mod.num_anims; i++) {
141 const mAliasAnim_t* a = &mod.animdata[i];
142 if (Q_streq(a->name, *animList))
143 break;
144 }
145 if (i == mod.num_anims)
146 UFO_CU_ASSERT_MSG(va("anm file %s does not contain the needed animation definition %s", filename, *animList));
147
148 animList++;
149 }
150 }
151 }
152
153 Mem_DeletePool(vid_modelPool);
154
155 FS_NextFileFromFileList(nullptr);
156 }
157
UFO_AddRendererTests(void)158 int UFO_AddRendererTests (void)
159 {
160 /* add a suite to the registry */
161 CU_pSuite RendererSuite = CU_add_suite("RendererTests", UFO_InitSuiteRenderer, UFO_CleanSuiteRenderer);
162
163 if (RendererSuite == nullptr)
164 return CU_get_error();
165
166 /* add the tests to the suite */
167 if (CU_ADD_TEST(RendererSuite, testLoadAllAnimationFiles) == nullptr)
168 return CU_get_error();
169
170 if (CU_ADD_TEST(RendererSuite, testCharacterAnimationFiles) == nullptr)
171 return CU_get_error();
172
173 return CUE_SUCCESS;
174 }
175