Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
nherriot
Date:
Wed Aug 29 14:13:49 2012 +0000
Revision:
13:8b69853966f8
Parent:
12:b50d37429dff
Child:
16:c89d426c6175
adding test number to base class, init lists and changing constructors for test cases

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 3:28336c2e94e4 1 #pragma once
ashleymills 4:1f8e079924ba 2 #include "VodafoneTestCase.h"
ashleymills 3:28336c2e94e4 3 class Test50 : public VodafoneTestCase {
ashleymills 3:28336c2e94e4 4 public:
nherriot 13:8b69853966f8 5 Test50(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) {
ashleymills 4:1f8e079924ba 6 _smsLen = 32;
ashleymills 4:1f8e079924ba 7 _numberLen = 16;
ashleymills 4:1f8e079924ba 8 }
ashleymills 4:1f8e079924ba 9
ashleymills 4:1f8e079924ba 10 virtual void setupTest() {
ashleymills 4:1f8e079924ba 11 allocStorage();
ashleymills 4:1f8e079924ba 12 }
ashleymills 4:1f8e079924ba 13
ashleymills 11:a286d8112b45 14 virtual void endTest() {
ashleymills 4:1f8e079924ba 15 freeStorage();
ashleymills 3:28336c2e94e4 16 }
ashleymills 3:28336c2e94e4 17
ashleymills 3:28336c2e94e4 18 virtual bool runTest() {
ashleymills 9:3ff68422f4d7 19 int numIterations = 10;
ashleymills 4:1f8e079924ba 20 size_t smCount;
nherriot 13:8b69853966f8 21 LOG("Test %d waiting for an SMS message...", _testCaseNumber);
ashleymills 4:1f8e079924ba 22 LOG("Getting MSISDN");
ashleymills 4:1f8e079924ba 23 _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
ashleymills 4:1f8e079924ba 24 LOG("Got MSISDN %s",_ownNumber);
ashleymills 9:3ff68422f4d7 25 for(int i=0; i<numIterations; i++) {
ashleymills 4:1f8e079924ba 26 createRandomString(_smsOut,_smsLen);
ashleymills 9:3ff68422f4d7 27 if(_modem->sendSM(_ownNumber,_smsOut)!=0) {
ashleymills 9:3ff68422f4d7 28 LOG("Error sending short message");
ashleymills 4:1f8e079924ba 29 }
ashleymills 12:b50d37429dff 30 LOG("Created: %s",_smsOut);
ashleymills 4:1f8e079924ba 31 bool gotMessage = false;
ashleymills 12:b50d37429dff 32 Timer t;
ashleymills 12:b50d37429dff 33 t.start();
ashleymills 12:b50d37429dff 34 while(!gotMessage && t.read_ms()<25000) {
ashleymills 4:1f8e079924ba 35 if(_modem->getSMCount(&smCount)!=0) {
ashleymills 4:1f8e079924ba 36 LOG("Faiure getting SM count");
ashleymills 4:1f8e079924ba 37 return false;
ashleymills 4:1f8e079924ba 38 }
ashleymills 4:1f8e079924ba 39
ashleymills 4:1f8e079924ba 40 if(smCount>0) {
ashleymills 4:1f8e079924ba 41 if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
ashleymills 4:1f8e079924ba 42 LOG("Failure getting SM");
ashleymills 4:1f8e079924ba 43 return false;
ashleymills 4:1f8e079924ba 44 }
ashleymills 4:1f8e079924ba 45 LOG("Got SMS: %s",_smsIn);
ashleymills 9:3ff68422f4d7 46 if(strcmp(_smsIn,_smsOut)!=0) {
ashleymills 9:3ff68422f4d7 47 LOG("FAIL: strings did not match");
ashleymills 9:3ff68422f4d7 48 return false;
ashleymills 9:3ff68422f4d7 49 }
ashleymills 4:1f8e079924ba 50 gotMessage = true;
ashleymills 4:1f8e079924ba 51 }
ashleymills 4:1f8e079924ba 52 Thread::wait(50);
ashleymills 4:1f8e079924ba 53 }
ashleymills 12:b50d37429dff 54 if(!gotMessage) {
ashleymills 12:b50d37429dff 55 LOG("FAIL: timeout on waiting for SMS");
ashleymills 12:b50d37429dff 56 return false;
ashleymills 12:b50d37429dff 57 }
ashleymills 4:1f8e079924ba 58 }
ashleymills 3:28336c2e94e4 59
ashleymills 4:1f8e079924ba 60 return true;
ashleymills 3:28336c2e94e4 61 }
ashleymills 3:28336c2e94e4 62
ashleymills 4:1f8e079924ba 63 private:
ashleymills 4:1f8e079924ba 64 void createRandomString(char *target, int len) {
ashleymills 4:1f8e079924ba 65 for(int i=0; i<len; i++) {
ashleymills 9:3ff68422f4d7 66 target[i] = 65+rand()%16;
ashleymills 4:1f8e079924ba 67 }
ashleymills 4:1f8e079924ba 68 target[len-1] = 0x00;
ashleymills 4:1f8e079924ba 69 }
ashleymills 4:1f8e079924ba 70
ashleymills 4:1f8e079924ba 71 void allocStorage() {
ashleymills 4:1f8e079924ba 72 _ownNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 4:1f8e079924ba 73 _senderNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 4:1f8e079924ba 74 _smsOut = (char*)malloc(_smsLen*sizeof(char));
ashleymills 4:1f8e079924ba 75 _smsIn = (char*)malloc(_smsLen*sizeof(char));
ashleymills 4:1f8e079924ba 76 }
ashleymills 3:28336c2e94e4 77
ashleymills 4:1f8e079924ba 78 void freeStorage() {
ashleymills 4:1f8e079924ba 79 free(_ownNumber);
ashleymills 4:1f8e079924ba 80 free(_senderNumber);
ashleymills 4:1f8e079924ba 81 free(_smsOut);
ashleymills 4:1f8e079924ba 82 free(_smsIn);
ashleymills 4:1f8e079924ba 83 }
ashleymills 4:1f8e079924ba 84
ashleymills 4:1f8e079924ba 85 char* _ownNumber;
ashleymills 4:1f8e079924ba 86 char* _senderNumber;
ashleymills 4:1f8e079924ba 87 char* _smsOut;
ashleymills 4:1f8e079924ba 88 char* _smsIn;
ashleymills 4:1f8e079924ba 89 int _smsLen;
ashleymills 4:1f8e079924ba 90 int _numberLen;
ashleymills 3:28336c2e94e4 91 };