Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Tests/Test10.h

Committer:
ashleymills
Date:
2012-09-13
Revision:
32:8ff0b67bb58c
Parent:
27:0297dbc3252b
Child:
33:16126e029d58

File content as of revision 32:8ff0b67bb58c:

#pragma once
#include "VodafoneTestCase.h"
#include "HTTPClient.h"

static const char* gTest10Description = "Connects to internet and downloads 100 byte file."; 
//const int gTest10Depends[] = {};

class Test10 : public VodafoneTestCase {
   public: 
      Test10(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) {
         _description = gTest10Description;
      }
      
      virtual void setupTest() {
         
         
      }
   
      virtual bool runTest() {
         HTTPClient http;
         char msgBuffer[125];
         bool outcome = true;
         LOG("Description: %s",gTest10Description);
         LOG("Connecting to internet");
         if(_modem->connect("internet","web","web")==0) {
            LOG("Connected to internet");
         } else {
            LOG("Failed to connect to internet");
            outcome = false;
         }
       
         LOG("Test %d, retrieving a 5MB file via HTTP.", _testCaseNumber);
         if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) {
            LOG("Got \"%s\"",msgBuffer);
            char c = 0;
            for(int i=0; i<100; i++) {
               if(msgBuffer[i]!=c) {
                  LOG("Strings do not match at char %d (%x,%x)",i,c,msgBuffer[i]);
                  outcome = false;
                  break;
               }
               c++;
               if(c==256)
                  c = 0;
            }
         } else {
            LOG("HTTP get failure");
            outcome = false;
         }
         _modem->disconnect();
         return outcome;
      }
      
      virtual void endTest() {
         
      }
      
   private:
      
};