Ashley Mills / Mbed 2 deprecated VodafoneTestSuite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Revision:
47:85c30274cc9b
Parent:
46:d2c22206031a
Child:
51:15ba73d1cc45
--- a/Tests/Test08.cpp	Wed Sep 19 09:52:46 2012 +0000
+++ b/Tests/Test08.cpp	Wed Sep 19 13:59:39 2012 +0000
@@ -1,5 +1,23 @@
 #include "Test08.h"
 
+const char *gTest08DNSIn[5] = {
+   "m2mthings.com",
+   "google.co.uk",
+   "example.com",
+   "freebsd.org",
+   "www.mbed.org",
+};
+
+const char *gTest08DNSOut[5] = {
+   "109.74.199.96",
+   "173.194.69.94",
+   "192.0.43.10",
+   "69.147.83.40",
+   "217.140.101.20",
+};
+
+const int gTest08NumDNSVals = 5;
+
 Test08::Test08(VodafoneUSBModem *m) : VodafoneTestCase(m) {
    _description = gTest08Description;
    _testCaseNumber = 8;
@@ -39,6 +57,7 @@
             server->h_addr[2],
             server->h_addr[3]
          );
+         outcome = true;
       } else {
          LOG("Only IPv4 addresses are supported.");
          outcome = false;
@@ -46,6 +65,45 @@
       }
    } while(0);
    
+   // this is the real test
+   
+   char dnsOut[32];
+   
+   for(int i=0; i<gTest08NumDNSVals; i++) {
+      LOG("Running DNS lookup for %s",gTest08DNSIn[i]);
+      server = ::gethostbyname(gTest08DNSIn[i]);
+      if(server==NULL) {
+         LOG("Failure getting host address!");
+         outcome = false;
+         break;
+      } else {
+         LOG("Got host address, length %d",server->h_length);
+      }
+      
+      if(server->h_length==4) {
+         sprintf(dnsOut,"%d.%d.%d.%d",
+            server->h_addr[0],
+            server->h_addr[1],
+            server->h_addr[2],
+            server->h_addr[3]
+         );
+         LOG("DNS lookup returned %s",dnsOut);
+      } else {
+         LOG("Error. Only IPv4 addresses are supported.");
+         outcome = false;
+         break;
+      }
+      
+      LOG("Expected %s, got %s",gTest08DNSOut[i],dnsOut);
+      if(strcmp(dnsOut,gTest08DNSOut[i])!=0) {
+         LOG("Mismatch. Fail.");
+         outcome = false;
+         break;
+      } else {
+         LOG("Match. OK.");
+      }
+   }
+   
    _modem->disconnect();
    return outcome;
 }