Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/test/clonegc.c

    r5271e4c r7470d97  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939PCUT_TEST_SUITE(clonegc);
    4040
     41static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4142static errno_t testgc_set_color(void *, gfx_color_t *);
    4243static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     
    4849
    4950static gfx_context_ops_t ops = {
     51        .set_clip_rect = testgc_set_clip_rect,
    5052        .set_color = testgc_set_color,
    5153        .fill_rect = testgc_fill_rect,
     
    5961        /** Error code to return */
    6062        errno_t rc;
     63
     64        bool set_clip_rect_called;
     65        gfx_rect_t *set_clip_rect_rect;
    6166
    6267        bool set_color_called;
     
    95100        rc = ds_clonegc_create(NULL, &cgc);
    96101        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     102
     103        rc = ds_clonegc_delete(cgc);
     104        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     105}
     106
     107/** Set clipping rectangle with two output GCs */
     108PCUT_TEST(set_clip_rect)
     109{
     110        ds_clonegc_t *cgc;
     111        gfx_context_t *gc;
     112        test_gc_t tgc1;
     113        gfx_context_t *gc1;
     114        test_gc_t tgc2;
     115        gfx_context_t *gc2;
     116        gfx_rect_t rect;
     117        errno_t rc;
     118
     119        /* Create clone GC */
     120        rc = ds_clonegc_create(NULL, &cgc);
     121        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     122
     123        gc = ds_clonegc_get_ctx(cgc);
     124        PCUT_ASSERT_NOT_NULL(gc);
     125
     126        /* Add two output GCs */
     127
     128        rc = gfx_context_new(&ops, &tgc1, &gc1);
     129        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     130
     131        rc = ds_clonegc_add_output(cgc, gc1);
     132        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     133
     134        rc = gfx_context_new(&ops, &tgc2, &gc2);
     135        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     136
     137        rc = ds_clonegc_add_output(cgc, gc2);
     138        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     139
     140        rect.p0.x = 1;
     141        rect.p0.y = 2;
     142        rect.p1.x = 3;
     143        rect.p1.y = 4;
     144
     145        /* Set clipping rectangle returning error */
     146
     147        tgc1.set_clip_rect_called = false;
     148        tgc2.set_clip_rect_called = false;
     149        tgc1.rc = EINVAL;
     150        tgc2.rc = EINVAL;
     151
     152        rc = gfx_set_clip_rect(gc, &rect);
     153        PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
     154
     155        PCUT_ASSERT_TRUE(tgc1.set_clip_rect_called);
     156        PCUT_ASSERT_EQUALS(&rect, tgc1.set_clip_rect_rect);
     157        PCUT_ASSERT_FALSE(tgc2.set_clip_rect_called);
     158
     159        /* Set clipping rectangle returning success for all outputs */
     160        tgc1.set_clip_rect_called = false;
     161        tgc2.set_clip_rect_called = false;
     162        tgc1.rc = EOK;
     163        tgc2.rc = EOK;
     164
     165        rc = gfx_set_clip_rect(gc, &rect);
     166        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     167
     168        PCUT_ASSERT_TRUE(tgc1.set_clip_rect_called);
     169        PCUT_ASSERT_EQUALS(&rect, tgc1.set_clip_rect_rect);
     170        PCUT_ASSERT_TRUE(tgc2.set_clip_rect_called);
     171        PCUT_ASSERT_EQUALS(&rect, tgc2.set_clip_rect_rect);
    97172
    98173        rc = ds_clonegc_delete(cgc);
     
    628703}
    629704
     705static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     706{
     707        test_gc_t *tgc = (test_gc_t *) arg;
     708
     709        tgc->set_clip_rect_called = true;
     710        tgc->set_clip_rect_rect = rect;
     711
     712        return tgc->rc;
     713}
     714
    630715static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    631716{
Note: See TracChangeset for help on using the changeset viewer.