Changeset 7470d97 in mainline for uspace/lib/gfx/test/render.c
- Timestamp:
- 2021-04-30T15:05:06Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 051349b
- Parents:
- 252d03c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/test/render.c
r252d03c r7470d97 38 38 PCUT_TEST_SUITE(render); 39 39 40 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *); 40 41 static errno_t testgc_set_color(void *, gfx_color_t *); 41 42 static errno_t testgc_fill_rect(void *, gfx_rect_t *); … … 43 44 44 45 static gfx_context_ops_t ops = { 46 .set_clip_rect = testgc_set_clip_rect, 45 47 .set_color = testgc_set_color, 46 48 .fill_rect = testgc_fill_rect, … … 50 52 /** Test graphics context data */ 51 53 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; 52 61 gfx_color_t *dclr; 53 gfx_rect_t *rect; 54 bool updated; 62 63 bool fill_rect; 64 gfx_rect_t frect; 65 66 bool update; 55 67 } test_gc_t; 56 68 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 */ 57 150 PCUT_TEST(set_color) 58 151 { … … 60 153 gfx_color_t *color; 61 154 gfx_context_t *gc = NULL; 155 uint16_t r, g, b; 62 156 test_gc_t tgc; 63 157 … … 70 164 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 71 165 166 PCUT_ASSERT_FALSE(tgc.set_color); 167 168 tgc.rc = EOK; 169 72 170 rc = gfx_set_color(gc, color); 73 171 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 74 PCUT_ASSERT_EQUALS(color, tgc.dclr); 75 PCUT_ASSERT_NULL(tgc.rect); 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 { 188 errno_t rc; 189 gfx_color_t *color; 190 gfx_context_t *gc = NULL; 191 test_gc_t tgc; 192 193 memset(&tgc, 0, sizeof(tgc)); 194 195 rc = gfx_context_new(&ops, &tgc, &gc); 196 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 197 198 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 201 PCUT_ASSERT_FALSE(tgc.set_color); 202 203 tgc.rc = EIO; 204 205 rc = gfx_set_color(gc, color); 206 PCUT_ASSERT_ERRNO_VAL(EIO, rc); 76 207 77 208 gfx_color_delete(color); … … 81 212 } 82 213 214 /** Fill rectangle */ 83 215 PCUT_TEST(fill_rect) 84 216 { 85 217 errno_t rc; 86 gfx_color_t *color;87 218 gfx_rect_t rect; 88 219 gfx_context_t *gc = NULL; … … 94 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 95 226 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); 227 rect.p0.x = 1; 228 rect.p0.y = 2; 229 rect.p1.x = 3; 230 rect.p1.y = 4; 231 232 PCUT_ASSERT_FALSE(tgc.fill_rect); 233 234 tgc.rc = EOK; 102 235 103 236 rc = gfx_fill_rect(gc, &rect); 104 237 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 238 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); 244 245 rc = gfx_context_delete(gc); 246 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 */ 113 279 PCUT_TEST(update) 114 280 { … … 122 288 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 123 289 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); 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; 130 335 } 131 336 … … 133 338 { 134 339 test_gc_t *tgc = (test_gc_t *) arg; 340 341 tgc->set_color = true; 135 342 136 343 /* Technically we should copy the data */ 137 344 tgc->dclr = color; 138 return EOK;345 return tgc->rc; 139 346 } 140 347 … … 143 350 test_gc_t *tgc = (test_gc_t *) arg; 144 351 145 /* Technically we should copy the data */146 tgc-> rect =rect;147 return EOK;352 tgc->fill_rect = true; 353 tgc->frect = *rect; 354 return tgc->rc; 148 355 } 149 356 … … 152 359 test_gc_t *tgc = (test_gc_t *) arg; 153 360 154 tgc->update d= true;155 return EOK;361 tgc->update = true; 362 return tgc->rc; 156 363 } 157 364
Note:
See TracChangeset
for help on using the changeset viewer.