|
| 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 "NWK_INTERFACE/Include/protocol.h" |
| 24 | +#include "6LoWPAN/ws/ws_common.h" |
| 25 | + |
| 26 | +/* Stubs */ |
| 27 | +#include "protocol_core_stub.h" |
| 28 | +#include "ws_common_stub.h" |
| 29 | + |
| 30 | +bool test_ws_management_node_init() |
| 31 | +{ |
| 32 | + protocol_interface_info_entry_t entry; |
| 33 | + ws_info_t ws_info_entry; |
| 34 | + char nw_name[] = "NW-NAME"; |
| 35 | + fhss_timer_t fhss_timer_entry; |
| 36 | + |
| 37 | + memset(&entry, 0, sizeof(protocol_interface_info_entry_t)); |
| 38 | + memset(&ws_info_entry, 0, sizeof(ws_info_t)); |
| 39 | + memset(&fhss_timer_entry, 0, sizeof(fhss_timer_t)); |
| 40 | + |
| 41 | + /* No interface info entry found */ |
| 42 | + if (-1 != ws_management_node_init(1, NULL, NULL)) { |
| 43 | + return false; |
| 44 | + } |
| 45 | + |
| 46 | + protocol_core_stub.entry_ptr = &entry; |
| 47 | + |
| 48 | + /* No ws_info found */ |
| 49 | + if (-1 != ws_management_node_init(1, NULL, NULL)) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + entry.ws_info = &ws_info_entry; |
| 54 | + |
| 55 | + /* NULL pointers as a parameters */ |
| 56 | + if (-2 != ws_management_node_init(1, NULL, NULL)) { |
| 57 | + return false; |
| 58 | + } |
| 59 | + |
| 60 | + /* NULL pointers as a FHSS info */ |
| 61 | + if (-2 != ws_management_node_init(1, nw_name, NULL)) { |
| 62 | + return false; |
| 63 | + } |
| 64 | + |
| 65 | + /* NULL pointers as a network name */ |
| 66 | + if (-2 != ws_management_node_init(1, NULL, fhss_timer_entry)) { |
| 67 | + return false; |
| 68 | + } |
| 69 | + |
| 70 | + /* OK case */ |
| 71 | + if (0 != ws_management_node_init(1, nw_name, fhss_timer_entry)) { |
| 72 | + return false; |
| 73 | + } |
| 74 | + |
| 75 | + return true; |
| 76 | +} |
| 77 | + |
| 78 | +bool test_ws_management_regulatory_domain_set() |
| 79 | +{ |
| 80 | + protocol_interface_info_entry_t entry; |
| 81 | + ws_info_t ws_info_entry; |
| 82 | + |
| 83 | + memset(&entry, 0, sizeof(protocol_interface_info_entry_t)); |
| 84 | + memset(&ws_info_entry, 0, sizeof(ws_info_t)); |
| 85 | + |
| 86 | + protocol_core_stub.entry_ptr = NULL; |
| 87 | + |
| 88 | + /* No protocol info entry */ |
| 89 | + if (-1 != ws_management_regulatory_domain_set(1,0,0,0)) { |
| 90 | + return false; |
| 91 | + } |
| 92 | + |
| 93 | + protocol_core_stub.entry_ptr = &entry; |
| 94 | + |
| 95 | + /* No ws_info found */ |
| 96 | + if (-1 != ws_management_regulatory_domain_set(1,0,0,0)) { |
| 97 | + return false; |
| 98 | + } |
| 99 | + |
| 100 | + entry.ws_info = &ws_info_entry; |
| 101 | + |
| 102 | + ws_common_stub.int8_value = -1; |
| 103 | + |
| 104 | + /* ws_common_regulatory_domain_config() fails */ |
| 105 | + if (-1 != ws_management_regulatory_domain_set(1,0,0,0)) { |
| 106 | + return false; |
| 107 | + } |
| 108 | + |
| 109 | + ws_common_stub.int8_value = 0; |
| 110 | + |
| 111 | + /* OK case */ |
| 112 | + if (0 != ws_management_regulatory_domain_set(1,0,0,0)) { |
| 113 | + return false; |
| 114 | + } |
| 115 | + |
| 116 | + return true; |
| 117 | +} |
| 118 | + |
| 119 | +bool test_ws_management_channel_mask_set() |
| 120 | +{ |
| 121 | + protocol_interface_info_entry_t entry; |
| 122 | + ws_info_t ws_info_entry; |
| 123 | + uint32_t channel_mask[8] = {0}; |
| 124 | + |
| 125 | + memset(&entry, 0, sizeof(protocol_interface_info_entry_t)); |
| 126 | + memset(&ws_info_entry, 0, sizeof(ws_info_t)); |
| 127 | + |
| 128 | + protocol_core_stub.entry_ptr = NULL; |
| 129 | + |
| 130 | + /* No protocol info entry */ |
| 131 | + if (-1 != ws_management_channel_mask_set(1, channel_mask)) { |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + protocol_core_stub.entry_ptr = &entry; |
| 136 | + |
| 137 | + /* No ws_info found */ |
| 138 | + if (-1 != ws_management_channel_mask_set(1, channel_mask)) { |
| 139 | + return false; |
| 140 | + } |
| 141 | + |
| 142 | + entry.ws_info = &ws_info_entry; |
| 143 | + |
| 144 | + /* OK case */ |
| 145 | + if (0 != ws_management_channel_mask_set(1, channel_mask)) { |
| 146 | + return false; |
| 147 | + } |
| 148 | + return true; |
| 149 | +} |
| 150 | + |
| 151 | +bool test_ws_management_channel_plan_set() |
| 152 | +{ |
| 153 | + protocol_interface_info_entry_t entry; |
| 154 | + ws_info_t ws_info_entry; |
| 155 | + |
| 156 | + memset(&entry, 0, sizeof(protocol_interface_info_entry_t)); |
| 157 | + memset(&ws_info_entry, 0, sizeof(ws_info_t)); |
| 158 | + |
| 159 | + protocol_core_stub.entry_ptr = NULL; |
| 160 | + |
| 161 | + /* No protocol info entry */ |
| 162 | + if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0)) { |
| 163 | + return false; |
| 164 | + } |
| 165 | + |
| 166 | + protocol_core_stub.entry_ptr = &entry; |
| 167 | + |
| 168 | + /* No ws_info found */ |
| 169 | + if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0)) { |
| 170 | + return false; |
| 171 | + } |
| 172 | + |
| 173 | + entry.ws_info = &ws_info_entry; |
| 174 | + |
| 175 | + /* OK case */ |
| 176 | + if (0 != ws_management_channel_plan_set(1,0,0,0,0,0)) { |
| 177 | + return false; |
| 178 | + } |
| 179 | + |
| 180 | + return true; |
| 181 | +} |
| 182 | + |
| 183 | +bool test_ws_management_fhss_timing_configure() |
| 184 | +{ |
| 185 | + protocol_interface_info_entry_t entry; |
| 186 | + ws_info_t ws_info_entry; |
| 187 | + |
| 188 | + memset(&entry, 0, sizeof(protocol_interface_info_entry_t)); |
| 189 | + memset(&ws_info_entry, 0, sizeof(ws_info_t)); |
| 190 | + |
| 191 | + protocol_core_stub.entry_ptr = NULL; |
| 192 | + |
| 193 | + /* No protocol info entry */ |
| 194 | + if (-1 != ws_management_fhss_timing_configure(1,0,0,0)) |
| 195 | + { |
| 196 | + return false; |
| 197 | + } |
| 198 | + |
| 199 | + protocol_core_stub.entry_ptr = &entry; |
| 200 | + |
| 201 | + /* No ws_info found */ |
| 202 | + if (-1 != ws_management_fhss_timing_configure(1,0,0,0)) |
| 203 | + { |
| 204 | + return false; |
| 205 | + } |
| 206 | + |
| 207 | + entry.ws_info = &ws_info_entry; |
| 208 | + |
| 209 | + /* OK case */ |
| 210 | + if (0 != ws_management_fhss_timing_configure(1,0,0,0)) |
| 211 | + { |
| 212 | + return false; |
| 213 | + } |
| 214 | + |
| 215 | + return true; |
| 216 | +} |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
0 commit comments