Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of NSAPITests by
Diff: NSAPITests.cpp
- Revision:
- 2:41bf867fedd2
- Parent:
- 1:796ba8b082b1
- Child:
- 3:8b595ee6219d
--- a/NSAPITests.cpp Thu Feb 25 12:38:05 2016 -0600 +++ b/NSAPITests.cpp Wed Mar 02 13:24:46 2016 -0600 @@ -1,8 +1,82 @@ #include "NetworkInterface.h" +#include "TCPSocket.h" +#include <stdio.h> +#include "string.h" + + +int nsapi_isConnected_test(NetworkInterface *iface) +{ + return !(iface->isConnected()); +} + +int nsapi_getIPAddress_test(NetworkInterface *iface) +{ + + if (!iface->getIPAddress()[0]) { + printf("'getIpAddress' did not return an IP address\r\n"); + return -1; + } + + return 0; +} + +int nsapi_getMACAddress_test(NetworkInterface *iface) +{ + + if (!iface->getMACAddress()[0]) { + printf("'getMacAddress' did not return a MAC address\r\n"); + return -1; + } + + return 0; +} + +int nsapi_getHostByName_test(NetworkInterface *iface) +{ + char ip_address[NS_IP_SIZE] = "\0"; + + int32_t ret = iface->getHostByName("google.com", ip_address); + + if (ret) { + printf("'getHostByName' failed\r\n"); + return -1; + } else if (!ip_address[0]) { + printf("Returned IP address was null\r\n"); + return -2; + } else { + return 0; + } +} + +int nsapi_run_test(const char *name, NetworkInterface *iface, int (*test)(NetworkInterface*)) { + int ret; + + printf("---------------------\r\n"); + printf("%s: running...\r\n", name); + + ret = test(iface); + + printf("%s: ", name); + + if (!ret) { + printf("PASS\r\n"); + } else { + printf("FAIL (Return code %d)\r\n", ret); + } + + return ret; +} int nsapi_tests(const char *name, NetworkInterface *iface) { + int ret = 0; + + ret |= nsapi_run_test("nsapi_isConnected_test", iface, &nsapi_isConnected_test); + ret |= nsapi_run_test("nsapi_getIPAddress_test", iface, &nsapi_getIPAddress_test); + ret |= nsapi_run_test("nsapi_getMACAddress_test", iface, &nsapi_getMACAddress_test); + ret |= nsapi_run_test("nsapi_getHostByName_test", iface, &nsapi_getHostByName_test); + return ret; }