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

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

Moving windows by mouse drag

  • Property mode set to 100644
File size: 4.2 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_get_ctx(). */
53PCUT_TEST(window_get_ctx)
54{
55 ds_display_t *disp;
56 ds_client_t *client;
57 ds_window_t *wnd;
58 display_wnd_params_t params;
59 gfx_context_t *gc;
60 errno_t rc;
61
62 rc = ds_display_create(NULL, &disp);
63 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
64
65 rc = ds_client_create(disp, NULL, NULL, &client);
66 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
67
68 display_wnd_params_init(&params);
69 params.rect.p0.x = params.rect.p0.y = 0;
70 params.rect.p1.x = params.rect.p1.y = 1;
71
72 rc = ds_window_create(client, &params, &wnd);
73 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
74
75 gc = ds_window_get_ctx(wnd);
76 PCUT_ASSERT_NOT_NULL(gc);
77
78 ds_window_destroy(wnd);
79 ds_client_destroy(client);
80 ds_display_destroy(disp);
81}
82
83/** Test ds_window_post_pos_event() */
84PCUT_TEST(window_post_pos_event)
85{
86 gfx_context_t *gc;
87 ds_display_t *disp;
88 ds_client_t *client;
89 ds_window_t *wnd;
90 display_wnd_params_t params;
91 pos_event_t event;
92 errno_t rc;
93
94 rc = gfx_context_new(&dummy_ops, NULL, &gc);
95 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
96
97 rc = ds_display_create(gc, &disp);
98 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
99
100 rc = ds_client_create(disp, NULL, NULL, &client);
101 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
102
103 display_wnd_params_init(&params);
104 params.rect.p0.x = params.rect.p0.y = 0;
105 params.rect.p1.x = params.rect.p1.y = 1;
106
107 rc = ds_window_create(client, &params, &wnd);
108 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
109
110 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
111
112 event.type = POS_PRESS;
113 event.hpos = 10;
114 event.vpos = 10;
115 rc = ds_window_post_pos_event(wnd, &event);
116 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
117
118 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
119
120 event.type = POS_UPDATE;
121 event.hpos = 11;
122 event.vpos = 12;
123 rc = ds_window_post_pos_event(wnd, &event);
124 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
125
126 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
127 PCUT_ASSERT_INT_EQUALS(wnd->dpos.x, 0);
128 PCUT_ASSERT_INT_EQUALS(wnd->dpos.y, 0);
129
130 event.type = POS_RELEASE;
131 event.hpos = 13;
132 event.vpos = 14;
133
134 rc = ds_window_post_pos_event(wnd, &event);
135 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
136
137 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
138 PCUT_ASSERT_INT_EQUALS(wnd->dpos.x, 3);
139 PCUT_ASSERT_INT_EQUALS(wnd->dpos.y, 4);
140
141 ds_window_destroy(wnd);
142 ds_client_destroy(client);
143 ds_display_destroy(disp);
144}
145
146static errno_t dummy_set_color(void *arg, gfx_color_t *color)
147{
148 return EOK;
149}
150
151static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
152{
153 return EOK;
154}
155
156PCUT_EXPORT(window);
Note: See TracBrowser for help on using the repository browser.