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 <s...@chromium.org>
---

 boot/cedit.c      | 75 ++++++++++++++++++++++++++---------------------
 include/cedit.h   | 13 ++++++++
 test/boot/cedit.c | 16 ++++++++++
 3 files changed, 71 insertions(+), 33 deletions(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index 3703538e5dc..bcbbe69fe33 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -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;
@@ -168,39 +209,7 @@ int cedit_run(struct expo *exp)
 
                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;
-                       }
+                       cedit_do_action(exp, scn, vid_priv, &act);
                } else if (ret != -EAGAIN) {
                        LOGR("cep", ret);
                }
diff --git a/include/cedit.h b/include/cedit.h
index 856509f0c7f..a9305ceebcb 100644
--- a/include/cedit.h
+++ b/include/cedit.h
@@ -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
  *
diff --git a/test/boot/cedit.c b/test/boot/cedit.c
index df191a09f89..9fab8750b40 100644
--- a/test/boot/cedit.c
+++ b/test/boot/cedit.c
@@ -228,6 +228,7 @@ static int cedit_render(struct unit_test_state *uts)
 {
        struct video_priv *vid_priv;
        extern struct expo *cur_exp;
+       struct expo_action act;
        struct udevice *dev;
        struct scene *scn;
        struct expo *exp;
@@ -240,6 +241,21 @@ static int cedit_render(struct unit_test_state *uts)
        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 field */
+       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));
+
        expo_destroy(exp);
        cur_exp = NULL;
 
-- 
2.43.0

Reply via email to