Crossfire Server, Trunk
check_image.c
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 
39 void setup(void) {
40  cctk_setdatadir(SOURCE_ROOT "lib");
41  cctk_setlog(LOGDIR "/unit/common/image.out");
43 }
44 
45 void teardown(void) {
46  /* put any cleanup steps here, they will be run after each testcase */
47 }
48 
49 static void test_faceset(const face_sets *fs) {
50  for (size_t idx = 0; idx < get_faces_count(); idx++) {
51  const Face *face = get_face_by_id(idx);
52  int fs_id = get_face_fallback(fs->id, idx);
53  const face_sets *actual = find_faceset(fs_id);
54  fail_unless(actual != NULL, "couldn't find faceset %d", fs_id);
55  fail_unless(idx < actual->allocated, "found face id %d but allocated %d!", idx, actual->allocated);
56  fail_unless(actual->faces[idx].datalen > 0, "empty face %d (%s) for faceset %d", idx, face ? face->name : "(null)", fs_id);
57  }
58 }
59 
60 START_TEST(test_all_faces_have_data) {
62 }
63 END_TEST
64 
65 Suite *image_suite(void) {
66  Suite *s = suite_create("image");
67  TCase *tc_core = tcase_create("Core");
68 
69  /*setup and teardown will be called before each test in testcase 'tc_core' */
70  tcase_add_checked_fixture(tc_core, setup, teardown);
71 
72  suite_add_tcase(s, tc_core);
73  tcase_add_test(tc_core, test_all_faces_have_data);
74 
75  return s;
76 }
77 
78 int main(void) {
79  int nf;
80  Suite *s = image_suite();
81  SRunner *sr = srunner_create(s);
82 
83  srunner_set_fork_status(sr, CK_NOFORK);
84 
85  srunner_set_xml(sr, LOGDIR "/unit/common/image.xml");
86  srunner_set_log(sr, LOGDIR "/unit/common/image.out");
87  srunner_run_all(sr, CK_ENV); /*verbosity from env variable*/
88  nf = srunner_ntests_failed(sr);
89  srunner_free(sr);
90  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
91 }
face_info * faces
Definition: image.h:26
void cctk_setdatadir(const char *datadir)
Definition: face.h:14
int id
Definition: image.h:18
const char * name
Definition: face.h:19
face_sets * find_faceset(int id)
Definition: assets.cpp:335
START_TEST(test_all_faces_have_data)
Definition: check_image.c:60
void teardown(void)
Definition: check_image.c:45
size_t allocated
Definition: image.h:25
void cctk_setlog(const char *logfile)
size_t get_faces_count()
Definition: assets.cpp:288
int main(void)
Definition: check_image.c:78
void facesets_for_each(faceset_op op)
Definition: assets.cpp:296
void setup(void)
Definition: check_image.c:39
uint16_t datalen
Definition: image.h:12
void cctk_init_std_archetypes(void)
END_TEST Suite * image_suite(void)
Definition: check_image.c:65
static void test_faceset(const face_sets *fs)
Definition: check_image.c:49
int get_face_fallback(int faceset, int imageno)
Definition: image.c:132
const Face * get_face_by_id(uint16_t id)
Definition: assets.cpp:314