Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test10.h@24:8f0f9551122a, 2012-09-06 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 06 12:15:54 2012 +0000
- Revision:
- 24:8f0f9551122a
- Parent:
- 23:408199b5d2cb
- Child:
- 25:55b865c41f21
Added HTTP test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 24:8f0f9551122a | 1 | #pragma once |
ashleymills | 24:8f0f9551122a | 2 | #include "VodafoneTestCase.h" |
ashleymills | 24:8f0f9551122a | 3 | #include "HTTPClient.h" |
ashleymills | 24:8f0f9551122a | 4 | |
ashleymills | 24:8f0f9551122a | 5 | static const char* gTest10Description = "Connects to internet and downloads 100 byte file.\0"; |
ashleymills | 24:8f0f9551122a | 6 | class Test10 : public VodafoneTestCase { |
ashleymills | 24:8f0f9551122a | 7 | public: |
ashleymills | 24:8f0f9551122a | 8 | Test10(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { |
ashleymills | 24:8f0f9551122a | 9 | } |
ashleymills | 24:8f0f9551122a | 10 | |
ashleymills | 24:8f0f9551122a | 11 | virtual void setupTest() { |
ashleymills | 24:8f0f9551122a | 12 | |
ashleymills | 24:8f0f9551122a | 13 | |
ashleymills | 24:8f0f9551122a | 14 | } |
ashleymills | 24:8f0f9551122a | 15 | |
ashleymills | 24:8f0f9551122a | 16 | virtual bool runTest() { |
ashleymills | 24:8f0f9551122a | 17 | HTTPClient http; |
ashleymills | 24:8f0f9551122a | 18 | char msgBuffer[125]; |
ashleymills | 24:8f0f9551122a | 19 | bool outcome = true; |
ashleymills | 24:8f0f9551122a | 20 | LOG("Description: %s",gTest10Description); |
ashleymills | 24:8f0f9551122a | 21 | LOG("Connecting to internet"); |
ashleymills | 24:8f0f9551122a | 22 | if(_modem->connect("internet","web","web")==0) { |
ashleymills | 24:8f0f9551122a | 23 | LOG("Connected to internet"); |
ashleymills | 24:8f0f9551122a | 24 | } else { |
ashleymills | 24:8f0f9551122a | 25 | LOG("Failed to connect to internet"); |
ashleymills | 24:8f0f9551122a | 26 | outcome = false; |
ashleymills | 24:8f0f9551122a | 27 | } |
ashleymills | 24:8f0f9551122a | 28 | |
ashleymills | 24:8f0f9551122a | 29 | LOG("Test %d, retrieving a 5MB file via HTTP.", _testCaseNumber); |
ashleymills | 24:8f0f9551122a | 30 | if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) { |
ashleymills | 24:8f0f9551122a | 31 | LOG("Got \"%s\"",msgBuffer); |
ashleymills | 24:8f0f9551122a | 32 | char c = 0; |
ashleymills | 24:8f0f9551122a | 33 | for(int i=0; i<100; i++) { |
ashleymills | 24:8f0f9551122a | 34 | if(msgBuffer[i]!=c) { |
ashleymills | 24:8f0f9551122a | 35 | LOG("Strings do not match at char %d (%x,%x)",i,c,msgBuffer[i]); |
ashleymills | 24:8f0f9551122a | 36 | outcome = false; |
ashleymills | 24:8f0f9551122a | 37 | break; |
ashleymills | 24:8f0f9551122a | 38 | } |
ashleymills | 24:8f0f9551122a | 39 | c++; |
ashleymills | 24:8f0f9551122a | 40 | if(c==256) |
ashleymills | 24:8f0f9551122a | 41 | c = 0; |
ashleymills | 24:8f0f9551122a | 42 | } |
ashleymills | 24:8f0f9551122a | 43 | } else { |
ashleymills | 24:8f0f9551122a | 44 | LOG("HTTP get failure"); |
ashleymills | 24:8f0f9551122a | 45 | outcome = false; |
ashleymills | 24:8f0f9551122a | 46 | } |
ashleymills | 24:8f0f9551122a | 47 | _modem->disconnect(); |
ashleymills | 24:8f0f9551122a | 48 | return outcome; |
ashleymills | 24:8f0f9551122a | 49 | } |
ashleymills | 24:8f0f9551122a | 50 | |
ashleymills | 24:8f0f9551122a | 51 | virtual void endTest() { |
ashleymills | 24:8f0f9551122a | 52 | |
ashleymills | 24:8f0f9551122a | 53 | } |
ashleymills | 24:8f0f9551122a | 54 | |
ashleymills | 24:8f0f9551122a | 55 | private: |
ashleymills | 24:8f0f9551122a | 56 | |
ashleymills | 23:408199b5d2cb | 57 | }; |