Changes in uspace/lib/ui/test/rbutton.c [7470d97:1fa6292] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/rbutton.c
r7470d97 r1fa6292 36 36 #include <ui/resource.h> 37 37 #include "../private/rbutton.h" 38 #include "../private/testgc.h" 38 39 39 40 PCUT_INIT; 40 41 41 42 PCUT_TEST_SUITE(rbutton); 42 43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);44 static errno_t testgc_set_color(void *, gfx_color_t *);45 static errno_t testgc_fill_rect(void *, gfx_rect_t *);46 static errno_t testgc_update(void *);47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,48 gfx_bitmap_alloc_t *, void **);49 static errno_t testgc_bitmap_destroy(void *);50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);52 53 static gfx_context_ops_t ops = {54 .set_clip_rect = testgc_set_clip_rect,55 .set_color = testgc_set_color,56 .fill_rect = testgc_fill_rect,57 .update = testgc_update,58 .bitmap_create = testgc_bitmap_create,59 .bitmap_destroy = testgc_bitmap_destroy,60 .bitmap_render = testgc_bitmap_render,61 .bitmap_get_alloc = testgc_bitmap_get_alloc62 };63 43 64 44 static void test_rbutton_select(ui_rbutton_group_t *, void *, void *); … … 70 50 static ui_rbutton_group_cb_t dummy_rbutton_group_cb = { 71 51 }; 72 73 typedef struct {74 bool bm_created;75 bool bm_destroyed;76 gfx_bitmap_params_t bm_params;77 void *bm_pixels;78 gfx_rect_t bm_srect;79 gfx_coord2_t bm_offs;80 bool bm_rendered;81 bool bm_got_alloc;82 } test_gc_t;83 84 typedef struct {85 test_gc_t *tgc;86 gfx_bitmap_alloc_t alloc;87 bool myalloc;88 } testgc_bitmap_t;89 52 90 53 typedef struct { … … 166 129 } 167 130 168 /** Paint radio button */ 169 PCUT_TEST(paint) 170 { 171 errno_t rc; 172 gfx_context_t *gc = NULL; 173 test_gc_t tgc; 174 ui_rbutton_group_t *group = NULL; 175 ui_resource_t *resource = NULL; 176 ui_rbutton_t *rbutton; 177 178 memset(&tgc, 0, sizeof(tgc)); 179 rc = gfx_context_new(&ops, &tgc, &gc); 180 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 181 182 rc = ui_resource_create(gc, false, &resource); 183 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 184 PCUT_ASSERT_NOT_NULL(resource); 185 186 rc = ui_rbutton_group_create(resource, &group); 187 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 188 189 rc = ui_rbutton_create(group, "Hello", NULL, &rbutton); 190 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 191 192 rc = ui_rbutton_paint(rbutton); 131 /** Paint radio button in graphics mode */ 132 PCUT_TEST(paint_gfx) 133 { 134 errno_t rc; 135 gfx_context_t *gc = NULL; 136 test_gc_t tgc; 137 ui_rbutton_group_t *group = NULL; 138 ui_resource_t *resource = NULL; 139 ui_rbutton_t *rbutton; 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 rc = ui_rbutton_group_create(resource, &group); 150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 151 152 rc = ui_rbutton_create(group, "Hello", NULL, &rbutton); 153 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 154 155 rc = ui_rbutton_paint_gfx(rbutton); 156 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 157 158 ui_rbutton_destroy(rbutton); 159 ui_rbutton_group_destroy(group); 160 ui_resource_destroy(resource); 161 162 rc = gfx_context_delete(gc); 163 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 164 } 165 166 /** Paint radio button in text mode */ 167 PCUT_TEST(paint_text) 168 { 169 errno_t rc; 170 gfx_context_t *gc = NULL; 171 test_gc_t tgc; 172 ui_rbutton_group_t *group = NULL; 173 ui_resource_t *resource = NULL; 174 ui_rbutton_t *rbutton; 175 176 memset(&tgc, 0, sizeof(tgc)); 177 rc = gfx_context_new(&ops, &tgc, &gc); 178 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 179 180 rc = ui_resource_create(gc, false, &resource); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 PCUT_ASSERT_NOT_NULL(resource); 183 184 rc = ui_rbutton_group_create(resource, &group); 185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 186 187 rc = ui_rbutton_create(group, "Hello", NULL, &rbutton); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 190 rc = ui_rbutton_paint_text(rbutton); 193 191 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 194 192 … … 557 555 } 558 556 559 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)560 {561 (void) arg;562 (void) rect;563 return EOK;564 }565 566 static errno_t testgc_set_color(void *arg, gfx_color_t *color)567 {568 (void) arg;569 (void) color;570 return EOK;571 }572 573 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)574 {575 (void) arg;576 (void) rect;577 return EOK;578 }579 580 static errno_t testgc_update(void *arg)581 {582 (void) arg;583 return EOK;584 }585 586 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,587 gfx_bitmap_alloc_t *alloc, void **rbm)588 {589 test_gc_t *tgc = (test_gc_t *) arg;590 testgc_bitmap_t *tbm;591 592 tbm = calloc(1, sizeof(testgc_bitmap_t));593 if (tbm == NULL)594 return ENOMEM;595 596 if (alloc == NULL) {597 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *598 sizeof(uint32_t);599 tbm->alloc.off0 = 0;600 tbm->alloc.pixels = calloc(sizeof(uint32_t),601 (params->rect.p1.x - params->rect.p0.x) *602 (params->rect.p1.y - params->rect.p0.y));603 tbm->myalloc = true;604 if (tbm->alloc.pixels == NULL) {605 free(tbm);606 return ENOMEM;607 }608 } else {609 tbm->alloc = *alloc;610 }611 612 tbm->tgc = tgc;613 tgc->bm_created = true;614 tgc->bm_params = *params;615 tgc->bm_pixels = tbm->alloc.pixels;616 *rbm = (void *)tbm;617 return EOK;618 }619 620 static errno_t testgc_bitmap_destroy(void *bm)621 {622 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;623 if (tbm->myalloc)624 free(tbm->alloc.pixels);625 tbm->tgc->bm_destroyed = true;626 free(tbm);627 return EOK;628 }629 630 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,631 gfx_coord2_t *offs)632 {633 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;634 tbm->tgc->bm_rendered = true;635 tbm->tgc->bm_srect = *srect;636 tbm->tgc->bm_offs = *offs;637 return EOK;638 }639 640 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)641 {642 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;643 *alloc = tbm->alloc;644 tbm->tgc->bm_got_alloc = true;645 return EOK;646 }647 648 557 static void test_rbutton_select(ui_rbutton_group_t *group, void *arg, 649 558 void *barg)
Note:
See TracChangeset
for help on using the changeset viewer.