Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test08.cpp@60:7efce4a3c26f, 2012-10-23 (annotated)
- Committer:
- ashleymills
- Date:
- Tue Oct 23 14:22:53 2012 +0000
- Revision:
- 60:7efce4a3c26f
- Parent:
- 53:54b2d3a0c7bf
- Child:
- 66:6b00a764e549
Added new SMS bulk test (incomplete).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 45:f68fea0831d7 | 1 | #include "Test08.h" |
ashleymills | 52:de6cc9d823ab | 2 | #include "socket.h" |
ashleymills | 52:de6cc9d823ab | 3 | |
ashleymills | 52:de6cc9d823ab | 4 | bool connectToSocket(char *ipAddress, int port, int *sockfd) { |
ashleymills | 52:de6cc9d823ab | 5 | int ret = -1; |
ashleymills | 52:de6cc9d823ab | 6 | *sockfd = -1; |
ashleymills | 52:de6cc9d823ab | 7 | // create the socket |
ashleymills | 52:de6cc9d823ab | 8 | if((*sockfd=socket(AF_INET,SOCK_STREAM,0))<0) { |
ashleymills | 52:de6cc9d823ab | 9 | LOG("Error opening socket\r\n"); |
ashleymills | 52:de6cc9d823ab | 10 | } else { |
ashleymills | 52:de6cc9d823ab | 11 | LOG("Socket open\r\n"); |
ashleymills | 52:de6cc9d823ab | 12 | } |
ashleymills | 52:de6cc9d823ab | 13 | |
ashleymills | 52:de6cc9d823ab | 14 | // create the socket address |
ashleymills | 52:de6cc9d823ab | 15 | sockaddr_in serverAddress; |
ashleymills | 52:de6cc9d823ab | 16 | std::memset(&serverAddress, 0, sizeof(struct sockaddr_in)); |
ashleymills | 52:de6cc9d823ab | 17 | serverAddress.sin_addr.s_addr = inet_addr(ipAddress); |
ashleymills | 52:de6cc9d823ab | 18 | serverAddress.sin_family = AF_INET; |
ashleymills | 52:de6cc9d823ab | 19 | serverAddress.sin_port = htons(port); |
ashleymills | 52:de6cc9d823ab | 20 | |
ashleymills | 52:de6cc9d823ab | 21 | // do socket connect |
ashleymills | 52:de6cc9d823ab | 22 | LOG("Connecting socket to %s:%d", inet_ntoa(serverAddress.sin_addr), ntohs(serverAddress.sin_port)); |
ashleymills | 52:de6cc9d823ab | 23 | if((ret=::connect(*sockfd, (const struct sockaddr *)&serverAddress, sizeof(serverAddress)))<0) { |
ashleymills | 52:de6cc9d823ab | 24 | ::close(*sockfd); |
ashleymills | 52:de6cc9d823ab | 25 | LOG("Could not connect"); |
ashleymills | 52:de6cc9d823ab | 26 | return false; |
ashleymills | 52:de6cc9d823ab | 27 | } else { |
ashleymills | 52:de6cc9d823ab | 28 | LOG("Connection OK"); |
ashleymills | 52:de6cc9d823ab | 29 | } |
ashleymills | 52:de6cc9d823ab | 30 | return true; |
ashleymills | 52:de6cc9d823ab | 31 | } |
ashleymills | 45:f68fea0831d7 | 32 | |
ashleymills | 47:85c30274cc9b | 33 | const char *gTest08DNSIn[5] = { |
ashleymills | 47:85c30274cc9b | 34 | "m2mthings.com", |
ashleymills | 51:15ba73d1cc45 | 35 | "kent.ac.uk", |
ashleymills | 47:85c30274cc9b | 36 | "example.com", |
ashleymills | 52:de6cc9d823ab | 37 | "m2mcontroller.com", |
ashleymills | 47:85c30274cc9b | 38 | "www.mbed.org", |
ashleymills | 47:85c30274cc9b | 39 | }; |
ashleymills | 47:85c30274cc9b | 40 | |
ashleymills | 47:85c30274cc9b | 41 | const char *gTest08DNSOut[5] = { |
ashleymills | 47:85c30274cc9b | 42 | "109.74.199.96", |
ashleymills | 51:15ba73d1cc45 | 43 | "129.12.10.249", |
ashleymills | 47:85c30274cc9b | 44 | "192.0.43.10", |
ashleymills | 52:de6cc9d823ab | 45 | "62.105.171.138", |
ashleymills | 47:85c30274cc9b | 46 | "217.140.101.20", |
ashleymills | 47:85c30274cc9b | 47 | }; |
ashleymills | 47:85c30274cc9b | 48 | |
ashleymills | 47:85c30274cc9b | 49 | const int gTest08NumDNSVals = 5; |
ashleymills | 47:85c30274cc9b | 50 | |
ashleymills | 60:7efce4a3c26f | 51 | Test08::Test08(VodafoneUSBModem *m) : VodafoneTestCase(m) {} |
ashleymills | 45:f68fea0831d7 | 52 | |
ashleymills | 45:f68fea0831d7 | 53 | void Test08::setupTest() {} |
ashleymills | 45:f68fea0831d7 | 54 | |
ashleymills | 45:f68fea0831d7 | 55 | bool Test08::executeTest() { |
ashleymills | 45:f68fea0831d7 | 56 | bool outcome = true; |
ashleymills | 45:f68fea0831d7 | 57 | LOG("Description: %s",gTest08Description); |
ashleymills | 45:f68fea0831d7 | 58 | LOG("Connecting to internet"); |
ashleymills | 45:f68fea0831d7 | 59 | if(_modem->connect("internet","web","web")==0) { |
ashleymills | 45:f68fea0831d7 | 60 | LOG("Connected to internet"); |
ashleymills | 45:f68fea0831d7 | 61 | } else { |
ashleymills | 45:f68fea0831d7 | 62 | LOG("Failed to connect to internet"); |
ashleymills | 45:f68fea0831d7 | 63 | outcome = false; |
ashleymills | 45:f68fea0831d7 | 64 | } |
ashleymills | 52:de6cc9d823ab | 65 | |
ashleymills | 52:de6cc9d823ab | 66 | // try connecting to DNS server directly |
ashleymills | 52:de6cc9d823ab | 67 | int sockfd; |
ashleymills | 52:de6cc9d823ab | 68 | //if(connectToSocket("88.82.13.28",53,&sockfd)) { |
ashleymills | 53:54b2d3a0c7bf | 69 | |
ashleymills | 52:de6cc9d823ab | 70 | if(connectToSocket("109.74.199.96",80,&sockfd)) { |
ashleymills | 52:de6cc9d823ab | 71 | close(sockfd); |
ashleymills | 52:de6cc9d823ab | 72 | } |
ashleymills | 52:de6cc9d823ab | 73 | |
ashleymills | 53:54b2d3a0c7bf | 74 | |
ashleymills | 46:d2c22206031a | 75 | struct hostent *server; |
ashleymills | 46:d2c22206031a | 76 | do { |
ashleymills | 46:d2c22206031a | 77 | while(1) { |
ashleymills | 46:d2c22206031a | 78 | LOG("Getting host address"); |
ashleymills | 46:d2c22206031a | 79 | server = ::gethostbyname("m2mthings.com"); |
ashleymills | 46:d2c22206031a | 80 | if(server==NULL) { |
ashleymills | 46:d2c22206031a | 81 | LOG("Failure getting host address!"); |
ashleymills | 46:d2c22206031a | 82 | outcome = false; |
ashleymills | 46:d2c22206031a | 83 | //break; |
ashleymills | 46:d2c22206031a | 84 | } else { |
ashleymills | 46:d2c22206031a | 85 | LOG("got host address, length %d",server->h_length); |
ashleymills | 46:d2c22206031a | 86 | break; |
ashleymills | 46:d2c22206031a | 87 | } |
ashleymills | 46:d2c22206031a | 88 | } |
ashleymills | 46:d2c22206031a | 89 | |
ashleymills | 46:d2c22206031a | 90 | if(server->h_length==4) { |
ashleymills | 46:d2c22206031a | 91 | LOG("DNS lookup returned %d.%d.%d.%d", |
ashleymills | 46:d2c22206031a | 92 | server->h_addr[0], |
ashleymills | 46:d2c22206031a | 93 | server->h_addr[1], |
ashleymills | 46:d2c22206031a | 94 | server->h_addr[2], |
ashleymills | 46:d2c22206031a | 95 | server->h_addr[3] |
ashleymills | 46:d2c22206031a | 96 | ); |
ashleymills | 47:85c30274cc9b | 97 | outcome = true; |
ashleymills | 46:d2c22206031a | 98 | } else { |
ashleymills | 46:d2c22206031a | 99 | LOG("Only IPv4 addresses are supported."); |
ashleymills | 46:d2c22206031a | 100 | outcome = false; |
ashleymills | 46:d2c22206031a | 101 | break; |
ashleymills | 46:d2c22206031a | 102 | } |
ashleymills | 46:d2c22206031a | 103 | } while(0); |
ashleymills | 45:f68fea0831d7 | 104 | |
ashleymills | 47:85c30274cc9b | 105 | // this is the real test |
ashleymills | 47:85c30274cc9b | 106 | |
ashleymills | 47:85c30274cc9b | 107 | char dnsOut[32]; |
ashleymills | 47:85c30274cc9b | 108 | |
ashleymills | 47:85c30274cc9b | 109 | for(int i=0; i<gTest08NumDNSVals; i++) { |
ashleymills | 47:85c30274cc9b | 110 | LOG("Running DNS lookup for %s",gTest08DNSIn[i]); |
ashleymills | 47:85c30274cc9b | 111 | server = ::gethostbyname(gTest08DNSIn[i]); |
ashleymills | 47:85c30274cc9b | 112 | if(server==NULL) { |
ashleymills | 47:85c30274cc9b | 113 | LOG("Failure getting host address!"); |
ashleymills | 47:85c30274cc9b | 114 | outcome = false; |
ashleymills | 47:85c30274cc9b | 115 | break; |
ashleymills | 47:85c30274cc9b | 116 | } else { |
ashleymills | 47:85c30274cc9b | 117 | LOG("Got host address, length %d",server->h_length); |
ashleymills | 47:85c30274cc9b | 118 | } |
ashleymills | 47:85c30274cc9b | 119 | |
ashleymills | 47:85c30274cc9b | 120 | if(server->h_length==4) { |
ashleymills | 47:85c30274cc9b | 121 | sprintf(dnsOut,"%d.%d.%d.%d", |
ashleymills | 47:85c30274cc9b | 122 | server->h_addr[0], |
ashleymills | 47:85c30274cc9b | 123 | server->h_addr[1], |
ashleymills | 47:85c30274cc9b | 124 | server->h_addr[2], |
ashleymills | 47:85c30274cc9b | 125 | server->h_addr[3] |
ashleymills | 47:85c30274cc9b | 126 | ); |
ashleymills | 47:85c30274cc9b | 127 | LOG("DNS lookup returned %s",dnsOut); |
ashleymills | 47:85c30274cc9b | 128 | } else { |
ashleymills | 47:85c30274cc9b | 129 | LOG("Error. Only IPv4 addresses are supported."); |
ashleymills | 47:85c30274cc9b | 130 | outcome = false; |
ashleymills | 47:85c30274cc9b | 131 | break; |
ashleymills | 47:85c30274cc9b | 132 | } |
ashleymills | 47:85c30274cc9b | 133 | |
ashleymills | 47:85c30274cc9b | 134 | LOG("Expected %s, got %s",gTest08DNSOut[i],dnsOut); |
ashleymills | 47:85c30274cc9b | 135 | if(strcmp(dnsOut,gTest08DNSOut[i])!=0) { |
ashleymills | 47:85c30274cc9b | 136 | LOG("Mismatch. Fail."); |
ashleymills | 47:85c30274cc9b | 137 | outcome = false; |
ashleymills | 47:85c30274cc9b | 138 | break; |
ashleymills | 47:85c30274cc9b | 139 | } else { |
ashleymills | 47:85c30274cc9b | 140 | LOG("Match. OK."); |
ashleymills | 47:85c30274cc9b | 141 | } |
ashleymills | 47:85c30274cc9b | 142 | } |
ashleymills | 47:85c30274cc9b | 143 | |
ashleymills | 45:f68fea0831d7 | 144 | _modem->disconnect(); |
ashleymills | 45:f68fea0831d7 | 145 | return outcome; |
ashleymills | 45:f68fea0831d7 | 146 | } |
ashleymills | 45:f68fea0831d7 | 147 | |
ashleymills | 45:f68fea0831d7 | 148 | void Test08::endTest() { } |