Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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