source: mainline/uspace/srv/hid/display/test/window.c@ a8eed5f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a8eed5f was 0e6e77f, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Window resize by client request

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2019 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 <disp_srv.h>
30#include <errno.h>
31#include <gfx/context.h>
32#include <pcut/pcut.h>
33#include <stdio.h>
34#include <str.h>
35
36#include "../client.h"
37#include "../display.h"
38#include "../window.h"
39
40PCUT_INIT;
41
42PCUT_TEST_SUITE(window);
43
44static errno_t dummy_set_color(void *, gfx_color_t *);
45static errno_t dummy_fill_rect(void *, gfx_rect_t *);
46
47static gfx_context_ops_t dummy_ops = {
48 .set_color = dummy_set_color,
49 .fill_rect = dummy_fill_rect
50};
51
52/** Test ds_window_resize(). */
53PCUT_TEST(window_resize)
54{
55 ds_display_t *disp;
56 ds_client_t *client;
57 ds_window_t *wnd;
58 display_wnd_params_t params;
59 gfx_coord2_t offs;
60 gfx_rect_t nrect;
61 errno_t rc;
62
63 rc = ds_display_create(NULL, &disp);
64 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
65
66 rc = ds_client_create(disp, NULL, NULL, &client);
67 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
68
69 display_wnd_params_init(&params);
70 params.rect.p0.x = params.rect.p0.y = 0;
71 params.rect.p1.x = params.rect.p1.y = 10;
72
73 rc = ds_window_create(client, &params, &wnd);
74 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
75
76 wnd->dpos.x = 100;
77 wnd->dpos.y = 100;
78
79 offs.x = -2;
80 offs.y = -3;
81 params.rect.p0.x = params.rect.p0.y = 0;
82 params.rect.p1.x = 12;
83 params.rect.p1.y = 13;
84 rc = ds_window_resize(wnd, &offs, &nrect);
85 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
86
87 PCUT_ASSERT_INT_EQUALS(98, wnd->dpos.x);
88 PCUT_ASSERT_INT_EQUALS(97, wnd->dpos.y);
89
90 ds_window_destroy(wnd);
91 ds_client_destroy(client);
92 ds_display_destroy(disp);
93}
94
95/** Test ds_window_get_ctx(). */
96PCUT_TEST(window_get_ctx)
97{
98 ds_display_t *disp;
99 ds_client_t *client;
100 ds_window_t *wnd;
101 display_wnd_params_t params;
102 gfx_context_t *gc;
103 errno_t rc;
104
105 rc = ds_display_create(NULL, &disp);
106 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
107
108 rc = ds_client_create(disp, NULL, NULL, &client);
109 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
110
111 display_wnd_params_init(&params);
112 params.rect.p0.x = params.rect.p0.y = 0;
113 params.rect.p1.x = params.rect.p1.y = 1;
114
115 rc = ds_window_create(client, &params, &wnd);
116 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
117
118 gc = ds_window_get_ctx(wnd);
119 PCUT_ASSERT_NOT_NULL(gc);
120
121 ds_window_destroy(wnd);
122 ds_client_destroy(client);
123 ds_display_destroy(disp);
124}
125
126/** Test ds_window_post_pos_event() */
127PCUT_TEST(window_post_pos_event)
128{
129 gfx_context_t *gc;
130 ds_display_t *disp;
131 ds_client_t *client;
132 ds_window_t *wnd;
133 display_wnd_params_t params;
134 pos_event_t event;
135 errno_t rc;
136
137 rc = gfx_context_new(&dummy_ops, NULL, &gc);
138 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
139
140 rc = ds_display_create(gc, &disp);
141 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
142
143 rc = ds_client_create(disp, NULL, NULL, &client);
144 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
145
146 display_wnd_params_init(&params);
147 params.rect.p0.x = params.rect.p0.y = 0;
148 params.rect.p1.x = params.rect.p1.y = 1;
149
150 rc = ds_window_create(client, &params, &wnd);
151 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
152
153 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
154
155 event.type = POS_PRESS;
156 event.hpos = 10;
157 event.vpos = 10;
158 rc = ds_window_post_pos_event(wnd, &event);
159 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
160
161 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
162
163 event.type = POS_UPDATE;
164 event.hpos = 11;
165 event.vpos = 12;
166 rc = ds_window_post_pos_event(wnd, &event);
167 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
168
169 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
170 PCUT_ASSERT_INT_EQUALS(wnd->dpos.x, 1);
171 PCUT_ASSERT_INT_EQUALS(wnd->dpos.y, 2);
172
173 event.type = POS_RELEASE;
174 event.hpos = 13;
175 event.vpos = 14;
176
177 rc = ds_window_post_pos_event(wnd, &event);
178 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
179
180 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
181 PCUT_ASSERT_INT_EQUALS(wnd->dpos.x, 3);
182 PCUT_ASSERT_INT_EQUALS(wnd->dpos.y, 4);
183
184 ds_window_destroy(wnd);
185 ds_client_destroy(client);
186 ds_display_destroy(disp);
187}
188
189static errno_t dummy_set_color(void *arg, gfx_color_t *color)
190{
191 return EOK;
192}
193
194static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
195{
196 return EOK;
197}
198
199PCUT_EXPORT(window);
Note: See TracBrowser for help on using the repository browser.