Changes in uspace/lib/gfx/test/render.c [7470d97:9259d20] in mainline
- File:
-
- 1 edited
-
uspace/lib/gfx/test/render.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/test/render.c
r7470d97 r9259d20 1 1 /* 2 * Copyright (c) 20 21Jiri Svoboda2 * Copyright (c) 2019 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 #include <pcut/pcut.h> 33 33 #include <mem.h> 34 #include <stdbool.h>35 34 36 35 PCUT_INIT; … … 38 37 PCUT_TEST_SUITE(render); 39 38 40 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);41 39 static errno_t testgc_set_color(void *, gfx_color_t *); 42 40 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 43 static errno_t testgc_update(void *);44 41 45 42 static gfx_context_ops_t ops = { 46 .set_clip_rect = testgc_set_clip_rect,47 43 .set_color = testgc_set_color, 48 .fill_rect = testgc_fill_rect, 49 .update = testgc_update 44 .fill_rect = testgc_fill_rect 50 45 }; 51 46 52 47 /** Test graphics context data */ 53 48 typedef struct { 54 errno_t rc;55 56 bool set_clip_rect;57 gfx_rect_t crect;58 bool do_clip;59 60 bool set_color;61 49 gfx_color_t *dclr; 62 63 bool fill_rect; 64 gfx_rect_t frect; 65 66 bool update; 50 gfx_rect_t *rect; 67 51 } test_gc_t; 68 52 69 /** Set clipping rectangle */70 PCUT_TEST(set_clip_rect)71 {72 errno_t rc;73 gfx_rect_t rect;74 gfx_context_t *gc = NULL;75 test_gc_t tgc;76 77 memset(&tgc, 0, sizeof(tgc));78 79 rc = gfx_context_new(&ops, &tgc, &gc);80 PCUT_ASSERT_ERRNO_VAL(EOK, rc);81 82 rect.p0.x = 1;83 rect.p0.y = 2;84 rect.p1.x = 3;85 rect.p1.y = 4;86 87 tgc.rc = EOK;88 89 rc = gfx_set_clip_rect(gc, &rect);90 PCUT_ASSERT_ERRNO_VAL(EOK, rc);91 92 PCUT_ASSERT_TRUE(tgc.set_clip_rect);93 PCUT_ASSERT_TRUE(tgc.do_clip);94 PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc.crect.p0.x);95 PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc.crect.p0.y);96 PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc.crect.p1.x);97 PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc.crect.p1.y);98 99 rc = gfx_context_delete(gc);100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);101 }102 103 /** Set null clipping rectangle */104 PCUT_TEST(set_clip_rect_null)105 {106 errno_t rc;107 gfx_context_t *gc = NULL;108 test_gc_t tgc;109 110 memset(&tgc, 0, sizeof(tgc));111 112 rc = gfx_context_new(&ops, &tgc, &gc);113 PCUT_ASSERT_ERRNO_VAL(EOK, rc);114 115 tgc.rc = EOK;116 117 rc = gfx_set_clip_rect(gc, NULL);118 PCUT_ASSERT_ERRNO_VAL(EOK, rc);119 120 PCUT_ASSERT_TRUE(tgc.set_clip_rect);121 PCUT_ASSERT_FALSE(tgc.do_clip);122 123 rc = gfx_context_delete(gc);124 PCUT_ASSERT_ERRNO_VAL(EOK, rc);125 }126 127 /** Set clipping rectangle with error return */128 PCUT_TEST(set_clip_rect_failure)129 {130 errno_t rc;131 gfx_rect_t rect;132 gfx_context_t *gc = NULL;133 test_gc_t tgc;134 135 memset(&tgc, 0, sizeof(tgc));136 137 rc = gfx_context_new(&ops, &tgc, &gc);138 PCUT_ASSERT_ERRNO_VAL(EOK, rc);139 140 tgc.rc = EIO;141 142 rc = gfx_set_clip_rect(gc, &rect);143 PCUT_ASSERT_ERRNO_VAL(EIO, rc);144 145 rc = gfx_context_delete(gc);146 PCUT_ASSERT_ERRNO_VAL(EOK, rc);147 }148 149 /** Set drawing color */150 53 PCUT_TEST(set_color) 151 {152 errno_t rc;153 gfx_color_t *color;154 gfx_context_t *gc = NULL;155 uint16_t r, g, b;156 test_gc_t tgc;157 158 memset(&tgc, 0, sizeof(tgc));159 160 rc = gfx_context_new(&ops, &tgc, &gc);161 PCUT_ASSERT_ERRNO_VAL(EOK, rc);162 163 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);164 PCUT_ASSERT_ERRNO_VAL(EOK, rc);165 166 PCUT_ASSERT_FALSE(tgc.set_color);167 168 tgc.rc = EOK;169 170 rc = gfx_set_color(gc, color);171 PCUT_ASSERT_ERRNO_VAL(EOK, rc);172 173 PCUT_ASSERT_TRUE(tgc.set_color);174 175 gfx_color_get_rgb_i16(tgc.dclr, &r, &g, &b);176 177 PCUT_ASSERT_INT_EQUALS(0xffff, r);178 PCUT_ASSERT_INT_EQUALS(0xffff, g);179 PCUT_ASSERT_INT_EQUALS(0xffff, b);180 181 rc = gfx_context_delete(gc);182 PCUT_ASSERT_ERRNO_VAL(EOK, rc);183 }184 185 /** Set drawing color with error return */186 PCUT_TEST(set_color_failure)187 54 { 188 55 errno_t rc; … … 199 66 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 67 201 PCUT_ASSERT_FALSE(tgc.set_color);202 203 tgc.rc = EIO;204 205 68 rc = gfx_set_color(gc, color); 206 PCUT_ASSERT_ERRNO_VAL(EIO, rc); 69 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 70 PCUT_ASSERT_EQUALS(color, tgc.dclr); 71 PCUT_ASSERT_NULL(tgc.rect); 207 72 208 73 gfx_color_delete(color); … … 212 77 } 213 78 214 /** Fill rectangle */215 79 PCUT_TEST(fill_rect) 216 80 { 217 81 errno_t rc; 82 gfx_color_t *color; 218 83 gfx_rect_t rect; 219 84 gfx_context_t *gc = NULL; … … 225 90 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 91 227 rect.p0.x = 1; 228 rect.p0.y = 2; 229 rect.p1.x = 3; 230 rect.p1.y = 4; 92 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 93 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 231 94 232 PCUT_ASSERT_FALSE(tgc.fill_rect);233 234 tgc.rc = EOK;95 rc = gfx_set_color(gc, color); 96 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 97 PCUT_ASSERT_EQUALS(color, tgc.dclr); 235 98 236 99 rc = gfx_fill_rect(gc, &rect); 237 100 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 101 PCUT_ASSERT_EQUALS(&rect, tgc.rect); 238 102 239 PCUT_ASSERT_TRUE(tgc.fill_rect); 240 PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc.frect.p0.x); 241 PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc.frect.p0.y); 242 PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc.frect.p1.x); 243 PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc.frect.p1.y); 103 gfx_color_delete(color); 244 104 245 105 rc = gfx_context_delete(gc); 246 106 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 247 }248 249 /** Fill rectangle with error return */250 PCUT_TEST(fill_rect_failure)251 {252 errno_t rc;253 gfx_rect_t rect;254 gfx_context_t *gc = NULL;255 test_gc_t tgc;256 257 memset(&tgc, 0, sizeof(tgc));258 259 rc = gfx_context_new(&ops, &tgc, &gc);260 PCUT_ASSERT_ERRNO_VAL(EOK, rc);261 262 rect.p0.x = 1;263 rect.p0.y = 2;264 rect.p1.x = 3;265 rect.p1.y = 4;266 267 PCUT_ASSERT_FALSE(tgc.fill_rect);268 269 tgc.rc = EIO;270 271 rc = gfx_fill_rect(gc, &rect);272 PCUT_ASSERT_ERRNO_VAL(EIO, rc);273 274 rc = gfx_context_delete(gc);275 PCUT_ASSERT_ERRNO_VAL(EOK, rc);276 }277 278 /** Update GC */279 PCUT_TEST(update)280 {281 errno_t rc;282 gfx_context_t *gc = NULL;283 test_gc_t tgc;284 285 memset(&tgc, 0, sizeof(tgc));286 287 rc = gfx_context_new(&ops, &tgc, &gc);288 PCUT_ASSERT_ERRNO_VAL(EOK, rc);289 290 tgc.rc = EOK;291 292 PCUT_ASSERT_FALSE(tgc.update);293 rc = gfx_update(gc);294 PCUT_ASSERT_ERRNO_VAL(EOK, rc);295 PCUT_ASSERT_TRUE(tgc.update);296 297 rc = gfx_context_delete(gc);298 PCUT_ASSERT_ERRNO_VAL(EOK, rc);299 }300 301 /** Update GC with error return */302 PCUT_TEST(update_failure)303 {304 errno_t rc;305 gfx_context_t *gc = NULL;306 test_gc_t tgc;307 308 memset(&tgc, 0, sizeof(tgc));309 310 rc = gfx_context_new(&ops, &tgc, &gc);311 PCUT_ASSERT_ERRNO_VAL(EOK, rc);312 313 tgc.rc = EIO;314 rc = gfx_update(gc);315 316 PCUT_ASSERT_ERRNO_VAL(EIO, rc);317 318 rc = gfx_context_delete(gc);319 PCUT_ASSERT_ERRNO_VAL(EOK, rc);320 }321 322 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)323 {324 test_gc_t *tgc = (test_gc_t *) arg;325 326 tgc->set_clip_rect = true;327 if (rect != NULL) {328 tgc->do_clip = true;329 tgc->crect = *rect;330 } else {331 tgc->do_clip = false;332 }333 334 return tgc->rc;335 107 } 336 108 … … 339 111 test_gc_t *tgc = (test_gc_t *) arg; 340 112 341 tgc->set_color = true;342 343 113 /* Technically we should copy the data */ 344 114 tgc->dclr = color; 345 return tgc->rc;115 return EOK; 346 116 } 347 117 … … 350 120 test_gc_t *tgc = (test_gc_t *) arg; 351 121 352 tgc->fill_rect = true; 353 tgc->frect = *rect; 354 return tgc->rc; 355 } 356 357 static errno_t testgc_update(void *arg) 358 { 359 test_gc_t *tgc = (test_gc_t *) arg; 360 361 tgc->update = true; 362 return tgc->rc; 122 /* Technically we should copy the data */ 123 tgc->rect = rect; 124 return EOK; 363 125 } 364 126
Note:
See TracChangeset
for help on using the changeset viewer.
