Changeset f59212cc in mainline for uspace/app/nav/test/menu.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (3 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c632c96
Parents:
5bbb4453
git-author:
Jiri Svoboda <jiri@…> (2021-10-19 20:54:17)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Add File / Open, properly deliver menu events to Navigator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/test/menu.c

    r5bbb4453 rf59212cc  
    2929#include <errno.h>
    3030#include <pcut/pcut.h>
     31#include <stdbool.h>
    3132#include "../menu.h"
    3233
     
    3435
    3536PCUT_TEST_SUITE(menu);
     37
     38static void test_menu_file_open(void *);
     39static void test_menu_file_exit(void *);
     40
     41static nav_menu_cb_t dummy_cb;
     42static nav_menu_cb_t test_cb = {
     43        .file_open = test_menu_file_open,
     44        .file_exit = test_menu_file_exit
     45};
     46
     47/** Test response */
     48typedef struct {
     49        bool file_open;
     50        bool file_exit;
     51} test_resp_t;
    3652
    3753/** Create and destroy menu. */
     
    6177}
    6278
     79/** nav_menu_set_cb() */
     80PCUT_TEST(set_cb)
     81{
     82        ui_t *ui;
     83        ui_window_t *window;
     84        ui_wnd_params_t params;
     85        nav_menu_t *menu;
     86        int foo;
     87        errno_t rc;
     88
     89        rc = ui_create_disp(NULL, &ui);
     90        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     91
     92        ui_wnd_params_init(&params);
     93        params.caption = "Test";
     94
     95        rc = ui_window_create(ui, &params, &window);
     96        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     97
     98        rc = nav_menu_create(window, &menu);
     99        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     100
     101        nav_menu_set_cb(menu, &test_cb, &foo);
     102        PCUT_ASSERT_EQUALS(&test_cb, menu->cb);
     103        PCUT_ASSERT_EQUALS(&foo, menu->cb_arg);
     104
     105        nav_menu_destroy(menu);
     106        ui_window_destroy(window);
     107        ui_destroy(ui);
     108}
     109
     110/** File / Open callback */
     111PCUT_TEST(file_open)
     112{
     113        ui_t *ui;
     114        ui_window_t *window;
     115        ui_wnd_params_t params;
     116        nav_menu_t *menu;
     117        test_resp_t resp;
     118        errno_t rc;
     119
     120        rc = ui_create_disp(NULL, &ui);
     121        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     122
     123        ui_wnd_params_init(&params);
     124        params.caption = "Test";
     125
     126        rc = ui_window_create(ui, &params, &window);
     127        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     128
     129        rc = nav_menu_create(window, &menu);
     130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     131
     132        /* Call back with no callbacks set */
     133        nav_menu_file_open(NULL, menu);
     134
     135        /* Call back with dummy callbacks set */
     136        nav_menu_set_cb(menu, &dummy_cb, &resp);
     137        nav_menu_file_open(NULL, menu);
     138
     139        /* Call back with test callbacks set */
     140        resp.file_open = false;
     141        nav_menu_set_cb(menu, &test_cb, &resp);
     142        nav_menu_file_open(NULL, menu);
     143        PCUT_ASSERT_TRUE(resp.file_open);
     144
     145        nav_menu_destroy(menu);
     146        ui_window_destroy(window);
     147        ui_destroy(ui);
     148}
     149
     150/** Testing File / Open callback */
     151static void test_menu_file_open(void *arg)
     152{
     153        test_resp_t *resp = (test_resp_t *)arg;
     154
     155        resp->file_open = true;
     156}
     157
     158/** Testing File / Exit callback */
     159static void test_menu_file_exit(void *arg)
     160{
     161        test_resp_t *resp = (test_resp_t *)arg;
     162
     163        resp->file_exit = true;
     164}
     165
    63166PCUT_EXPORT(menu);
Note: See TracChangeset for help on using the changeset viewer.