BA / Mbed OS BaBoRo1
Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /*
borlanic 0:380207fcb5c1 2 * Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
borlanic 0:380207fcb5c1 3 * SPDX-License-Identifier: Apache-2.0
borlanic 0:380207fcb5c1 4 *
borlanic 0:380207fcb5c1 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
borlanic 0:380207fcb5c1 6 * not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 7 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 8 *
borlanic 0:380207fcb5c1 9 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 10 *
borlanic 0:380207fcb5c1 11 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
borlanic 0:380207fcb5c1 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 14 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 15 * limitations under the License.
borlanic 0:380207fcb5c1 16 */
borlanic 0:380207fcb5c1 17
borlanic 0:380207fcb5c1 18 #ifndef MBED_CONF_APP_CONNECT_STATEMENT
borlanic 0:380207fcb5c1 19 #error [NOT_SUPPORTED] No network configuration found for this target.
borlanic 0:380207fcb5c1 20 #endif
borlanic 0:380207fcb5c1 21
borlanic 0:380207fcb5c1 22 #include "mbed.h"
borlanic 0:380207fcb5c1 23 #include "greentea-client/test_env.h"
borlanic 0:380207fcb5c1 24 #include "unity.h"
borlanic 0:380207fcb5c1 25 #include "utest.h"
borlanic 0:380207fcb5c1 26
borlanic 0:380207fcb5c1 27 using namespace utest::v1;
borlanic 0:380207fcb5c1 28
borlanic 0:380207fcb5c1 29
borlanic 0:380207fcb5c1 30 // IP parsing verification
borlanic 0:380207fcb5c1 31 void test_ip_accept(const char *string, nsapi_addr_t addr) {
borlanic 0:380207fcb5c1 32 SocketAddress address;
borlanic 0:380207fcb5c1 33 TEST_ASSERT(address.set_ip_address(string));
borlanic 0:380207fcb5c1 34 TEST_ASSERT(address == SocketAddress(addr));
borlanic 0:380207fcb5c1 35 }
borlanic 0:380207fcb5c1 36
borlanic 0:380207fcb5c1 37 template <const char *string>
borlanic 0:380207fcb5c1 38 void test_ip_reject() {
borlanic 0:380207fcb5c1 39 SocketAddress address;
borlanic 0:380207fcb5c1 40 TEST_ASSERT(!address.set_ip_address(string));
borlanic 0:380207fcb5c1 41 TEST_ASSERT(!address);
borlanic 0:380207fcb5c1 42 }
borlanic 0:380207fcb5c1 43
borlanic 0:380207fcb5c1 44 #define TEST_IP_ACCEPT(name, string, ...) \
borlanic 0:380207fcb5c1 45 void name() { \
borlanic 0:380207fcb5c1 46 nsapi_addr_t addr = __VA_ARGS__; \
borlanic 0:380207fcb5c1 47 test_ip_accept(string, addr); \
borlanic 0:380207fcb5c1 48 }
borlanic 0:380207fcb5c1 49
borlanic 0:380207fcb5c1 50 #define TEST_IP_REJECT(name, string) \
borlanic 0:380207fcb5c1 51 void name() { \
borlanic 0:380207fcb5c1 52 test_ip_reject(string); \
borlanic 0:380207fcb5c1 53 }
borlanic 0:380207fcb5c1 54
borlanic 0:380207fcb5c1 55
borlanic 0:380207fcb5c1 56 // Test cases
borlanic 0:380207fcb5c1 57 TEST_IP_ACCEPT(test_simple_ipv4_address,
borlanic 0:380207fcb5c1 58 "12.34.56.78",
borlanic 0:380207fcb5c1 59 {NSAPI_IPv4,{12,34,56,78}})
borlanic 0:380207fcb5c1 60 TEST_IP_ACCEPT(test_left_weighted_ipv4_address,
borlanic 0:380207fcb5c1 61 "255.0.0.0",
borlanic 0:380207fcb5c1 62 {NSAPI_IPv4,{255,0,0,0}})
borlanic 0:380207fcb5c1 63 TEST_IP_ACCEPT(test_right_weighted_ipv4_address,
borlanic 0:380207fcb5c1 64 "0.0.0.255",
borlanic 0:380207fcb5c1 65 {NSAPI_IPv4,{0,0,0,255}})
borlanic 0:380207fcb5c1 66 TEST_IP_ACCEPT(test_null_ipv4_address,
borlanic 0:380207fcb5c1 67 "0.0.0.0",
borlanic 0:380207fcb5c1 68 {NSAPI_IPv4,{0,0,0,0}})
borlanic 0:380207fcb5c1 69
borlanic 0:380207fcb5c1 70 TEST_IP_ACCEPT(test_simple_ipv6_address,
borlanic 0:380207fcb5c1 71 "1234:5678:9abc:def0:1234:5678:9abc:def0",
borlanic 0:380207fcb5c1 72 {NSAPI_IPv6,{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
borlanic 0:380207fcb5c1 73 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}})
borlanic 0:380207fcb5c1 74 TEST_IP_ACCEPT(test_left_weighted_ipv6_address,
borlanic 0:380207fcb5c1 75 "1234:5678::",
borlanic 0:380207fcb5c1 76 {NSAPI_IPv6,{0x12,0x34,0x56,0x78,0x00,0x00,0x00,0x00,
borlanic 0:380207fcb5c1 77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}})
borlanic 0:380207fcb5c1 78 TEST_IP_ACCEPT(test_right_weighted_ipv6_address,
borlanic 0:380207fcb5c1 79 "::1234:5678",
borlanic 0:380207fcb5c1 80 {NSAPI_IPv6,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
borlanic 0:380207fcb5c1 81 0x00,0x00,0x00,0x00,0x12,0x34,0x56,0x78}})
borlanic 0:380207fcb5c1 82 TEST_IP_ACCEPT(test_hollowed_ipv6_address,
borlanic 0:380207fcb5c1 83 "1234:5678::9abc:def8",
borlanic 0:380207fcb5c1 84 {NSAPI_IPv6,{0x12,0x34,0x56,0x78,0x00,0x00,0x00,0x00,
borlanic 0:380207fcb5c1 85 0x00,0x00,0x00,0x00,0x9a,0xbc,0xde,0xf8}})
borlanic 0:380207fcb5c1 86 TEST_IP_ACCEPT(test_null_ipv6_address,
borlanic 0:380207fcb5c1 87 "::",
borlanic 0:380207fcb5c1 88 {NSAPI_IPv6,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
borlanic 0:380207fcb5c1 89 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}})
borlanic 0:380207fcb5c1 90
borlanic 0:380207fcb5c1 91
borlanic 0:380207fcb5c1 92 // Test setup
borlanic 0:380207fcb5c1 93 utest::v1::status_t test_setup(const size_t number_of_cases) {
borlanic 0:380207fcb5c1 94 GREENTEA_SETUP(10, "default_auto");
borlanic 0:380207fcb5c1 95 return verbose_test_setup_handler(number_of_cases);
borlanic 0:380207fcb5c1 96 }
borlanic 0:380207fcb5c1 97
borlanic 0:380207fcb5c1 98 Case cases[] = {
borlanic 0:380207fcb5c1 99 Case("Simple IPv4 address", test_simple_ipv4_address),
borlanic 0:380207fcb5c1 100 Case("Left-weighted IPv4 address", test_left_weighted_ipv4_address),
borlanic 0:380207fcb5c1 101 Case("Right-weighted IPv4 address", test_right_weighted_ipv4_address),
borlanic 0:380207fcb5c1 102 Case("Null IPv4 address", test_null_ipv4_address),
borlanic 0:380207fcb5c1 103
borlanic 0:380207fcb5c1 104 Case("Simple IPv6 address", test_simple_ipv6_address),
borlanic 0:380207fcb5c1 105 Case("Left-weighted IPv6 address", test_left_weighted_ipv6_address),
borlanic 0:380207fcb5c1 106 Case("Right-weighted IPv6 address", test_right_weighted_ipv6_address),
borlanic 0:380207fcb5c1 107 Case("Hollowed IPv6 address", test_hollowed_ipv6_address),
borlanic 0:380207fcb5c1 108 Case("Null IPv6 address", test_null_ipv6_address),
borlanic 0:380207fcb5c1 109 };
borlanic 0:380207fcb5c1 110
borlanic 0:380207fcb5c1 111 Specification specification(test_setup, cases);
borlanic 0:380207fcb5c1 112
borlanic 0:380207fcb5c1 113 int main() {
borlanic 0:380207fcb5c1 114 return !Harness::run(specification);
borlanic 0:380207fcb5c1 115 }