Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
Simon Glass | b8c2655 | 2023-06-01 10:23:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 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 Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 16 | #include <test/cedit-test.h> |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 17 | #include "../../boot/scene_internal.h" |
| 18 | |
| 19 | enum { |
| 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 Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 32 | STR_SCENE_TITLE, |
| 33 | |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 34 | 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 */ |
| 76 | static 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 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 117 | BOOTSTD_TEST(expo_base, UTF_DM | UTF_SCAN_FDT); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 118 | |
| 119 | /* Check creating a scene */ |
| 120 | static 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 Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 126 | int id, title_id; |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 127 | |
| 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 Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 147 | title_id = expo_str(exp, "title", STR_SCENE_TITLE, SCENE_TITLE); |
| 148 | ut_assert(title_id >= 0); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 149 | |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 150 | /* Use an allocated ID - this will be allocated after the title str */ |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 151 | scn = NULL; |
| 152 | id = scene_new(exp, SCENE_NAME2, 0, &scn); |
| 153 | ut_assertnonnull(scn); |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 154 | 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 Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 157 | ut_asserteq_ptr(exp, scn->expo); |
| 158 | |
| 159 | ut_asserteq_str(SCENE_NAME2, scn->name); |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 160 | ut_asserteq(title_id, scn->title_id); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 161 | |
| 162 | expo_destroy(exp); |
| 163 | |
| 164 | ut_assertok(ut_check_delta(start_mem)); |
| 165 | |
| 166 | return 0; |
| 167 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 168 | BOOTSTD_TEST(expo_scene, UTF_DM | UTF_SCAN_FDT); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 169 | |
| 170 | /* Check creating a scene with objects */ |
| 171 | static 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 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 228 | BOOTSTD_TEST(expo_object, UTF_DM | UTF_SCAN_FDT); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 229 | |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 230 | /* Check setting object attributes and using themes */ |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 231 | static 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 Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 240 | ofnode node; |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 241 | 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 Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 255 | ut_asserteq(123, img->obj.dim.x); |
| 256 | ut_asserteq(456, img->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 257 | |
| 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 Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 278 | 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 Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 283 | expo_destroy(exp); |
| 284 | |
| 285 | ut_assertok(ut_check_delta(start_mem)); |
| 286 | |
| 287 | return 0; |
| 288 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 289 | BOOTSTD_TEST(expo_object_attr, UTF_DM | UTF_SCAN_FDT); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 290 | |
Simon Glass | e90acd8 | 2023-08-14 16:40:23 -0600 | [diff] [blame] | 291 | /** |
| 292 | * struct test_iter_priv - private data for expo-iterator test |
| 293 | * |
| 294 | * @count: number of scene objects |
| 295 | * @menu_count: number of menus |
| 296 | * @fail_at: item ID at which to return an error |
| 297 | */ |
| 298 | struct test_iter_priv { |
| 299 | int count; |
| 300 | int menu_count; |
| 301 | int fail_at; |
| 302 | }; |
| 303 | |
| 304 | int h_test_iter(struct scene_obj *obj, void *vpriv) |
| 305 | { |
| 306 | struct test_iter_priv *priv = vpriv; |
| 307 | |
| 308 | if (priv->fail_at == obj->id) |
| 309 | return -EINVAL; |
| 310 | |
| 311 | priv->count++; |
| 312 | if (obj->type == SCENEOBJT_MENU) |
| 313 | priv->menu_count++; |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 318 | /* Check creating a scene with a menu */ |
| 319 | static int expo_object_menu(struct unit_test_state *uts) |
| 320 | { |
| 321 | struct scene_obj_menu *menu; |
| 322 | struct scene_menitem *item; |
| 323 | int id, label_id, desc_id, key_id, pointer_id, preview_id; |
| 324 | struct scene_obj_txt *ptr, *name1, *desc1, *key1, *tit, *prev1; |
Simon Glass | e90acd8 | 2023-08-14 16:40:23 -0600 | [diff] [blame] | 325 | struct test_iter_priv priv; |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 326 | struct scene *scn; |
| 327 | struct expo *exp; |
| 328 | ulong start_mem; |
| 329 | |
| 330 | start_mem = ut_check_free(); |
| 331 | |
| 332 | ut_assertok(expo_new(EXPO_NAME, NULL, &exp)); |
| 333 | id = scene_new(exp, SCENE_NAME1, SCENE1, &scn); |
| 334 | ut_assert(id > 0); |
| 335 | |
| 336 | id = scene_menu(scn, "main", OBJ_MENU, &menu); |
| 337 | ut_assert(id > 0); |
| 338 | ut_assertnonnull(menu); |
| 339 | ut_asserteq(OBJ_MENU, id); |
| 340 | ut_asserteq(SCENEOBJT_MENU, menu->obj.type); |
| 341 | ut_asserteq(0, menu->title_id); |
| 342 | ut_asserteq(0, menu->pointer_id); |
| 343 | |
| 344 | ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400)); |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 345 | ut_asserteq(50, menu->obj.dim.x); |
| 346 | ut_asserteq(400, menu->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 347 | |
| 348 | id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE, |
| 349 | "Main Menu", &tit); |
| 350 | ut_assert(id > 0); |
| 351 | ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_MENU_TITLE)); |
| 352 | ut_asserteq(OBJ_MENU_TITLE, menu->title_id); |
| 353 | |
| 354 | pointer_id = scene_txt_str(scn, "cur_item", POINTER_TEXT, |
| 355 | STR_POINTER_TEXT, ">", &ptr); |
| 356 | ut_assert(pointer_id > 0); |
| 357 | |
| 358 | ut_assertok(scene_menu_set_pointer(scn, OBJ_MENU, POINTER_TEXT)); |
| 359 | ut_asserteq(POINTER_TEXT, menu->pointer_id); |
| 360 | |
| 361 | label_id = scene_txt_str(scn, "label1", ITEM1_LABEL, STR_ITEM1_LABEL, |
| 362 | "Play", &name1); |
| 363 | ut_assert(label_id > 0); |
| 364 | |
| 365 | desc_id = scene_txt_str(scn, "desc1", ITEM1_DESC, STR_ITEM1_DESC, |
| 366 | "Lord Melchett", &desc1); |
| 367 | ut_assert(desc_id > 0); |
| 368 | |
| 369 | key_id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1", |
| 370 | &key1); |
| 371 | ut_assert(key_id > 0); |
| 372 | |
| 373 | preview_id = scene_txt_str(scn, "item1-preview", ITEM1_PREVIEW, |
| 374 | STR_ITEM1_PREVIEW, "(preview1)", &prev1); |
| 375 | ut_assert(preview_id > 0); |
| 376 | |
| 377 | id = scene_menuitem(scn, OBJ_MENU, "linux", ITEM1, ITEM1_KEY, |
| 378 | ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, &item); |
| 379 | ut_asserteq(ITEM1, id); |
| 380 | ut_asserteq(id, item->id); |
| 381 | ut_asserteq(key_id, item->key_id); |
| 382 | ut_asserteq(label_id, item->label_id); |
| 383 | ut_asserteq(desc_id, item->desc_id); |
| 384 | ut_asserteq(preview_id, item->preview_id); |
| 385 | |
Simon Glass | d7e32a8 | 2023-06-01 10:22:35 -0600 | [diff] [blame] | 386 | ut_assertok(scene_arrange(scn)); |
| 387 | |
| 388 | /* arranging the scene should cause the first item to become current */ |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 389 | ut_asserteq(id, menu->cur_item_id); |
| 390 | |
| 391 | /* the title should be at the top */ |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 392 | ut_asserteq(menu->obj.dim.x, tit->obj.dim.x); |
| 393 | ut_asserteq(menu->obj.dim.y, tit->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 394 | |
| 395 | /* the first item should be next */ |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 396 | ut_asserteq(menu->obj.dim.x, name1->obj.dim.x); |
| 397 | ut_asserteq(menu->obj.dim.y + 32, name1->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 398 | |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 399 | ut_asserteq(menu->obj.dim.x + 230, key1->obj.dim.x); |
| 400 | ut_asserteq(menu->obj.dim.y + 32, key1->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 401 | |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 402 | ut_asserteq(menu->obj.dim.x + 200, ptr->obj.dim.x); |
| 403 | ut_asserteq(menu->obj.dim.y + 32, ptr->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 404 | |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 405 | ut_asserteq(menu->obj.dim.x + 280, desc1->obj.dim.x); |
| 406 | ut_asserteq(menu->obj.dim.y + 32, desc1->obj.dim.y); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 407 | |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 408 | ut_asserteq(-4, prev1->obj.dim.x); |
| 409 | ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y); |
Simon Glass | c55eeba | 2023-06-01 10:22:54 -0600 | [diff] [blame] | 410 | ut_asserteq(true, prev1->obj.flags & SCENEOF_HIDE); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 411 | |
Simon Glass | e90acd8 | 2023-08-14 16:40:23 -0600 | [diff] [blame] | 412 | /* check iterating through scene items */ |
| 413 | memset(&priv, '\0', sizeof(priv)); |
| 414 | ut_assertok(expo_iter_scene_objs(exp, h_test_iter, &priv)); |
| 415 | ut_asserteq(7, priv.count); |
| 416 | ut_asserteq(1, priv.menu_count); |
| 417 | |
| 418 | /* check the iterator failing part way through iteration */ |
| 419 | memset(&priv, '\0', sizeof(priv)); |
| 420 | priv.fail_at = key_id; |
| 421 | ut_asserteq(-EINVAL, expo_iter_scene_objs(exp, h_test_iter, &priv)); |
| 422 | |
| 423 | /* 2 items (preview_id and the menuitem) are after key_id, 7 - 2 = 5 */ |
| 424 | ut_asserteq(5, priv.count); |
| 425 | |
| 426 | /* menu is first, so is still processed */ |
| 427 | ut_asserteq(1, priv.menu_count); |
| 428 | |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 429 | expo_destroy(exp); |
| 430 | |
| 431 | ut_assertok(ut_check_delta(start_mem)); |
| 432 | |
| 433 | return 0; |
| 434 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 435 | BOOTSTD_TEST(expo_object_menu, UTF_DM | UTF_SCAN_FDT); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 436 | |
| 437 | /* Check rendering a scene */ |
| 438 | static int expo_render_image(struct unit_test_state *uts) |
| 439 | { |
| 440 | struct scene_obj_menu *menu; |
| 441 | struct scene *scn, *scn2; |
| 442 | struct expo_action act; |
| 443 | struct scene_obj *obj; |
| 444 | struct udevice *dev; |
| 445 | struct expo *exp; |
| 446 | int id; |
| 447 | |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 448 | ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); |
| 449 | |
| 450 | ut_assertok(expo_new(EXPO_NAME, NULL, &exp)); |
| 451 | id = scene_new(exp, SCENE_NAME1, SCENE1, &scn); |
| 452 | ut_assert(id > 0); |
| 453 | ut_assertok(expo_set_display(exp, dev)); |
| 454 | |
| 455 | id = scene_img(scn, "logo", OBJ_LOGO, video_get_u_boot_logo(), NULL); |
| 456 | ut_assert(id > 0); |
| 457 | ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 50, 20)); |
| 458 | |
| 459 | id = scene_txt_str(scn, "text", OBJ_TEXT, STR_TEXT, "my string", NULL); |
| 460 | ut_assert(id > 0); |
| 461 | ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, "cantoraone_regular", |
| 462 | 40)); |
| 463 | ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT, 400, 100)); |
| 464 | |
| 465 | id = scene_txt_str(scn, "text", OBJ_TEXT2, STR_TEXT2, "another string", |
| 466 | NULL); |
| 467 | ut_assert(id > 0); |
| 468 | ut_assertok(scene_txt_set_font(scn, OBJ_TEXT2, "nimbus_sans_l_regular", |
| 469 | 60)); |
| 470 | ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT2, 200, 600)); |
| 471 | |
| 472 | id = scene_menu(scn, "main", OBJ_MENU, &menu); |
| 473 | ut_assert(id > 0); |
| 474 | |
| 475 | id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE, |
| 476 | "Main Menu", NULL); |
| 477 | ut_assert(id > 0); |
| 478 | ut_assertok(scene_menu_set_title(scn, OBJ_MENU, OBJ_MENU_TITLE)); |
| 479 | |
| 480 | id = scene_txt_str(scn, "cur_item", POINTER_TEXT, STR_POINTER_TEXT, ">", |
| 481 | NULL); |
| 482 | ut_assert(id > 0); |
| 483 | ut_assertok(scene_menu_set_pointer(scn, OBJ_MENU, POINTER_TEXT)); |
| 484 | |
| 485 | id = scene_txt_str(scn, "label1", ITEM1_LABEL, STR_ITEM1_LABEL, "Play", |
| 486 | NULL); |
| 487 | ut_assert(id > 0); |
| 488 | id = scene_txt_str(scn, "item1 txt", ITEM1_DESC, STR_ITEM1_DESC, |
| 489 | "Lord Melchett", NULL); |
| 490 | ut_assert(id > 0); |
| 491 | id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1", |
| 492 | NULL); |
| 493 | ut_assert(id > 0); |
| 494 | id = scene_img(scn, "item1-preview", ITEM1_PREVIEW, |
| 495 | video_get_u_boot_logo(), NULL); |
| 496 | id = scene_menuitem(scn, OBJ_MENU, "item1", ITEM1, ITEM1_KEY, |
| 497 | ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, NULL); |
| 498 | ut_assert(id > 0); |
| 499 | |
| 500 | id = scene_txt_str(scn, "label2", ITEM2_LABEL, STR_ITEM2_LABEL, "Now", |
| 501 | NULL); |
| 502 | ut_assert(id > 0); |
| 503 | id = scene_txt_str(scn, "item2 txt", ITEM2_DESC, STR_ITEM2_DESC, |
| 504 | "Lord Percy", NULL); |
| 505 | ut_assert(id > 0); |
| 506 | id = scene_txt_str(scn, "item2-key", ITEM2_KEY, STR_ITEM2_KEY, "2", |
| 507 | NULL); |
| 508 | ut_assert(id > 0); |
| 509 | id = scene_img(scn, "item2-preview", ITEM2_PREVIEW, |
| 510 | video_get_u_boot_logo(), NULL); |
| 511 | ut_assert(id > 0); |
| 512 | |
| 513 | id = scene_menuitem(scn, OBJ_MENU, "item2", ITEM2, ITEM2_KEY, |
| 514 | ITEM2_LABEL, ITEM2_DESC, ITEM2_PREVIEW, 0, NULL); |
| 515 | ut_assert(id > 0); |
| 516 | |
| 517 | ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400)); |
| 518 | |
| 519 | scn2 = expo_lookup_scene_id(exp, SCENE1); |
| 520 | ut_asserteq_ptr(scn, scn2); |
| 521 | scn2 = expo_lookup_scene_id(exp, SCENE2); |
| 522 | ut_assertnull(scn2); |
| 523 | |
| 524 | /* render without a scene */ |
| 525 | ut_asserteq(-ECHILD, expo_render(exp)); |
| 526 | |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 527 | ut_assertok(expo_calc_dims(exp)); |
| 528 | ut_assertok(scene_arrange(scn)); |
| 529 | |
| 530 | /* check dimensions of text */ |
| 531 | obj = scene_obj_find(scn, OBJ_TEXT, SCENEOBJT_NONE); |
| 532 | ut_assertnonnull(obj); |
| 533 | ut_asserteq(400, obj->dim.x); |
| 534 | ut_asserteq(100, obj->dim.y); |
| 535 | ut_asserteq(126, obj->dim.w); |
| 536 | ut_asserteq(40, obj->dim.h); |
| 537 | |
| 538 | /* check dimensions of image */ |
| 539 | obj = scene_obj_find(scn, OBJ_LOGO, SCENEOBJT_NONE); |
| 540 | ut_assertnonnull(obj); |
| 541 | ut_asserteq(50, obj->dim.x); |
| 542 | ut_asserteq(20, obj->dim.y); |
| 543 | ut_asserteq(160, obj->dim.w); |
| 544 | ut_asserteq(160, obj->dim.h); |
| 545 | |
| 546 | /* check dimensions of menu labels - both should be the same width */ |
| 547 | obj = scene_obj_find(scn, ITEM1_LABEL, SCENEOBJT_NONE); |
| 548 | ut_assertnonnull(obj); |
| 549 | ut_asserteq(50, obj->dim.x); |
| 550 | ut_asserteq(436, obj->dim.y); |
| 551 | ut_asserteq(29, obj->dim.w); |
| 552 | ut_asserteq(18, obj->dim.h); |
| 553 | |
| 554 | obj = scene_obj_find(scn, ITEM2_LABEL, SCENEOBJT_NONE); |
| 555 | ut_assertnonnull(obj); |
| 556 | ut_asserteq(50, obj->dim.x); |
| 557 | ut_asserteq(454, obj->dim.y); |
| 558 | ut_asserteq(29, obj->dim.w); |
| 559 | ut_asserteq(18, obj->dim.h); |
| 560 | |
| 561 | /* check dimensions of menu */ |
| 562 | obj = scene_obj_find(scn, OBJ_MENU, SCENEOBJT_NONE); |
| 563 | ut_assertnonnull(obj); |
| 564 | ut_asserteq(50, obj->dim.x); |
| 565 | ut_asserteq(400, obj->dim.y); |
| 566 | ut_asserteq(160, obj->dim.w); |
| 567 | ut_asserteq(160, obj->dim.h); |
| 568 | |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 569 | /* render it */ |
| 570 | expo_set_scene_id(exp, SCENE1); |
| 571 | ut_assertok(expo_render(exp)); |
| 572 | |
| 573 | /* move down */ |
| 574 | ut_assertok(expo_send_key(exp, BKEY_DOWN)); |
| 575 | |
| 576 | ut_assertok(expo_action_get(exp, &act)); |
| 577 | |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 578 | ut_asserteq(EXPOACT_POINT_ITEM, act.type); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 579 | ut_asserteq(ITEM2, act.select.id); |
| 580 | ut_assertok(expo_render(exp)); |
| 581 | |
| 582 | /* make sure only the preview for the second item is shown */ |
| 583 | obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE); |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 584 | ut_asserteq(true, obj->flags & SCENEOF_HIDE); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 585 | |
| 586 | obj = scene_obj_find(scn, ITEM2_PREVIEW, SCENEOBJT_NONE); |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 587 | ut_asserteq(false, obj->flags & SCENEOF_HIDE); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 588 | |
| 589 | /* select it */ |
| 590 | ut_assertok(expo_send_key(exp, BKEY_SELECT)); |
| 591 | |
| 592 | ut_assertok(expo_action_get(exp, &act)); |
| 593 | ut_asserteq(EXPOACT_SELECT, act.type); |
| 594 | ut_asserteq(ITEM2, act.select.id); |
| 595 | |
| 596 | /* make sure the action doesn't come again */ |
| 597 | ut_asserteq(-EAGAIN, expo_action_get(exp, &act)); |
| 598 | |
| 599 | /* make sure there was no console output */ |
| 600 | ut_assert_console_end(); |
| 601 | |
| 602 | /* now try in text mode */ |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 603 | expo_set_text_mode(exp, true); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 604 | ut_assertok(expo_render(exp)); |
| 605 | |
| 606 | ut_assert_nextline("U-Boot : Boot Menu"); |
| 607 | ut_assert_nextline("%s", ""); |
| 608 | ut_assert_nextline("Main Menu"); |
| 609 | ut_assert_nextline("%s", ""); |
| 610 | ut_assert_nextline(" 1 Play Lord Melchett"); |
| 611 | ut_assert_nextline(" > 2 Now Lord Percy"); |
| 612 | |
| 613 | /* Move back up to the first item */ |
| 614 | ut_assertok(expo_send_key(exp, BKEY_UP)); |
| 615 | |
| 616 | ut_assertok(expo_action_get(exp, &act)); |
| 617 | |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 618 | ut_asserteq(EXPOACT_POINT_ITEM, act.type); |
Simon Glass | 6592499 | 2023-01-06 08:52:39 -0600 | [diff] [blame] | 619 | ut_asserteq(ITEM1, act.select.id); |
| 620 | |
| 621 | ut_assertok(expo_render(exp)); |
| 622 | ut_assert_nextline("U-Boot : Boot Menu"); |
| 623 | ut_assert_nextline("%s", ""); |
| 624 | ut_assert_nextline("Main Menu"); |
| 625 | ut_assert_nextline("%s", ""); |
| 626 | ut_assert_nextline(" > 1 Play Lord Melchett"); |
| 627 | ut_assert_nextline(" 2 Now Lord Percy"); |
| 628 | |
| 629 | ut_assert_console_end(); |
| 630 | |
| 631 | expo_destroy(exp); |
| 632 | |
| 633 | return 0; |
| 634 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 635 | BOOTSTD_TEST(expo_render_image, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 636 | |
| 637 | /* Check building an expo from a devicetree description */ |
| 638 | static int expo_test_build(struct unit_test_state *uts) |
| 639 | { |
| 640 | struct scene_obj_menu *menu; |
| 641 | struct scene_menitem *item; |
| 642 | struct scene_obj_txt *txt; |
| 643 | struct scene_obj *obj; |
| 644 | struct scene *scn; |
| 645 | struct expo *exp; |
| 646 | int count; |
| 647 | ofnode node; |
| 648 | |
| 649 | node = ofnode_path("/cedit"); |
| 650 | ut_assert(ofnode_valid(node)); |
| 651 | ut_assertok(expo_build(node, &exp)); |
| 652 | |
| 653 | ut_asserteq_str("name", exp->name); |
| 654 | ut_asserteq(0, exp->scene_id); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 655 | ut_asserteq(ID_DYNAMIC_START + 24, exp->next_id); |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 656 | ut_asserteq(false, exp->popup); |
| 657 | |
| 658 | /* check the scene */ |
| 659 | scn = expo_lookup_scene_id(exp, ID_SCENE1); |
| 660 | ut_assertnonnull(scn); |
| 661 | ut_asserteq_str("main", scn->name); |
| 662 | ut_asserteq(ID_SCENE1, scn->id); |
| 663 | ut_asserteq(ID_DYNAMIC_START + 1, scn->title_id); |
| 664 | ut_asserteq(0, scn->highlight_id); |
| 665 | |
| 666 | /* check the title */ |
| 667 | txt = scene_obj_find(scn, scn->title_id, SCENEOBJT_NONE); |
| 668 | ut_assertnonnull(txt); |
| 669 | obj = &txt->obj; |
| 670 | ut_asserteq_ptr(scn, obj->scene); |
| 671 | ut_asserteq_str("title", obj->name); |
| 672 | ut_asserteq(scn->title_id, obj->id); |
| 673 | ut_asserteq(SCENEOBJT_TEXT, obj->type); |
| 674 | ut_asserteq(0, obj->flags); |
| 675 | ut_asserteq_str("Test Configuration", expo_get_str(exp, txt->str_id)); |
| 676 | |
| 677 | /* check the menu */ |
| 678 | menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_NONE); |
| 679 | obj = &menu->obj; |
| 680 | ut_asserteq_ptr(scn, obj->scene); |
| 681 | ut_asserteq_str("cpu-speed", obj->name); |
| 682 | ut_asserteq(ID_CPU_SPEED, obj->id); |
| 683 | ut_asserteq(SCENEOBJT_MENU, obj->type); |
| 684 | ut_asserteq(0, obj->flags); |
| 685 | |
| 686 | txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); |
| 687 | ut_asserteq_str("CPU speed", expo_get_str(exp, txt->str_id)); |
| 688 | |
| 689 | ut_asserteq(0, menu->cur_item_id); |
| 690 | ut_asserteq(0, menu->pointer_id); |
| 691 | |
| 692 | /* check the items */ |
| 693 | item = list_first_entry(&menu->item_head, struct scene_menitem, |
| 694 | sibling); |
| 695 | ut_asserteq_str("00", item->name); |
| 696 | ut_asserteq(ID_CPU_SPEED_1, item->id); |
| 697 | ut_asserteq(0, item->key_id); |
| 698 | ut_asserteq(0, item->desc_id); |
| 699 | ut_asserteq(0, item->preview_id); |
| 700 | ut_asserteq(0, item->flags); |
| 701 | |
| 702 | txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE); |
| 703 | ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id)); |
| 704 | |
Sughosh Ganu | ebb1c20 | 2024-08-28 22:24:22 +0530 | [diff] [blame] | 705 | count = list_count_nodes(&menu->item_head); |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 706 | ut_asserteq(3, count); |
| 707 | |
| 708 | expo_destroy(exp); |
| 709 | |
| 710 | return 0; |
| 711 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 712 | BOOTSTD_TEST(expo_test_build, UTF_DM); |