blob: e7148024fe303230c114fafa96eacf413e436d6d [file] [log] [blame]
Simon Glass65924992023-01-06 08:52:39 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <expo.h>
10#include <menu.h>
11#include <video.h>
12#include <linux/input.h>
13#include <test/suites.h>
14#include <test/ut.h>
15#include "bootstd_common.h"
Simon Glass61300722023-06-01 10:23:01 -060016#include <test/cedit-test.h>
Simon Glass65924992023-01-06 08:52:39 -060017#include "../../boot/scene_internal.h"
18
19enum {
20 /* scenes */
21 SCENE1 = 7,
22 SCENE2,
23
24 /* objects */
25 OBJ_LOGO,
26 OBJ_TEXT,
27 OBJ_TEXT2,
28 OBJ_MENU,
29 OBJ_MENU_TITLE,
30
31 /* strings */
Simon Glassea274b62023-06-01 10:22:27 -060032 STR_SCENE_TITLE,
33
Simon Glass65924992023-01-06 08:52:39 -060034 STR_TEXT,
35 STR_TEXT2,
36 STR_MENU_TITLE,
37 STR_POINTER_TEXT,
38
39 STR_ITEM1_LABEL,
40 STR_ITEM1_DESC,
41 STR_ITEM1_KEY,
42 STR_ITEM1_PREVIEW,
43
44 STR_ITEM2_LABEL,
45 STR_ITEM2_DESC,
46 STR_ITEM2_KEY,
47 STR_ITEM2_PREVIEW,
48
49 /* menu items */
50 ITEM1,
51 ITEM1_LABEL,
52 ITEM1_DESC,
53 ITEM1_KEY,
54 ITEM1_PREVIEW,
55
56 ITEM2,
57 ITEM2_LABEL,
58 ITEM2_DESC,
59 ITEM2_KEY,
60 ITEM2_PREVIEW,
61
62 /* pointer to current item */
63 POINTER_TEXT,
64};
65
66#define BAD_POINTER ((void *)1)
67
68/* names for various things */
69#define EXPO_NAME "my menus"
70#define SCENE_NAME1 "main"
71#define SCENE_NAME2 "second"
72#define SCENE_TITLE "Main Menu"
73#define LOGO_NAME "logo"
74
75/* Check base expo support */
76static int expo_base(struct unit_test_state *uts)
77{
78 struct udevice *dev;
79 struct expo *exp;
80 ulong start_mem;
81 char name[100];
82 int i;
83
84 ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
85
86 start_mem = ut_check_free();
87
88 exp = NULL;
89 strcpy(name, EXPO_NAME);
90 ut_assertok(expo_new(name, NULL, &exp));
91 *name = '\0';
92 ut_assertnonnull(exp);
93 ut_asserteq(0, exp->scene_id);
94 ut_asserteq(0, exp->next_id);
95
96 /* Make sure the name was allocated */
97 ut_assertnonnull(exp->name);
98 ut_asserteq_str(EXPO_NAME, exp->name);
99
100 ut_assertok(expo_set_display(exp, dev));
101 expo_destroy(exp);
102 ut_assertok(ut_check_delta(start_mem));
103
104 /* test handling out-of-memory conditions */
105 for (i = 0; i < 2; i++) {
106 struct expo *exp2;
107
108 malloc_enable_testing(i);
109 exp2 = BAD_POINTER;
110 ut_asserteq(-ENOMEM, expo_new(EXPO_NAME, NULL, &exp2));
111 ut_asserteq_ptr(BAD_POINTER, exp2);
112 malloc_disable_testing();
113 }
114
115 return 0;
116}
117BOOTSTD_TEST(expo_base, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
118
119/* Check creating a scene */
120static int expo_scene(struct unit_test_state *uts)
121{
122 struct scene *scn;
123 struct expo *exp;
124 ulong start_mem;
125 char name[100];
Simon Glassea274b62023-06-01 10:22:27 -0600126 int id, title_id;
Simon Glass65924992023-01-06 08:52:39 -0600127
128 start_mem = ut_check_free();
129
130 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
131
132 scn = NULL;
133 ut_asserteq(0, exp->next_id);
134 strcpy(name, SCENE_NAME1);
135 id = scene_new(exp, name, SCENE1, &scn);
136 *name = '\0';
137 ut_assertnonnull(scn);
138 ut_asserteq(SCENE1, id);
139 ut_asserteq(SCENE1 + 1, exp->next_id);
140 ut_asserteq_ptr(exp, scn->expo);
141
142 /* Make sure the name was allocated */
143 ut_assertnonnull(scn->name);
144 ut_asserteq_str(SCENE_NAME1, scn->name);
145
146 /* Set the title */
Simon Glassea274b62023-06-01 10:22:27 -0600147 title_id = expo_str(exp, "title", STR_SCENE_TITLE, SCENE_TITLE);
148 ut_assert(title_id >= 0);
Simon Glass65924992023-01-06 08:52:39 -0600149
Simon Glassea274b62023-06-01 10:22:27 -0600150 /* Use an allocated ID - this will be allocated after the title str */
Simon Glass65924992023-01-06 08:52:39 -0600151 scn = NULL;
152 id = scene_new(exp, SCENE_NAME2, 0, &scn);
153 ut_assertnonnull(scn);
Simon Glassea274b62023-06-01 10:22:27 -0600154 ut_assertok(scene_title_set(scn, title_id));
155 ut_asserteq(STR_SCENE_TITLE + 1, id);
156 ut_asserteq(STR_SCENE_TITLE + 2, exp->next_id);
Simon Glass65924992023-01-06 08:52:39 -0600157 ut_asserteq_ptr(exp, scn->expo);
158
159 ut_asserteq_str(SCENE_NAME2, scn->name);
Simon Glassea274b62023-06-01 10:22:27 -0600160 ut_asserteq(title_id, scn->title_id);
Simon Glass65924992023-01-06 08:52:39 -0600161
162 expo_destroy(exp);
163
164 ut_assertok(ut_check_delta(start_mem));
165
166 return 0;
167}
168BOOTSTD_TEST(expo_scene, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
169
170/* Check creating a scene with objects */
171static int expo_object(struct unit_test_state *uts)
172{
173 struct scene_obj_img *img;
174 struct scene_obj_txt *txt;
175 struct scene *scn;
176 struct expo *exp;
177 ulong start_mem;
178 char name[100];
179 char *data;
180 int id;
181
182 start_mem = ut_check_free();
183
184 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
185 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
186 ut_assert(id > 0);
187
188 ut_asserteq(0, scene_obj_count(scn));
189
190 data = NULL;
191 strcpy(name, LOGO_NAME);
192 id = scene_img(scn, name, OBJ_LOGO, data, &img);
193 ut_assert(id > 0);
194 *name = '\0';
195 ut_assertnonnull(img);
196 ut_asserteq(OBJ_LOGO, id);
197 ut_asserteq(OBJ_LOGO + 1, exp->next_id);
198 ut_asserteq_ptr(scn, img->obj.scene);
199 ut_asserteq(SCENEOBJT_IMAGE, img->obj.type);
200
201 ut_asserteq_ptr(data, img->data);
202
203 /* Make sure the name was allocated */
204 ut_assertnonnull(scn->name);
205 ut_asserteq_str(SCENE_NAME1, scn->name);
206
207 ut_asserteq(1, scene_obj_count(scn));
208
209 id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", &txt);
210 ut_assert(id > 0);
211 ut_assertnonnull(txt);
212 ut_asserteq(OBJ_TEXT, id);
213 ut_asserteq(SCENEOBJT_TEXT, txt->obj.type);
214 ut_asserteq(2, scene_obj_count(scn));
215
216 /* Check passing NULL as the final parameter */
217 id = scene_txt_str(scn, "text2", OBJ_TEXT2, STR_TEXT2, "another string",
218 NULL);
219 ut_assert(id > 0);
220 ut_asserteq(3, scene_obj_count(scn));
221
222 expo_destroy(exp);
223
224 ut_assertok(ut_check_delta(start_mem));
225
226 return 0;
227}
228BOOTSTD_TEST(expo_object, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
229
Simon Glassc999e172023-06-01 10:22:53 -0600230/* Check setting object attributes and using themes */
Simon Glass65924992023-01-06 08:52:39 -0600231static int expo_object_attr(struct unit_test_state *uts)
232{
233 struct scene_obj_menu *menu;
234 struct scene_obj_img *img;
235 struct scene_obj_txt *txt;
236 struct scene *scn;
237 struct expo *exp;
238 ulong start_mem;
239 char name[100];
Simon Glassc999e172023-06-01 10:22:53 -0600240 ofnode node;
Simon Glass65924992023-01-06 08:52:39 -0600241 char *data;
242 int id;
243
244 start_mem = ut_check_free();
245
246 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
247 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
248 ut_assert(id > 0);
249
250 data = NULL;
251 id = scene_img(scn, LOGO_NAME, OBJ_LOGO, data, &img);
252 ut_assert(id > 0);
253
254 ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 123, 456));
Simon Glass7b043952023-06-01 10:22:49 -0600255 ut_asserteq(123, img->obj.dim.x);
256 ut_asserteq(456, img->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600257
258 ut_asserteq(-ENOENT, scene_obj_set_pos(scn, OBJ_TEXT2, 0, 0));
259
260 id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", &txt);
261 ut_assert(id > 0);
262
263 strcpy(name, "font2");
264 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, name, 42));
265 ut_asserteq_ptr(name, txt->font_name);
266 ut_asserteq(42, txt->font_size);
267
268 ut_asserteq(-ENOENT, scene_txt_set_font(scn, OBJ_TEXT2, name, 42));
269
270 id = scene_menu(scn, "main", OBJ_MENU, &menu);
271 ut_assert(id > 0);
272
273 ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_TEXT));
274
275 ut_asserteq(-ENOENT, scene_menu_set_title(scn, OBJ_TEXT2, OBJ_TEXT));
276 ut_asserteq(-EINVAL, scene_menu_set_title(scn, OBJ_MENU, OBJ_TEXT2));
277
Simon Glassc999e172023-06-01 10:22:53 -0600278 node = ofnode_path("/bootstd/theme");
279 ut_assert(ofnode_valid(node));
280 ut_assertok(expo_apply_theme(exp, node));
281 ut_asserteq(30, txt->font_size);
282
Simon Glass65924992023-01-06 08:52:39 -0600283 expo_destroy(exp);
284
285 ut_assertok(ut_check_delta(start_mem));
286
287 return 0;
288}
289BOOTSTD_TEST(expo_object_attr, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
290
291/* Check creating a scene with a menu */
292static int expo_object_menu(struct unit_test_state *uts)
293{
294 struct scene_obj_menu *menu;
295 struct scene_menitem *item;
296 int id, label_id, desc_id, key_id, pointer_id, preview_id;
297 struct scene_obj_txt *ptr, *name1, *desc1, *key1, *tit, *prev1;
298 struct scene *scn;
299 struct expo *exp;
300 ulong start_mem;
301
302 start_mem = ut_check_free();
303
304 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
305 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
306 ut_assert(id > 0);
307
308 id = scene_menu(scn, "main", OBJ_MENU, &menu);
309 ut_assert(id > 0);
310 ut_assertnonnull(menu);
311 ut_asserteq(OBJ_MENU, id);
312 ut_asserteq(SCENEOBJT_MENU, menu->obj.type);
313 ut_asserteq(0, menu->title_id);
314 ut_asserteq(0, menu->pointer_id);
315
316 ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400));
Simon Glass7b043952023-06-01 10:22:49 -0600317 ut_asserteq(50, menu->obj.dim.x);
318 ut_asserteq(400, menu->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600319
320 id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE,
321 "Main Menu", &tit);
322 ut_assert(id > 0);
323 ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_MENU_TITLE));
324 ut_asserteq(OBJ_MENU_TITLE, menu->title_id);
325
326 pointer_id = scene_txt_str(scn, "cur_item", POINTER_TEXT,
327 STR_POINTER_TEXT, ">", &ptr);
328 ut_assert(pointer_id > 0);
329
330 ut_assertok(scene_menu_set_pointer(scn, OBJ_MENU, POINTER_TEXT));
331 ut_asserteq(POINTER_TEXT, menu->pointer_id);
332
333 label_id = scene_txt_str(scn, "label1", ITEM1_LABEL, STR_ITEM1_LABEL,
334 "Play", &name1);
335 ut_assert(label_id > 0);
336
337 desc_id = scene_txt_str(scn, "desc1", ITEM1_DESC, STR_ITEM1_DESC,
338 "Lord Melchett", &desc1);
339 ut_assert(desc_id > 0);
340
341 key_id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1",
342 &key1);
343 ut_assert(key_id > 0);
344
345 preview_id = scene_txt_str(scn, "item1-preview", ITEM1_PREVIEW,
346 STR_ITEM1_PREVIEW, "(preview1)", &prev1);
347 ut_assert(preview_id > 0);
348
349 id = scene_menuitem(scn, OBJ_MENU, "linux", ITEM1, ITEM1_KEY,
350 ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, &item);
351 ut_asserteq(ITEM1, id);
352 ut_asserteq(id, item->id);
353 ut_asserteq(key_id, item->key_id);
354 ut_asserteq(label_id, item->label_id);
355 ut_asserteq(desc_id, item->desc_id);
356 ut_asserteq(preview_id, item->preview_id);
357
Simon Glassd7e32a82023-06-01 10:22:35 -0600358 ut_assertok(scene_arrange(scn));
359
360 /* arranging the scene should cause the first item to become current */
Simon Glass65924992023-01-06 08:52:39 -0600361 ut_asserteq(id, menu->cur_item_id);
362
363 /* the title should be at the top */
Simon Glass7b043952023-06-01 10:22:49 -0600364 ut_asserteq(menu->obj.dim.x, tit->obj.dim.x);
365 ut_asserteq(menu->obj.dim.y, tit->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600366
367 /* the first item should be next */
Simon Glass7b043952023-06-01 10:22:49 -0600368 ut_asserteq(menu->obj.dim.x, name1->obj.dim.x);
369 ut_asserteq(menu->obj.dim.y + 32, name1->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600370
Simon Glass7b043952023-06-01 10:22:49 -0600371 ut_asserteq(menu->obj.dim.x + 230, key1->obj.dim.x);
372 ut_asserteq(menu->obj.dim.y + 32, key1->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600373
Simon Glass7b043952023-06-01 10:22:49 -0600374 ut_asserteq(menu->obj.dim.x + 200, ptr->obj.dim.x);
375 ut_asserteq(menu->obj.dim.y + 32, ptr->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600376
Simon Glass7b043952023-06-01 10:22:49 -0600377 ut_asserteq(menu->obj.dim.x + 280, desc1->obj.dim.x);
378 ut_asserteq(menu->obj.dim.y + 32, desc1->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600379
Simon Glass7b043952023-06-01 10:22:49 -0600380 ut_asserteq(-4, prev1->obj.dim.x);
381 ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
Simon Glassc55eeba2023-06-01 10:22:54 -0600382 ut_asserteq(true, prev1->obj.flags & SCENEOF_HIDE);
Simon Glass65924992023-01-06 08:52:39 -0600383
384 expo_destroy(exp);
385
386 ut_assertok(ut_check_delta(start_mem));
387
388 return 0;
389}
390BOOTSTD_TEST(expo_object_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
391
392/* Check rendering a scene */
393static int expo_render_image(struct unit_test_state *uts)
394{
395 struct scene_obj_menu *menu;
396 struct scene *scn, *scn2;
397 struct expo_action act;
398 struct scene_obj *obj;
399 struct udevice *dev;
400 struct expo *exp;
401 int id;
402
403 console_record_reset_enable();
404 ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
405
406 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
407 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
408 ut_assert(id > 0);
409 ut_assertok(expo_set_display(exp, dev));
410
411 id = scene_img(scn, "logo", OBJ_LOGO, video_get_u_boot_logo(), NULL);
412 ut_assert(id > 0);
413 ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 50, 20));
414
415 id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", NULL);
416 ut_assert(id > 0);
417 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, "cantoraone_regular",
418 40));
419 ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT, 400, 100));
420
421 id = scene_txt_str(scn, "text", OBJ_TEXT2, STR_TEXT2, "another string",
422 NULL);
423 ut_assert(id > 0);
424 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT2, "nimbus_sans_l_regular",
425 60));
426 ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT2, 200, 600));
427
428 id = scene_menu(scn, "main", OBJ_MENU, &menu);
429 ut_assert(id > 0);
430
431 id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE,
432 "Main Menu", NULL);
433 ut_assert(id > 0);
434 ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_MENU_TITLE));
435
436 id = scene_txt_str(scn, "cur_item", POINTER_TEXT, STR_POINTER_TEXT, ">",
437 NULL);
438 ut_assert(id > 0);
439 ut_assertok(scene_menu_set_pointer(scn, OBJ_MENU, POINTER_TEXT));
440
441 id = scene_txt_str(scn, "label1", ITEM1_LABEL, STR_ITEM1_LABEL, "Play",
442 NULL);
443 ut_assert(id > 0);
444 id = scene_txt_str(scn, "item1 txt", ITEM1_DESC, STR_ITEM1_DESC,
445 "Lord Melchett", NULL);
446 ut_assert(id > 0);
447 id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1",
448 NULL);
449 ut_assert(id > 0);
450 id = scene_img(scn, "item1-preview", ITEM1_PREVIEW,
451 video_get_u_boot_logo(), NULL);
452 id = scene_menuitem(scn, OBJ_MENU, "item1", ITEM1, ITEM1_KEY,
453 ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, NULL);
454 ut_assert(id > 0);
455
456 id = scene_txt_str(scn, "label2", ITEM2_LABEL, STR_ITEM2_LABEL, "Now",
457 NULL);
458 ut_assert(id > 0);
459 id = scene_txt_str(scn, "item2 txt", ITEM2_DESC, STR_ITEM2_DESC,
460 "Lord Percy", NULL);
461 ut_assert(id > 0);
462 id = scene_txt_str(scn, "item2-key", ITEM2_KEY, STR_ITEM2_KEY, "2",
463 NULL);
464 ut_assert(id > 0);
465 id = scene_img(scn, "item2-preview", ITEM2_PREVIEW,
466 video_get_u_boot_logo(), NULL);
467 ut_assert(id > 0);
468
469 id = scene_menuitem(scn, OBJ_MENU, "item2", ITEM2, ITEM2_KEY,
470 ITEM2_LABEL, ITEM2_DESC, ITEM2_PREVIEW, 0, NULL);
471 ut_assert(id > 0);
472
473 ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400));
474
475 scn2 = expo_lookup_scene_id(exp, SCENE1);
476 ut_asserteq_ptr(scn, scn2);
477 scn2 = expo_lookup_scene_id(exp, SCENE2);
478 ut_assertnull(scn2);
479
480 /* render without a scene */
481 ut_asserteq(-ECHILD, expo_render(exp));
482
Simon Glass7a960052023-06-01 10:22:52 -0600483 ut_assertok(expo_calc_dims(exp));
484 ut_assertok(scene_arrange(scn));
485
486 /* check dimensions of text */
487 obj = scene_obj_find(scn, OBJ_TEXT, SCENEOBJT_NONE);
488 ut_assertnonnull(obj);
489 ut_asserteq(400, obj->dim.x);
490 ut_asserteq(100, obj->dim.y);
491 ut_asserteq(126, obj->dim.w);
492 ut_asserteq(40, obj->dim.h);
493
494 /* check dimensions of image */
495 obj = scene_obj_find(scn, OBJ_LOGO, SCENEOBJT_NONE);
496 ut_assertnonnull(obj);
497 ut_asserteq(50, obj->dim.x);
498 ut_asserteq(20, obj->dim.y);
499 ut_asserteq(160, obj->dim.w);
500 ut_asserteq(160, obj->dim.h);
501
502 /* check dimensions of menu labels - both should be the same width */
503 obj = scene_obj_find(scn, ITEM1_LABEL, SCENEOBJT_NONE);
504 ut_assertnonnull(obj);
505 ut_asserteq(50, obj->dim.x);
506 ut_asserteq(436, obj->dim.y);
507 ut_asserteq(29, obj->dim.w);
508 ut_asserteq(18, obj->dim.h);
509
510 obj = scene_obj_find(scn, ITEM2_LABEL, SCENEOBJT_NONE);
511 ut_assertnonnull(obj);
512 ut_asserteq(50, obj->dim.x);
513 ut_asserteq(454, obj->dim.y);
514 ut_asserteq(29, obj->dim.w);
515 ut_asserteq(18, obj->dim.h);
516
517 /* check dimensions of menu */
518 obj = scene_obj_find(scn, OBJ_MENU, SCENEOBJT_NONE);
519 ut_assertnonnull(obj);
520 ut_asserteq(50, obj->dim.x);
521 ut_asserteq(400, obj->dim.y);
522 ut_asserteq(160, obj->dim.w);
523 ut_asserteq(160, obj->dim.h);
524
Simon Glass65924992023-01-06 08:52:39 -0600525 /* render it */
526 expo_set_scene_id(exp, SCENE1);
527 ut_assertok(expo_render(exp));
528
529 /* move down */
530 ut_assertok(expo_send_key(exp, BKEY_DOWN));
531
532 ut_assertok(expo_action_get(exp, &act));
533
Simon Glass719a3c62023-06-01 10:22:56 -0600534 ut_asserteq(EXPOACT_POINT_ITEM, act.type);
Simon Glass65924992023-01-06 08:52:39 -0600535 ut_asserteq(ITEM2, act.select.id);
536 ut_assertok(expo_render(exp));
537
538 /* make sure only the preview for the second item is shown */
539 obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE);
Simon Glass6081b0f2023-06-01 10:22:50 -0600540 ut_asserteq(true, obj->flags & SCENEOF_HIDE);
Simon Glass65924992023-01-06 08:52:39 -0600541
542 obj = scene_obj_find(scn, ITEM2_PREVIEW, SCENEOBJT_NONE);
Simon Glass6081b0f2023-06-01 10:22:50 -0600543 ut_asserteq(false, obj->flags & SCENEOF_HIDE);
Simon Glass65924992023-01-06 08:52:39 -0600544
545 /* select it */
546 ut_assertok(expo_send_key(exp, BKEY_SELECT));
547
548 ut_assertok(expo_action_get(exp, &act));
549 ut_asserteq(EXPOACT_SELECT, act.type);
550 ut_asserteq(ITEM2, act.select.id);
551
552 /* make sure the action doesn't come again */
553 ut_asserteq(-EAGAIN, expo_action_get(exp, &act));
554
555 /* make sure there was no console output */
556 ut_assert_console_end();
557
558 /* now try in text mode */
Simon Glassb2c40342023-06-01 10:22:37 -0600559 expo_set_text_mode(exp, true);
Simon Glass65924992023-01-06 08:52:39 -0600560 ut_assertok(expo_render(exp));
561
562 ut_assert_nextline("U-Boot : Boot Menu");
563 ut_assert_nextline("%s", "");
564 ut_assert_nextline("Main Menu");
565 ut_assert_nextline("%s", "");
566 ut_assert_nextline(" 1 Play Lord Melchett");
567 ut_assert_nextline(" > 2 Now Lord Percy");
568
569 /* Move back up to the first item */
570 ut_assertok(expo_send_key(exp, BKEY_UP));
571
572 ut_assertok(expo_action_get(exp, &act));
573
Simon Glass719a3c62023-06-01 10:22:56 -0600574 ut_asserteq(EXPOACT_POINT_ITEM, act.type);
Simon Glass65924992023-01-06 08:52:39 -0600575 ut_asserteq(ITEM1, act.select.id);
576
577 ut_assertok(expo_render(exp));
578 ut_assert_nextline("U-Boot : Boot Menu");
579 ut_assert_nextline("%s", "");
580 ut_assert_nextline("Main Menu");
581 ut_assert_nextline("%s", "");
582 ut_assert_nextline(" > 1 Play Lord Melchett");
583 ut_assert_nextline(" 2 Now Lord Percy");
584
585 ut_assert_console_end();
586
587 expo_destroy(exp);
588
589 return 0;
590}
591BOOTSTD_TEST(expo_render_image, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
Simon Glass61300722023-06-01 10:23:01 -0600592
593/* Check building an expo from a devicetree description */
594static int expo_test_build(struct unit_test_state *uts)
595{
596 struct scene_obj_menu *menu;
597 struct scene_menitem *item;
598 struct scene_obj_txt *txt;
599 struct scene_obj *obj;
600 struct scene *scn;
601 struct expo *exp;
602 int count;
603 ofnode node;
604
605 node = ofnode_path("/cedit");
606 ut_assert(ofnode_valid(node));
607 ut_assertok(expo_build(node, &exp));
608
609 ut_asserteq_str("name", exp->name);
610 ut_asserteq(0, exp->scene_id);
611 ut_asserteq(ID_DYNAMIC_START + 20, exp->next_id);
612 ut_asserteq(false, exp->popup);
613
614 /* check the scene */
615 scn = expo_lookup_scene_id(exp, ID_SCENE1);
616 ut_assertnonnull(scn);
617 ut_asserteq_str("main", scn->name);
618 ut_asserteq(ID_SCENE1, scn->id);
619 ut_asserteq(ID_DYNAMIC_START + 1, scn->title_id);
620 ut_asserteq(0, scn->highlight_id);
621
622 /* check the title */
623 txt = scene_obj_find(scn, scn->title_id, SCENEOBJT_NONE);
624 ut_assertnonnull(txt);
625 obj = &txt->obj;
626 ut_asserteq_ptr(scn, obj->scene);
627 ut_asserteq_str("title", obj->name);
628 ut_asserteq(scn->title_id, obj->id);
629 ut_asserteq(SCENEOBJT_TEXT, obj->type);
630 ut_asserteq(0, obj->flags);
631 ut_asserteq_str("Test Configuration", expo_get_str(exp, txt->str_id));
632
633 /* check the menu */
634 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_NONE);
635 obj = &menu->obj;
636 ut_asserteq_ptr(scn, obj->scene);
637 ut_asserteq_str("cpu-speed", obj->name);
638 ut_asserteq(ID_CPU_SPEED, obj->id);
639 ut_asserteq(SCENEOBJT_MENU, obj->type);
640 ut_asserteq(0, obj->flags);
641
642 txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE);
643 ut_asserteq_str("CPU speed", expo_get_str(exp, txt->str_id));
644
645 ut_asserteq(0, menu->cur_item_id);
646 ut_asserteq(0, menu->pointer_id);
647
648 /* check the items */
649 item = list_first_entry(&menu->item_head, struct scene_menitem,
650 sibling);
651 ut_asserteq_str("00", item->name);
652 ut_asserteq(ID_CPU_SPEED_1, item->id);
653 ut_asserteq(0, item->key_id);
654 ut_asserteq(0, item->desc_id);
655 ut_asserteq(0, item->preview_id);
656 ut_asserteq(0, item->flags);
657
658 txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE);
659 ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id));
660
661 count = 0;
662 list_for_each_entry(item, &menu->item_head, sibling)
663 count++;
664 ut_asserteq(3, count);
665
666 expo_destroy(exp);
667
668 return 0;
669}
670BOOTSTD_TEST(expo_test_build, UT_TESTF_DM);