]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_get_self.c
53a083350ba2e8cafca8f60eaa97a7166a9efc07
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_get_self.c
1 /*
2     test_cases_get_port.c -- Execution of specific meshlink black box test cases
3     Copyright (C) 2018  Guus Sliepen <guus@meshlink.io>
4
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.
9
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.
14
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.
18 */
19
20 #include "execute_tests.h"
21 #include "test_cases_get_self.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <setjmp.h>
28 #include <cmocka.h>
29 #include <assert.h>
30 #include <string.h>
31
32 static void test_case_mesh_get_self_01(void **state);
33 static bool test_steps_mesh_get_self_01(void);
34 static void test_case_mesh_get_self_02(void **state);
35 static bool test_steps_mesh_get_self_02(void);
36
37 /* State structure for meshlink_get_self Test Case #1 */
38 static black_box_state_t test_mesh_get_self_01_state = {
39         .test_case_name = "test_case_mesh_get_self_01",
40 };
41
42 /* State structure for meshlink_get_self Test Case #2 */
43 static black_box_state_t test_mesh_get_self_02_state = {
44         .test_case_name = "test_case_mesh_get_self_02",
45 };
46
47 /* Execute meshlink_get_self Test Case # 1 */
48 static void test_case_mesh_get_self_01(void **state) {
49         execute_test(test_steps_mesh_get_self_01, state);
50 }
51
52 /* Test Steps for meshlink_get_self Test Case # 1
53
54     Test Steps:
55     1. Open node instance
56     2. Get node's self handle
57
58     Expected Result:
59     node handle of it's own is obtained
60 */
61 static bool test_steps_mesh_get_self_01(void) {
62         meshlink_handle_t *mesh = meshlink_open("self_conf", "foo", "test", DEV_CLASS_STATIONARY);
63         assert(mesh);
64
65         assert(meshlink_start(mesh));
66         meshlink_node_t *dest_node = meshlink_get_self(mesh);
67         assert_int_not_equal(dest_node, NULL);
68
69         if(strcmp(dest_node->name, "foo")) {
70                 return false;
71         }
72
73         meshlink_close(mesh);
74         meshlink_destroy("self_conf");
75         return true;
76
77 }
78
79 /* Execute meshlink_get_self Test Case # 2 */
80 static void test_case_mesh_get_self_02(void **state) {
81         execute_test(test_steps_mesh_get_self_02, state);
82 }
83
84 /* Test Steps for meshlink_get_self Test Case # 2
85
86     Test Steps:
87     1. Open NUT(Node Under Test) & bar meshes.
88     2. Export and Import mutually
89
90     Expected Result:
91     Both the nodes imports successfully
92 */
93 static bool test_steps_mesh_get_self_02(void) {
94         meshlink_node_t *dest_node = meshlink_get_self(NULL);
95         assert_int_equal(dest_node, NULL);
96
97         return true;
98 }
99
100 int test_meshlink_get_self(void) {
101         const struct CMUnitTest blackbox_get_self_tests[] = {
102                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_self_01, NULL, NULL,
103                                 (void *)&test_mesh_get_self_01_state),
104                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_self_02, NULL, NULL,
105                                 (void *)&test_mesh_get_self_02_state)
106         };
107
108         total_tests += sizeof(blackbox_get_self_tests) / sizeof(blackbox_get_self_tests[0]);
109
110         return cmocka_run_group_tests(blackbox_get_self_tests, NULL, NULL);
111 }