HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- testgc_bitmap_create
- testgc_bitmap_destroy
- testgc_bitmap_render
- testgc_bitmap_get_alloc
- test_expose
#include <gfx/context.h>
#include <mem.h>
#include <pcut/pcut.h>
#include <stdbool.h>
#include <ui/resource.h>
#include "../private/resource.h"
PCUT_INIT;
PCUT_TEST_SUITE(resource);
static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
gfx_bitmap_alloc_t *, void **);
static errno_t testgc_bitmap_destroy(void *);
static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
static void test_expose(void *);
static gfx_context_ops_t ops = {
.bitmap_create = testgc_bitmap_create,
.bitmap_destroy = testgc_bitmap_destroy,
.bitmap_render = testgc_bitmap_render,
.bitmap_get_alloc = testgc_bitmap_get_alloc
};
typedef struct {
bool bm_created;
bool bm_destroyed;
gfx_bitmap_params_t bm_params;
void *bm_pixels;
gfx_rect_t bm_srect;
gfx_coord2_t bm_offs;
bool bm_rendered;
bool bm_got_alloc;
} test_gc_t;
typedef struct {
test_gc_t *tgc;
gfx_bitmap_alloc_t alloc;
bool myalloc;
} testgc_bitmap_t;
typedef struct {
bool expose;
} test_resp_t;
PCUT_TEST(create_destroy)
{
errno_t rc;
gfx_context_t *gc = NULL;
test_gc_t tgc;
ui_resource_t *resource = NULL;
memset(&tgc, 0, sizeof(tgc));
rc = gfx_context_new(&ops, &tgc, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_resource_create(gc, false, &resource);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(resource);
PCUT_ASSERT_NOT_NULL(resource->tface);
PCUT_ASSERT_NOT_NULL(resource->font);
ui_resource_destroy(resource);
rc = gfx_context_delete(gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST(destroy_null)
{
ui_resource_destroy(NULL);
}
PCUT_TEST(set_expose_cb_expose)
{
errno_t rc;
gfx_context_t *gc = NULL;
test_gc_t tgc;
ui_resource_t *resource = NULL;
test_resp_t resp;
memset(&tgc, 0, sizeof(tgc));
rc = gfx_context_new(&ops, &tgc, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_resource_create(gc, false, &resource);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(resource);
ui_resource_set_expose_cb(resource, test_expose, &resp);
resp.expose = false;
ui_resource_expose(resource);
PCUT_ASSERT_TRUE(resp.expose);
ui_resource_destroy(resource);
rc = gfx_context_delete(gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST(get_font)
{
errno_t rc;
gfx_context_t *gc = NULL;
test_gc_t tgc;
ui_resource_t *resource = NULL;
gfx_font_t *font;
memset(&tgc, 0, sizeof(tgc));
rc = gfx_context_new(&ops, &tgc, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_resource_create(gc, false, &resource);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(resource);
font = ui_resource_get_font(resource);
PCUT_ASSERT_EQUALS(resource->font, font);
ui_resource_destroy(resource);
rc = gfx_context_delete(gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST(is_textmode)
{
errno_t rc;
gfx_context_t *gc = NULL;
test_gc_t tgc;
ui_resource_t *resource = NULL;
memset(&tgc, 0, sizeof(tgc));
rc = gfx_context_new(&ops, &tgc, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_resource_create(gc, false, &resource);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(resource);
resource->textmode = true;
PCUT_ASSERT_TRUE(ui_resource_is_textmode(resource));
resource->textmode = false;
PCUT_ASSERT_FALSE(ui_resource_is_textmode(resource));
ui_resource_destroy(resource);
rc = gfx_context_delete(gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST(get_wnd_face_color)
{
errno_t rc;
gfx_context_t *gc = NULL;
test_gc_t tgc;
ui_resource_t *resource = NULL;
gfx_color_t *color;
memset(&tgc, 0, sizeof(tgc));
rc = gfx_context_new(&ops, &tgc, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_resource_create(gc, false, &resource);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(resource);
color = ui_resource_get_wnd_face_color(resource);
PCUT_ASSERT_EQUALS(resource->wnd_face_color, color);
ui_resource_destroy(resource);
rc = gfx_context_delete(gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST(get_wnd_text_color)
{
errno_t rc;
gfx_context_t *gc = NULL;
test_gc_t tgc;
ui_resource_t *resource = NULL;
gfx_color_t *color;
memset(&tgc, 0, sizeof(tgc));
rc = gfx_context_new(&ops, &tgc, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_resource_create(gc, false, &resource);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(resource);
color = ui_resource_get_wnd_text_color(resource);
PCUT_ASSERT_EQUALS(resource->wnd_text_color, color);
ui_resource_destroy(resource);
rc = gfx_context_delete(gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
gfx_bitmap_alloc_t *alloc, void **rbm)
{
test_gc_t *tgc = (test_gc_t *) arg;
testgc_bitmap_t *tbm;
tbm = calloc(1, sizeof(testgc_bitmap_t));
if (tbm == NULL)
return ENOMEM;
if (alloc == NULL) {
tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
sizeof(uint32_t);
tbm->alloc.off0 = 0;
tbm->alloc.pixels = calloc(sizeof(uint32_t),
(params->rect.p1.x - params->rect.p0.x) *
(params->rect.p1.y - params->rect.p0.y));
tbm->myalloc = true;
if (tbm->alloc.pixels == NULL) {
free(tbm);
return ENOMEM;
}
} else {
tbm->alloc = *alloc;
}
tbm->tgc = tgc;
tgc->bm_created = true;
tgc->bm_params = *params;
tgc->bm_pixels = tbm->alloc.pixels;
*rbm = (void *)tbm;
return EOK;
}
static errno_t testgc_bitmap_destroy(void *bm)
{
testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
if (tbm->myalloc)
free(tbm->alloc.pixels);
tbm->tgc->bm_destroyed = true;
free(tbm);
return EOK;
}
static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
gfx_coord2_t *offs)
{
testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
tbm->tgc->bm_rendered = true;
tbm->tgc->bm_srect = *srect;
tbm->tgc->bm_offs = *offs;
return EOK;
}
static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
{
testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
*alloc = tbm->alloc;
tbm->tgc->bm_got_alloc = true;
return EOK;
}
static void test_expose(void *arg)
{
test_resp_t *resp = (test_resp_t *) arg;
resp->expose = true;
}
PCUT_EXPORT(resource);
HelenOS homepage, sources at GitHub