Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
ashleymills
Date:
Thu Sep 06 14:28:01 2012 +0000
Revision:
26:9eefab9e28df
Parent:
25:55b865c41f21
Child:
27:0297dbc3252b
Started changing test framework to add dependencies.;

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