Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
ashleymills
Date:
Thu Nov 01 11:19:47 2012 +0000
Revision:
66:6b00a764e549
Child:
68:2f3ead00ab0a
Renamed tests in sequential order to make it easier to manage and cleaner to follow.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 66:6b00a764e549 1 #pragma once
ashleymills 66:6b00a764e549 2 #include "VodafoneTestCase.h"
ashleymills 66:6b00a764e549 3
ashleymills 66:6b00a764e549 4 extern const char* gTest11Description;
ashleymills 66:6b00a764e549 5
ashleymills 66:6b00a764e549 6 class Test11 : public VodafoneTestCase {
ashleymills 66:6b00a764e549 7 public:
ashleymills 66:6b00a764e549 8 Test11(VodafoneUSBModem *m) : VodafoneTestCase(m) {
ashleymills 66:6b00a764e549 9 _smsLen = 32;
ashleymills 66:6b00a764e549 10 _smsMaxSize = 160; // max size of SMS using
ashleymills 66:6b00a764e549 11 _numberLen = 16;
ashleymills 66:6b00a764e549 12 }
ashleymills 66:6b00a764e549 13
ashleymills 66:6b00a764e549 14 private:
ashleymills 66:6b00a764e549 15
ashleymills 66:6b00a764e549 16 virtual void setupTest() {
ashleymills 66:6b00a764e549 17 allocStorage();
ashleymills 66:6b00a764e549 18 }
ashleymills 66:6b00a764e549 19
ashleymills 66:6b00a764e549 20 virtual void endTest() {
ashleymills 66:6b00a764e549 21 freeStorage();
ashleymills 66:6b00a764e549 22 }
ashleymills 66:6b00a764e549 23
ashleymills 66:6b00a764e549 24 virtual bool executeTest() {
ashleymills 66:6b00a764e549 25 LOG(gTest11Description);
ashleymills 66:6b00a764e549 26 int numIterations = 10;
ashleymills 66:6b00a764e549 27 size_t smCount;
ashleymills 66:6b00a764e549 28
ashleymills 66:6b00a764e549 29 // Clear out the SMS mail box before we run this test.
ashleymills 66:6b00a764e549 30 // loop 3 times with a 1/2 second break in between each
ashleymills 66:6b00a764e549 31 LOG("... Clearing out SMS mail box first");
ashleymills 66:6b00a764e549 32 for(int j=0; j<3; j++) {
ashleymills 66:6b00a764e549 33 if(_modem->getSMCount(&smCount)!=0) {
ashleymills 66:6b00a764e549 34 LOG("Faiure getting SM count");
ashleymills 66:6b00a764e549 35 return false;
ashleymills 66:6b00a764e549 36 }
ashleymills 66:6b00a764e549 37
ashleymills 66:6b00a764e549 38 for(int i=0; i<smCount; i++) {
ashleymills 66:6b00a764e549 39 if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) {
ashleymills 66:6b00a764e549 40 LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?");
ashleymills 66:6b00a764e549 41 return false;
ashleymills 66:6b00a764e549 42 }
ashleymills 66:6b00a764e549 43 LOG("Got SMS: %s",_smsJunkBuffer);
ashleymills 66:6b00a764e549 44 LOG("Clearing that out before running the test.");
ashleymills 66:6b00a764e549 45 }
ashleymills 66:6b00a764e549 46 Thread::wait(500);
ashleymills 66:6b00a764e549 47 }
ashleymills 66:6b00a764e549 48
ashleymills 66:6b00a764e549 49 LOG("Getting MSISDN");
ashleymills 66:6b00a764e549 50 _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
ashleymills 66:6b00a764e549 51 LOG("Got MSISDN %s",_ownNumber);
ashleymills 66:6b00a764e549 52 for(int i=0; i<numIterations; i++) {
ashleymills 66:6b00a764e549 53 createRandomString(_smsOut,_smsLen);
ashleymills 66:6b00a764e549 54 if(_modem->sendSM(_ownNumber,_smsOut)!=0) {
ashleymills 66:6b00a764e549 55 LOG("Error sending short message");
ashleymills 66:6b00a764e549 56 }
ashleymills 66:6b00a764e549 57 LOG("Created: %s",_smsOut);
ashleymills 66:6b00a764e549 58 bool gotMessage = false;
ashleymills 66:6b00a764e549 59 Timer t;
ashleymills 66:6b00a764e549 60 t.start();
ashleymills 66:6b00a764e549 61 while(!gotMessage && t.read_ms()<25000) {
ashleymills 66:6b00a764e549 62 if(_modem->getSMCount(&smCount)!=0) {
ashleymills 66:6b00a764e549 63 LOG("Faiure getting SM count");
ashleymills 66:6b00a764e549 64 return false;
ashleymills 66:6b00a764e549 65 }
ashleymills 66:6b00a764e549 66
ashleymills 66:6b00a764e549 67 if(smCount>0) {
ashleymills 66:6b00a764e549 68 if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
ashleymills 66:6b00a764e549 69 LOG("Failure getting SM");
ashleymills 66:6b00a764e549 70 return false;
ashleymills 66:6b00a764e549 71 }
ashleymills 66:6b00a764e549 72 LOG("Got SMS: %s",_smsIn);
ashleymills 66:6b00a764e549 73 if(strcmp(_smsIn,_smsOut)!=0) {
ashleymills 66:6b00a764e549 74 LOG("FAIL: strings did not match");
ashleymills 66:6b00a764e549 75 return false;
ashleymills 66:6b00a764e549 76 }
ashleymills 66:6b00a764e549 77 gotMessage = true;
ashleymills 66:6b00a764e549 78 }
ashleymills 66:6b00a764e549 79 Thread::wait(50);
ashleymills 66:6b00a764e549 80 }
ashleymills 66:6b00a764e549 81 if(!gotMessage) {
ashleymills 66:6b00a764e549 82 LOG("FAIL: timeout on waiting for SMS");
ashleymills 66:6b00a764e549 83 return false;
ashleymills 66:6b00a764e549 84 }
ashleymills 66:6b00a764e549 85 }
ashleymills 66:6b00a764e549 86
ashleymills 66:6b00a764e549 87 return true;
ashleymills 66:6b00a764e549 88 }
ashleymills 66:6b00a764e549 89
ashleymills 66:6b00a764e549 90 void createRandomString(char *target, int len) {
ashleymills 66:6b00a764e549 91 for(int i=0; i<len; i++) {
ashleymills 66:6b00a764e549 92 target[i] = 65+rand()%16;
ashleymills 66:6b00a764e549 93 }
ashleymills 66:6b00a764e549 94 target[len-1] = 0x00;
ashleymills 66:6b00a764e549 95 }
ashleymills 66:6b00a764e549 96
ashleymills 66:6b00a764e549 97 void allocStorage() {
ashleymills 66:6b00a764e549 98 _ownNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 66:6b00a764e549 99 _senderNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 66:6b00a764e549 100 _smsOut = (char*)malloc(_smsLen*sizeof(char));
ashleymills 66:6b00a764e549 101 _smsIn = (char*)malloc(_smsLen*sizeof(char));
ashleymills 66:6b00a764e549 102 _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char));
ashleymills 66:6b00a764e549 103 }
ashleymills 66:6b00a764e549 104
ashleymills 66:6b00a764e549 105 void freeStorage() {
ashleymills 66:6b00a764e549 106 free(_ownNumber);
ashleymills 66:6b00a764e549 107 free(_senderNumber);
ashleymills 66:6b00a764e549 108 free(_smsOut);
ashleymills 66:6b00a764e549 109 free(_smsIn);
ashleymills 66:6b00a764e549 110 free(_smsJunkBuffer);
ashleymills 66:6b00a764e549 111 }
ashleymills 66:6b00a764e549 112
ashleymills 66:6b00a764e549 113 char* _ownNumber;
ashleymills 66:6b00a764e549 114 char* _senderNumber;
ashleymills 66:6b00a764e549 115 char* _smsOut;
ashleymills 66:6b00a764e549 116 char* _smsIn;
ashleymills 66:6b00a764e549 117 char* _smsJunkBuffer;
ashleymills 66:6b00a764e549 118 int _smsLen;
ashleymills 66:6b00a764e549 119 int _smsMaxSize;
ashleymills 66:6b00a764e549 120 int _numberLen;
ashleymills 66:6b00a764e549 121 };