Skip to content

Commit 47458c8

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
WS IE Lib unit test and fixed mac ie lib stub
1 parent 6b6e509 commit 47458c8

File tree

6 files changed

+421
-0
lines changed

6 files changed

+421
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = ws_ie_lib_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/6LoWPAN/ws/ws_ie_lib.c
8+
9+
TEST_SRC_FILES = \
10+
main.cpp \
11+
ws_ie_libtest.cpp \
12+
test_ws_ie_lib.c \
13+
../../stub/common_functions_stub.c \
14+
../../stub/nsdynmemLIB_stub.c \
15+
../../stub/mbed_trace_stub.c \
16+
../../stub/platform_stub.c \
17+
../../stub/address_stub.c \
18+
../../stub/etx_stub.c \
19+
../../stub/protocol_stats_stub.c \
20+
../../stub/randLIB_stub.c \
21+
../../stub/mesh_stub.c \
22+
../../stub/nsdynmemLIB_stub.c \
23+
../../stub/mbed_trace_stub.c \
24+
../../stub/buffer_dyn_stub.c \
25+
../../stub/protocol_core_stub.c \
26+
../../stub/socket_stub.c \
27+
../../stub/iphc_decompress_stub.c \
28+
../../stub/mac_ie_lib_stub.c \
29+
30+
31+
include ../../MakefileWorker.mk
32+
33+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
34+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2016, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "CppUTest/CommandLineTestRunner.h"
19+
#include "CppUTest/TestPlugin.h"
20+
#include "CppUTest/TestRegistry.h"
21+
#include "CppUTestExt/MockSupportPlugin.h"
22+
int main(int ac, char** av)
23+
{
24+
return CommandLineTestRunner::RunAllTests(ac, av);
25+
}
26+
27+
IMPORT_TEST_GROUP(ws_ie_lib);
28+
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "nsconfig.h"
18+
#include <string.h>
19+
#include "ns_types.h"
20+
#include "ns_list.h"
21+
#include "ns_trace.h"
22+
#include "nsdynmemLIB.h"
23+
#include "common_functions.h"
24+
#include "mac_common_defines.h"
25+
#include "6LoWPAN/ws/ws_ie_lib.h"
26+
#include "6LoWPAN/ws/ws_common_defines.h"
27+
#include "common_functions_stub.h"
28+
29+
bool test_ws_ie_lib_header()
30+
{
31+
uint8_t test_buf[100];
32+
33+
uint8_t vendor[10];
34+
memset(vendor, 4, 10);
35+
36+
uint8_t *ptr = ws_wh_utt_write(test_buf, 1);
37+
if (ptr != &test_buf[7] || test_buf[3] != 1 || test_buf[2] != WH_IE_UTT_TYPE) {
38+
return false;
39+
}
40+
ptr = ws_wh_bt_write(test_buf);
41+
42+
if (ptr != &test_buf[8] || test_buf[2] != WH_IE_BT_TYPE) {
43+
return false;
44+
}
45+
46+
ptr = ws_wh_fc_write(test_buf, 10);
47+
if (ptr != &test_buf[4] || test_buf[3] != 10 || test_buf[2] != WH_IE_FC_TYPE) {
48+
return false;
49+
}
50+
51+
ptr = ws_wh_rsl_write(test_buf, 20);
52+
if (ptr != &test_buf[4] || test_buf[3] != 20 || test_buf[2] != WH_IE_RSL_TYPE) {
53+
return false;
54+
}
55+
56+
ptr = ws_wh_vh_write(test_buf, NULL, 0);
57+
if (ptr != &test_buf[3] || test_buf[2] != WH_IE_VH_TYPE) {
58+
return false;
59+
}
60+
61+
ptr = ws_wh_vh_write(test_buf, vendor, 10);
62+
if (ptr != &test_buf[13] || test_buf[2] != WH_IE_VH_TYPE || memcmp(&test_buf[3],vendor, 10 ) ) {
63+
return false;
64+
}
65+
66+
67+
return true;
68+
}
69+
70+
bool test_ws_ie_lib_payload()
71+
{
72+
uint8_t test_buf[35];
73+
ws_pan_information_t pan_configuration;
74+
75+
uint8_t vendor[32];
76+
memset(vendor, 4, 32);
77+
uint8_t * ptr = ws_wp_base_write(test_buf, 10);
78+
if (ptr != &test_buf[2]) {
79+
return false;
80+
}
81+
82+
ptr = ws_wp_nested_us_write(test_buf,vendor, 10);
83+
if (ptr != &test_buf[12] || memcmp(&test_buf[2],vendor, 10 ) ) {
84+
return false;
85+
}
86+
memset(vendor, 5, 10);
87+
88+
ptr = ws_wp_nested_bs_write(test_buf,vendor, 10);
89+
if (ptr != &test_buf[12] || memcmp(&test_buf[2],vendor, 10 ) ) {
90+
return false;
91+
}
92+
memset(vendor, 6, 10);
93+
94+
ptr = ws_wp_nested_vp_write(test_buf,vendor, 10);
95+
if (ptr != &test_buf[12] || memcmp(&test_buf[2],vendor, 10 ) ) {
96+
return false;
97+
}
98+
memset(vendor, 7, 10);
99+
100+
ptr = ws_wp_nested_pan_info_write(test_buf, &pan_configuration);
101+
if (ptr != &test_buf[7]) {
102+
return false;
103+
}
104+
105+
ptr = ws_wp_nested_pan_info_write(test_buf, NULL);
106+
if (ptr != &test_buf[2]) {
107+
return false;
108+
}
109+
ptr = ws_wp_nested_netname_write(test_buf, vendor, 20);
110+
if (ptr != &test_buf[22] || memcmp(&test_buf[2],vendor, 20 )) {
111+
return false;
112+
}
113+
ptr = ws_wp_nested_pan_ver_write(test_buf, NULL);
114+
if (ptr != &test_buf[2]) {
115+
return false;
116+
}
117+
118+
ptr = ws_wp_nested_pan_ver_write(test_buf, &pan_configuration);
119+
if (ptr != &test_buf[4]) {
120+
return false;
121+
}
122+
123+
ptr = ws_wp_nested_gtkhash_write(test_buf, vendor, 32);
124+
if (ptr != &test_buf[34] || memcmp(&test_buf[2],vendor, 32 )) {
125+
return false;
126+
}
127+
128+
return true;
129+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef TEST_WS_IE_LIB_H_
19+
#define TEST_WS_IE_LIB_H_
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
#include <stdbool.h>
26+
27+
bool test_ws_ie_lib_header();
28+
29+
bool test_ws_ie_lib_payload();
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
36+
37+
#endif /* TEST_WS_IE_LIB_H_ */
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "CppUTest/TestHarness.h"
19+
#include "test_ws_ie_lib.h"
20+
21+
TEST_GROUP(ws_ie_lib)
22+
{
23+
void setup()
24+
{
25+
}
26+
27+
void teardown()
28+
{
29+
}
30+
};
31+
32+
TEST(ws_ie_lib, test_ws_ie_lib_header)
33+
{
34+
CHECK(test_ws_ie_lib_header());
35+
}
36+
37+
TEST(ws_ie_lib, test_ws_ie_lib_payload)
38+
{
39+
CHECK(test_ws_ie_lib_payload());
40+
}
41+
42+
43+
44+
45+

0 commit comments

Comments
 (0)