[8965860c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2022 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 <errno.h>
|
---|
| 30 | #include <pcut/pcut.h>
|
---|
| 31 | #include <ui/clickmatic.h>
|
---|
| 32 | #include <ui/ui.h>
|
---|
| 33 | #include "../private/clickmatic.h"
|
---|
| 34 |
|
---|
| 35 | PCUT_INIT;
|
---|
| 36 |
|
---|
| 37 | PCUT_TEST_SUITE(clickmatic);
|
---|
| 38 |
|
---|
| 39 | static void test_clicked(ui_clickmatic_t *, void *);
|
---|
| 40 |
|
---|
| 41 | static ui_clickmatic_cb_t test_cb = {
|
---|
| 42 | .clicked = test_clicked
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | typedef struct {
|
---|
| 46 | int clicked_cnt;
|
---|
| 47 | } test_resp_t;
|
---|
| 48 |
|
---|
| 49 | /** Create and destroy clickmatic */
|
---|
| 50 | PCUT_TEST(create_destroy)
|
---|
| 51 | {
|
---|
| 52 | ui_t *ui = NULL;
|
---|
| 53 | ui_clickmatic_t *clickmatic = NULL;
|
---|
| 54 | errno_t rc;
|
---|
| 55 |
|
---|
| 56 | rc = ui_create_disp(NULL, &ui);
|
---|
| 57 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 58 |
|
---|
| 59 | rc = ui_clickmatic_create(ui, &clickmatic);
|
---|
| 60 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 61 | PCUT_ASSERT_NOT_NULL(clickmatic);
|
---|
| 62 |
|
---|
| 63 | ui_clickmatic_destroy(clickmatic);
|
---|
| 64 | ui_destroy(ui);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /** ui_clickmatic_destroy() can take NULL argument (no-op) */
|
---|
| 68 | PCUT_TEST(destroy_null)
|
---|
| 69 | {
|
---|
| 70 | ui_clickmatic_destroy(NULL);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /** ui_clickmatic_set_cb() sets internal fields */
|
---|
| 74 | PCUT_TEST(set_cb)
|
---|
| 75 | {
|
---|
| 76 | ui_t *ui = NULL;
|
---|
| 77 | ui_clickmatic_t *clickmatic = NULL;
|
---|
| 78 | test_resp_t test_resp;
|
---|
| 79 | errno_t rc;
|
---|
| 80 |
|
---|
| 81 | rc = ui_create_disp(NULL, &ui);
|
---|
| 82 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 83 |
|
---|
| 84 | rc = ui_clickmatic_create(ui, &clickmatic);
|
---|
| 85 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 86 | PCUT_ASSERT_NOT_NULL(clickmatic);
|
---|
| 87 |
|
---|
| 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);
|
---|
| 91 |
|
---|
| 92 | ui_clickmatic_destroy(clickmatic);
|
---|
| 93 | ui_destroy(ui);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /** Pressing and releasing clickmatic generates one event */
|
---|
| 97 | PCUT_TEST(press_release)
|
---|
| 98 | {
|
---|
| 99 | ui_t *ui = NULL;
|
---|
| 100 | ui_clickmatic_t *clickmatic = NULL;
|
---|
| 101 | test_resp_t test_resp;
|
---|
| 102 | errno_t rc;
|
---|
| 103 |
|
---|
| 104 | rc = ui_create_disp(NULL, &ui);
|
---|
| 105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 106 |
|
---|
| 107 | rc = ui_clickmatic_create(ui, &clickmatic);
|
---|
| 108 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 109 | PCUT_ASSERT_NOT_NULL(clickmatic);
|
---|
| 110 |
|
---|
| 111 | test_resp.clicked_cnt = 0;
|
---|
| 112 |
|
---|
| 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);
|
---|
| 116 |
|
---|
| 117 | PCUT_ASSERT_INT_EQUALS(0, test_resp.clicked_cnt);
|
---|
| 118 |
|
---|
| 119 | ui_clickmatic_press(clickmatic);
|
---|
| 120 | ui_clickmatic_release(clickmatic);
|
---|
| 121 |
|
---|
| 122 | PCUT_ASSERT_INT_EQUALS(1, test_resp.clicked_cnt);
|
---|
| 123 |
|
---|
| 124 | ui_clickmatic_destroy(clickmatic);
|
---|
| 125 | ui_destroy(ui);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | static void test_clicked(ui_clickmatic_t *clickmatic, void *arg)
|
---|
| 129 | {
|
---|
| 130 | test_resp_t *test_resp = (test_resp_t *)arg;
|
---|
| 131 |
|
---|
| 132 | ++test_resp->clicked_cnt;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | PCUT_EXPORT(clickmatic);
|
---|