Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Revision:
72:0e8e769fcf76
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tests/Test15.h	Fri Sep 20 12:36:03 2013 +0000
@@ -0,0 +1,158 @@
+#pragma once
+#include "VodafoneTestCase.h"
+// Test 15: Sends SMSs to self that contain carriage returns and newlines
+extern const char* gTest15Description;
+
+class Test15 : public VodafoneTestCase {
+   public:
+      Test15(VodafoneUSBModem *m) : VodafoneTestCase(m) {
+         _smsLen = 32;
+         _smsMaxSize = 160;     // max size of SMS
+         _numberLen = 16;
+      }
+      
+   private:
+      
+      virtual void setupTest() {
+         allocStorage();
+      }
+      
+      virtual void endTest() {
+         freeStorage();
+      }
+      
+      virtual bool executeTest() {
+         LOG(gTest15Description);
+         size_t smCount;
+         
+         // Clear out the SMS mail box before we run this test.
+         // loop 3 times with a 1/2 second break in between each
+         LOG("... Clearing out SMS mail box first");
+         bool smsCleared = false;
+         for(int j=0; j<3; j++) {
+            if(_modem->getSMCount(&smCount)!=0) {
+               LOG("Failure getting SM count");
+               return false;
+            }
+         
+            for(int i=0; i<smCount; i++) {
+               if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) {
+                  LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?");
+                  return false;
+               }
+               LOG("Got SMS: %s",_smsJunkBuffer);
+               LOG("Clearing that out before running the test.");
+               smsCleared = true;
+            }
+            Thread::wait(500);
+         }
+         if(!smsCleared) {
+            LOG("Nothing found to clear out.");
+         }
+
+         LOG("Getting MSISDN");
+         _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
+         LOG("Got  MSISDN %s",_ownNumber);
+
+         // try sending SMS to self that contain CRLF sequences
+         // CR
+         // LF
+         // CRLF
+         // LFCR     
+         
+         // note, you can't pass in a pointer to a const string, because the SMSInterface.cpp tries to write to the string
+         // this is probably a bug as the user might not expect this
+         
+         char crTestString[20],lfTestString[20],crlfTestString[20];
+         sprintf((char*)&crTestString,"CR\rCR\rCR");
+         sprintf((char*)&lfTestString,"LF\nLF\nLF");
+         sprintf((char*)&crlfTestString,"CRLF\r\nCRLF");
+         
+         int numTestMessages = 3;
+         char *testMessages[3] = {
+            (char*)&lfTestString,
+            (char*)&crTestString,
+            (char*)&crlfTestString
+         };
+         
+         for(int i=0; i<numTestMessages; i++) {
+            _smsOut = testMessages[i];
+            
+            LOG("Artificially waiting for 2 seconds");
+            Thread::wait(2000);
+            LOG("Attempting to send SMS %d of %d",i+1,numTestMessages);
+            int tries = 3;
+            int sent = 0;
+            while(tries--) { 
+               if(_modem->sendSM(_ownNumber,_smsOut)==0) {
+                  sent = 1;
+                  break;
+               }
+               LOG("Error sending short message");
+            }
+            
+            if(!sent) {
+               LOG("Failure to send SMS after 3 tries, aborting.");
+               return false;
+            } else {
+               LOG("Sent: %s",_smsOut);
+            }
+            
+            
+            bool gotMessage = false;
+            Timer t;
+            t.start();
+            int msToWait = 60000;
+            LOG("Waiting %d seconds for response",msToWait/1000);
+            while(!gotMessage && t.read_ms()<msToWait) {
+               if(_modem->getSMCount(&smCount)!=0) {
+                  LOG("Failure getting SM count");
+                  return false;
+               }
+               
+               if(smCount>0) {
+                  if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
+                     LOG("Failure getting SM");
+                     return false;
+                  }
+                  LOG("Got SMS: %s after %f seconds.",_smsIn,t.read_ms()/1000.0);
+                  if(strcmp(_smsIn,_smsOut)!=0) {
+                     LOG("FAIL: strings did not match");
+                     return false;
+                  }
+                  gotMessage = true;
+               }
+               Thread::wait(50);
+            }
+            if(!gotMessage) {
+               LOG("FAIL: timeout on waiting for SMS");
+               return false;
+            }
+         }
+         
+         return true;
+      }
+      
+      void allocStorage() {
+         _ownNumber    = (char*)malloc(_numberLen*sizeof(char));
+         _senderNumber = (char*)malloc(_numberLen*sizeof(char));
+         _smsIn        = (char*)malloc(_smsLen*sizeof(char));
+         _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char));
+      }
+      
+      void freeStorage() {
+         free(_ownNumber);
+         free(_senderNumber);
+         free(_smsIn);
+         free(_smsJunkBuffer);
+      }
+      
+      char* _ownNumber;
+      char* _senderNumber;
+      char* _smsOut;
+      char* _smsIn;
+      char* _smsJunkBuffer;
+      int _smsLen;
+      int _smsMaxSize;
+      int _numberLen;
+};
\ No newline at end of file