Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test50.h@37:847f5f86e9ff, 2012-09-13 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 13 15:26:49 2012 +0000
- Revision:
- 37:847f5f86e9ff
- Parent:
- 34:d9e45aad85f2
- Child:
- 44:6d0ac4747f5b
Test only constructed when executed. INCOMPLETE, need to change som e other stuff to reflect this.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 3:28336c2e94e4 | 1 | #pragma once |
ashleymills | 4:1f8e079924ba | 2 | #include "VodafoneTestCase.h" |
ashleymills | 25:55b865c41f21 | 3 | |
ashleymills | 37:847f5f86e9ff | 4 | extern const char* gTest50Description; |
ashleymills | 25:55b865c41f21 | 5 | |
ashleymills | 3:28336c2e94e4 | 6 | class Test50 : public VodafoneTestCase { |
ashleymills | 3:28336c2e94e4 | 7 | public: |
ashleymills | 33:16126e029d58 | 8 | Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) { |
ashleymills | 4:1f8e079924ba | 9 | _smsLen = 32; |
ashleymills | 4:1f8e079924ba | 10 | _numberLen = 16; |
ashleymills | 33:16126e029d58 | 11 | _description = gTest50Description; |
ashleymills | 33:16126e029d58 | 12 | _testCaseNumber = 50; |
ashleymills | 4:1f8e079924ba | 13 | } |
ashleymills | 4:1f8e079924ba | 14 | |
ashleymills | 4:1f8e079924ba | 15 | virtual void setupTest() { |
ashleymills | 4:1f8e079924ba | 16 | allocStorage(); |
ashleymills | 4:1f8e079924ba | 17 | } |
ashleymills | 4:1f8e079924ba | 18 | |
ashleymills | 11:a286d8112b45 | 19 | virtual void endTest() { |
ashleymills | 4:1f8e079924ba | 20 | freeStorage(); |
ashleymills | 3:28336c2e94e4 | 21 | } |
ashleymills | 3:28336c2e94e4 | 22 | |
ashleymills | 34:d9e45aad85f2 | 23 | virtual bool execute() { |
ashleymills | 25:55b865c41f21 | 24 | LOG(gTest50Description); |
ashleymills | 9:3ff68422f4d7 | 25 | int numIterations = 10; |
ashleymills | 4:1f8e079924ba | 26 | size_t smCount; |
ashleymills | 25:55b865c41f21 | 27 | LOG("...", _testCaseNumber); |
ashleymills | 4:1f8e079924ba | 28 | LOG("Getting MSISDN"); |
ashleymills | 4:1f8e079924ba | 29 | _modem->sendUSSD("*#100#",_ownNumber,_numberLen); |
ashleymills | 4:1f8e079924ba | 30 | LOG("Got MSISDN %s",_ownNumber); |
ashleymills | 9:3ff68422f4d7 | 31 | for(int i=0; i<numIterations; i++) { |
ashleymills | 4:1f8e079924ba | 32 | createRandomString(_smsOut,_smsLen); |
ashleymills | 9:3ff68422f4d7 | 33 | if(_modem->sendSM(_ownNumber,_smsOut)!=0) { |
ashleymills | 9:3ff68422f4d7 | 34 | LOG("Error sending short message"); |
ashleymills | 4:1f8e079924ba | 35 | } |
ashleymills | 12:b50d37429dff | 36 | LOG("Created: %s",_smsOut); |
ashleymills | 4:1f8e079924ba | 37 | bool gotMessage = false; |
ashleymills | 12:b50d37429dff | 38 | Timer t; |
ashleymills | 12:b50d37429dff | 39 | t.start(); |
ashleymills | 12:b50d37429dff | 40 | while(!gotMessage && t.read_ms()<25000) { |
ashleymills | 4:1f8e079924ba | 41 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 4:1f8e079924ba | 42 | LOG("Faiure getting SM count"); |
ashleymills | 4:1f8e079924ba | 43 | return false; |
ashleymills | 4:1f8e079924ba | 44 | } |
ashleymills | 4:1f8e079924ba | 45 | |
ashleymills | 4:1f8e079924ba | 46 | if(smCount>0) { |
ashleymills | 4:1f8e079924ba | 47 | if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { |
ashleymills | 4:1f8e079924ba | 48 | LOG("Failure getting SM"); |
ashleymills | 4:1f8e079924ba | 49 | return false; |
ashleymills | 4:1f8e079924ba | 50 | } |
ashleymills | 4:1f8e079924ba | 51 | LOG("Got SMS: %s",_smsIn); |
ashleymills | 9:3ff68422f4d7 | 52 | if(strcmp(_smsIn,_smsOut)!=0) { |
ashleymills | 9:3ff68422f4d7 | 53 | LOG("FAIL: strings did not match"); |
ashleymills | 9:3ff68422f4d7 | 54 | return false; |
ashleymills | 9:3ff68422f4d7 | 55 | } |
ashleymills | 4:1f8e079924ba | 56 | gotMessage = true; |
ashleymills | 4:1f8e079924ba | 57 | } |
ashleymills | 4:1f8e079924ba | 58 | Thread::wait(50); |
ashleymills | 4:1f8e079924ba | 59 | } |
ashleymills | 12:b50d37429dff | 60 | if(!gotMessage) { |
ashleymills | 12:b50d37429dff | 61 | LOG("FAIL: timeout on waiting for SMS"); |
ashleymills | 12:b50d37429dff | 62 | return false; |
ashleymills | 12:b50d37429dff | 63 | } |
ashleymills | 4:1f8e079924ba | 64 | } |
ashleymills | 3:28336c2e94e4 | 65 | |
ashleymills | 4:1f8e079924ba | 66 | return true; |
ashleymills | 3:28336c2e94e4 | 67 | } |
ashleymills | 3:28336c2e94e4 | 68 | |
ashleymills | 4:1f8e079924ba | 69 | private: |
ashleymills | 4:1f8e079924ba | 70 | void createRandomString(char *target, int len) { |
ashleymills | 4:1f8e079924ba | 71 | for(int i=0; i<len; i++) { |
ashleymills | 9:3ff68422f4d7 | 72 | target[i] = 65+rand()%16; |
ashleymills | 4:1f8e079924ba | 73 | } |
ashleymills | 4:1f8e079924ba | 74 | target[len-1] = 0x00; |
ashleymills | 4:1f8e079924ba | 75 | } |
ashleymills | 4:1f8e079924ba | 76 | |
ashleymills | 4:1f8e079924ba | 77 | void allocStorage() { |
ashleymills | 4:1f8e079924ba | 78 | _ownNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 4:1f8e079924ba | 79 | _senderNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 4:1f8e079924ba | 80 | _smsOut = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 4:1f8e079924ba | 81 | _smsIn = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 4:1f8e079924ba | 82 | } |
ashleymills | 3:28336c2e94e4 | 83 | |
ashleymills | 4:1f8e079924ba | 84 | void freeStorage() { |
ashleymills | 4:1f8e079924ba | 85 | free(_ownNumber); |
ashleymills | 4:1f8e079924ba | 86 | free(_senderNumber); |
ashleymills | 4:1f8e079924ba | 87 | free(_smsOut); |
ashleymills | 4:1f8e079924ba | 88 | free(_smsIn); |
ashleymills | 4:1f8e079924ba | 89 | } |
ashleymills | 4:1f8e079924ba | 90 | |
ashleymills | 4:1f8e079924ba | 91 | char* _ownNumber; |
ashleymills | 4:1f8e079924ba | 92 | char* _senderNumber; |
ashleymills | 4:1f8e079924ba | 93 | char* _smsOut; |
ashleymills | 4:1f8e079924ba | 94 | char* _smsIn; |
ashleymills | 4:1f8e079924ba | 95 | int _smsLen; |
ashleymills | 4:1f8e079924ba | 96 | int _numberLen; |
ashleymills | 3:28336c2e94e4 | 97 | }; |