HelenOS sources

root/uspace/lib/ui/test/resource.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. PCUT_TEST
  2. PCUT_TEST
  3. PCUT_TEST
  4. PCUT_TEST
  5. PCUT_TEST
  6. PCUT_TEST
  7. PCUT_TEST
  8. test_expose

/*
 * Copyright (c) 2021 Jiri Svoboda
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - The name of the author may not be used to endorse or promote products
 *   derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <gfx/context.h>
#include <mem.h>
#include <pcut/pcut.h>
#include <stdbool.h>
#include <ui/resource.h>
#include "../private/resource.h"
#include "../private/testgc.h"

PCUT_INIT;

PCUT_TEST_SUITE(resource);

static void test_expose(void *);

typedef struct {
        bool expose;
} test_resp_t;

/** Create and destroy UI resource */
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);
}

/** ui_resource_destroy() can take NULL argument (no-op) */
PCUT_TEST(destroy_null)
{
        ui_resource_destroy(NULL);
}

/** ui_resource_set_expose_cb() / ui_resource_expose() */
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);
}

/** ui_resource_get_font() returns the font */
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);
}

/** ui_resource_is_textmode() returns the textmode flag */
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);

        /* To make sure let's test both true and false case */
        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);
}

/** ui_resource_get_wnd_face_color() returns window face color */
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);
}

/** ui_resource_get_wnd_text_color() returns window text color */
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 void test_expose(void *arg)
{
        test_resp_t *resp = (test_resp_t *) arg;

        resp->expose = true;
}

PCUT_EXPORT(resource);

/* [<][>][^][v][top][bottom][index][help] */
HelenOS homepage, sources at GitHub