source: mainline/uspace/app/nav/test/panel.c@ b36ebb42

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b36ebb42 was b36ebb42, checked in by jxsvoboda <5887334+jxsvoboda@…>, 4 years ago

Create, position panels and paint boxes around them

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2021 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <errno.h>
30#include <pcut/pcut.h>
31#include "../panel.h"
32
33PCUT_INIT;
34
35PCUT_TEST_SUITE(panel);
36
37/** Create and destroy panel. */
38PCUT_TEST(create_destroy)
39{
40 panel_t *panel;
41 errno_t rc;
42
43 rc = panel_create(NULL, &panel);
44 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
45
46 panel_destroy(panel);
47}
48
49
50/** Test panel_paint() */
51PCUT_TEST(paint)
52{
53 ui_t *ui;
54 ui_window_t *window;
55 ui_wnd_params_t params;
56 panel_t *panel;
57 errno_t rc;
58
59 rc = ui_create_disp(NULL, &ui);
60 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
61
62 ui_wnd_params_init(&params);
63 params.caption = "Test";
64
65 rc = ui_window_create(ui, &params, &window);
66 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
67
68 rc = panel_create(window, &panel);
69 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
70
71 rc = panel_paint(panel);
72 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
73
74 panel_destroy(panel);
75 ui_window_destroy(window);
76 ui_destroy(ui);
77}
78
79/** panel_ctl() returns a valid UI control */
80PCUT_TEST(ctl)
81{
82 panel_t *panel;
83 ui_control_t *control;
84 errno_t rc;
85
86 rc = panel_create(NULL, &panel);
87 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
88
89 control = panel_ctl(panel);
90 PCUT_ASSERT_NOT_NULL(control);
91
92 panel_destroy(panel);
93}
94
95/** Test panel_pos_event() */
96PCUT_TEST(pos_event)
97{
98 panel_t *panel;
99 ui_control_t *control;
100 ui_evclaim_t claimed;
101 pos_event_t event;
102 errno_t rc;
103
104 rc = panel_create(NULL, &panel);
105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
106
107 control = panel_ctl(panel);
108 PCUT_ASSERT_NOT_NULL(control);
109
110 claimed = panel_pos_event(panel, &event);
111 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
112
113 panel_destroy(panel);
114}
115
116/** panel_set_rect() sets internal field */
117PCUT_TEST(set_rect)
118{
119 panel_t *panel;
120 ui_control_t *control;
121 gfx_rect_t rect;
122 errno_t rc;
123
124 rc = panel_create(NULL, &panel);
125 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
126
127 control = panel_ctl(panel);
128 PCUT_ASSERT_NOT_NULL(control);
129
130 rect.p0.x = 1;
131 rect.p0.y = 2;
132 rect.p1.x = 3;
133 rect.p1.y = 4;
134
135 panel_set_rect(panel, &rect);
136 PCUT_ASSERT_INT_EQUALS(rect.p0.x, panel->rect.p0.x);
137 PCUT_ASSERT_INT_EQUALS(rect.p0.y, panel->rect.p0.y);
138 PCUT_ASSERT_INT_EQUALS(rect.p1.x, panel->rect.p1.x);
139 PCUT_ASSERT_INT_EQUALS(rect.p1.y, panel->rect.p1.y);
140
141 panel_destroy(panel);
142}
143
144PCUT_EXPORT(panel);
Note: See TracBrowser for help on using the repository browser.