blob: db14ff86f8b52d56c6605378b9945356aaec5212 [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
Simon Glassb8c26552023-06-01 10:23:03 -06007#include <command.h>
Simon Glass65924992023-01-06 08:52:39 -06008#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);
Simon Glass53a0a2f2024-10-14 16:31:57 -060094 ut_asserteq(EXPOID_BASE_ID, exp->next_id);
Simon Glass65924992023-01-06 08:52:39 -060095
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}
Simon Glass1a92f832024-08-22 07:57:48 -0600117BOOTSTD_TEST(expo_base, UTF_DM | UTF_SCAN_FDT);
Simon Glass65924992023-01-06 08:52:39 -0600118
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;
Simon Glass53a0a2f2024-10-14 16:31:57 -0600133 ut_asserteq(EXPOID_BASE_ID, exp->next_id);
Simon Glass65924992023-01-06 08:52:39 -0600134 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 Glassf9577852024-10-14 16:32:02 -0600154 scn->title_id = title_id;
Simon Glassea274b62023-06-01 10:22:27 -0600155 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}
Simon Glass1a92f832024-08-22 07:57:48 -0600168BOOTSTD_TEST(expo_scene, UTF_DM | UTF_SCAN_FDT);
Simon Glass65924992023-01-06 08:52:39 -0600169
Simon Glass5c6926c2024-10-14 16:31:56 -0600170/* Check creating a scene with no ID */
171static int expo_scene_no_id(struct unit_test_state *uts)
172{
173 struct scene *scn;
174 struct expo *exp;
175 char name[100];
176 int id;
177
178 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
Simon Glass53a0a2f2024-10-14 16:31:57 -0600179 ut_asserteq(EXPOID_BASE_ID, exp->next_id);
Simon Glass5c6926c2024-10-14 16:31:56 -0600180
181 strcpy(name, SCENE_NAME1);
182 id = scene_new(exp, SCENE_NAME1, 0, &scn);
Simon Glass53a0a2f2024-10-14 16:31:57 -0600183 ut_asserteq(EXPOID_BASE_ID, scn->id);
Simon Glass5c6926c2024-10-14 16:31:56 -0600184
185 return 0;
186}
187BOOTSTD_TEST(expo_scene_no_id, UTF_DM | UTF_SCAN_FDT);
188
Simon Glass65924992023-01-06 08:52:39 -0600189/* Check creating a scene with objects */
190static int expo_object(struct unit_test_state *uts)
191{
192 struct scene_obj_img *img;
193 struct scene_obj_txt *txt;
194 struct scene *scn;
195 struct expo *exp;
196 ulong start_mem;
197 char name[100];
198 char *data;
199 int id;
200
201 start_mem = ut_check_free();
202
203 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
204 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
205 ut_assert(id > 0);
206
207 ut_asserteq(0, scene_obj_count(scn));
208
209 data = NULL;
210 strcpy(name, LOGO_NAME);
211 id = scene_img(scn, name, OBJ_LOGO, data, &img);
212 ut_assert(id > 0);
213 *name = '\0';
214 ut_assertnonnull(img);
215 ut_asserteq(OBJ_LOGO, id);
216 ut_asserteq(OBJ_LOGO + 1, exp->next_id);
217 ut_asserteq_ptr(scn, img->obj.scene);
218 ut_asserteq(SCENEOBJT_IMAGE, img->obj.type);
219
220 ut_asserteq_ptr(data, img->data);
221
222 /* Make sure the name was allocated */
223 ut_assertnonnull(scn->name);
224 ut_asserteq_str(SCENE_NAME1, scn->name);
225
226 ut_asserteq(1, scene_obj_count(scn));
227
228 id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", &txt);
229 ut_assert(id > 0);
230 ut_assertnonnull(txt);
231 ut_asserteq(OBJ_TEXT, id);
232 ut_asserteq(SCENEOBJT_TEXT, txt->obj.type);
233 ut_asserteq(2, scene_obj_count(scn));
234
235 /* Check passing NULL as the final parameter */
236 id = scene_txt_str(scn, "text2", OBJ_TEXT2, STR_TEXT2, "another string",
237 NULL);
238 ut_assert(id > 0);
239 ut_asserteq(3, scene_obj_count(scn));
240
241 expo_destroy(exp);
242
243 ut_assertok(ut_check_delta(start_mem));
244
245 return 0;
246}
Simon Glass1a92f832024-08-22 07:57:48 -0600247BOOTSTD_TEST(expo_object, UTF_DM | UTF_SCAN_FDT);
Simon Glass65924992023-01-06 08:52:39 -0600248
Simon Glassc999e172023-06-01 10:22:53 -0600249/* Check setting object attributes and using themes */
Simon Glass65924992023-01-06 08:52:39 -0600250static int expo_object_attr(struct unit_test_state *uts)
251{
252 struct scene_obj_menu *menu;
253 struct scene_obj_img *img;
254 struct scene_obj_txt *txt;
255 struct scene *scn;
256 struct expo *exp;
257 ulong start_mem;
258 char name[100];
Simon Glassc999e172023-06-01 10:22:53 -0600259 ofnode node;
Simon Glass65924992023-01-06 08:52:39 -0600260 char *data;
261 int id;
262
263 start_mem = ut_check_free();
264
265 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
266 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
267 ut_assert(id > 0);
268
269 data = NULL;
270 id = scene_img(scn, LOGO_NAME, OBJ_LOGO, data, &img);
271 ut_assert(id > 0);
272
273 ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 123, 456));
Simon Glass7b043952023-06-01 10:22:49 -0600274 ut_asserteq(123, img->obj.dim.x);
275 ut_asserteq(456, img->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600276
277 ut_asserteq(-ENOENT, scene_obj_set_pos(scn, OBJ_TEXT2, 0, 0));
278
279 id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", &txt);
280 ut_assert(id > 0);
281
282 strcpy(name, "font2");
283 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, name, 42));
284 ut_asserteq_ptr(name, txt->font_name);
285 ut_asserteq(42, txt->font_size);
286
287 ut_asserteq(-ENOENT, scene_txt_set_font(scn, OBJ_TEXT2, name, 42));
288
289 id = scene_menu(scn, "main", OBJ_MENU, &menu);
290 ut_assert(id > 0);
291
292 ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_TEXT));
293
294 ut_asserteq(-ENOENT, scene_menu_set_title(scn, OBJ_TEXT2, OBJ_TEXT));
295 ut_asserteq(-EINVAL, scene_menu_set_title(scn, OBJ_MENU, OBJ_TEXT2));
296
Simon Glassc999e172023-06-01 10:22:53 -0600297 node = ofnode_path("/bootstd/theme");
298 ut_assert(ofnode_valid(node));
299 ut_assertok(expo_apply_theme(exp, node));
300 ut_asserteq(30, txt->font_size);
301
Simon Glass65924992023-01-06 08:52:39 -0600302 expo_destroy(exp);
303
304 ut_assertok(ut_check_delta(start_mem));
305
306 return 0;
307}
Simon Glass1a92f832024-08-22 07:57:48 -0600308BOOTSTD_TEST(expo_object_attr, UTF_DM | UTF_SCAN_FDT);
Simon Glass65924992023-01-06 08:52:39 -0600309
Simon Glasse90acd82023-08-14 16:40:23 -0600310/**
311 * struct test_iter_priv - private data for expo-iterator test
312 *
313 * @count: number of scene objects
314 * @menu_count: number of menus
315 * @fail_at: item ID at which to return an error
316 */
317struct test_iter_priv {
318 int count;
319 int menu_count;
320 int fail_at;
321};
322
323int h_test_iter(struct scene_obj *obj, void *vpriv)
324{
325 struct test_iter_priv *priv = vpriv;
326
327 if (priv->fail_at == obj->id)
328 return -EINVAL;
329
330 priv->count++;
331 if (obj->type == SCENEOBJT_MENU)
332 priv->menu_count++;
333
334 return 0;
335}
336
Simon Glass65924992023-01-06 08:52:39 -0600337/* Check creating a scene with a menu */
338static int expo_object_menu(struct unit_test_state *uts)
339{
340 struct scene_obj_menu *menu;
341 struct scene_menitem *item;
342 int id, label_id, desc_id, key_id, pointer_id, preview_id;
343 struct scene_obj_txt *ptr, *name1, *desc1, *key1, *tit, *prev1;
Simon Glasse90acd82023-08-14 16:40:23 -0600344 struct test_iter_priv priv;
Simon Glass65924992023-01-06 08:52:39 -0600345 struct scene *scn;
346 struct expo *exp;
347 ulong start_mem;
348
349 start_mem = ut_check_free();
350
351 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
352 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
353 ut_assert(id > 0);
354
355 id = scene_menu(scn, "main", OBJ_MENU, &menu);
356 ut_assert(id > 0);
357 ut_assertnonnull(menu);
358 ut_asserteq(OBJ_MENU, id);
359 ut_asserteq(SCENEOBJT_MENU, menu->obj.type);
360 ut_asserteq(0, menu->title_id);
361 ut_asserteq(0, menu->pointer_id);
362
363 ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400));
Simon Glass7b043952023-06-01 10:22:49 -0600364 ut_asserteq(50, menu->obj.dim.x);
365 ut_asserteq(400, menu->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600366
367 id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE,
368 "Main Menu", &tit);
369 ut_assert(id > 0);
370 ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_MENU_TITLE));
371 ut_asserteq(OBJ_MENU_TITLE, menu->title_id);
372
373 pointer_id = scene_txt_str(scn, "cur_item", POINTER_TEXT,
374 STR_POINTER_TEXT, ">", &ptr);
375 ut_assert(pointer_id > 0);
376
377 ut_assertok(scene_menu_set_pointer(scn, OBJ_MENU, POINTER_TEXT));
378 ut_asserteq(POINTER_TEXT, menu->pointer_id);
379
380 label_id = scene_txt_str(scn, "label1", ITEM1_LABEL, STR_ITEM1_LABEL,
381 "Play", &name1);
382 ut_assert(label_id > 0);
383
384 desc_id = scene_txt_str(scn, "desc1", ITEM1_DESC, STR_ITEM1_DESC,
385 "Lord Melchett", &desc1);
386 ut_assert(desc_id > 0);
387
388 key_id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1",
389 &key1);
390 ut_assert(key_id > 0);
391
392 preview_id = scene_txt_str(scn, "item1-preview", ITEM1_PREVIEW,
393 STR_ITEM1_PREVIEW, "(preview1)", &prev1);
394 ut_assert(preview_id > 0);
395
396 id = scene_menuitem(scn, OBJ_MENU, "linux", ITEM1, ITEM1_KEY,
397 ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, &item);
398 ut_asserteq(ITEM1, id);
399 ut_asserteq(id, item->id);
400 ut_asserteq(key_id, item->key_id);
401 ut_asserteq(label_id, item->label_id);
402 ut_asserteq(desc_id, item->desc_id);
403 ut_asserteq(preview_id, item->preview_id);
404
Simon Glassd7e32a82023-06-01 10:22:35 -0600405 ut_assertok(scene_arrange(scn));
406
407 /* arranging the scene should cause the first item to become current */
Simon Glass65924992023-01-06 08:52:39 -0600408 ut_asserteq(id, menu->cur_item_id);
409
410 /* the title should be at the top */
Simon Glass7b043952023-06-01 10:22:49 -0600411 ut_asserteq(menu->obj.dim.x, tit->obj.dim.x);
412 ut_asserteq(menu->obj.dim.y, tit->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600413
414 /* the first item should be next */
Simon Glass7b043952023-06-01 10:22:49 -0600415 ut_asserteq(menu->obj.dim.x, name1->obj.dim.x);
416 ut_asserteq(menu->obj.dim.y + 32, name1->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600417
Simon Glass7b043952023-06-01 10:22:49 -0600418 ut_asserteq(menu->obj.dim.x + 230, key1->obj.dim.x);
419 ut_asserteq(menu->obj.dim.y + 32, key1->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600420
Simon Glass7b043952023-06-01 10:22:49 -0600421 ut_asserteq(menu->obj.dim.x + 200, ptr->obj.dim.x);
422 ut_asserteq(menu->obj.dim.y + 32, ptr->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600423
Simon Glass7b043952023-06-01 10:22:49 -0600424 ut_asserteq(menu->obj.dim.x + 280, desc1->obj.dim.x);
425 ut_asserteq(menu->obj.dim.y + 32, desc1->obj.dim.y);
Simon Glass65924992023-01-06 08:52:39 -0600426
Simon Glass7b043952023-06-01 10:22:49 -0600427 ut_asserteq(-4, prev1->obj.dim.x);
428 ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
Simon Glassc55eeba2023-06-01 10:22:54 -0600429 ut_asserteq(true, prev1->obj.flags & SCENEOF_HIDE);
Simon Glass65924992023-01-06 08:52:39 -0600430
Simon Glasse90acd82023-08-14 16:40:23 -0600431 /* check iterating through scene items */
432 memset(&priv, '\0', sizeof(priv));
433 ut_assertok(expo_iter_scene_objs(exp, h_test_iter, &priv));
434 ut_asserteq(7, priv.count);
435 ut_asserteq(1, priv.menu_count);
436
437 /* check the iterator failing part way through iteration */
438 memset(&priv, '\0', sizeof(priv));
439 priv.fail_at = key_id;
440 ut_asserteq(-EINVAL, expo_iter_scene_objs(exp, h_test_iter, &priv));
441
442 /* 2 items (preview_id and the menuitem) are after key_id, 7 - 2 = 5 */
443 ut_asserteq(5, priv.count);
444
445 /* menu is first, so is still processed */
446 ut_asserteq(1, priv.menu_count);
447
Simon Glass65924992023-01-06 08:52:39 -0600448 expo_destroy(exp);
449
450 ut_assertok(ut_check_delta(start_mem));
451
452 return 0;
453}
Simon Glass1a92f832024-08-22 07:57:48 -0600454BOOTSTD_TEST(expo_object_menu, UTF_DM | UTF_SCAN_FDT);
Simon Glass65924992023-01-06 08:52:39 -0600455
456/* Check rendering a scene */
457static int expo_render_image(struct unit_test_state *uts)
458{
459 struct scene_obj_menu *menu;
460 struct scene *scn, *scn2;
461 struct expo_action act;
462 struct scene_obj *obj;
463 struct udevice *dev;
464 struct expo *exp;
465 int id;
466
Simon Glass65924992023-01-06 08:52:39 -0600467 ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
468
469 ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
470 id = scene_new(exp, SCENE_NAME1, SCENE1, &scn);
471 ut_assert(id > 0);
472 ut_assertok(expo_set_display(exp, dev));
473
474 id = scene_img(scn, "logo", OBJ_LOGO, video_get_u_boot_logo(), NULL);
475 ut_assert(id > 0);
476 ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 50, 20));
477
478 id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", NULL);
479 ut_assert(id > 0);
480 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, "cantoraone_regular",
481 40));
482 ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT, 400, 100));
483
484 id = scene_txt_str(scn, "text", OBJ_TEXT2, STR_TEXT2, "another string",
485 NULL);
486 ut_assert(id > 0);
487 ut_assertok(scene_txt_set_font(scn, OBJ_TEXT2, "nimbus_sans_l_regular",
488 60));
489 ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT2, 200, 600));
490
491 id = scene_menu(scn, "main", OBJ_MENU, &menu);
492 ut_assert(id > 0);
493
494 id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE,
495 "Main Menu", NULL);
496 ut_assert(id > 0);
497 ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_MENU_TITLE));
498
499 id = scene_txt_str(scn, "cur_item", POINTER_TEXT, STR_POINTER_TEXT, ">",
500 NULL);
501 ut_assert(id > 0);
502 ut_assertok(scene_menu_set_pointer(scn, OBJ_MENU, POINTER_TEXT));
503
504 id = scene_txt_str(scn, "label1", ITEM1_LABEL, STR_ITEM1_LABEL, "Play",
505 NULL);
506 ut_assert(id > 0);
507 id = scene_txt_str(scn, "item1 txt", ITEM1_DESC, STR_ITEM1_DESC,
508 "Lord Melchett", NULL);
509 ut_assert(id > 0);
510 id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1",
511 NULL);
512 ut_assert(id > 0);
513 id = scene_img(scn, "item1-preview", ITEM1_PREVIEW,
514 video_get_u_boot_logo(), NULL);
515 id = scene_menuitem(scn, OBJ_MENU, "item1", ITEM1, ITEM1_KEY,
516 ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, NULL);
517 ut_assert(id > 0);
518
519 id = scene_txt_str(scn, "label2", ITEM2_LABEL, STR_ITEM2_LABEL, "Now",
520 NULL);
521 ut_assert(id > 0);
522 id = scene_txt_str(scn, "item2 txt", ITEM2_DESC, STR_ITEM2_DESC,
523 "Lord Percy", NULL);
524 ut_assert(id > 0);
525 id = scene_txt_str(scn, "item2-key", ITEM2_KEY, STR_ITEM2_KEY, "2",
526 NULL);
527 ut_assert(id > 0);
528 id = scene_img(scn, "item2-preview", ITEM2_PREVIEW,
529 video_get_u_boot_logo(), NULL);
530 ut_assert(id > 0);
531
532 id = scene_menuitem(scn, OBJ_MENU, "item2", ITEM2, ITEM2_KEY,
533 ITEM2_LABEL, ITEM2_DESC, ITEM2_PREVIEW, 0, NULL);
534 ut_assert(id > 0);
535
536 ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400));
537
538 scn2 = expo_lookup_scene_id(exp, SCENE1);
539 ut_asserteq_ptr(scn, scn2);
540 scn2 = expo_lookup_scene_id(exp, SCENE2);
541 ut_assertnull(scn2);
542
543 /* render without a scene */
544 ut_asserteq(-ECHILD, expo_render(exp));
545
Simon Glass7a960052023-06-01 10:22:52 -0600546 ut_assertok(expo_calc_dims(exp));
547 ut_assertok(scene_arrange(scn));
548
549 /* check dimensions of text */
550 obj = scene_obj_find(scn, OBJ_TEXT, SCENEOBJT_NONE);
551 ut_assertnonnull(obj);
552 ut_asserteq(400, obj->dim.x);
553 ut_asserteq(100, obj->dim.y);
554 ut_asserteq(126, obj->dim.w);
555 ut_asserteq(40, obj->dim.h);
556
557 /* check dimensions of image */
558 obj = scene_obj_find(scn, OBJ_LOGO, SCENEOBJT_NONE);
559 ut_assertnonnull(obj);
560 ut_asserteq(50, obj->dim.x);
561 ut_asserteq(20, obj->dim.y);
562 ut_asserteq(160, obj->dim.w);
563 ut_asserteq(160, obj->dim.h);
564
565 /* check dimensions of menu labels - both should be the same width */
566 obj = scene_obj_find(scn, ITEM1_LABEL, SCENEOBJT_NONE);
567 ut_assertnonnull(obj);
568 ut_asserteq(50, obj->dim.x);
569 ut_asserteq(436, obj->dim.y);
570 ut_asserteq(29, obj->dim.w);
571 ut_asserteq(18, obj->dim.h);
572
573 obj = scene_obj_find(scn, ITEM2_LABEL, SCENEOBJT_NONE);
574 ut_assertnonnull(obj);
575 ut_asserteq(50, obj->dim.x);
576 ut_asserteq(454, obj->dim.y);
577 ut_asserteq(29, obj->dim.w);
578 ut_asserteq(18, obj->dim.h);
579
580 /* check dimensions of menu */
581 obj = scene_obj_find(scn, OBJ_MENU, SCENEOBJT_NONE);
582 ut_assertnonnull(obj);
583 ut_asserteq(50, obj->dim.x);
584 ut_asserteq(400, obj->dim.y);
585 ut_asserteq(160, obj->dim.w);
586 ut_asserteq(160, obj->dim.h);
587
Simon Glass65924992023-01-06 08:52:39 -0600588 /* render it */
589 expo_set_scene_id(exp, SCENE1);
590 ut_assertok(expo_render(exp));
591
592 /* move down */
593 ut_assertok(expo_send_key(exp, BKEY_DOWN));
594
595 ut_assertok(expo_action_get(exp, &act));
596
Simon Glass719a3c62023-06-01 10:22:56 -0600597 ut_asserteq(EXPOACT_POINT_ITEM, act.type);
Simon Glass65924992023-01-06 08:52:39 -0600598 ut_asserteq(ITEM2, act.select.id);
599 ut_assertok(expo_render(exp));
600
601 /* make sure only the preview for the second item is shown */
602 obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE);
Simon Glass6081b0f2023-06-01 10:22:50 -0600603 ut_asserteq(true, obj->flags & SCENEOF_HIDE);
Simon Glass65924992023-01-06 08:52:39 -0600604
605 obj = scene_obj_find(scn, ITEM2_PREVIEW, SCENEOBJT_NONE);
Simon Glass6081b0f2023-06-01 10:22:50 -0600606 ut_asserteq(false, obj->flags & SCENEOF_HIDE);
Simon Glass65924992023-01-06 08:52:39 -0600607
608 /* select it */
609 ut_assertok(expo_send_key(exp, BKEY_SELECT));
610
611 ut_assertok(expo_action_get(exp, &act));
612 ut_asserteq(EXPOACT_SELECT, act.type);
613 ut_asserteq(ITEM2, act.select.id);
614
615 /* make sure the action doesn't come again */
616 ut_asserteq(-EAGAIN, expo_action_get(exp, &act));
617
618 /* make sure there was no console output */
619 ut_assert_console_end();
620
621 /* now try in text mode */
Simon Glassb2c40342023-06-01 10:22:37 -0600622 expo_set_text_mode(exp, true);
Simon Glass65924992023-01-06 08:52:39 -0600623 ut_assertok(expo_render(exp));
624
625 ut_assert_nextline("U-Boot : Boot Menu");
626 ut_assert_nextline("%s", "");
627 ut_assert_nextline("Main Menu");
628 ut_assert_nextline("%s", "");
629 ut_assert_nextline(" 1 Play Lord Melchett");
630 ut_assert_nextline(" > 2 Now Lord Percy");
631
632 /* Move back up to the first item */
633 ut_assertok(expo_send_key(exp, BKEY_UP));
634
635 ut_assertok(expo_action_get(exp, &act));
636
Simon Glass719a3c62023-06-01 10:22:56 -0600637 ut_asserteq(EXPOACT_POINT_ITEM, act.type);
Simon Glass65924992023-01-06 08:52:39 -0600638 ut_asserteq(ITEM1, act.select.id);
639
640 ut_assertok(expo_render(exp));
641 ut_assert_nextline("U-Boot : Boot Menu");
642 ut_assert_nextline("%s", "");
643 ut_assert_nextline("Main Menu");
644 ut_assert_nextline("%s", "");
645 ut_assert_nextline(" > 1 Play Lord Melchett");
646 ut_assert_nextline(" 2 Now Lord Percy");
647
648 ut_assert_console_end();
649
650 expo_destroy(exp);
651
652 return 0;
653}
Simon Glassf0425022024-08-22 07:57:54 -0600654BOOTSTD_TEST(expo_render_image, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
Simon Glass61300722023-06-01 10:23:01 -0600655
656/* Check building an expo from a devicetree description */
657static int expo_test_build(struct unit_test_state *uts)
658{
659 struct scene_obj_menu *menu;
660 struct scene_menitem *item;
661 struct scene_obj_txt *txt;
662 struct scene_obj *obj;
663 struct scene *scn;
664 struct expo *exp;
665 int count;
666 ofnode node;
667
668 node = ofnode_path("/cedit");
669 ut_assert(ofnode_valid(node));
670 ut_assertok(expo_build(node, &exp));
671
672 ut_asserteq_str("name", exp->name);
673 ut_asserteq(0, exp->scene_id);
Simon Glass70c579b2023-10-01 19:13:39 -0600674 ut_asserteq(ID_DYNAMIC_START + 24, exp->next_id);
Simon Glass61300722023-06-01 10:23:01 -0600675 ut_asserteq(false, exp->popup);
676
677 /* check the scene */
678 scn = expo_lookup_scene_id(exp, ID_SCENE1);
679 ut_assertnonnull(scn);
680 ut_asserteq_str("main", scn->name);
681 ut_asserteq(ID_SCENE1, scn->id);
682 ut_asserteq(ID_DYNAMIC_START + 1, scn->title_id);
683 ut_asserteq(0, scn->highlight_id);
684
685 /* check the title */
686 txt = scene_obj_find(scn, scn->title_id, SCENEOBJT_NONE);
687 ut_assertnonnull(txt);
688 obj = &txt->obj;
689 ut_asserteq_ptr(scn, obj->scene);
690 ut_asserteq_str("title", obj->name);
691 ut_asserteq(scn->title_id, obj->id);
692 ut_asserteq(SCENEOBJT_TEXT, obj->type);
693 ut_asserteq(0, obj->flags);
694 ut_asserteq_str("Test Configuration", expo_get_str(exp, txt->str_id));
695
696 /* check the menu */
697 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_NONE);
698 obj = &menu->obj;
699 ut_asserteq_ptr(scn, obj->scene);
700 ut_asserteq_str("cpu-speed", obj->name);
701 ut_asserteq(ID_CPU_SPEED, obj->id);
702 ut_asserteq(SCENEOBJT_MENU, obj->type);
703 ut_asserteq(0, obj->flags);
704
705 txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE);
706 ut_asserteq_str("CPU speed", expo_get_str(exp, txt->str_id));
707
708 ut_asserteq(0, menu->cur_item_id);
709 ut_asserteq(0, menu->pointer_id);
710
711 /* check the items */
712 item = list_first_entry(&menu->item_head, struct scene_menitem,
713 sibling);
714 ut_asserteq_str("00", item->name);
715 ut_asserteq(ID_CPU_SPEED_1, item->id);
716 ut_asserteq(0, item->key_id);
717 ut_asserteq(0, item->desc_id);
718 ut_asserteq(0, item->preview_id);
719 ut_asserteq(0, item->flags);
Simon Glass100389f2024-10-14 16:31:58 -0600720 ut_asserteq(0, item->value);
Simon Glass61300722023-06-01 10:23:01 -0600721
722 txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE);
723 ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id));
724
Sughosh Ganuebb1c202024-08-28 22:24:22 +0530725 count = list_count_nodes(&menu->item_head);
Simon Glass61300722023-06-01 10:23:01 -0600726 ut_asserteq(3, count);
727
728 expo_destroy(exp);
729
730 return 0;
731}
Simon Glass1a92f832024-08-22 07:57:48 -0600732BOOTSTD_TEST(expo_test_build, UTF_DM);