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.
20 #include "execute_tests.h"
21 #include "test_cases.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
25 #include "test_cases_get_fingerprint.h"
33 /* Modify this to change the logging level of Meshlink */
34 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
36 static void test_case_get_fingerprint_cb_01(void **state);
37 static bool test_get_fingerprint_cb_01(void);
38 static void test_case_get_fingerprint_cb_02(void **state);
39 static bool test_get_fingerprint_cb_02(void);
40 static void test_case_get_fingerprint_cb_03(void **state);
41 static bool test_get_fingerprint_cb_03(void);
43 /* State structure for get_fingerprint Test Case #1 */
44 static black_box_state_t test_case_get_fingerprint_cb_01_state = {
45 .test_case_name = "test_case_get_fingerprint_cb_01",
47 /* State structure for get_fingerprint Test Case #2 */
48 static black_box_state_t test_case_get_fingerprint_cb_02_state = {
49 .test_case_name = "test_case_get_fingerprint_cb_02",
51 /* State structure for get_fingerprint Test Case #3 */
52 static black_box_state_t test_case_get_fingerprint_cb_03_state = {
53 .test_case_name = "test_case_get_fingerprint_cb_03",
56 /* Execute get_fingerprint Test Case # 1 - Valid Case of obtaing publickey of NUT */
57 static void test_case_get_fingerprint_cb_01(void **state) {
58 execute_test(test_get_fingerprint_cb_01, state);
60 /* Test Steps for get_fingerprint Test Case # 1 - Valid case
63 1. Run NUT(Node Under Test)
64 2. Get node handle for ourself(for NUT) and obtain fingerprint
67 Obtain fingerprint of NUT successfully.
69 static bool test_get_fingerprint_cb_01(void) {
70 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
72 /* Create meshlink instance */
73 meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1);
75 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
77 meshlink_node_t *node = meshlink_get_self(mesh_handle);
80 char *fp = meshlink_get_fingerprint(mesh_handle, node);
81 assert_int_not_equal(fp, NULL);
83 meshlink_close(mesh_handle);
84 meshlink_destroy("getfingerprintconf");
89 /* Execute get_fingerprint Test Case # 2 - Invalid Case - trying t0 obtain publickey of a node in a
90 mesh by passing NULL as mesh handle argument*/
91 static void test_case_get_fingerprint_cb_02(void **state) {
92 execute_test(test_get_fingerprint_cb_02, state);
95 /* Test Steps for get_fingerprint Test Case # 2 - Invalid case
98 1. Run NUT(Node Under Test)
99 2. Get node handle for ourself(for NUT)
100 3. Obtain fingerprint by passing NULL as mesh handle
103 Return NULL by reporting error successfully.
105 static bool test_get_fingerprint_cb_02(void) {
106 /* Set up logging for Meshlink */
107 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
109 /* Create meshlink instance */
110 PRINT_TEST_CASE_MSG("Opening NUT\n");
111 meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1);
114 /* Set up logging for Meshlink with the newly acquired Mesh Handle */
115 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
116 /* Getting node handle for itself */
117 meshlink_node_t *node = meshlink_get_self(mesh_handle);
118 assert(node != NULL);
120 /* passing NULL as mesh handle for meshlink_get_fingerprint API */
121 char *fp = meshlink_get_fingerprint(NULL, node);
122 assert_int_equal(fp, NULL);
124 meshlink_close(mesh_handle);
125 meshlink_destroy("getfingerprintconf");
130 /* Execute get_fingerprint Test Case # 3 - Invalid Case - trying t0 obtain publickey of a node in a
131 mesh by passing NULL as node handle argument */
132 static void test_case_get_fingerprint_cb_03(void **state) {
133 execute_test(test_get_fingerprint_cb_03, state);
135 /* Test Steps for get_fingerprint Test Case # 3 - Invalid case
138 1. Run NUT(Node Under Test)
139 2. Get node handle for ourself(for NUT)
140 3. Obtain fingerprint by passing NULL as node handle
143 Return NULL by reporting error successfully.
145 static bool test_get_fingerprint_cb_03(void) {
146 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
148 /* Create meshlink instance */
149 meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1);
151 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
153 char *fp = meshlink_get_fingerprint(mesh_handle, NULL);
154 assert_int_equal(fp, NULL);
156 meshlink_close(mesh_handle);
157 meshlink_destroy("getfingerprintconf");
162 int test_meshlink_get_fingerprint(void) {
163 const struct CMUnitTest blackbox_get_fingerprint_tests[] = {
164 cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_01, NULL, NULL,
165 (void *)&test_case_get_fingerprint_cb_01_state),
166 cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_02, NULL, NULL,
167 (void *)&test_case_get_fingerprint_cb_02_state),
168 cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_03, NULL, NULL,
169 (void *)&test_case_get_fingerprint_cb_03_state)
172 total_tests += sizeof(blackbox_get_fingerprint_tests) / sizeof(blackbox_get_fingerprint_tests[0]);
174 return cmocka_run_group_tests(blackbox_get_fingerprint_tests, NULL, NULL);