-set socket options before “socket.bind” -listen for incoming SOCK_STREAM connections only before “socket.accept” resolves ubuntu errors.

Fork of NSAPITests by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
Brian Daniels
Date:
Wed Mar 02 13:24:46 2016 -0600
Parent:
1:796ba8b082b1
Child:
3:8b595ee6219d
Commit message:
Adding NetworkInterface tests

Changed in this revision

NSAPITests.cpp Show annotated file Show diff for this revision Revisions of this file
NSAPITests.h Show annotated file Show diff for this revision Revisions of this file
--- 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;
 }
 
--- a/NSAPITests.h	Thu Feb 25 12:38:05 2016 -0600
+++ b/NSAPITests.h	Wed Mar 02 13:24:46 2016 -0600
@@ -20,5 +20,6 @@
 #include "NetworkInterface.h"
 
 int nsapi_tests(const char *name, NetworkInterface *iface);
+int nsapi_run_test(const char *name, NetworkInterface *iface, int (*test)(NetworkInterface*));
 
 #endif