Changeset 4ed00d3 in mainline for uspace/lib/ui/test/resource.c
- Timestamp:
- 2020-10-15T09:16:24Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- faca61b8
- Parents:
- c9a7adc
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-14 18:15:54)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-15 09:16:24)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/resource.c
rc9a7adc r4ed00d3 27 27 */ 28 28 29 #include <errno.h> 29 #include <gfx/context.h> 30 #include <mem.h> 30 31 #include <pcut/pcut.h> 32 #include <stdbool.h> 31 33 #include <ui/resource.h> 34 #include "../private/resource.h" 32 35 33 36 PCUT_INIT; … … 35 38 PCUT_TEST_SUITE(resource); 36 39 37 PCUT_TEST(dummy) 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 }; 52 53 typedef struct { 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; 69 70 /** Create and destroy UI resource */ 71 PCUT_TEST(create_destroy) 38 72 { 73 errno_t rc; 74 gfx_context_t *gc = NULL; 75 test_gc_t tgc; 76 ui_resource_t *resource = NULL; 77 78 memset(&tgc, 0, sizeof(tgc)); 79 rc = gfx_context_new(&ops, &tgc, &gc); 80 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 81 82 rc = ui_resource_create(gc, &resource); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 PCUT_ASSERT_NOT_NULL(resource); 85 86 PCUT_ASSERT_NOT_NULL(resource->tface); 87 PCUT_ASSERT_NOT_NULL(resource->font); 88 89 ui_resource_destroy(resource); 90 91 rc = gfx_context_delete(gc); 92 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 } 94 95 /** ui_resource_destroy() can take NULL argument (no-op) */ 96 PCUT_TEST(destroy_null) 97 { 98 ui_resource_destroy(NULL); 99 } 100 101 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 102 gfx_bitmap_alloc_t *alloc, void **rbm) 103 { 104 test_gc_t *tgc = (test_gc_t *) arg; 105 testgc_bitmap_t *tbm; 106 107 tbm = calloc(1, sizeof(testgc_bitmap_t)); 108 if (tbm == NULL) 109 return ENOMEM; 110 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 } 126 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; 133 } 134 135 static errno_t testgc_bitmap_destroy(void *bm) 136 { 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; 143 } 144 145 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 146 gfx_coord2_t *offs) 147 { 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; 153 } 154 155 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 156 { 157 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 158 *alloc = tbm->alloc; 159 tbm->tgc->bm_got_alloc = true; 160 return EOK; 39 161 } 40 162
Note:
See TracChangeset
for help on using the changeset viewer.