Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test11.h
- Committer:
- ashleymills
- Date:
- 2012-11-01
- Revision:
- 66:6b00a764e549
- Child:
- 68:2f3ead00ab0a
File content as of revision 66:6b00a764e549:
#pragma once #include "VodafoneTestCase.h" extern const char* gTest11Description; class Test11 : public VodafoneTestCase { public: Test11(VodafoneUSBModem *m) : VodafoneTestCase(m) { _smsLen = 32; _smsMaxSize = 160; // max size of SMS using _numberLen = 16; } private: virtual void setupTest() { allocStorage(); } virtual void endTest() { freeStorage(); } virtual bool executeTest() { LOG(gTest11Description); int numIterations = 10; size_t smCount; // Clear out the SMS mail box before we run this test. // loop 3 times with a 1/2 second break in between each LOG("... Clearing out SMS mail box first"); for(int j=0; j<3; j++) { if(_modem->getSMCount(&smCount)!=0) { LOG("Faiure getting SM count"); return false; } for(int i=0; i<smCount; i++) { if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); return false; } LOG("Got SMS: %s",_smsJunkBuffer); LOG("Clearing that out before running the test."); } Thread::wait(500); } LOG("Getting MSISDN"); _modem->sendUSSD("*#100#",_ownNumber,_numberLen); LOG("Got MSISDN %s",_ownNumber); for(int i=0; i<numIterations; i++) { createRandomString(_smsOut,_smsLen); if(_modem->sendSM(_ownNumber,_smsOut)!=0) { LOG("Error sending short message"); } LOG("Created: %s",_smsOut); bool gotMessage = false; Timer t; t.start(); while(!gotMessage && t.read_ms()<25000) { 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); if(strcmp(_smsIn,_smsOut)!=0) { LOG("FAIL: strings did not match"); return false; } gotMessage = true; } Thread::wait(50); } if(!gotMessage) { LOG("FAIL: timeout on waiting for SMS"); return false; } } return true; } 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)); _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); } void freeStorage() { free(_ownNumber); free(_senderNumber); free(_smsOut); free(_smsIn); free(_smsJunkBuffer); } char* _ownNumber; char* _senderNumber; char* _smsOut; char* _smsIn; char* _smsJunkBuffer; int _smsLen; int _smsMaxSize; int _numberLen; };