[bef51cf] | 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 |
|
---|
[3434233] | 29 | #include <disp_srv.h>
|
---|
[bef51cf] | 30 | #include <errno.h>
|
---|
[a40ae0d] | 31 | #include <gfx/context.h>
|
---|
[bef51cf] | 32 | #include <pcut/pcut.h>
|
---|
| 33 | #include <stdio.h>
|
---|
| 34 | #include <str.h>
|
---|
| 35 |
|
---|
[b3c185b6] | 36 | #include "../client.h"
|
---|
[b2d1df3] | 37 | #include "../display.h"
|
---|
[bef51cf] | 38 | #include "../window.h"
|
---|
| 39 |
|
---|
| 40 | PCUT_INIT;
|
---|
| 41 |
|
---|
| 42 | PCUT_TEST_SUITE(window);
|
---|
| 43 |
|
---|
[a40ae0d] | 44 | static errno_t dummy_set_color(void *, gfx_color_t *);
|
---|
| 45 | static errno_t dummy_fill_rect(void *, gfx_rect_t *);
|
---|
| 46 |
|
---|
| 47 | static gfx_context_ops_t dummy_ops = {
|
---|
| 48 | .set_color = dummy_set_color,
|
---|
| 49 | .fill_rect = dummy_fill_rect
|
---|
| 50 | };
|
---|
| 51 |
|
---|
[bef51cf] | 52 | /** Test ds_window_get_ctx(). */
|
---|
| 53 | PCUT_TEST(window_get_ctx)
|
---|
| 54 | {
|
---|
[b2d1df3] | 55 | ds_display_t *disp;
|
---|
[b3c185b6] | 56 | ds_client_t *client;
|
---|
[bef51cf] | 57 | ds_window_t *wnd;
|
---|
[3434233] | 58 | display_wnd_params_t params;
|
---|
[bef51cf] | 59 | gfx_context_t *gc;
|
---|
| 60 | errno_t rc;
|
---|
| 61 |
|
---|
[b2d1df3] | 62 | rc = ds_display_create(NULL, &disp);
|
---|
| 63 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 64 |
|
---|
| 65 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
[bef51cf] | 66 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 67 |
|
---|
[3434233] | 68 | display_wnd_params_init(¶ms);
|
---|
| 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, ¶ms, &wnd);
|
---|
[bef51cf] | 73 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 74 |
|
---|
| 75 | gc = ds_window_get_ctx(wnd);
|
---|
| 76 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
| 77 |
|
---|
[648e2ac] | 78 | ds_window_destroy(wnd);
|
---|
[b3c185b6] | 79 | ds_client_destroy(client);
|
---|
[b2d1df3] | 80 | ds_display_destroy(disp);
|
---|
[bef51cf] | 81 | }
|
---|
| 82 |
|
---|
[a40ae0d] | 83 | /** Test ds_window_post_pos_event() */
|
---|
| 84 | PCUT_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(¶ms);
|
---|
| 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, ¶ms, &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 |
|
---|
| 146 | static errno_t dummy_set_color(void *arg, gfx_color_t *color)
|
---|
| 147 | {
|
---|
| 148 | return EOK;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
| 152 | {
|
---|
| 153 | return EOK;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[bef51cf] | 156 | PCUT_EXPORT(window);
|
---|