Fix typo in the Gentoo initscript.
[fbsplash.git] / core / src / test / test_parser.c
blob060961d696b40036c1e7ec0adc012c42587e075b
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdbool.h>
4 #include <unistd.h>
5 #include "../common.h"
6 #include "../render.h"
7 #include "parse.h"
9 #undef iprint
10 #define iprint(lev, args...) ;
12 char *icons_ok[] = {
13 "icon dummy.png 0 0",
14 "icon dummy.png 100 23 svc_start dummysvc",
15 "icon dummy.png 340 40 crop <0,0,0,0> <30,30,10,10>",
16 "icon dummy.png 45 65 crop <1,1,1,1> <23,4,5,6> svc_stop dummysvc ",
17 "icon dummy.png 67 40 svc_start dummysvc blendout(45)",
20 char *icons_err[] = {
21 "icondummy.png 0 0",
22 "icon dummy.png",
23 "icon",
24 "icon dummy.png svc_start dummysvc",
25 "icon dummy.png 0 svc_start dummysvc",
26 "icon dummy.png 10 100 crop <0,0,0,0>",
27 "icon dummy.png 34 34 svc_stop",
28 "icon 3 5",
31 char *anims_ok[] = {
32 "anim once dummy.mng 0 0",
33 "anim loop dummy.mng 30 40 svc_started dummysvc",
34 "anim proportional dummy.mng 30 40 svc_start_failed dummysvc",
35 "anim once dummy.mng 0 0 svc_started dummysvc blendin(450)",
38 char *anims_err[] = {
39 "anim dummy.png 0 0",
40 "anim once dummy.png svc_start dummysvc",
41 "anim loop 0 0",
42 "anim loop dummy.png 0",
43 "anim loop dummy.png 0 3 svc_start ",
46 char *text_ok[] = {
47 "text dummy.ttf 12 0 0 #000000 \"foobar\"",
48 "text silent verbose dummy.ttf 12 0 0 #fe09ae \"dummy\"",
49 "text silent dummy.ttf biu 12 5 left 5 top #deadbeef exec eval \"$progress test\"",
50 "text verbose dummy.ttf ubi 3 100 middle 347 middle #ffffff exec \"dummy\"",
51 "text verbose dummy.ttf b 1 100 right 100 bottom #123456 eval \"just a test\"",
52 "text dummy.ttf 12 0 0 #000000 \"foo\" blendin(24345)",
55 char *text_err[] = {
56 "text 12 0 0",
57 "text dummy.ttf biu 3 4",
58 "text dummy.ttf 3 top 4 middle",
59 "text dummy.ttf 4 5 \"test\"",
60 "text dummy.ttf 4 4 5 \"test\"",
61 "text dummy.ttf 12 0 0 #fff00 \"test\"",
62 "text dummy.ttf 12 0 0 #ff00ff00f \"test\"",
63 "text dummy.ttf 12 0 0 #ffffff test",
66 char *box_ok[] = {
67 "box silent 0 0 1 1 #001122",
68 "box 0 0 0 0 #12345678",
69 "box silent 0 1 2 3 #000000 #111111 #222222 #333333",
70 "box silent 0 1 2 3 #000000 blendin(134)",
73 char *box_err[] = {
74 "box silent 1 1 2 2",
75 "box 1 2 3 4 #0012gf",
76 "box 1 3 #00f0f0",
77 "box 1 2 3 #f0f0f0",
78 "box 5 5 1 1 #f0f0f0",
79 "box 1 1 4 4 #f0f0f0 #f0f0f0",
80 "box 2 5 6 7 #f0f0f0 #f0f0f0 #deadbeef",
81 "box 7 7 8 8 #708090 #909090 #deadbeef #beefdeade",
82 "box silent 0 349 1279 450 #22222c #22222c #383849 #040454498",
83 "box silent 0 1 2 3 #000000 blendout(34",
84 "box silent 0 1 2 3 #134342 blendout(45) blendin(345",
87 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
89 int tests_failed = 0;
90 int tests_run = 0;
92 bool parse_box_wrapper(char *t)
94 void *p = parse_box(t);
95 return (p == NULL) ? false : true;
98 void test_parse(bool (*parsef)(char*), bool expect, char *stuff, int offset)
100 char *p = strdup(stuff);
101 bool out = parsef(p + offset);
103 tests_run++;
105 if (out != expect) {
106 printf("* Failed: %s\n", stuff);
107 tests_failed++;
108 } else {
109 printf("* OK: %s\n", stuff);
112 free(p);
113 return;
116 int main(int argc, char **argv)
118 int i;
119 char *p;
120 fbspl_cfg_t *config;
122 config = fbsplash_lib_init(fbspl_bootup);
123 fbsplash_acc_theme_set("test");
124 fbsplashr_init(false);
126 config->verbosity = FBSPL_VERB_QUIET;
128 tmptheme.xres = 1000;
129 tmptheme.yres = 1000;
131 for (i = 0; i < ARRAY_SIZE(icons_ok); i++) {
132 test_parse(parse_icon, true, icons_ok[i], 4);
135 for (i = 0; i < ARRAY_SIZE(icons_err); i++) {
136 test_parse(parse_icon, false, icons_err[i], 4);
139 #if WANT_MNG
140 for (i = 0; i < ARRAY_SIZE(anims_ok); i++) {
141 test_parse(parse_anim, true, anims_ok[i], 4);
144 for (i = 0; i < ARRAY_SIZE(anims_err); i++) {
145 test_parse(parse_anim, false, anims_err[i], 4);
147 #endif
149 #if WANT_TTF
150 for (i = 0; i < ARRAY_SIZE(text_ok); i++) {
151 test_parse(parse_text, true, text_ok[i], 4);
154 for (i = 0; i < ARRAY_SIZE(text_err); i++) {
155 test_parse(parse_text, false, text_err[i], 4);
157 #endif
159 for (i = 0; i < ARRAY_SIZE(box_ok); i++) {
160 test_parse(parse_box_wrapper, true, box_ok[i], 3);
163 for (i = 0; i < ARRAY_SIZE(box_err); i++) {
164 test_parse(parse_box_wrapper, false, box_err[i], 3);
167 printf("Ran %d tests, %d failed.\n", tests_run, tests_failed);
169 fbsplashr_cleanup();
170 fbsplash_lib_cleanup();
172 return tests_failed;