Ashley Mills / Mbed 2 deprecated VodafoneTestSuite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
ashleymills
Date:
Fri Sep 21 11:29:28 2012 +0000
Revision:
51:15ba73d1cc45
Parent:
47:85c30274cc9b
Child:
52:de6cc9d823ab
Updated to latest bleeding edge library. Changed DNS test to refer to servers with smaller numbers of IPs.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 45:f68fea0831d7 1 #include "Test08.h"
ashleymills 45:f68fea0831d7 2
ashleymills 47:85c30274cc9b 3 const char *gTest08DNSIn[5] = {
ashleymills 47:85c30274cc9b 4 "m2mthings.com",
ashleymills 51:15ba73d1cc45 5 "kent.ac.uk",
ashleymills 47:85c30274cc9b 6 "example.com",
ashleymills 47:85c30274cc9b 7 "freebsd.org",
ashleymills 47:85c30274cc9b 8 "www.mbed.org",
ashleymills 47:85c30274cc9b 9 };
ashleymills 47:85c30274cc9b 10
ashleymills 47:85c30274cc9b 11 const char *gTest08DNSOut[5] = {
ashleymills 47:85c30274cc9b 12 "109.74.199.96",
ashleymills 51:15ba73d1cc45 13 "129.12.10.249",
ashleymills 47:85c30274cc9b 14 "192.0.43.10",
ashleymills 47:85c30274cc9b 15 "69.147.83.40",
ashleymills 47:85c30274cc9b 16 "217.140.101.20",
ashleymills 47:85c30274cc9b 17 };
ashleymills 47:85c30274cc9b 18
ashleymills 47:85c30274cc9b 19 const int gTest08NumDNSVals = 5;
ashleymills 47:85c30274cc9b 20
ashleymills 45:f68fea0831d7 21 Test08::Test08(VodafoneUSBModem *m) : VodafoneTestCase(m) {
ashleymills 45:f68fea0831d7 22 _description = gTest08Description;
ashleymills 45:f68fea0831d7 23 _testCaseNumber = 8;
ashleymills 45:f68fea0831d7 24 }
ashleymills 45:f68fea0831d7 25
ashleymills 45:f68fea0831d7 26 void Test08::setupTest() {}
ashleymills 45:f68fea0831d7 27
ashleymills 45:f68fea0831d7 28 bool Test08::executeTest() {
ashleymills 45:f68fea0831d7 29 bool outcome = true;
ashleymills 45:f68fea0831d7 30 LOG("Description: %s",gTest08Description);
ashleymills 45:f68fea0831d7 31 LOG("Connecting to internet");
ashleymills 45:f68fea0831d7 32 if(_modem->connect("internet","web","web")==0) {
ashleymills 45:f68fea0831d7 33 LOG("Connected to internet");
ashleymills 45:f68fea0831d7 34 } else {
ashleymills 45:f68fea0831d7 35 LOG("Failed to connect to internet");
ashleymills 45:f68fea0831d7 36 outcome = false;
ashleymills 45:f68fea0831d7 37 }
ashleymills 46:d2c22206031a 38 struct hostent *server;
ashleymills 46:d2c22206031a 39 do {
ashleymills 46:d2c22206031a 40 while(1) {
ashleymills 46:d2c22206031a 41 LOG("Getting host address");
ashleymills 46:d2c22206031a 42 server = ::gethostbyname("m2mthings.com");
ashleymills 46:d2c22206031a 43 if(server==NULL) {
ashleymills 46:d2c22206031a 44 LOG("Failure getting host address!");
ashleymills 46:d2c22206031a 45 outcome = false;
ashleymills 46:d2c22206031a 46 //break;
ashleymills 46:d2c22206031a 47 } else {
ashleymills 46:d2c22206031a 48 LOG("got host address, length %d",server->h_length);
ashleymills 46:d2c22206031a 49 break;
ashleymills 46:d2c22206031a 50 }
ashleymills 46:d2c22206031a 51 }
ashleymills 46:d2c22206031a 52
ashleymills 46:d2c22206031a 53 if(server->h_length==4) {
ashleymills 46:d2c22206031a 54 LOG("DNS lookup returned %d.%d.%d.%d",
ashleymills 46:d2c22206031a 55 server->h_addr[0],
ashleymills 46:d2c22206031a 56 server->h_addr[1],
ashleymills 46:d2c22206031a 57 server->h_addr[2],
ashleymills 46:d2c22206031a 58 server->h_addr[3]
ashleymills 46:d2c22206031a 59 );
ashleymills 47:85c30274cc9b 60 outcome = true;
ashleymills 46:d2c22206031a 61 } else {
ashleymills 46:d2c22206031a 62 LOG("Only IPv4 addresses are supported.");
ashleymills 46:d2c22206031a 63 outcome = false;
ashleymills 46:d2c22206031a 64 break;
ashleymills 46:d2c22206031a 65 }
ashleymills 46:d2c22206031a 66 } while(0);
ashleymills 45:f68fea0831d7 67
ashleymills 47:85c30274cc9b 68 // this is the real test
ashleymills 47:85c30274cc9b 69
ashleymills 47:85c30274cc9b 70 char dnsOut[32];
ashleymills 47:85c30274cc9b 71
ashleymills 47:85c30274cc9b 72 for(int i=0; i<gTest08NumDNSVals; i++) {
ashleymills 47:85c30274cc9b 73 LOG("Running DNS lookup for %s",gTest08DNSIn[i]);
ashleymills 47:85c30274cc9b 74 server = ::gethostbyname(gTest08DNSIn[i]);
ashleymills 47:85c30274cc9b 75 if(server==NULL) {
ashleymills 47:85c30274cc9b 76 LOG("Failure getting host address!");
ashleymills 47:85c30274cc9b 77 outcome = false;
ashleymills 47:85c30274cc9b 78 break;
ashleymills 47:85c30274cc9b 79 } else {
ashleymills 47:85c30274cc9b 80 LOG("Got host address, length %d",server->h_length);
ashleymills 47:85c30274cc9b 81 }
ashleymills 47:85c30274cc9b 82
ashleymills 47:85c30274cc9b 83 if(server->h_length==4) {
ashleymills 47:85c30274cc9b 84 sprintf(dnsOut,"%d.%d.%d.%d",
ashleymills 47:85c30274cc9b 85 server->h_addr[0],
ashleymills 47:85c30274cc9b 86 server->h_addr[1],
ashleymills 47:85c30274cc9b 87 server->h_addr[2],
ashleymills 47:85c30274cc9b 88 server->h_addr[3]
ashleymills 47:85c30274cc9b 89 );
ashleymills 47:85c30274cc9b 90 LOG("DNS lookup returned %s",dnsOut);
ashleymills 47:85c30274cc9b 91 } else {
ashleymills 47:85c30274cc9b 92 LOG("Error. Only IPv4 addresses are supported.");
ashleymills 47:85c30274cc9b 93 outcome = false;
ashleymills 47:85c30274cc9b 94 break;
ashleymills 47:85c30274cc9b 95 }
ashleymills 47:85c30274cc9b 96
ashleymills 47:85c30274cc9b 97 LOG("Expected %s, got %s",gTest08DNSOut[i],dnsOut);
ashleymills 47:85c30274cc9b 98 if(strcmp(dnsOut,gTest08DNSOut[i])!=0) {
ashleymills 47:85c30274cc9b 99 LOG("Mismatch. Fail.");
ashleymills 47:85c30274cc9b 100 outcome = false;
ashleymills 47:85c30274cc9b 101 break;
ashleymills 47:85c30274cc9b 102 } else {
ashleymills 47:85c30274cc9b 103 LOG("Match. OK.");
ashleymills 47:85c30274cc9b 104 }
ashleymills 47:85c30274cc9b 105 }
ashleymills 47:85c30274cc9b 106
ashleymills 45:f68fea0831d7 107 _modem->disconnect();
ashleymills 45:f68fea0831d7 108 return outcome;
ashleymills 45:f68fea0831d7 109 }
ashleymills 45:f68fea0831d7 110
ashleymills 45:f68fea0831d7 111 void Test08::endTest() { }