Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test15.h Source File

Test15.h

00001 #pragma once
00002 #include "VodafoneTestCase.h"
00003 // Test 15: Sends SMSs to self that contain carriage returns and newlines
00004 extern const char* gTest15Description;
00005 
00006 class Test15 : public VodafoneTestCase {
00007    public:
00008       Test15(VodafoneUSBModem *m) : VodafoneTestCase(m) {
00009          _smsLen = 32;
00010          _smsMaxSize = 160;     // max size of SMS
00011          _numberLen = 16;
00012       }
00013       
00014    private:
00015       
00016       virtual void setupTest() {
00017          allocStorage();
00018       }
00019       
00020       virtual void endTest() {
00021          freeStorage();
00022       }
00023       
00024       virtual bool executeTest() {
00025          LOG(gTest15Description);
00026          size_t smCount;
00027          
00028          // Clear out the SMS mail box before we run this test.
00029          // loop 3 times with a 1/2 second break in between each
00030          LOG("... Clearing out SMS mail box first");
00031          bool smsCleared = false;
00032          for(int j=0; j<3; j++) {
00033             if(_modem->getSMCount(&smCount)!=0) {
00034                LOG("Failure getting SM count");
00035                return false;
00036             }
00037          
00038             for(int i=0; i<smCount; i++) {
00039                if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) {
00040                   LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?");
00041                   return false;
00042                }
00043                LOG("Got SMS: %s",_smsJunkBuffer);
00044                LOG("Clearing that out before running the test.");
00045                smsCleared = true;
00046             }
00047             Thread::wait(500);
00048          }
00049          if(!smsCleared) {
00050             LOG("Nothing found to clear out.");
00051          }
00052 
00053          LOG("Getting MSISDN");
00054          _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
00055          LOG("Got  MSISDN %s",_ownNumber);
00056 
00057          // try sending SMS to self that contain CRLF sequences
00058          // CR
00059          // LF
00060          // CRLF
00061          // LFCR     
00062          
00063          // note, you can't pass in a pointer to a const string, because the SMSInterface.cpp tries to write to the string
00064          // this is probably a bug as the user might not expect this
00065          
00066          char crTestString[20],lfTestString[20],crlfTestString[20];
00067          sprintf((char*)&crTestString,"CR\rCR\rCR");
00068          sprintf((char*)&lfTestString,"LF\nLF\nLF");
00069          sprintf((char*)&crlfTestString,"CRLF\r\nCRLF");
00070          
00071          int numTestMessages = 3;
00072          char *testMessages[3] = {
00073             (char*)&lfTestString,
00074             (char*)&crTestString,
00075             (char*)&crlfTestString
00076          };
00077          
00078          for(int i=0; i<numTestMessages; i++) {
00079             _smsOut = testMessages[i];
00080             
00081             LOG("Artificially waiting for 2 seconds");
00082             Thread::wait(2000);
00083             LOG("Attempting to send SMS %d of %d",i+1,numTestMessages);
00084             int tries = 3;
00085             int sent = 0;
00086             while(tries--) { 
00087                if(_modem->sendSM(_ownNumber,_smsOut)==0) {
00088                   sent = 1;
00089                   break;
00090                }
00091                LOG("Error sending short message");
00092             }
00093             
00094             if(!sent) {
00095                LOG("Failure to send SMS after 3 tries, aborting.");
00096                return false;
00097             } else {
00098                LOG("Sent: %s",_smsOut);
00099             }
00100             
00101             
00102             bool gotMessage = false;
00103             Timer t;
00104             t.start();
00105             int msToWait = 60000;
00106             LOG("Waiting %d seconds for response",msToWait/1000);
00107             while(!gotMessage && t.read_ms()<msToWait) {
00108                if(_modem->getSMCount(&smCount)!=0) {
00109                   LOG("Failure getting SM count");
00110                   return false;
00111                }
00112                
00113                if(smCount>0) {
00114                   if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
00115                      LOG("Failure getting SM");
00116                      return false;
00117                   }
00118                   LOG("Got SMS: %s after %f seconds.",_smsIn,t.read_ms()/1000.0);
00119                   if(strcmp(_smsIn,_smsOut)!=0) {
00120                      LOG("FAIL: strings did not match");
00121                      return false;
00122                   }
00123                   gotMessage = true;
00124                }
00125                Thread::wait(50);
00126             }
00127             if(!gotMessage) {
00128                LOG("FAIL: timeout on waiting for SMS");
00129                return false;
00130             }
00131          }
00132          
00133          return true;
00134       }
00135       
00136       void allocStorage() {
00137          _ownNumber    = (char*)malloc(_numberLen*sizeof(char));
00138          _senderNumber = (char*)malloc(_numberLen*sizeof(char));
00139          _smsIn        = (char*)malloc(_smsLen*sizeof(char));
00140          _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char));
00141       }
00142       
00143       void freeStorage() {
00144          free(_ownNumber);
00145          free(_senderNumber);
00146          free(_smsIn);
00147          free(_smsJunkBuffer);
00148       }
00149       
00150       char* _ownNumber;
00151       char* _senderNumber;
00152       char* _smsOut;
00153       char* _smsIn;
00154       char* _smsJunkBuffer;
00155       int _smsLen;
00156       int _smsMaxSize;
00157       int _numberLen;
00158 };