2 test_cases_get_fingerprint.c -- Execution of specific meshlink black box test cases
3 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "execute_tests.h"
25 #include "test_cases.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
29 #include "test_cases_get_fingerprint.h"
37 /* Modify this to change the logging level of Meshlink */
38 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
40 static void test_case_get_fingerprint_cb_01(void **state);
41 static bool test_get_fingerprint_cb_01(void);
42 static void test_case_get_fingerprint_cb_02(void **state);
43 static bool test_get_fingerprint_cb_02(void);
44 static void test_case_get_fingerprint_cb_03(void **state);
45 static bool test_get_fingerprint_cb_03(void);
47 /* State structure for get_fingerprint Test Case #1 */
48 static black_box_state_t test_case_get_fingerprint_cb_01_state = {
49 .test_case_name = "test_case_get_fingerprint_cb_01",
51 /* State structure for get_fingerprint Test Case #2 */
52 static black_box_state_t test_case_get_fingerprint_cb_02_state = {
53 .test_case_name = "test_case_get_fingerprint_cb_02",
55 /* State structure for get_fingerprint Test Case #3 */
56 static black_box_state_t test_case_get_fingerprint_cb_03_state = {
57 .test_case_name = "test_case_get_fingerprint_cb_03",
60 /* Execute get_fingerprint Test Case # 1 - Valid Case of obtaing publickey of NUT */
61 static void test_case_get_fingerprint_cb_01(void **state) {
62 execute_test(test_get_fingerprint_cb_01, state);
64 /* Test Steps for get_fingerprint Test Case # 1 - Valid case
67 1. Run NUT(Node Under Test)
68 2. Get node handle for ourself(for NUT) and obtain fingerprint
71 Obtain fingerprint of NUT successfully.
73 static bool test_get_fingerprint_cb_01(void) {
74 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
76 /* Create meshlink instance */
77 meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1);
79 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
81 meshlink_node_t *node = meshlink_get_self(mesh_handle);
84 char *fp = meshlink_get_fingerprint(mesh_handle, node);
85 assert_int_not_equal(fp, NULL);
87 meshlink_close(mesh_handle);
88 assert(meshlink_destroy("getfingerprintconf"));
93 /* Execute get_fingerprint Test Case # 2 - Invalid Case - trying t0 obtain publickey of a node in a
94 mesh by passing NULL as mesh handle argument*/
95 static void test_case_get_fingerprint_cb_02(void **state) {
96 execute_test(test_get_fingerprint_cb_02, state);
99 /* Test Steps for get_fingerprint Test Case # 2 - Invalid case
102 1. Run NUT(Node Under Test)
103 2. Get node handle for ourself(for NUT)
104 3. Obtain fingerprint by passing NULL as mesh handle
107 Return NULL by reporting error successfully.
109 static bool test_get_fingerprint_cb_02(void) {
110 /* Set up logging for Meshlink */
111 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
113 /* Create meshlink instance */
114 PRINT_TEST_CASE_MSG("Opening NUT\n");
115 meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1);
118 /* Set up logging for Meshlink with the newly acquired Mesh Handle */
119 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
120 /* Getting node handle for itself */
121 meshlink_node_t *node = meshlink_get_self(mesh_handle);
122 assert(node != NULL);
124 /* passing NULL as mesh handle for meshlink_get_fingerprint API */
125 char *fp = meshlink_get_fingerprint(NULL, node);
126 assert_int_equal(fp, NULL);
128 meshlink_close(mesh_handle);
129 assert(meshlink_destroy("getfingerprintconf"));
134 /* Execute get_fingerprint Test Case # 3 - Invalid Case - trying t0 obtain publickey of a node in a
135 mesh by passing NULL as node handle argument */
136 static void test_case_get_fingerprint_cb_03(void **state) {
137 execute_test(test_get_fingerprint_cb_03, state);
139 /* Test Steps for get_fingerprint Test Case # 3 - Invalid case
142 1. Run NUT(Node Under Test)
143 2. Get node handle for ourself(for NUT)
144 3. Obtain fingerprint by passing NULL as node handle
147 Return NULL by reporting error successfully.
149 static bool test_get_fingerprint_cb_03(void) {
150 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
152 /* Create meshlink instance */
153 meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1);
155 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
157 char *fp = meshlink_get_fingerprint(mesh_handle, NULL);
158 assert_int_equal(fp, NULL);
160 meshlink_close(mesh_handle);
161 assert(meshlink_destroy("getfingerprintconf"));
166 int test_meshlink_get_fingerprint(void) {
167 const struct CMUnitTest blackbox_get_fingerprint_tests[] = {
168 cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_01, NULL, NULL,
169 (void *)&test_case_get_fingerprint_cb_01_state),
170 cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_02, NULL, NULL,
171 (void *)&test_case_get_fingerprint_cb_02_state),
172 cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_03, NULL, NULL,
173 (void *)&test_case_get_fingerprint_cb_03_state)
176 total_tests += sizeof(blackbox_get_fingerprint_tests) / sizeof(blackbox_get_fingerprint_tests[0]);
178 return cmocka_run_group_tests(blackbox_get_fingerprint_tests, NULL, NULL);