Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Revision 8:6c30647f75d7, committed 2012-08-24
- Comitter:
- ashleymills
- Date:
- Fri Aug 24 10:35:19 2012 +0000
- Parent:
- 4:1f8e079924ba
- Child:
- 10:65ee3973594e
- Commit message:
- Improved the framework so that it automatically logs test times and outcomes.
Changed in this revision
--- a/Tests/Test20.h Thu Aug 23 15:41:20 2012 +0000 +++ b/Tests/Test20.h Fri Aug 24 10:35:19 2012 +0000 @@ -4,22 +4,28 @@ public: Test20(VodafoneUSBModem *m) : VodafoneTestCase(m) { } + + virtual void setupTest() { + _ussdResponse = (char*)malloc(16*sizeof(char)); + } virtual bool runTest() { - char* ussdResponse = (char*)malloc(16*sizeof(char)); - _lastRunTime = time(NULL); + LOG("Sending USSD, waiting for response."); - if(_modem->sendUSSD("*#100#",ussdResponse,16)!=0) { + if(_modem->sendUSSD("*#100#",_ussdResponse,16)!=0) { LOG("Error sending USSD"); - _lastRunOutcome = false; - free(ussdResponse); return false; } - LOG("Received USSD response: \"%s\"",ussdResponse); - _lastRunOutcome = true; - free(ussdResponse); + LOG("Received USSD response: \"%s\"",_ussdResponse); return true; } -}; \ No newline at end of file + + virtual void endTest() { + free(_ussdResponse); + } + + private: + char *_ussdResponse; +};
--- a/Tests/Test50.h Thu Aug 23 15:41:20 2012 +0000 +++ b/Tests/Test50.h Fri Aug 24 10:35:19 2012 +0000 @@ -1,83 +1,82 @@ -#pragma once -#include "VodafoneTestCase.h" -class Test50 : public VodafoneTestCase { - public: - Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) { - _smsLen = 32; - _numberLen = 16; - } - - virtual void setupTest() { - allocStorage(); - } - - virtual bool endTest(bool state) { - freeStorage(); - return state; - } - - virtual bool runTest() { - size_t smCount; - LOG("Getting MSISDN"); - _modem->sendUSSD("*#100#",_ownNumber,_numberLen); - LOG("Got MSISDN %s",_ownNumber); - for(int i=0; i<5; i++) { - LOG("Creating random string"); - createRandomString(_smsOut,_smsLen); - LOG("Created: %s",_smsOut); - if(_modem->sendSM(_ownNumber,_smsOut)==0) { - LOG("Sent short message"); - } - bool gotMessage = false; - while(!gotMessage) { - if(_modem->getSMCount(&smCount)!=0) { - LOG("Faiure getting SM count"); - return false; - } else { - //LOG("Got SMCount (%d)",smCount); - } - - if(smCount>0) { - if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { - LOG("Failure getting SM"); - return false; - } - LOG("Got SMS: %s",_smsIn); - gotMessage = true; - } - Thread::wait(50); - } - } - - return true; - } - - private: - void createRandomString(char *target, int len) { - for(int i=0; i<len; i++) { - target[i] = 65+rand()%32; - } - target[len-1] = 0x00; - } - - void allocStorage() { - _ownNumber = (char*)malloc(_numberLen*sizeof(char)); - _senderNumber = (char*)malloc(_numberLen*sizeof(char)); - _smsOut = (char*)malloc(_smsLen*sizeof(char)); - _smsIn = (char*)malloc(_smsLen*sizeof(char)); - } - - void freeStorage() { - free(_ownNumber); - free(_senderNumber); - free(_smsOut); - free(_smsIn); - } - - char* _ownNumber; - char* _senderNumber; - char* _smsOut; - char* _smsIn; - int _smsLen; - int _numberLen; +#pragma once +#include "VodafoneTestCase.h" +class Test50 : public VodafoneTestCase { + public: + Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _smsLen = 32; + _numberLen = 16; + } + + virtual void setupTest() { + allocStorage(); + } + + virtual bool endTest(bool state) { + freeStorage(); + return state; + } + + virtual bool runTest() { + size_t smCount; + int numMessages = 10; + LOG("Getting MSISDN"); + _modem->sendUSSD("*#100#",_ownNumber,_numberLen); + LOG("Got MSISDN %s",_ownNumber); + for(int i=0; i<numMessages; i++) { + LOG("Creating random string"); + createRandomString(_smsOut,_smsLen); + LOG("Created: %s",_smsOut); + if(_modem->sendSM(_ownNumber,_smsOut)!=0) { + LOG("Failure to send short message"); + } + bool gotMessage = false; + while(!gotMessage) { + if(_modem->getSMCount(&smCount)!=0) { + LOG("Faiure getting SM count"); + return false; + } + + if(smCount>0) { + if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { + LOG("Failure getting SM"); + return false; + } + LOG("Got SMS: %s",_smsIn); + gotMessage = true; + } + Thread::wait(50); + } + } + + return true; + } + + private: + void createRandomString(char *target, int len) { + for(int i=0; i<len; i++) { + target[i] = 65+rand()%16; + } + target[len-1] = 0x00; + } + + void allocStorage() { + _ownNumber = (char*)malloc(_numberLen*sizeof(char)); + _senderNumber = (char*)malloc(_numberLen*sizeof(char)); + _smsOut = (char*)malloc(_smsLen*sizeof(char)); + _smsIn = (char*)malloc(_smsLen*sizeof(char)); + } + + void freeStorage() { + free(_ownNumber); + free(_senderNumber); + free(_smsOut); + free(_smsIn); + } + + char* _ownNumber; + char* _senderNumber; + char* _smsOut; + char* _smsIn; + int _smsLen; + int _numberLen; }; \ No newline at end of file
--- a/VodafoneTestCase.h Thu Aug 23 15:41:20 2012 +0000 +++ b/VodafoneTestCase.h Fri Aug 24 10:35:19 2012 +0000 @@ -9,8 +9,11 @@ } bool run() { + _lastRunTime = time(NULL); setupTest(); - return endTest(runTest()); + _lastRunOutcome = runTest(); + endTest(); + return _lastRunOutcome; } virtual void setupTest() { @@ -21,9 +24,8 @@ return true; } - virtual bool endTest(bool status) { - _lastRunOutcome = status; - return status; + virtual void endTest() { + } protected: