Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
ashleymills
Date:
Fri Aug 24 10:35:19 2012 +0000
Revision:
8:6c30647f75d7
Parent:
4:1f8e079924ba
Child:
10:65ee3973594e
Improved the framework so that it automatically logs test times and outcomes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 8:6c30647f75d7 1 #pragma once
ashleymills 8:6c30647f75d7 2 #include "VodafoneTestCase.h"
ashleymills 8:6c30647f75d7 3 class Test50 : public VodafoneTestCase {
ashleymills 8:6c30647f75d7 4 public:
ashleymills 8:6c30647f75d7 5 Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) {
ashleymills 8:6c30647f75d7 6 _smsLen = 32;
ashleymills 8:6c30647f75d7 7 _numberLen = 16;
ashleymills 8:6c30647f75d7 8 }
ashleymills 8:6c30647f75d7 9
ashleymills 8:6c30647f75d7 10 virtual void setupTest() {
ashleymills 8:6c30647f75d7 11 allocStorage();
ashleymills 8:6c30647f75d7 12 }
ashleymills 8:6c30647f75d7 13
ashleymills 8:6c30647f75d7 14 virtual bool endTest(bool state) {
ashleymills 8:6c30647f75d7 15 freeStorage();
ashleymills 8:6c30647f75d7 16 return state;
ashleymills 8:6c30647f75d7 17 }
ashleymills 8:6c30647f75d7 18
ashleymills 8:6c30647f75d7 19 virtual bool runTest() {
ashleymills 8:6c30647f75d7 20 size_t smCount;
ashleymills 8:6c30647f75d7 21 int numMessages = 10;
ashleymills 8:6c30647f75d7 22 LOG("Getting MSISDN");
ashleymills 8:6c30647f75d7 23 _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
ashleymills 8:6c30647f75d7 24 LOG("Got MSISDN %s",_ownNumber);
ashleymills 8:6c30647f75d7 25 for(int i=0; i<numMessages; i++) {
ashleymills 8:6c30647f75d7 26 LOG("Creating random string");
ashleymills 8:6c30647f75d7 27 createRandomString(_smsOut,_smsLen);
ashleymills 8:6c30647f75d7 28 LOG("Created: %s",_smsOut);
ashleymills 8:6c30647f75d7 29 if(_modem->sendSM(_ownNumber,_smsOut)!=0) {
ashleymills 8:6c30647f75d7 30 LOG("Failure to send short message");
ashleymills 8:6c30647f75d7 31 }
ashleymills 8:6c30647f75d7 32 bool gotMessage = false;
ashleymills 8:6c30647f75d7 33 while(!gotMessage) {
ashleymills 8:6c30647f75d7 34 if(_modem->getSMCount(&smCount)!=0) {
ashleymills 8:6c30647f75d7 35 LOG("Faiure getting SM count");
ashleymills 8:6c30647f75d7 36 return false;
ashleymills 8:6c30647f75d7 37 }
ashleymills 8:6c30647f75d7 38
ashleymills 8:6c30647f75d7 39 if(smCount>0) {
ashleymills 8:6c30647f75d7 40 if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
ashleymills 8:6c30647f75d7 41 LOG("Failure getting SM");
ashleymills 8:6c30647f75d7 42 return false;
ashleymills 8:6c30647f75d7 43 }
ashleymills 8:6c30647f75d7 44 LOG("Got SMS: %s",_smsIn);
ashleymills 8:6c30647f75d7 45 gotMessage = true;
ashleymills 8:6c30647f75d7 46 }
ashleymills 8:6c30647f75d7 47 Thread::wait(50);
ashleymills 8:6c30647f75d7 48 }
ashleymills 8:6c30647f75d7 49 }
ashleymills 8:6c30647f75d7 50
ashleymills 8:6c30647f75d7 51 return true;
ashleymills 8:6c30647f75d7 52 }
ashleymills 8:6c30647f75d7 53
ashleymills 8:6c30647f75d7 54 private:
ashleymills 8:6c30647f75d7 55 void createRandomString(char *target, int len) {
ashleymills 8:6c30647f75d7 56 for(int i=0; i<len; i++) {
ashleymills 8:6c30647f75d7 57 target[i] = 65+rand()%16;
ashleymills 8:6c30647f75d7 58 }
ashleymills 8:6c30647f75d7 59 target[len-1] = 0x00;
ashleymills 8:6c30647f75d7 60 }
ashleymills 8:6c30647f75d7 61
ashleymills 8:6c30647f75d7 62 void allocStorage() {
ashleymills 8:6c30647f75d7 63 _ownNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 8:6c30647f75d7 64 _senderNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 8:6c30647f75d7 65 _smsOut = (char*)malloc(_smsLen*sizeof(char));
ashleymills 8:6c30647f75d7 66 _smsIn = (char*)malloc(_smsLen*sizeof(char));
ashleymills 8:6c30647f75d7 67 }
ashleymills 8:6c30647f75d7 68
ashleymills 8:6c30647f75d7 69 void freeStorage() {
ashleymills 8:6c30647f75d7 70 free(_ownNumber);
ashleymills 8:6c30647f75d7 71 free(_senderNumber);
ashleymills 8:6c30647f75d7 72 free(_smsOut);
ashleymills 8:6c30647f75d7 73 free(_smsIn);
ashleymills 8:6c30647f75d7 74 }
ashleymills 8:6c30647f75d7 75
ashleymills 8:6c30647f75d7 76 char* _ownNumber;
ashleymills 8:6c30647f75d7 77 char* _senderNumber;
ashleymills 8:6c30647f75d7 78 char* _smsOut;
ashleymills 8:6c30647f75d7 79 char* _smsIn;
ashleymills 8:6c30647f75d7 80 int _smsLen;
ashleymills 8:6c30647f75d7 81 int _numberLen;
ashleymills 3:28336c2e94e4 82 };