2 * Copyright (c) 2022 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include <pcut/pcut.h>
31 #include <ui/clickmatic.h>
33 #include "../private/clickmatic.h"
37 PCUT_TEST_SUITE(clickmatic
);
39 static void test_clicked(ui_clickmatic_t
*, void *);
41 static ui_clickmatic_cb_t test_cb
= {
42 .clicked
= test_clicked
49 /** Create and destroy clickmatic */
50 PCUT_TEST(create_destroy
)
53 ui_clickmatic_t
*clickmatic
= NULL
;
56 rc
= ui_create_disp(NULL
, &ui
);
57 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
59 rc
= ui_clickmatic_create(ui
, &clickmatic
);
60 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
61 PCUT_ASSERT_NOT_NULL(clickmatic
);
63 ui_clickmatic_destroy(clickmatic
);
67 /** ui_clickmatic_destroy() can take NULL argument (no-op) */
68 PCUT_TEST(destroy_null
)
70 ui_clickmatic_destroy(NULL
);
73 /** ui_clickmatic_set_cb() sets internal fields */
77 ui_clickmatic_t
*clickmatic
= NULL
;
78 test_resp_t test_resp
;
81 rc
= ui_create_disp(NULL
, &ui
);
82 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
84 rc
= ui_clickmatic_create(ui
, &clickmatic
);
85 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
86 PCUT_ASSERT_NOT_NULL(clickmatic
);
88 ui_clickmatic_set_cb(clickmatic
, &test_cb
, (void *)&test_resp
);
89 PCUT_ASSERT_EQUALS(&test_cb
, clickmatic
->cb
);
90 PCUT_ASSERT_EQUALS((void *)&test_resp
, clickmatic
->arg
);
92 ui_clickmatic_destroy(clickmatic
);
96 /** Pressing and releasing clickmatic generates one event */
97 PCUT_TEST(press_release
)
100 ui_clickmatic_t
*clickmatic
= NULL
;
101 test_resp_t test_resp
;
104 rc
= ui_create_disp(NULL
, &ui
);
105 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
107 rc
= ui_clickmatic_create(ui
, &clickmatic
);
108 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
109 PCUT_ASSERT_NOT_NULL(clickmatic
);
111 test_resp
.clicked_cnt
= 0;
113 ui_clickmatic_set_cb(clickmatic
, &test_cb
, (void *)&test_resp
);
114 PCUT_ASSERT_EQUALS(&test_cb
, clickmatic
->cb
);
115 PCUT_ASSERT_EQUALS((void *)&test_resp
, clickmatic
->arg
);
117 PCUT_ASSERT_INT_EQUALS(0, test_resp
.clicked_cnt
);
119 ui_clickmatic_press(clickmatic
);
120 ui_clickmatic_release(clickmatic
);
122 PCUT_ASSERT_INT_EQUALS(1, test_resp
.clicked_cnt
);
124 ui_clickmatic_destroy(clickmatic
);
128 static void test_clicked(ui_clickmatic_t
*clickmatic
, void *arg
)
130 test_resp_t
*test_resp
= (test_resp_t
*)arg
;
132 ++test_resp
->clicked_cnt
;
135 PCUT_EXPORT(clickmatic
);