[47728678] | 1 | /*
|
---|
[95a9cbc] | 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
[47728678] | 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 |
|
---|
[4ed00d3] | 29 | #include <gfx/context.h>
|
---|
| 30 | #include <mem.h>
|
---|
[47728678] | 31 | #include <pcut/pcut.h>
|
---|
[4ed00d3] | 32 | #include <stdbool.h>
|
---|
[47728678] | 33 | #include <ui/resource.h>
|
---|
[4ed00d3] | 34 | #include "../private/resource.h"
|
---|
[1fa6292] | 35 | #include "../private/testgc.h"
|
---|
[47728678] | 36 |
|
---|
| 37 | PCUT_INIT;
|
---|
| 38 |
|
---|
| 39 | PCUT_TEST_SUITE(resource);
|
---|
| 40 |
|
---|
[95a9cbc] | 41 | static void test_expose(void *);
|
---|
| 42 |
|
---|
| 43 | typedef struct {
|
---|
| 44 | bool expose;
|
---|
| 45 | } test_resp_t;
|
---|
| 46 |
|
---|
[4ed00d3] | 47 | /** Create and destroy UI resource */
|
---|
| 48 | PCUT_TEST(create_destroy)
|
---|
| 49 | {
|
---|
| 50 | errno_t rc;
|
---|
| 51 | gfx_context_t *gc = NULL;
|
---|
| 52 | test_gc_t tgc;
|
---|
| 53 | ui_resource_t *resource = NULL;
|
---|
| 54 |
|
---|
| 55 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 56 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 57 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 58 |
|
---|
[9c7dc8e] | 59 | rc = ui_resource_create(gc, false, &resource);
|
---|
[4ed00d3] | 60 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 61 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
| 62 |
|
---|
| 63 | PCUT_ASSERT_NOT_NULL(resource->tface);
|
---|
| 64 | PCUT_ASSERT_NOT_NULL(resource->font);
|
---|
| 65 |
|
---|
| 66 | ui_resource_destroy(resource);
|
---|
| 67 |
|
---|
| 68 | rc = gfx_context_delete(gc);
|
---|
| 69 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /** ui_resource_destroy() can take NULL argument (no-op) */
|
---|
| 73 | PCUT_TEST(destroy_null)
|
---|
| 74 | {
|
---|
| 75 | ui_resource_destroy(NULL);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[95a9cbc] | 78 | /** ui_resource_set_expose_cb() / ui_resource_expose() */
|
---|
| 79 | PCUT_TEST(set_expose_cb_expose)
|
---|
| 80 | {
|
---|
| 81 | errno_t rc;
|
---|
| 82 | gfx_context_t *gc = NULL;
|
---|
| 83 | test_gc_t tgc;
|
---|
| 84 | ui_resource_t *resource = NULL;
|
---|
| 85 | test_resp_t resp;
|
---|
| 86 |
|
---|
| 87 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 88 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 89 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 90 |
|
---|
| 91 | rc = ui_resource_create(gc, false, &resource);
|
---|
| 92 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 93 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
| 94 |
|
---|
| 95 | ui_resource_set_expose_cb(resource, test_expose, &resp);
|
---|
| 96 |
|
---|
| 97 | resp.expose = false;
|
---|
| 98 | ui_resource_expose(resource);
|
---|
| 99 | PCUT_ASSERT_TRUE(resp.expose);
|
---|
| 100 |
|
---|
| 101 | ui_resource_destroy(resource);
|
---|
| 102 |
|
---|
| 103 | rc = gfx_context_delete(gc);
|
---|
| 104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[e0e612b] | 107 | /** ui_resource_get_font() returns the font */
|
---|
| 108 | PCUT_TEST(get_font)
|
---|
| 109 | {
|
---|
| 110 | errno_t rc;
|
---|
| 111 | gfx_context_t *gc = NULL;
|
---|
| 112 | test_gc_t tgc;
|
---|
| 113 | ui_resource_t *resource = NULL;
|
---|
| 114 | gfx_font_t *font;
|
---|
| 115 |
|
---|
| 116 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 117 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 118 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 119 |
|
---|
| 120 | rc = ui_resource_create(gc, false, &resource);
|
---|
| 121 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 122 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
| 123 |
|
---|
| 124 | font = ui_resource_get_font(resource);
|
---|
| 125 | PCUT_ASSERT_EQUALS(resource->font, font);
|
---|
| 126 |
|
---|
| 127 | ui_resource_destroy(resource);
|
---|
| 128 |
|
---|
| 129 | rc = gfx_context_delete(gc);
|
---|
| 130 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | /** ui_resource_is_textmode() returns the textmode flag */
|
---|
| 134 | PCUT_TEST(is_textmode)
|
---|
| 135 | {
|
---|
| 136 | errno_t rc;
|
---|
| 137 | gfx_context_t *gc = NULL;
|
---|
| 138 | test_gc_t tgc;
|
---|
| 139 | ui_resource_t *resource = NULL;
|
---|
| 140 |
|
---|
| 141 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 142 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 143 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 144 |
|
---|
| 145 | rc = ui_resource_create(gc, false, &resource);
|
---|
| 146 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 147 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
| 148 |
|
---|
| 149 | /* To make sure let's test both true and false case */
|
---|
| 150 | resource->textmode = true;
|
---|
| 151 | PCUT_ASSERT_TRUE(ui_resource_is_textmode(resource));
|
---|
| 152 | resource->textmode = false;
|
---|
| 153 | PCUT_ASSERT_FALSE(ui_resource_is_textmode(resource));
|
---|
| 154 |
|
---|
| 155 | ui_resource_destroy(resource);
|
---|
| 156 |
|
---|
| 157 | rc = gfx_context_delete(gc);
|
---|
| 158 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /** ui_resource_get_wnd_face_color() returns window face color */
|
---|
| 162 | PCUT_TEST(get_wnd_face_color)
|
---|
| 163 | {
|
---|
| 164 | errno_t rc;
|
---|
| 165 | gfx_context_t *gc = NULL;
|
---|
| 166 | test_gc_t tgc;
|
---|
| 167 | ui_resource_t *resource = NULL;
|
---|
| 168 | gfx_color_t *color;
|
---|
| 169 |
|
---|
| 170 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 171 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 173 |
|
---|
| 174 | rc = ui_resource_create(gc, false, &resource);
|
---|
| 175 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 176 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
| 177 |
|
---|
| 178 | color = ui_resource_get_wnd_face_color(resource);
|
---|
| 179 | PCUT_ASSERT_EQUALS(resource->wnd_face_color, color);
|
---|
| 180 |
|
---|
| 181 | ui_resource_destroy(resource);
|
---|
| 182 |
|
---|
| 183 | rc = gfx_context_delete(gc);
|
---|
| 184 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /** ui_resource_get_wnd_text_color() returns window text color */
|
---|
| 188 | PCUT_TEST(get_wnd_text_color)
|
---|
| 189 | {
|
---|
| 190 | errno_t rc;
|
---|
| 191 | gfx_context_t *gc = NULL;
|
---|
| 192 | test_gc_t tgc;
|
---|
| 193 | ui_resource_t *resource = NULL;
|
---|
| 194 | gfx_color_t *color;
|
---|
| 195 |
|
---|
| 196 | memset(&tgc, 0, sizeof(tgc));
|
---|
| 197 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
| 198 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 199 |
|
---|
| 200 | rc = ui_resource_create(gc, false, &resource);
|
---|
| 201 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 202 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
| 203 |
|
---|
| 204 | color = ui_resource_get_wnd_text_color(resource);
|
---|
| 205 | PCUT_ASSERT_EQUALS(resource->wnd_text_color, color);
|
---|
| 206 |
|
---|
| 207 | ui_resource_destroy(resource);
|
---|
| 208 |
|
---|
| 209 | rc = gfx_context_delete(gc);
|
---|
| 210 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[95a9cbc] | 213 | static void test_expose(void *arg)
|
---|
| 214 | {
|
---|
| 215 | test_resp_t *resp = (test_resp_t *) arg;
|
---|
| 216 |
|
---|
| 217 | resp->expose = true;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[47728678] | 220 | PCUT_EXPORT(resource);
|
---|