1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "gx_api.h"
6 #include "gx_validation_utility.h"
7 
8 TEST_PARAM test_parameter = {
9     "guix_binres_theme_load", /* Test name */
10     5, 5, 630, 470  /* Define the coordinates of the capture area.
11                          In this test, we only need to capture the line
12                          drawing area.  */
13 };
14 
15 static VOID      control_thread_entry(ULONG);
main(int argc,char ** argv)16 int main(int argc, char ** argv)
17 {
18 #ifdef GX_UTF8_SUPPORT
19     /* Parse the command line argument. */
20     gx_validation_setup(argc, argv);
21 #else
22     printf("guix_binres_theme_load:Skip Testing!\n");
23 #endif
24     /* Start ThreadX system */
25     tx_kernel_enter();
26     return(0);
27 }
28 
tx_application_define(void * first_unused_memory)29 VOID tx_application_define(void *first_unused_memory)
30 {
31 
32     /* Create a dedicated thread to perform various operations
33        on the line drawing example. These operations simulate
34        user input. */
35     gx_validation_control_thread_create(control_thread_entry);
36 
37     /* Termiante the test if it runs for more than 100 ticks */
38     /* This function is not implemented yet. */
39     gx_validation_watchdog_create(100);
40 
41     /* Call the actual line example routine. */
42     gx_validation_application_define(first_unused_memory);
43 
44 }
45 
46 
47 /* Replace the default graphics driver with the validation driver. */
48 #ifdef win32_graphics_driver_setup_565rgb
49 #undef win32_graphics_driver_setup_565rgb
50 #endif
51 #define win32_graphics_driver_setup_565rgb  gx_validation_graphics_driver_setup_565rgb
52 
53 
54 #ifdef WIN32
55 #undef WIN32
56 #endif
57 
58 #define REGRESSION_TEST_MODE
59 
60 #include "gx_validation_wrapper.h"
61 
62 #include "demo_guix_multi_themes_16bpp.c"
63 
64 char test_comment[256];
65 
66 typedef struct TEST_TRUCT{
67 char *bin_file_path;
68 char *comment;
69 int   load_theme_id;
70 }TEST;
71 
72 TEST test_list[]={
73 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_font_magic_number.bin", "invalid font magic number", 0},
74 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_page_magic_number.bin", "invalid font page magic number", 0},
75 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_res_magic_number.bin", "invalid resource magic number", 0},
76 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_theme_count.bin", "invalid theme count", 0},
77 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_theme_magic_number.bin", "invalid theme magic number", 0},
78 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_no_color_font.bin", "no color and font table", 0},
79 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_no_pixelmap.bin", "no pixelmap table", 0},
80 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_pixelmap_magic_number.bin", "invalid pixelmap magic number", 0},
81 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_glyph_magic_number.bin", "invalid glyph magic number", 0},
82 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_color_magic_number.bin", "invalid_color_magic_number", 0},
83 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_font_header_bits.bin", "invalid font header bits", 0},
84 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_pixelmap_data_size.bin", "invalid pixelmap data size", 0},
85 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_old_version_pixmap_header_index.bin", "old version pixmap header index", 0},
86 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_1.bin", "theme 1", 0},
87 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_theme_pixelmap_font_data_size.bin", "invalid theme pixelmap font data size", 0},
88 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_1.bin", "theme 1, loaded theme id = 1(invalid)", 1},
89 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_palette_magic_number.bin", "invalid palette magic number", 0},
90 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_compressed_glyph_magic_number.bin", "invalid compressed glyph magic number", 0},
91 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_font_count.bin", "invalid font count", 0},
92 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_pixelmap_count.bin", "invalid pixelmap count", 0},
93 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_4_invalid_palette_color_count.bin", "invalid color count", 0},
94 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_5_font_pages_5460.bin", "5460 font pages with invalid glyph ranges[0, 0xffff]", 0},
95 {"..//..//..//example_internal//multi_themes_16bpp//binary_files_for_regression//theme_5_font_pages_5472.bin", "5472 font pages with invalid glyph ranges[0, 0xffff]", 0},
96 {GX_NULL, GX_NULL, 0}
97 };
98 
test_load_binres_to_ram(char * pathname)99 UINT test_load_binres_to_ram(char *pathname)
100 {
101     FILE *p_file;
102     size_t total_length;
103     size_t result;
104 
105     p_file = fopen(pathname, "rb");
106 
107     if (!p_file)
108     {
109         printf("Cannot open file: %s\n", pathname);
110         return GX_FAILURE;
111     }
112 
113     fseek(p_file, 0, SEEK_END);
114     total_length = ftell(p_file);
115     fseek(p_file, SEEK_SET, SEEK_SET);
116 
117     if(binres_root_address)
118     {
119         memory_free((void *)binres_root_address);
120     }
121 
122     binres_root_address = memory_allocate(total_length);
123     result = fread(binres_root_address, 1, total_length, p_file);
124 
125     fclose(p_file);
126 
127     if (result != total_length)
128     {
129         return GX_FAILURE;
130     }
131     return GX_SUCCESS;
132 }
133 
test_load_binres_theme(GX_UBYTE * root_address,INT theme_id)134 UINT test_load_binres_theme(GX_UBYTE *root_address, INT theme_id)
135 {
136 UINT  status = GX_SUCCESS;
137 
138     if (theme)
139     {
140         memory_free(theme);
141         theme = GX_NULL;
142     }
143 
144     status = gx_binres_theme_load(root_address, theme_id, &theme);
145 
146     if (theme &&
147         theme->theme_color_table &&
148         theme->theme_font_table &&
149         theme->theme_pixelmap_table)
150     {
151         gx_display_theme_install(multi_themes_16bpp_display_table[MAIN_DISPLAY].display, theme);
152     }
153 
154     return status;
155 }
156 
control_thread_entry(ULONG input)157 static VOID control_thread_entry(ULONG input)
158 {
159 #ifdef GX_UTF8_SUPPORT
160 INT   frame_id = 1;
161 TEST *test = test_list;
162 char  pathname[255];
163 int   pathlen;
164 
165     gx_display_theme_install(multi_themes_16bpp_display_table[MAIN_DISPLAY].display, main_display_theme_table[MAIN_DISPLAY_THEME_2]);
166 
167     gx_validation_extract_path(__FILE__, pathname, &pathlen);
168 
169     while(test->bin_file_path)
170     {
171         sprintf(pathname + pathlen, "%s", test->bin_file_path);
172         test_load_binres_to_ram(pathname);
173         test_load_binres_theme(binres_root_address, test->load_theme_id);
174 
175         gx_validation_set_frame_id(frame_id++);
176         gx_validation_set_frame_comment(test->comment);
177         gx_validation_screen_refresh();
178 
179         gx_display_theme_install(multi_themes_16bpp_display_table[MAIN_DISPLAY].display, main_display_theme_table[MAIN_DISPLAY_THEME_2]);
180         test++;
181     }
182 
183     /* Signal the end of the test case.  Verify the output. */
184     gx_validation_end();
185 #endif
186     exit(0);
187 }
188