5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 #include "mbed.h"
group-onsemi 0:098463de4c5d 2 #include "greentea-client/test_env.h"
group-onsemi 0:098463de4c5d 3 #include "unity.h"
group-onsemi 0:098463de4c5d 4 #include "utest.h"
group-onsemi 0:098463de4c5d 5
group-onsemi 0:098463de4c5d 6 using namespace utest::v1;
group-onsemi 0:098463de4c5d 7
group-onsemi 0:098463de4c5d 8
group-onsemi 0:098463de4c5d 9 // IP parsing verification
group-onsemi 0:098463de4c5d 10 void test_ip_accept(const char *string, nsapi_addr_t addr) {
group-onsemi 0:098463de4c5d 11 SocketAddress address;
group-onsemi 0:098463de4c5d 12 TEST_ASSERT(address.set_ip_address(string));
group-onsemi 0:098463de4c5d 13 TEST_ASSERT(address == SocketAddress(addr));
group-onsemi 0:098463de4c5d 14 }
group-onsemi 0:098463de4c5d 15
group-onsemi 0:098463de4c5d 16 template <const char *string>
group-onsemi 0:098463de4c5d 17 void test_ip_reject() {
group-onsemi 0:098463de4c5d 18 SocketAddress address;
group-onsemi 0:098463de4c5d 19 TEST_ASSERT(!address.set_ip_address(string));
group-onsemi 0:098463de4c5d 20 TEST_ASSERT(!address);
group-onsemi 0:098463de4c5d 21 }
group-onsemi 0:098463de4c5d 22
group-onsemi 0:098463de4c5d 23 #define TEST_IP_ACCEPT(name, string, ...) \
group-onsemi 0:098463de4c5d 24 void name() { \
group-onsemi 0:098463de4c5d 25 nsapi_addr_t addr = __VA_ARGS__; \
group-onsemi 0:098463de4c5d 26 test_ip_accept(string, addr); \
group-onsemi 0:098463de4c5d 27 }
group-onsemi 0:098463de4c5d 28
group-onsemi 0:098463de4c5d 29 #define TEST_IP_REJECT(name, string) \
group-onsemi 0:098463de4c5d 30 void name() { \
group-onsemi 0:098463de4c5d 31 test_ip_reject(string); \
group-onsemi 0:098463de4c5d 32 }
group-onsemi 0:098463de4c5d 33
group-onsemi 0:098463de4c5d 34
group-onsemi 0:098463de4c5d 35 // Test cases
group-onsemi 0:098463de4c5d 36 TEST_IP_ACCEPT(test_simple_ipv4_address,
group-onsemi 0:098463de4c5d 37 "12.34.56.78",
group-onsemi 0:098463de4c5d 38 {NSAPI_IPv4,{12,34,56,78}})
group-onsemi 0:098463de4c5d 39 TEST_IP_ACCEPT(test_left_weighted_ipv4_address,
group-onsemi 0:098463de4c5d 40 "255.0.0.0",
group-onsemi 0:098463de4c5d 41 {NSAPI_IPv4,{255,0,0,0}})
group-onsemi 0:098463de4c5d 42 TEST_IP_ACCEPT(test_right_weighted_ipv4_address,
group-onsemi 0:098463de4c5d 43 "0.0.0.255",
group-onsemi 0:098463de4c5d 44 {NSAPI_IPv4,{0,0,0,255}})
group-onsemi 0:098463de4c5d 45 TEST_IP_ACCEPT(test_null_ipv4_address,
group-onsemi 0:098463de4c5d 46 "0.0.0.0",
group-onsemi 0:098463de4c5d 47 {NSAPI_IPv4,{0,0,0,0}})
group-onsemi 0:098463de4c5d 48
group-onsemi 0:098463de4c5d 49 TEST_IP_ACCEPT(test_simple_ipv6_address,
group-onsemi 0:098463de4c5d 50 "1234:5678:9abc:def0:1234:5678:9abc:def0",
group-onsemi 0:098463de4c5d 51 {NSAPI_IPv6,{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
group-onsemi 0:098463de4c5d 52 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}})
group-onsemi 0:098463de4c5d 53 TEST_IP_ACCEPT(test_left_weighted_ipv6_address,
group-onsemi 0:098463de4c5d 54 "1234:5678::",
group-onsemi 0:098463de4c5d 55 {NSAPI_IPv6,{0x12,0x34,0x56,0x78,0x00,0x00,0x00,0x00,
group-onsemi 0:098463de4c5d 56 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}})
group-onsemi 0:098463de4c5d 57 TEST_IP_ACCEPT(test_right_weighted_ipv6_address,
group-onsemi 0:098463de4c5d 58 "::1234:5678",
group-onsemi 0:098463de4c5d 59 {NSAPI_IPv6,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
group-onsemi 0:098463de4c5d 60 0x00,0x00,0x00,0x00,0x12,0x34,0x56,0x78}})
group-onsemi 0:098463de4c5d 61 TEST_IP_ACCEPT(test_hollowed_ipv6_address,
group-onsemi 0:098463de4c5d 62 "1234:5678::9abc:def8",
group-onsemi 0:098463de4c5d 63 {NSAPI_IPv6,{0x12,0x34,0x56,0x78,0x00,0x00,0x00,0x00,
group-onsemi 0:098463de4c5d 64 0x00,0x00,0x00,0x00,0x9a,0xbc,0xde,0xf8}})
group-onsemi 0:098463de4c5d 65 TEST_IP_ACCEPT(test_null_ipv6_address,
group-onsemi 0:098463de4c5d 66 "::",
group-onsemi 0:098463de4c5d 67 {NSAPI_IPv6,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
group-onsemi 0:098463de4c5d 68 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}})
group-onsemi 0:098463de4c5d 69
group-onsemi 0:098463de4c5d 70
group-onsemi 0:098463de4c5d 71 // Test setup
group-onsemi 0:098463de4c5d 72 utest::v1::status_t test_setup(const size_t number_of_cases) {
group-onsemi 0:098463de4c5d 73 GREENTEA_SETUP(10, "default_auto");
group-onsemi 0:098463de4c5d 74 return verbose_test_setup_handler(number_of_cases);
group-onsemi 0:098463de4c5d 75 }
group-onsemi 0:098463de4c5d 76
group-onsemi 0:098463de4c5d 77 Case cases[] = {
group-onsemi 0:098463de4c5d 78 Case("Simple IPv4 address", test_simple_ipv4_address),
group-onsemi 0:098463de4c5d 79 Case("Left-weighted IPv4 address", test_left_weighted_ipv4_address),
group-onsemi 0:098463de4c5d 80 Case("Right-weighted IPv4 address", test_right_weighted_ipv4_address),
group-onsemi 0:098463de4c5d 81 Case("Null IPv4 address", test_null_ipv4_address),
group-onsemi 0:098463de4c5d 82
group-onsemi 0:098463de4c5d 83 Case("Simple IPv6 address", test_simple_ipv6_address),
group-onsemi 0:098463de4c5d 84 Case("Left-weighted IPv6 address", test_left_weighted_ipv6_address),
group-onsemi 0:098463de4c5d 85 Case("Right-weighted IPv6 address", test_right_weighted_ipv6_address),
group-onsemi 0:098463de4c5d 86 Case("Hollowed IPv6 address", test_hollowed_ipv6_address),
group-onsemi 0:098463de4c5d 87 Case("Null IPv6 address", test_null_ipv6_address),
group-onsemi 0:098463de4c5d 88 };
group-onsemi 0:098463de4c5d 89
group-onsemi 0:098463de4c5d 90 Specification specification(test_setup, cases);
group-onsemi 0:098463de4c5d 91
group-onsemi 0:098463de4c5d 92 int main() {
group-onsemi 0:098463de4c5d 93 return !Harness::run(specification);
group-onsemi 0:098463de4c5d 94 }