1 | /*
|
---|
2 | * Copyright (c) 2021 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 | #include <stdbool.h>
|
---|
35 |
|
---|
36 | PCUT_INIT;
|
---|
37 |
|
---|
38 | PCUT_TEST_SUITE(render);
|
---|
39 |
|
---|
40 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
---|
41 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
---|
42 | static errno_t testgc_update(void *);
|
---|
43 |
|
---|
44 | static gfx_context_ops_t ops = {
|
---|
45 | .set_color = testgc_set_color,
|
---|
46 | .fill_rect = testgc_fill_rect,
|
---|
47 | .update = testgc_update
|
---|
48 | };
|
---|
49 |
|
---|
50 | /** Test graphics context data */
|
---|
51 | typedef struct {
|
---|
52 | gfx_color_t *dclr;
|
---|
53 | gfx_rect_t *rect;
|
---|
54 | bool updated;
|
---|
55 | } test_gc_t;
|
---|
56 |
|
---|
57 | PCUT_TEST(set_color)
|
---|
58 | {
|
---|
59 | errno_t rc;
|
---|
60 | gfx_color_t *color;
|
---|
61 | gfx_context_t *gc = NULL;
|
---|
62 | test_gc_t tgc;
|
---|
63 |
|
---|
64 | memset(&tgc, 0, sizeof(tgc));
|
---|
65 |
|
---|
66 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
67 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
68 |
|
---|
69 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
|
---|
70 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
71 |
|
---|
72 | rc = gfx_set_color(gc, color);
|
---|
73 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
74 | PCUT_ASSERT_EQUALS(color, tgc.dclr);
|
---|
75 | PCUT_ASSERT_NULL(tgc.rect);
|
---|
76 |
|
---|
77 | gfx_color_delete(color);
|
---|
78 |
|
---|
79 | rc = gfx_context_delete(gc);
|
---|
80 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
81 | }
|
---|
82 |
|
---|
83 | PCUT_TEST(fill_rect)
|
---|
84 | {
|
---|
85 | errno_t rc;
|
---|
86 | gfx_color_t *color;
|
---|
87 | gfx_rect_t rect;
|
---|
88 | gfx_context_t *gc = NULL;
|
---|
89 | test_gc_t tgc;
|
---|
90 |
|
---|
91 | memset(&tgc, 0, sizeof(tgc));
|
---|
92 |
|
---|
93 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
94 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
95 |
|
---|
96 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
|
---|
97 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
98 |
|
---|
99 | rc = gfx_set_color(gc, color);
|
---|
100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
101 | PCUT_ASSERT_EQUALS(color, tgc.dclr);
|
---|
102 |
|
---|
103 | rc = gfx_fill_rect(gc, &rect);
|
---|
104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
105 | PCUT_ASSERT_EQUALS(&rect, tgc.rect);
|
---|
106 |
|
---|
107 | gfx_color_delete(color);
|
---|
108 |
|
---|
109 | rc = gfx_context_delete(gc);
|
---|
110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
111 | }
|
---|
112 |
|
---|
113 | PCUT_TEST(update)
|
---|
114 | {
|
---|
115 | errno_t rc;
|
---|
116 | gfx_context_t *gc = NULL;
|
---|
117 | test_gc_t tgc;
|
---|
118 |
|
---|
119 | memset(&tgc, 0, sizeof(tgc));
|
---|
120 |
|
---|
121 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
122 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
123 |
|
---|
124 | PCUT_ASSERT_FALSE(tgc.updated);
|
---|
125 | gfx_update(gc);
|
---|
126 | PCUT_ASSERT_TRUE(tgc.updated);
|
---|
127 |
|
---|
128 | rc = gfx_context_delete(gc);
|
---|
129 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
130 | }
|
---|
131 |
|
---|
132 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
---|
133 | {
|
---|
134 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
135 |
|
---|
136 | /* Technically we should copy the data */
|
---|
137 | tgc->dclr = color;
|
---|
138 | return EOK;
|
---|
139 | }
|
---|
140 |
|
---|
141 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
142 | {
|
---|
143 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
144 |
|
---|
145 | /* Technically we should copy the data */
|
---|
146 | tgc->rect = rect;
|
---|
147 | return EOK;
|
---|
148 | }
|
---|
149 |
|
---|
150 | static errno_t testgc_update(void *arg)
|
---|
151 | {
|
---|
152 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
153 |
|
---|
154 | tgc->updated = true;
|
---|
155 | return EOK;
|
---|
156 | }
|
---|
157 |
|
---|
158 | PCUT_EXPORT(render);
|
---|