]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
expo: Test some cedit actions
authorSimon Glass <sjg@chromium.org>
Fri, 2 May 2025 14:46:21 +0000 (08:46 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 30 May 2025 08:49:32 +0000 (09:49 +0100)
Refactor the action-processing code into a new cedit_do_action()
function so we can call it from a test. Check moving to a new field and
opening the menu, to ensure that rendering is correct.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/cedit.c
include/cedit.h
test/boot/cedit.c

index 8c6948d1d4610272a15856a2d9d39d208ee619e9..f1a9ee7ce201a4c1c5a18b582ae3494024fcfb58 100644 (file)
@@ -149,6 +149,47 @@ int cedit_prepare(struct expo *exp, struct video_priv **vid_privp,
        return scene_id;
 }
 
+int cedit_do_action(struct expo *exp, struct scene *scn,
+                   struct video_priv *vid_priv, struct expo_action *act)
+{
+       switch (act->type) {
+       case EXPOACT_NONE:
+       case EXPOACT_POINT_ITEM:
+               return -EAGAIN;
+       case EXPOACT_POINT_OBJ:
+               scene_set_highlight_id(scn, act->select.id);
+               cedit_arange(exp, vid_priv, scn->id);
+               break;
+       case EXPOACT_OPEN:
+               scene_set_open(scn, act->select.id, true);
+               cedit_arange(exp, vid_priv, scn->id);
+               switch (scn->highlight_id) {
+               case EXPOID_SAVE:
+                       exp->done = true;
+                       exp->save = true;
+                       break;
+               case EXPOID_DISCARD:
+                       exp->done = true;
+                       break;
+               }
+               break;
+       case EXPOACT_CLOSE:
+               scene_set_open(scn, act->select.id, false);
+               cedit_arange(exp, vid_priv, scn->id);
+               break;
+       case EXPOACT_SELECT:
+               scene_set_open(scn, scn->highlight_id, false);
+               cedit_arange(exp, vid_priv, scn->id);
+               break;
+       case EXPOACT_QUIT:
+               log_debug("quitting\n");
+               exp->done = true;
+               break;
+       }
+
+       return 0;
+}
+
 int cedit_run(struct expo *exp)
 {
        struct video_priv *vid_priv;
@@ -167,43 +208,10 @@ int cedit_run(struct expo *exp)
                struct expo_action act;
 
                ret = expo_poll(exp, &act);
-               if (!ret) {
-                       switch (act.type) {
-                       case EXPOACT_POINT_OBJ:
-                               scene_set_highlight_id(scn, act.select.id);
-                               cedit_arange(exp, vid_priv, scene_id);
-                               break;
-                       case EXPOACT_OPEN:
-                               scene_set_open(scn, act.select.id, true);
-                               cedit_arange(exp, vid_priv, scene_id);
-                               switch (scn->highlight_id) {
-                               case EXPOID_SAVE:
-                                       exp->done = true;
-                                       exp->save = true;
-                                       break;
-                               case EXPOID_DISCARD:
-                                       exp->done = true;
-                                       break;
-                               }
-                               break;
-                       case EXPOACT_CLOSE:
-                               scene_set_open(scn, act.select.id, false);
-                               cedit_arange(exp, vid_priv, scene_id);
-                               break;
-                       case EXPOACT_SELECT:
-                               scene_set_open(scn, scn->highlight_id, false);
-                               cedit_arange(exp, vid_priv, scene_id);
-                               break;
-                       case EXPOACT_QUIT:
-                               log_debug("quitting\n");
-                               exp->done = true;
-                               break;
-                       default:
-                               break;
-                       }
-               } else if (ret != -EAGAIN) {
+               if (!ret)
+                       cedit_do_action(exp, scn, vid_priv, &act);
+               else if (ret != -EAGAIN)
                        return log_msg_ret("cep", ret);
-               }
        } while (!exp->done);
 
        if (ret)
index 856509f0c7fa60f5e1e4ff86246fb9ffde4d0400..a9305ceebcb3c466e228ecd0bee65ae563b1a712 100644 (file)
@@ -13,6 +13,7 @@
 
 struct abuf;
 struct expo;
+struct expo_action;
 struct scene;
 struct udevice;
 struct video_priv;
@@ -62,6 +63,18 @@ int cedit_run(struct expo *exp);
 int cedit_prepare(struct expo *exp, struct video_priv **vid_privp,
                  struct scene **scnp);
 
+/**
+ * cedit_do_action() - Process an action on a cedit
+ *
+ * @exp: Expo to use
+ * @scn: Current scene
+ * @vid_priv: Private data for the video device
+ * @act: Action to process
+ * Return: 0 on success, -EAGAIN if there was no action taken
+ */
+int cedit_do_action(struct expo *exp, struct scene *scn,
+                   struct video_priv *vid_priv, struct expo_action *act);
+
 /**
  * cedit_write_settings() - Write settings in FDT format
  *
index df191a09f8932c54159fa99f2356d21df9c253bd..5b3e9b586a6add21ad9d706f255a4950370c480b 100644 (file)
@@ -226,8 +226,10 @@ BOOTSTD_TEST(cedit_cmos, UTF_CONSOLE);
 /* Check the cedit displays correctely */
 static int cedit_render(struct unit_test_state *uts)
 {
+       struct scene_obj_menu *menu;
        struct video_priv *vid_priv;
        extern struct expo *cur_exp;
+       struct expo_action act;
        struct udevice *dev;
        struct scene *scn;
        struct expo *exp;
@@ -237,9 +239,50 @@ static int cedit_render(struct unit_test_state *uts)
        exp = cur_exp;
        ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
        ut_asserteq(ID_SCENE1, cedit_prepare(exp, &vid_priv, &scn));
+
+       menu = scene_obj_find(scn, ID_POWER_LOSS, SCENEOBJT_MENU);
+       ut_assertnonnull(menu);
+       ut_asserteq(ID_AC_OFF, menu->cur_item_id);
+
        ut_assertok(expo_render(exp));
        ut_asserteq(4929, video_compress_fb(uts, dev, false));
        ut_assertok(video_check_copy_fb(uts, dev));
+
+       /* move to the second menu */
+       act.type = EXPOACT_POINT_OBJ;
+       act.select.id = ID_POWER_LOSS;
+       ut_assertok(cedit_do_action(exp, scn, vid_priv, &act));
+       ut_assertok(expo_render(exp));
+       ut_asserteq(4986, video_compress_fb(uts, dev, false));
+
+       /* open the menu */
+       act.type = EXPOACT_OPEN;
+       act.select.id = ID_POWER_LOSS;
+       ut_assertok(cedit_do_action(exp, scn, vid_priv, &act));
+       ut_assertok(expo_render(exp));
+       ut_asserteq(5393, video_compress_fb(uts, dev, false));
+
+       /* close the menu */
+       act.type = EXPOACT_CLOSE;
+       act.select.id = ID_POWER_LOSS;
+       ut_assertok(cedit_do_action(exp, scn, vid_priv, &act));
+       ut_assertok(expo_render(exp));
+       ut_asserteq(4986, video_compress_fb(uts, dev, false));
+
+       /* open the menu again to check it looks the same */
+       act.type = EXPOACT_OPEN;
+       act.select.id = ID_POWER_LOSS;
+       ut_assertok(cedit_do_action(exp, scn, vid_priv, &act));
+       ut_assertok(expo_render(exp));
+       ut_asserteq(5393, video_compress_fb(uts, dev, false));
+
+       /* close the menu */
+       act.type = EXPOACT_CLOSE;
+       act.select.id = ID_POWER_LOSS;
+       ut_assertok(cedit_do_action(exp, scn, vid_priv, &act));
+       ut_assertok(expo_render(exp));
+       ut_asserteq(4986, video_compress_fb(uts, dev, false));
+
        expo_destroy(exp);
        cur_exp = NULL;