[bb14312] | 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 <gfx/context.h>
|
---|
| 30 | #include <gfx/cursor.h>
|
---|
| 31 | #include <pcut/pcut.h>
|
---|
| 32 | #include <mem.h>
|
---|
| 33 | #include <stdbool.h>
|
---|
| 34 |
|
---|
| 35 | PCUT_INIT;
|
---|
| 36 |
|
---|
| 37 | PCUT_TEST_SUITE(cursor);
|
---|
| 38 |
|
---|
| 39 | static errno_t testgc_cursor_get_pos(void *, gfx_coord2_t *);
|
---|
| 40 | static errno_t testgc_cursor_set_pos(void *, gfx_coord2_t *);
|
---|
| 41 | static errno_t testgc_cursor_set_visible(void *, bool);
|
---|
| 42 |
|
---|
| 43 | static gfx_context_ops_t ops = {
|
---|
| 44 | .cursor_get_pos = testgc_cursor_get_pos,
|
---|
| 45 | .cursor_set_pos = testgc_cursor_set_pos,
|
---|
| 46 | .cursor_set_visible = testgc_cursor_set_visible
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | /** Test graphics context data */
|
---|
| 50 | typedef struct {
|
---|
| 51 | errno_t rc;
|
---|
| 52 |
|
---|
| 53 | bool cursor_get_pos;
|
---|
| 54 | gfx_coord2_t get_pos_pos;
|
---|
| 55 |
|
---|
| 56 | bool cursor_set_pos;
|
---|
| 57 | gfx_coord2_t set_pos_pos;
|
---|
| 58 |
|
---|
| 59 | bool cursor_set_visible;
|
---|
| 60 | bool set_visible_vis;
|
---|
| 61 | } test_gc_t;
|
---|
| 62 |
|
---|
| 63 | /** Get hardware cursor position with error return */
|
---|
| 64 | PCUT_TEST(cursor_get_pos_failure)
|
---|
| 65 | {
|
---|
| 66 | errno_t rc;
|
---|
| 67 | gfx_coord2_t pos;
|
---|
| 68 | gfx_context_t *gc = NULL;
|
---|
| 69 | test_gc_t tgc;
|
---|
| 70 |
|
---|
| 71 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 72 |
|
---|
| 73 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 74 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 75 |
|
---|
| 76 | tgc.rc = EIO;
|
---|
| 77 |
|
---|
| 78 | rc = gfx_cursor_get_pos(gc, &pos);
|
---|
| 79 | PCUT_ASSERT_ERRNO_VAL(tgc.rc, rc);
|
---|
| 80 |
|
---|
| 81 | PCUT_ASSERT_TRUE(tgc.cursor_get_pos);
|
---|
| 82 |
|
---|
| 83 | rc = gfx_context_delete(gc);
|
---|
| 84 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | /** Get hardware cursor position */
|
---|
| 88 | PCUT_TEST(cursor_get_pos_success)
|
---|
| 89 | {
|
---|
| 90 | errno_t rc;
|
---|
| 91 | gfx_coord2_t pos;
|
---|
| 92 | gfx_context_t *gc = NULL;
|
---|
| 93 | test_gc_t tgc;
|
---|
| 94 |
|
---|
| 95 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 96 |
|
---|
| 97 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 98 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 99 |
|
---|
| 100 | tgc.rc = EOK;
|
---|
| 101 | tgc.get_pos_pos.x = 1;
|
---|
| 102 | tgc.get_pos_pos.y = 2;
|
---|
| 103 |
|
---|
| 104 | rc = gfx_cursor_get_pos(gc, &pos);
|
---|
| 105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 106 |
|
---|
| 107 | PCUT_ASSERT_TRUE(tgc.cursor_get_pos);
|
---|
| 108 | PCUT_ASSERT_INT_EQUALS(tgc.get_pos_pos.x, pos.x);
|
---|
| 109 | PCUT_ASSERT_INT_EQUALS(tgc.get_pos_pos.y, pos.y);
|
---|
| 110 |
|
---|
| 111 | rc = gfx_context_delete(gc);
|
---|
| 112 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /** Set hardware cursor position with error return */
|
---|
| 116 | PCUT_TEST(cursor_set_pos_failure)
|
---|
| 117 | {
|
---|
| 118 | errno_t rc;
|
---|
| 119 | gfx_coord2_t pos;
|
---|
| 120 | gfx_context_t *gc = NULL;
|
---|
| 121 | test_gc_t tgc;
|
---|
| 122 |
|
---|
| 123 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 124 |
|
---|
| 125 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 126 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 127 |
|
---|
| 128 | tgc.rc = EIO;
|
---|
| 129 | pos.x = 1;
|
---|
| 130 | pos.y = 2;
|
---|
| 131 |
|
---|
| 132 | rc = gfx_cursor_set_pos(gc, &pos);
|
---|
| 133 | PCUT_ASSERT_ERRNO_VAL(tgc.rc, rc);
|
---|
| 134 |
|
---|
| 135 | PCUT_ASSERT_TRUE(tgc.cursor_set_pos);
|
---|
| 136 | PCUT_ASSERT_INT_EQUALS(pos.x, tgc.set_pos_pos.x);
|
---|
| 137 | PCUT_ASSERT_INT_EQUALS(pos.y, tgc.set_pos_pos.y);
|
---|
| 138 |
|
---|
| 139 | rc = gfx_context_delete(gc);
|
---|
| 140 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /** Set hardware cursor position */
|
---|
| 144 | PCUT_TEST(cursor_set_pos_success)
|
---|
| 145 | {
|
---|
| 146 | errno_t rc;
|
---|
| 147 | gfx_coord2_t pos;
|
---|
| 148 | gfx_context_t *gc = NULL;
|
---|
| 149 | test_gc_t tgc;
|
---|
| 150 |
|
---|
| 151 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 152 |
|
---|
| 153 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 154 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 155 |
|
---|
| 156 | tgc.rc = EOK;
|
---|
| 157 | pos.x = 1;
|
---|
| 158 | pos.y = 2;
|
---|
| 159 |
|
---|
| 160 | rc = gfx_cursor_set_pos(gc, &pos);
|
---|
| 161 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 162 |
|
---|
| 163 | PCUT_ASSERT_TRUE(tgc.cursor_set_pos);
|
---|
| 164 | PCUT_ASSERT_INT_EQUALS(pos.x, tgc.set_pos_pos.x);
|
---|
| 165 | PCUT_ASSERT_INT_EQUALS(pos.y, tgc.set_pos_pos.y);
|
---|
| 166 |
|
---|
| 167 | rc = gfx_context_delete(gc);
|
---|
| 168 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | /** Set hardware cursor visibility with error return */
|
---|
| 172 | PCUT_TEST(cursor_set_visible_failure)
|
---|
| 173 | {
|
---|
| 174 | errno_t rc;
|
---|
| 175 | gfx_context_t *gc = NULL;
|
---|
| 176 | test_gc_t tgc;
|
---|
| 177 |
|
---|
| 178 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 179 |
|
---|
| 180 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 181 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 182 |
|
---|
| 183 | tgc.rc = EIO;
|
---|
| 184 |
|
---|
| 185 | rc = gfx_cursor_set_visible(gc, true);
|
---|
| 186 | PCUT_ASSERT_ERRNO_VAL(tgc.rc, rc);
|
---|
| 187 |
|
---|
| 188 | PCUT_ASSERT_TRUE(tgc.cursor_set_visible);
|
---|
| 189 | PCUT_ASSERT_TRUE(tgc.set_visible_vis);
|
---|
| 190 |
|
---|
| 191 | tgc.cursor_set_visible = false;
|
---|
| 192 |
|
---|
| 193 | rc = gfx_cursor_set_visible(gc, false);
|
---|
| 194 | PCUT_ASSERT_ERRNO_VAL(tgc.rc, rc);
|
---|
| 195 |
|
---|
| 196 | PCUT_ASSERT_TRUE(tgc.cursor_set_visible);
|
---|
| 197 | PCUT_ASSERT_FALSE(tgc.set_visible_vis);
|
---|
| 198 |
|
---|
| 199 | rc = gfx_context_delete(gc);
|
---|
| 200 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /** Set hardware cursor visibility */
|
---|
| 204 | PCUT_TEST(cursor_set_visible_success)
|
---|
| 205 | {
|
---|
| 206 | errno_t rc;
|
---|
| 207 | gfx_context_t *gc = NULL;
|
---|
| 208 | test_gc_t tgc;
|
---|
| 209 |
|
---|
| 210 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 211 |
|
---|
| 212 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 213 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 214 |
|
---|
| 215 | tgc.rc = EOK;
|
---|
| 216 |
|
---|
| 217 | rc = gfx_cursor_set_visible(gc, true);
|
---|
| 218 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 219 |
|
---|
| 220 | PCUT_ASSERT_TRUE(tgc.cursor_set_visible);
|
---|
| 221 | PCUT_ASSERT_TRUE(tgc.set_visible_vis);
|
---|
| 222 |
|
---|
| 223 | tgc.cursor_set_visible = false;
|
---|
| 224 |
|
---|
| 225 | rc = gfx_cursor_set_visible(gc, false);
|
---|
| 226 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 227 |
|
---|
| 228 | PCUT_ASSERT_TRUE(tgc.cursor_set_visible);
|
---|
| 229 | PCUT_ASSERT_FALSE(tgc.set_visible_vis);
|
---|
| 230 |
|
---|
| 231 | rc = gfx_context_delete(gc);
|
---|
| 232 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | static errno_t testgc_cursor_get_pos(void *arg, gfx_coord2_t *pos)
|
---|
| 236 | {
|
---|
| 237 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
| 238 |
|
---|
| 239 | tgc->cursor_get_pos = true;
|
---|
| 240 | *pos = tgc->get_pos_pos;
|
---|
| 241 |
|
---|
| 242 | return tgc->rc;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | static errno_t testgc_cursor_set_pos(void *arg, gfx_coord2_t *pos)
|
---|
| 246 | {
|
---|
| 247 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
| 248 |
|
---|
| 249 | tgc->cursor_set_pos = true;
|
---|
| 250 | tgc->set_pos_pos = *pos;
|
---|
| 251 |
|
---|
| 252 | return tgc->rc;
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | static errno_t testgc_cursor_set_visible(void *arg, bool visible)
|
---|
| 256 | {
|
---|
| 257 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
| 258 |
|
---|
| 259 | tgc->cursor_set_visible = true;
|
---|
| 260 | tgc->set_visible_vis = visible;
|
---|
| 261 |
|
---|
| 262 | return tgc->rc;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | PCUT_EXPORT(cursor);
|
---|