source: mainline/uspace/lib/ui/test/image.c@ 0d71fd6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0d71fd6 was f93e4e3, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Add UI image

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2020 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/context.h>
30#include <gfx/coord.h>
31#include <mem.h>
32#include <pcut/pcut.h>
33#include <stdbool.h>
34#include <ui/control.h>
35#include <ui/image.h>
36#include <ui/ui.h>
37#include "../private/dummygc.h"
38#include "../private/image.h"
39
40PCUT_INIT;
41
42PCUT_TEST_SUITE(image);
43
44typedef struct {
45 bool clicked;
46} test_cb_resp_t;
47
48/** Create and destroy image */
49PCUT_TEST(create_destroy)
50{
51 ui_image_t *image = NULL;
52 gfx_rect_t brect;
53 errno_t rc;
54
55 rc = ui_image_create(NULL, NULL, &brect, &image);
56 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
57 PCUT_ASSERT_NOT_NULL(image);
58
59 ui_image_destroy(image);
60}
61
62/** ui_image_destroy() can take NULL argument (no-op) */
63PCUT_TEST(destroy_null)
64{
65 ui_image_destroy(NULL);
66}
67
68/** ui_image_ctl() returns control that has a working virtual destructor */
69PCUT_TEST(ctl)
70{
71 ui_image_t *image = NULL;
72 ui_control_t *control;
73 gfx_rect_t brect;
74 errno_t rc;
75
76 rc = ui_image_create(NULL, NULL, &brect, &image);
77 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
78 PCUT_ASSERT_NOT_NULL(image);
79
80 control = ui_image_ctl(image);
81 PCUT_ASSERT_NOT_NULL(control);
82
83 ui_control_destroy(control);
84}
85
86/** Set image rectangle sets internal field */
87PCUT_TEST(set_rect)
88{
89
90 ui_image_t *image = NULL;
91 gfx_rect_t brect;
92 gfx_rect_t rect;
93 errno_t rc;
94
95 rc = ui_image_create(NULL, NULL, &brect, &image);
96 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
97 PCUT_ASSERT_NOT_NULL(image);
98
99 rect.p0.x = 1;
100 rect.p0.y = 2;
101 rect.p1.x = 3;
102 rect.p1.y = 4;
103
104 ui_image_set_rect(image, &rect);
105 PCUT_ASSERT_INT_EQUALS(rect.p0.x, image->rect.p0.x);
106 PCUT_ASSERT_INT_EQUALS(rect.p0.y, image->rect.p0.y);
107 PCUT_ASSERT_INT_EQUALS(rect.p1.x, image->rect.p1.x);
108 PCUT_ASSERT_INT_EQUALS(rect.p1.y, image->rect.p1.y);
109
110 ui_image_destroy(image);
111}
112
113/** Paint image */
114PCUT_TEST(paint)
115{
116 dummy_gc_t *dgc;
117 gfx_context_t *gc;
118 gfx_bitmap_params_t params;
119 gfx_bitmap_t *bitmap;
120 ui_image_t *image = NULL;
121 gfx_rect_t brect;
122 errno_t rc;
123
124 rc = dummygc_create(&dgc);
125 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
126
127 gc = dummygc_get_ctx(dgc);
128
129 gfx_bitmap_params_init(&params);
130 rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
131 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
132
133 rc = ui_image_create(NULL, bitmap, &brect, &image);
134 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
135 PCUT_ASSERT_NOT_NULL(image);
136
137 rc = ui_image_paint(image);
138 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
139
140 ui_image_destroy(image);
141}
142
143PCUT_EXPORT(image);
Note: See TracBrowser for help on using the repository browser.