Changes in uspace/lib/ui/test/resource.c [1fa6292:faca61b8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/resource.c
r1fa6292 rfaca61b8 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2020 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 33 33 #include <ui/resource.h> 34 34 #include "../private/resource.h" 35 #include "../private/testgc.h"36 35 37 36 PCUT_INIT; … … 39 38 PCUT_TEST_SUITE(resource); 40 39 41 static void test_expose(void *); 40 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *, 41 gfx_bitmap_alloc_t *, void **); 42 static errno_t testgc_bitmap_destroy(void *); 43 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 44 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 45 46 static gfx_context_ops_t ops = { 47 .bitmap_create = testgc_bitmap_create, 48 .bitmap_destroy = testgc_bitmap_destroy, 49 .bitmap_render = testgc_bitmap_render, 50 .bitmap_get_alloc = testgc_bitmap_get_alloc 51 }; 42 52 43 53 typedef struct { 44 bool expose; 45 } test_resp_t; 54 bool bm_created; 55 bool bm_destroyed; 56 gfx_bitmap_params_t bm_params; 57 void *bm_pixels; 58 gfx_rect_t bm_srect; 59 gfx_coord2_t bm_offs; 60 bool bm_rendered; 61 bool bm_got_alloc; 62 } test_gc_t; 63 64 typedef struct { 65 test_gc_t *tgc; 66 gfx_bitmap_alloc_t alloc; 67 bool myalloc; 68 } testgc_bitmap_t; 46 69 47 70 /** Create and destroy UI resource */ … … 57 80 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 58 81 59 rc = ui_resource_create(gc, false,&resource);82 rc = ui_resource_create(gc, &resource); 60 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 61 84 PCUT_ASSERT_NOT_NULL(resource); … … 76 99 } 77 100 78 /** ui_resource_set_expose_cb() / ui_resource_expose() */ 79 PCUT_TEST(set_expose_cb_expose)101 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 102 gfx_bitmap_alloc_t *alloc, void **rbm) 80 103 { 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; 104 test_gc_t *tgc = (test_gc_t *) arg; 105 testgc_bitmap_t *tbm; 86 106 87 memset(&tgc, 0, sizeof(tgc));88 rc = gfx_context_new(&ops, &tgc, &gc);89 PCUT_ASSERT_ERRNO_VAL(EOK, rc);107 tbm = calloc(1, sizeof(testgc_bitmap_t)); 108 if (tbm == NULL) 109 return ENOMEM; 90 110 91 rc = ui_resource_create(gc, false, &resource); 92 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 PCUT_ASSERT_NOT_NULL(resource); 111 if (alloc == NULL) { 112 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 113 sizeof(uint32_t); 114 tbm->alloc.off0 = 0; 115 tbm->alloc.pixels = calloc(sizeof(uint32_t), 116 (params->rect.p1.x - params->rect.p0.x) * 117 (params->rect.p1.y - params->rect.p0.y)); 118 tbm->myalloc = true; 119 if (tbm->alloc.pixels == NULL) { 120 free(tbm); 121 return ENOMEM; 122 } 123 } else { 124 tbm->alloc = *alloc; 125 } 94 126 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); 127 tbm->tgc = tgc; 128 tgc->bm_created = true; 129 tgc->bm_params = *params; 130 tgc->bm_pixels = tbm->alloc.pixels; 131 *rbm = (void *)tbm; 132 return EOK; 105 133 } 106 134 107 /** ui_resource_get_font() returns the font */ 108 PCUT_TEST(get_font) 135 static errno_t testgc_bitmap_destroy(void *bm) 109 136 { 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); 137 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 138 if (tbm->myalloc) 139 free(tbm->alloc.pixels); 140 tbm->tgc->bm_destroyed = true; 141 free(tbm); 142 return EOK; 131 143 } 132 144 133 /** ui_resource_is_textmode() returns the textmode flag */ 134 PCUT_TEST(is_textmode)145 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 146 gfx_coord2_t *offs) 135 147 { 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); 148 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 149 tbm->tgc->bm_rendered = true; 150 tbm->tgc->bm_srect = *srect; 151 tbm->tgc->bm_offs = *offs; 152 return EOK; 159 153 } 160 154 161 /** ui_resource_get_wnd_face_color() returns window face color */ 162 PCUT_TEST(get_wnd_face_color) 155 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 163 156 { 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 213 static void test_expose(void *arg) 214 { 215 test_resp_t *resp = (test_resp_t *) arg; 216 217 resp->expose = true; 157 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 158 *alloc = tbm->alloc; 159 tbm->tgc->bm_got_alloc = true; 160 return EOK; 218 161 } 219 162
Note:
See TracChangeset
for help on using the changeset viewer.