Crossfire Server, Trunk
check_image.cpp
Go to the documentation of this file.
1 /*
2  * static char *rcsid_check_image_c =
3  * "$Id$";
4  */
5 
6 /*
7  * CrossFire, A Multiplayer game for X-windows
8  *
9  * Copyright (C) 2020 Crossfire Development Team
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * The authors can be reached via e-mail at crossfire-devel@real-time.com
26  */
27 
28 /*
29  * This is the unit tests file for common/image.c
30  */
31 
32 #include <stdlib.h>
33 #include <check.h>
34 #include "global.h"
35 #include <toolkit_common.h>
36 #include "image.h"
37 #include "assets.h"
38 #include "AssetsManager.h"
39 
40 void setup(void) {
41  cctk_setdatadir(SOURCE_ROOT "lib");
42  cctk_setlog(LOGDIR "/unit/common/image.out");
44 }
45 
46 void teardown(void) {
47  /* put any cleanup steps here, they will be run after each testcase */
48 }
49 
50 static void test_faceset(const face_sets *fs) {
51  for (size_t idx = 0; idx < get_faces_count(); idx++) {
52  const Face *face = get_face_by_id(idx);
53  int fs_id = get_face_fallback(fs->id, idx);
54  const face_sets *actual = find_faceset(fs_id);
55  FAIL_UNLESS(actual != NULL, "couldn't find faceset %d", fs_id);
56  FAIL_UNLESS(idx < actual->allocated, "found face id %d but allocated %d!", int(idx), int(actual->allocated));
57  FAIL_UNLESS(actual->faces[idx].datalen > 0, "empty face %d (%s) for faceset %d", int(idx), face ? face->name : "(null)", fs_id);
58  }
59 }
60 
61 START_TEST(test_all_faces_have_data) {
63 }
64 END_TEST
65 
66 Suite *image_suite(void) {
67  Suite *s = suite_create("image");
68  TCase *tc_core = tcase_create("Core");
69 
70  /*setup and teardown will be called before each test in testcase 'tc_core' */
71  tcase_add_checked_fixture(tc_core, setup, teardown);
72 
73  suite_add_tcase(s, tc_core);
74  tcase_add_test(tc_core, test_all_faces_have_data);
75 
76  return s;
77 }
78 
79 int main(void) {
80  int nf;
81  Suite *s = image_suite();
82  SRunner *sr = srunner_create(s);
83 
84  srunner_set_fork_status(sr, CK_NOFORK);
85 
86  srunner_set_xml(sr, LOGDIR "/unit/common/image.xml");
87  srunner_set_log(sr, LOGDIR "/unit/common/image.out");
88  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
89  nf = srunner_ntests_failed(sr);
90  srunner_free(sr);
91  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
92 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
global.h
AssetsManager.h
cctk_setdatadir
void cctk_setdatadir(const char *datadir)
Definition: toolkit_common.cpp:69
get_face_fallback
int get_face_fallback(int faceset, uint16_t imageno)
Definition: image.cpp:133
find_faceset
face_sets * find_faceset(int id)
Definition: assets.cpp:328
face_sets::allocated
size_t allocated
Definition: image.h:25
face_sets::id
int id
Definition: image.h:18
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
FAIL_UNLESS
#define FAIL_UNLESS(expr,...)
Definition: toolkit_common.h:11
teardown
void teardown(void)
Definition: check_image.cpp:46
image_suite
END_TEST Suite * image_suite(void)
Definition: check_image.cpp:66
toolkit_common.h
cctk_setlog
void cctk_setlog(const char *logfile)
Definition: toolkit_common.cpp:64
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
get_face_by_id
const Face * get_face_by_id(uint16_t id)
Definition: assets.cpp:315
AssetsManager::facesets
Facesets * facesets()
Definition: AssetsManager.h:65
test_faceset
static void test_faceset(const face_sets *fs)
Definition: check_image.cpp:50
image.h
main
int main(void)
Definition: check_image.cpp:79
cctk_init_std_archetypes
void cctk_init_std_archetypes(void)
Definition: toolkit_common.cpp:83
setup
void setup(void)
Definition: check_image.cpp:40
assets.h
face_info::datalen
uint16_t datalen
Definition: image.h:12
START_TEST
START_TEST(test_all_faces_have_data)
Definition: check_image.cpp:61
get_faces_count
size_t get_faces_count()
Definition: assets.cpp:293
face_sets
Definition: image.h:17
face_sets::faces
face_info * faces
Definition: image.h:26