API:
[blender.git] / source / creator / tests / alltest.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <check.h>
4
5 #include "MEM_guardedalloc.h"
6
7 #include "BKE_blender.h"
8 #include "BKE_image.h"
9 #include "BKE_utildefines.h"
10 #include "BKE_global.h"
11
12 #include "BLI_listbase.h"
13
14 #include "DNA_image_types.h"
15
16 char bprogname[FILE_MAXDIR+FILE_MAXFILE];
17 char btempdir[FILE_MAXDIR+FILE_MAXFILE];
18
19 typedef struct ImageTestData {
20         char *path; /* image filename */
21         char *expect_path; /* file path that we expect */
22         int type; /* image type */
23         int ret;  /* expected function return value */
24 } ImageTestData;
25
26 /* check that BKE_copy_images manipulates paths correctly */
27 START_TEST(test_copy_images)
28 {
29         char *dest_dir[] = {"/tmp/", "/tmp", NULL};
30         char **dir;
31         ImageTestData *test;
32
33         /* XXX Windows not tested */    
34 #ifdef WIN32
35         static ImageTestData test_data[] = {
36                 {"//bar/image.png", "C:\\Temp\\bar\\image.png"},
37                 /* TODO add more */
38                 {NULL, NULL},
39         };
40         
41         BLI_strncpy(G.sce, "C:\\Temp\untitled.blend", sizeof(G.sce));
42 #else
43         /*
44           XXX are these paths possible in image->name?:
45
46           ./foo/image.png
47           ../foo/image.png
48
49           if so, BKE_copy_images currently doesn't support them!
50          */
51         static ImageTestData test_data[] = {
52                 {"//bar/image.png", "/tmp/bar/image.png", IMA_TYPE_IMAGE, 1},
53                 {"/foo/bar/image.png", "/tmp/image.png", IMA_TYPE_IMAGE, 1},
54                 {"//image.png", "/tmp/image.png", IMA_TYPE_IMAGE, 1},
55                 {"//../../../foo/bar/image.png", "/tmp/image.png", IMA_TYPE_IMAGE, 1},
56                 {"//./foo/bar/image.png", "/tmp/foo/bar/image.png", IMA_TYPE_IMAGE, 1},
57                 {"/tmp/image.png", "/tmp/image.png", IMA_TYPE_IMAGE, 1},
58                 {"//textures/test/foo/bar/image.png", "/tmp/textures/test/foo/bar/image.png", IMA_TYPE_IMAGE, 1},
59                 {"//textures/test/foo/bar/image.png", "", IMA_TYPE_MULTILAYER, 0},
60                 {"", "", IMA_TYPE_IMAGE, 0},
61                 {NULL, NULL},
62         };
63
64         /* substitute G.sce */
65         BLI_strncpy(G.sce, "/tmp/foo/bar/untitled.blend", sizeof(G.sce));
66 #endif
67
68         for (dir = dest_dir; *dir; dir++) {
69                 for (test= &test_data[0]; test->path; test++) {
70                         Image image;
71                         char path[FILE_MAX];
72                         int ret;
73
74                         BLI_strncpy(image.name, test->path, sizeof(image.name));
75                         image.type= test->type;
76
77                         ret= BKE_export_image(&image, *dest_dir, path, sizeof(path));
78
79                         /* check if we got correct output */
80                         fail_if(ret != test->ret, "For image with filename %s and type %d, expected %d as return value got %d.",
81                                         test->path, test->type, test->ret, ret);
82                         fail_if(strcmp(path, test->expect_path), "For image with filename %s and type %d, expected path '%s' got '%s'.",
83                                         test->path, test->type, test->expect_path, path);
84                 }
85         }
86 }
87 END_TEST
88
89 static Suite *image_suite(void)
90 {
91         Suite *s = suite_create("Image");
92
93         /* Core test case */
94         TCase *tc_core = tcase_create("Core");
95         tcase_add_test(tc_core, test_copy_images);
96         suite_add_tcase(s, tc_core);
97
98         return s;
99 }
100
101 int run_tests()
102 {
103         int totfail;
104         Suite *s = image_suite();
105         SRunner *sr = srunner_create(s);
106
107         /* run tests */
108         srunner_run_all(sr, CK_VERBOSE);
109
110         totfail= srunner_ntests_failed(sr);
111         srunner_free(sr);
112
113         return !totfail ? EXIT_SUCCESS : EXIT_FAILURE;
114 }