| 1 | /*
|
|---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #include <gfx/color.h>
|
|---|
| 30 | #include <gfx/context.h>
|
|---|
| 31 | #include <gfx/render.h>
|
|---|
| 32 | #include <pcut/pcut.h>
|
|---|
| 33 | #include <mem.h>
|
|---|
| 34 |
|
|---|
| 35 | PCUT_INIT;
|
|---|
| 36 |
|
|---|
| 37 | PCUT_TEST_SUITE(render);
|
|---|
| 38 |
|
|---|
| 39 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
|---|
| 40 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
|---|
| 41 |
|
|---|
| 42 | static gfx_context_ops_t ops = {
|
|---|
| 43 | .set_color = testgc_set_color,
|
|---|
| 44 | .fill_rect = testgc_fill_rect
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | /** Test graphics context data */
|
|---|
| 48 | typedef struct {
|
|---|
| 49 | gfx_color_t *dclr;
|
|---|
| 50 | gfx_rect_t *rect;
|
|---|
| 51 | } test_gc_t;
|
|---|
| 52 |
|
|---|
| 53 | PCUT_TEST(set_color)
|
|---|
| 54 | {
|
|---|
| 55 | errno_t rc;
|
|---|
| 56 | gfx_color_t *color;
|
|---|
| 57 | gfx_context_t *gc = NULL;
|
|---|
| 58 | test_gc_t tgc;
|
|---|
| 59 |
|
|---|
| 60 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 61 |
|
|---|
| 62 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 63 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 64 |
|
|---|
| 65 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
|
|---|
| 66 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 67 |
|
|---|
| 68 | rc = gfx_set_color(gc, color);
|
|---|
| 69 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 70 | PCUT_ASSERT_EQUALS(color, tgc.dclr);
|
|---|
| 71 | PCUT_ASSERT_NULL(tgc.rect);
|
|---|
| 72 |
|
|---|
| 73 | gfx_color_delete(color);
|
|---|
| 74 |
|
|---|
| 75 | rc = gfx_context_delete(gc);
|
|---|
| 76 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | PCUT_TEST(fill_rect)
|
|---|
| 80 | {
|
|---|
| 81 | errno_t rc;
|
|---|
| 82 | gfx_color_t *color;
|
|---|
| 83 | gfx_rect_t rect;
|
|---|
| 84 | gfx_context_t *gc = NULL;
|
|---|
| 85 | test_gc_t tgc;
|
|---|
| 86 |
|
|---|
| 87 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 88 |
|
|---|
| 89 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 90 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 91 |
|
|---|
| 92 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
|
|---|
| 93 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 94 |
|
|---|
| 95 | rc = gfx_set_color(gc, color);
|
|---|
| 96 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 97 | PCUT_ASSERT_EQUALS(color, tgc.dclr);
|
|---|
| 98 |
|
|---|
| 99 | rc = gfx_fill_rect(gc, &rect);
|
|---|
| 100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 101 | PCUT_ASSERT_EQUALS(&rect, tgc.rect);
|
|---|
| 102 |
|
|---|
| 103 | gfx_color_delete(color);
|
|---|
| 104 |
|
|---|
| 105 | rc = gfx_context_delete(gc);
|
|---|
| 106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
|---|
| 110 | {
|
|---|
| 111 | test_gc_t *tgc = (test_gc_t *) arg;
|
|---|
| 112 |
|
|---|
| 113 | /* Technically we should copy the data */
|
|---|
| 114 | tgc->dclr = color;
|
|---|
| 115 | return EOK;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
|---|
| 119 | {
|
|---|
| 120 | test_gc_t *tgc = (test_gc_t *) arg;
|
|---|
| 121 |
|
|---|
| 122 | /* Technically we should copy the data */
|
|---|
| 123 | tgc->rect = rect;
|
|---|
| 124 | return EOK;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | PCUT_EXPORT(render);
|
|---|