Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test15.h@74:e52ac9624f7f, 2014-01-29 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Jan 29 16:34:38 2014 +0000
- Revision:
- 74:e52ac9624f7f
- Parent:
- 72:0e8e769fcf76
Updated dependencies to latest versions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 72:0e8e769fcf76 | 1 | #pragma once |
ashleymills | 72:0e8e769fcf76 | 2 | #include "VodafoneTestCase.h" |
ashleymills | 72:0e8e769fcf76 | 3 | // Test 15: Sends SMSs to self that contain carriage returns and newlines |
ashleymills | 72:0e8e769fcf76 | 4 | extern const char* gTest15Description; |
ashleymills | 72:0e8e769fcf76 | 5 | |
ashleymills | 72:0e8e769fcf76 | 6 | class Test15 : public VodafoneTestCase { |
ashleymills | 72:0e8e769fcf76 | 7 | public: |
ashleymills | 72:0e8e769fcf76 | 8 | Test15(VodafoneUSBModem *m) : VodafoneTestCase(m) { |
ashleymills | 72:0e8e769fcf76 | 9 | _smsLen = 32; |
ashleymills | 72:0e8e769fcf76 | 10 | _smsMaxSize = 160; // max size of SMS |
ashleymills | 72:0e8e769fcf76 | 11 | _numberLen = 16; |
ashleymills | 72:0e8e769fcf76 | 12 | } |
ashleymills | 72:0e8e769fcf76 | 13 | |
ashleymills | 72:0e8e769fcf76 | 14 | private: |
ashleymills | 72:0e8e769fcf76 | 15 | |
ashleymills | 72:0e8e769fcf76 | 16 | virtual void setupTest() { |
ashleymills | 72:0e8e769fcf76 | 17 | allocStorage(); |
ashleymills | 72:0e8e769fcf76 | 18 | } |
ashleymills | 72:0e8e769fcf76 | 19 | |
ashleymills | 72:0e8e769fcf76 | 20 | virtual void endTest() { |
ashleymills | 72:0e8e769fcf76 | 21 | freeStorage(); |
ashleymills | 72:0e8e769fcf76 | 22 | } |
ashleymills | 72:0e8e769fcf76 | 23 | |
ashleymills | 72:0e8e769fcf76 | 24 | virtual bool executeTest() { |
ashleymills | 72:0e8e769fcf76 | 25 | LOG(gTest15Description); |
ashleymills | 72:0e8e769fcf76 | 26 | size_t smCount; |
ashleymills | 72:0e8e769fcf76 | 27 | |
ashleymills | 72:0e8e769fcf76 | 28 | // Clear out the SMS mail box before we run this test. |
ashleymills | 72:0e8e769fcf76 | 29 | // loop 3 times with a 1/2 second break in between each |
ashleymills | 72:0e8e769fcf76 | 30 | LOG("... Clearing out SMS mail box first"); |
ashleymills | 72:0e8e769fcf76 | 31 | bool smsCleared = false; |
ashleymills | 72:0e8e769fcf76 | 32 | for(int j=0; j<3; j++) { |
ashleymills | 72:0e8e769fcf76 | 33 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 72:0e8e769fcf76 | 34 | LOG("Failure getting SM count"); |
ashleymills | 72:0e8e769fcf76 | 35 | return false; |
ashleymills | 72:0e8e769fcf76 | 36 | } |
ashleymills | 72:0e8e769fcf76 | 37 | |
ashleymills | 72:0e8e769fcf76 | 38 | for(int i=0; i<smCount; i++) { |
ashleymills | 72:0e8e769fcf76 | 39 | if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { |
ashleymills | 72:0e8e769fcf76 | 40 | LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); |
ashleymills | 72:0e8e769fcf76 | 41 | return false; |
ashleymills | 72:0e8e769fcf76 | 42 | } |
ashleymills | 72:0e8e769fcf76 | 43 | LOG("Got SMS: %s",_smsJunkBuffer); |
ashleymills | 72:0e8e769fcf76 | 44 | LOG("Clearing that out before running the test."); |
ashleymills | 72:0e8e769fcf76 | 45 | smsCleared = true; |
ashleymills | 72:0e8e769fcf76 | 46 | } |
ashleymills | 72:0e8e769fcf76 | 47 | Thread::wait(500); |
ashleymills | 72:0e8e769fcf76 | 48 | } |
ashleymills | 72:0e8e769fcf76 | 49 | if(!smsCleared) { |
ashleymills | 72:0e8e769fcf76 | 50 | LOG("Nothing found to clear out."); |
ashleymills | 72:0e8e769fcf76 | 51 | } |
ashleymills | 72:0e8e769fcf76 | 52 | |
ashleymills | 72:0e8e769fcf76 | 53 | LOG("Getting MSISDN"); |
ashleymills | 72:0e8e769fcf76 | 54 | _modem->sendUSSD("*#100#",_ownNumber,_numberLen); |
ashleymills | 72:0e8e769fcf76 | 55 | LOG("Got MSISDN %s",_ownNumber); |
ashleymills | 72:0e8e769fcf76 | 56 | |
ashleymills | 72:0e8e769fcf76 | 57 | // try sending SMS to self that contain CRLF sequences |
ashleymills | 72:0e8e769fcf76 | 58 | // CR |
ashleymills | 72:0e8e769fcf76 | 59 | // LF |
ashleymills | 72:0e8e769fcf76 | 60 | // CRLF |
ashleymills | 72:0e8e769fcf76 | 61 | // LFCR |
ashleymills | 72:0e8e769fcf76 | 62 | |
ashleymills | 72:0e8e769fcf76 | 63 | // note, you can't pass in a pointer to a const string, because the SMSInterface.cpp tries to write to the string |
ashleymills | 72:0e8e769fcf76 | 64 | // this is probably a bug as the user might not expect this |
ashleymills | 72:0e8e769fcf76 | 65 | |
ashleymills | 72:0e8e769fcf76 | 66 | char crTestString[20],lfTestString[20],crlfTestString[20]; |
ashleymills | 72:0e8e769fcf76 | 67 | sprintf((char*)&crTestString,"CR\rCR\rCR"); |
ashleymills | 72:0e8e769fcf76 | 68 | sprintf((char*)&lfTestString,"LF\nLF\nLF"); |
ashleymills | 72:0e8e769fcf76 | 69 | sprintf((char*)&crlfTestString,"CRLF\r\nCRLF"); |
ashleymills | 72:0e8e769fcf76 | 70 | |
ashleymills | 72:0e8e769fcf76 | 71 | int numTestMessages = 3; |
ashleymills | 72:0e8e769fcf76 | 72 | char *testMessages[3] = { |
ashleymills | 72:0e8e769fcf76 | 73 | (char*)&lfTestString, |
ashleymills | 72:0e8e769fcf76 | 74 | (char*)&crTestString, |
ashleymills | 72:0e8e769fcf76 | 75 | (char*)&crlfTestString |
ashleymills | 72:0e8e769fcf76 | 76 | }; |
ashleymills | 72:0e8e769fcf76 | 77 | |
ashleymills | 72:0e8e769fcf76 | 78 | for(int i=0; i<numTestMessages; i++) { |
ashleymills | 72:0e8e769fcf76 | 79 | _smsOut = testMessages[i]; |
ashleymills | 72:0e8e769fcf76 | 80 | |
ashleymills | 72:0e8e769fcf76 | 81 | LOG("Artificially waiting for 2 seconds"); |
ashleymills | 72:0e8e769fcf76 | 82 | Thread::wait(2000); |
ashleymills | 72:0e8e769fcf76 | 83 | LOG("Attempting to send SMS %d of %d",i+1,numTestMessages); |
ashleymills | 72:0e8e769fcf76 | 84 | int tries = 3; |
ashleymills | 72:0e8e769fcf76 | 85 | int sent = 0; |
ashleymills | 72:0e8e769fcf76 | 86 | while(tries--) { |
ashleymills | 72:0e8e769fcf76 | 87 | if(_modem->sendSM(_ownNumber,_smsOut)==0) { |
ashleymills | 72:0e8e769fcf76 | 88 | sent = 1; |
ashleymills | 72:0e8e769fcf76 | 89 | break; |
ashleymills | 72:0e8e769fcf76 | 90 | } |
ashleymills | 72:0e8e769fcf76 | 91 | LOG("Error sending short message"); |
ashleymills | 72:0e8e769fcf76 | 92 | } |
ashleymills | 72:0e8e769fcf76 | 93 | |
ashleymills | 72:0e8e769fcf76 | 94 | if(!sent) { |
ashleymills | 72:0e8e769fcf76 | 95 | LOG("Failure to send SMS after 3 tries, aborting."); |
ashleymills | 72:0e8e769fcf76 | 96 | return false; |
ashleymills | 72:0e8e769fcf76 | 97 | } else { |
ashleymills | 72:0e8e769fcf76 | 98 | LOG("Sent: %s",_smsOut); |
ashleymills | 72:0e8e769fcf76 | 99 | } |
ashleymills | 72:0e8e769fcf76 | 100 | |
ashleymills | 72:0e8e769fcf76 | 101 | |
ashleymills | 72:0e8e769fcf76 | 102 | bool gotMessage = false; |
ashleymills | 72:0e8e769fcf76 | 103 | Timer t; |
ashleymills | 72:0e8e769fcf76 | 104 | t.start(); |
ashleymills | 72:0e8e769fcf76 | 105 | int msToWait = 60000; |
ashleymills | 72:0e8e769fcf76 | 106 | LOG("Waiting %d seconds for response",msToWait/1000); |
ashleymills | 72:0e8e769fcf76 | 107 | while(!gotMessage && t.read_ms()<msToWait) { |
ashleymills | 72:0e8e769fcf76 | 108 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 72:0e8e769fcf76 | 109 | LOG("Failure getting SM count"); |
ashleymills | 72:0e8e769fcf76 | 110 | return false; |
ashleymills | 72:0e8e769fcf76 | 111 | } |
ashleymills | 72:0e8e769fcf76 | 112 | |
ashleymills | 72:0e8e769fcf76 | 113 | if(smCount>0) { |
ashleymills | 72:0e8e769fcf76 | 114 | if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { |
ashleymills | 72:0e8e769fcf76 | 115 | LOG("Failure getting SM"); |
ashleymills | 72:0e8e769fcf76 | 116 | return false; |
ashleymills | 72:0e8e769fcf76 | 117 | } |
ashleymills | 72:0e8e769fcf76 | 118 | LOG("Got SMS: %s after %f seconds.",_smsIn,t.read_ms()/1000.0); |
ashleymills | 72:0e8e769fcf76 | 119 | if(strcmp(_smsIn,_smsOut)!=0) { |
ashleymills | 72:0e8e769fcf76 | 120 | LOG("FAIL: strings did not match"); |
ashleymills | 72:0e8e769fcf76 | 121 | return false; |
ashleymills | 72:0e8e769fcf76 | 122 | } |
ashleymills | 72:0e8e769fcf76 | 123 | gotMessage = true; |
ashleymills | 72:0e8e769fcf76 | 124 | } |
ashleymills | 72:0e8e769fcf76 | 125 | Thread::wait(50); |
ashleymills | 72:0e8e769fcf76 | 126 | } |
ashleymills | 72:0e8e769fcf76 | 127 | if(!gotMessage) { |
ashleymills | 72:0e8e769fcf76 | 128 | LOG("FAIL: timeout on waiting for SMS"); |
ashleymills | 72:0e8e769fcf76 | 129 | return false; |
ashleymills | 72:0e8e769fcf76 | 130 | } |
ashleymills | 72:0e8e769fcf76 | 131 | } |
ashleymills | 72:0e8e769fcf76 | 132 | |
ashleymills | 72:0e8e769fcf76 | 133 | return true; |
ashleymills | 72:0e8e769fcf76 | 134 | } |
ashleymills | 72:0e8e769fcf76 | 135 | |
ashleymills | 72:0e8e769fcf76 | 136 | void allocStorage() { |
ashleymills | 72:0e8e769fcf76 | 137 | _ownNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 72:0e8e769fcf76 | 138 | _senderNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 72:0e8e769fcf76 | 139 | _smsIn = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 72:0e8e769fcf76 | 140 | _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); |
ashleymills | 72:0e8e769fcf76 | 141 | } |
ashleymills | 72:0e8e769fcf76 | 142 | |
ashleymills | 72:0e8e769fcf76 | 143 | void freeStorage() { |
ashleymills | 72:0e8e769fcf76 | 144 | free(_ownNumber); |
ashleymills | 72:0e8e769fcf76 | 145 | free(_senderNumber); |
ashleymills | 72:0e8e769fcf76 | 146 | free(_smsIn); |
ashleymills | 72:0e8e769fcf76 | 147 | free(_smsJunkBuffer); |
ashleymills | 72:0e8e769fcf76 | 148 | } |
ashleymills | 72:0e8e769fcf76 | 149 | |
ashleymills | 72:0e8e769fcf76 | 150 | char* _ownNumber; |
ashleymills | 72:0e8e769fcf76 | 151 | char* _senderNumber; |
ashleymills | 72:0e8e769fcf76 | 152 | char* _smsOut; |
ashleymills | 72:0e8e769fcf76 | 153 | char* _smsIn; |
ashleymills | 72:0e8e769fcf76 | 154 | char* _smsJunkBuffer; |
ashleymills | 72:0e8e769fcf76 | 155 | int _smsLen; |
ashleymills | 72:0e8e769fcf76 | 156 | int _smsMaxSize; |
ashleymills | 72:0e8e769fcf76 | 157 | int _numberLen; |
ashleymills | 72:0e8e769fcf76 | 158 | }; |