HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- test_ddev_conn
- test_get_gc
- test_get_info
- test_gc_set_color
#include <async.h>
#include <errno.h>
#include <ddev.h>
#include <ddev_srv.h>
#include <fibril_synch.h>
#include <gfx/color.h>
#include <gfx/context.h>
#include <gfx/render.h>
#include <ipcgfx/server.h>
#include <loc.h>
#include <pcut/pcut.h>
PCUT_INIT;
PCUT_TEST_SUITE(ddev);
static const char *test_ddev_server = "test-ddev";
static const char *test_ddev_svc = "test/ddev";
static void test_ddev_conn(ipc_call_t *, void *);
static errno_t test_get_gc(void *, sysarg_t *, sysarg_t *);
static errno_t test_get_info(void *, ddev_info_t *);
static errno_t test_gc_set_color(void *, gfx_color_t *);
static ddev_ops_t test_ddev_ops = {
.get_gc = test_get_gc,
.get_info = test_get_info
};
static gfx_context_ops_t test_gc_ops = {
.set_color = test_gc_set_color
};
typedef struct {
errno_t rc;
bool set_color_called;
ddev_srv_t *srv;
ddev_info_t info;
} test_response_t;
PCUT_TEST(open_close)
{
errno_t rc;
service_id_t sid;
ddev_t *ddev = NULL;
test_response_t resp;
loc_srv_t *srv;
async_set_fallback_port_handler(test_ddev_conn, &resp);
rc = loc_server_register(test_ddev_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_ddev_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ddev_open(test_ddev_svc, &ddev);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(ddev);
ddev_close(ddev);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(dev_get_gc_failure)
{
errno_t rc;
service_id_t sid;
ddev_t *ddev = NULL;
test_response_t resp;
gfx_context_t *gc;
loc_srv_t *srv;
async_set_fallback_port_handler(test_ddev_conn, &resp);
rc = loc_server_register(test_ddev_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_ddev_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ddev_open(test_ddev_svc, &ddev);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(ddev);
gc = NULL;
resp.rc = ENOMEM;
rc = ddev_get_gc(ddev, &gc);
PCUT_ASSERT_ERRNO_VAL(ENOMEM, rc);
PCUT_ASSERT_NULL(gc);
ddev_close(ddev);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(dev_get_gc_success)
{
errno_t rc;
service_id_t sid;
ddev_t *ddev = NULL;
test_response_t resp;
gfx_context_t *gc;
gfx_color_t *color;
loc_srv_t *srv;
async_set_fallback_port_handler(test_ddev_conn, &resp);
rc = loc_server_register(test_ddev_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_ddev_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ddev_open(test_ddev_svc, &ddev);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(ddev);
resp.rc = EOK;
gc = NULL;
rc = ddev_get_gc(ddev, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(gc);
rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
resp.set_color_called = false;
rc = gfx_set_color(gc, color);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(resp.set_color_called);
gfx_color_delete(color);
ddev_close(ddev);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(dev_get_info_failure)
{
errno_t rc;
service_id_t sid;
ddev_t *ddev = NULL;
test_response_t resp;
ddev_info_t info;
loc_srv_t *srv;
async_set_fallback_port_handler(test_ddev_conn, &resp);
rc = loc_server_register(test_ddev_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_ddev_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ddev_open(test_ddev_svc, &ddev);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(ddev);
resp.rc = ENOMEM;
rc = ddev_get_info(ddev, &info);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
ddev_close(ddev);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(dev_get_info_success)
{
errno_t rc;
service_id_t sid;
ddev_t *ddev = NULL;
test_response_t resp;
ddev_info_t info;
loc_srv_t *srv;
async_set_fallback_port_handler(test_ddev_conn, &resp);
rc = loc_server_register(test_ddev_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_ddev_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ddev_open(test_ddev_svc, &ddev);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(ddev);
resp.rc = EOK;
ddev_info_init(&resp.info);
resp.info.rect.p0.x = 1;
resp.info.rect.p0.y = 2;
resp.info.rect.p1.x = 3;
resp.info.rect.p1.y = 4;
rc = ddev_get_info(ddev, &info);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
PCUT_ASSERT_INT_EQUALS(resp.info.rect.p0.x, info.rect.p0.x);
PCUT_ASSERT_INT_EQUALS(resp.info.rect.p0.y, info.rect.p0.y);
PCUT_ASSERT_INT_EQUALS(resp.info.rect.p1.x, info.rect.p1.x);
PCUT_ASSERT_INT_EQUALS(resp.info.rect.p1.y, info.rect.p1.y);
ddev_close(ddev);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
static void test_ddev_conn(ipc_call_t *icall, void *arg)
{
test_response_t *resp = (test_response_t *) arg;
ddev_srv_t srv;
sysarg_t svc_id;
gfx_context_t *gc;
errno_t rc;
svc_id = ipc_get_arg2(icall);
if (svc_id != 0) {
ddev_srv_initialize(&srv);
srv.ops = &test_ddev_ops;
srv.arg = arg;
resp->srv = &srv;
ddev_conn(icall, &srv);
resp->srv = NULL;
} else {
if (resp->rc != EOK) {
async_answer_0(icall, resp->rc);
return;
}
rc = gfx_context_new(&test_gc_ops, arg, &gc);
if (rc != EOK) {
async_answer_0(icall, ENOMEM);
return;
}
gc_conn(icall, gc);
}
}
static errno_t test_get_gc(void *arg, sysarg_t *arg2, sysarg_t *arg3)
{
*arg2 = 0;
*arg3 = 42;
return EOK;
}
static errno_t test_get_info(void *arg, ddev_info_t *info)
{
test_response_t *resp = (test_response_t *) arg;
if (resp->rc != EOK)
return resp->rc;
*info = resp->info;
return EOK;
}
static errno_t test_gc_set_color(void *arg, gfx_color_t *color)
{
test_response_t *resp = (test_response_t *) arg;
resp->set_color_called = true;
return resp->rc;
}
PCUT_EXPORT(ddev);
HelenOS homepage, sources at GitHub