Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Files at this revision

API Documentation at this revision

Comitter:
ashleymills
Date:
Fri Sep 14 12:16:09 2012 +0000
Parent:
39:368988b1542f
Child:
41:9d802bf152fa
Commit message:
Refactoring.

Changed in this revision

TestManager.cpp Show annotated file Show diff for this revision Revisions of this file
TestManager.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test10.cpp Show annotated file Show diff for this revision Revisions of this file
Tests/Test10.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test12.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test13.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test14.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test16.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test23.cpp Show annotated file Show diff for this revision Revisions of this file
Tests/Test56.h Show annotated file Show diff for this revision Revisions of this file
Tests/Tests.cpp Show annotated file Show diff for this revision Revisions of this file
Tests/Tests.h Show annotated file Show diff for this revision Revisions of this file
VodafoneTestCase.h Show annotated file Show diff for this revision Revisions of this file
VodafoneUSBModem_bleedingedge.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TestManager.cpp	Thu Sep 13 15:46:50 2012 +0000
+++ b/TestManager.cpp	Fri Sep 14 12:16:09 2012 +0000
@@ -68,11 +68,20 @@
       case 57: break;
       case 58: break;
       case 59: break;
+      default: return NULL;
    };
+   return NULL; //< For compiler warning
 }
 
 TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) {
-   
+   //_testOutcomes = (bool*)malloc(NUMBER_OF_TESTS*sizeof(bool));
+   //resetTestOutcomes();
+}
+
+void TestManager::resetTestOutcomes() {
+   for(int i=0; i<NUMBER_OF_TESTS; i++) {
+      _testOutcomes[i] = false;
+   }
 }
 
 int TestManager::getTestProfileLength(TestProfile profile) {
@@ -85,6 +94,7 @@
 }
 
 int TestManager::executeTestProfile(TestProfile profile) {
+   //resetTestOutcomes();
    int numPassed = 0;
    if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned
       numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]);
@@ -102,19 +112,15 @@
 void TestManager::listFailures(const int *list, const int listLen) {
    for(int i=0; i<listLen; i++) {
       int testIndex = list[i];
-      VodafoneTestCase* test = getTest(testIndex);
-      if(test==NULL) {
-         LOG("ERROR: Test %d is not in test list!.",testIndex);
-         continue;
-      }
       
-      if(test->_lastRunOutcome==false) {
-         LOG("Test %d:",test->_testCaseNumber);
-         LOG(test->_description);
+      if(_testOutcomes[testIndex]==false) {
+         LOG("Test %d:",testIndex);
+         //LOG(gTestDescriptions[testIndex]);
       }
    }
 }
 
+/*
 VodafoneTestCase* TestManager::getTest(int index) {
    for(int i=0; i<_tests.size(); i++) {
       if(index==_tests[i]->_testCaseNumber)
@@ -122,6 +128,7 @@
    }
    return NULL;
 }
+*/
 
 int TestManager::executeTestList(const int *list, const int listLen) {
    int successfullTests = 0;
--- a/TestManager.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/TestManager.h	Fri Sep 14 12:16:09 2012 +0000
@@ -4,10 +4,7 @@
 #include "Tests.h"
 #include <vector>
 
-enum TestNames {
-   TEST0_SMSSHORT=0,
-   TEST1_SMSLONG
-};
+#define NUMBER_OF_TESTS 100
 
 class TestManager {
 
@@ -15,20 +12,19 @@
       TestManager(VodafoneUSBModem *m);
       void addTest(VodafoneTestCase *tc);
       
-      void listFailures(const int *list, const int listLen);
-      
       bool executeTest(int id);
       bool executeTest(int id, int numTimes);
-      int  executeTestProfile(TestProfile profile);
-      int  executeTestList(const int *list, const int listLen);
+      int executeTestProfile(TestProfile profile);
+      int getTestProfileLength(TestProfile profile);
       
-      VodafoneTestCase* constructTest(int id);
-      
-      VodafoneTestCase* getTest(int index);
-      int getTestProfileLength(TestProfile profile);
       
    private:
       VodafoneUSBModem *_modem;
       vector<VodafoneTestCase*> _tests;
+      VodafoneTestCase* constructTest(int id);
+      int executeTestList(const int *list, const int listLen);
+      void listFailures(const int *list, const int listLen);
+      void resetTestOutcomes();
+      bool *_testOutcomes;
       
 };
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tests/Test10.cpp	Fri Sep 14 12:16:09 2012 +0000
@@ -0,0 +1,46 @@
+#include "Test10.h"
+
+Test10::Test10(VodafoneUSBModem *m) : VodafoneTestCase(m) {
+   _description = gTest10Description;
+   _testCaseNumber = 10;
+}
+      
+void Test10::setupTest() {}
+   
+bool Test10::execute() {
+   HTTPClient http;
+   char msgBuffer[125];
+   bool outcome = true;
+   LOG("Description: %s",gTest10Description);
+   LOG("Connecting to internet");
+   if(_modem->connect("internet","web","web")==0) {
+      LOG("Connected to internet");
+   } else {
+      LOG("Failed to connect to internet");
+      outcome = false;
+   }
+       
+   LOG("Doing HTTP GET for http://www.m2mthings.com/test100.txt");
+   if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) {
+      LOG("Got buffer");
+      char c = 0;
+      for(int i=0; i<100; i++) {
+         if(msgBuffer[i]!=c) {
+            LOG("Strings do not match at char %d (%x,%x)",i,c,msgBuffer[i]);
+            outcome = false;
+            break;
+         }
+         c++;
+         if(c==256)
+            c = 0;
+      }
+      LOG("All bytes match! PASS.");
+   } else {
+      LOG("HTTP get failure");
+      outcome = false;
+   }
+   _modem->disconnect();
+   return outcome;
+}
+      
+void Test10::endTest() { }
\ No newline at end of file
--- a/Tests/Test10.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test10.h	Fri Sep 14 12:16:09 2012 +0000
@@ -3,58 +3,10 @@
 #include "HTTPClient.h"
 extern const char *gTest10Description;
 
-//const int gTest10Depends[] = {};
-
 class Test10 : public VodafoneTestCase {
    public: 
-      Test10(VodafoneUSBModem *m) : VodafoneTestCase(m) {
-         _description = gTest10Description;
-         _testCaseNumber = 10;
-      }
-      
-      virtual void setupTest() {
-         
-      }
-   
-      virtual bool execute() {
-         HTTPClient http;
-         char msgBuffer[125];
-         bool outcome = true;
-         LOG("Description: %s",gTest10Description);
-         LOG("Connecting to internet");
-         if(_modem->connect("internet","web","web")==0) {
-            LOG("Connected to internet");
-         } else {
-            LOG("Failed to connect to internet");
-            outcome = false;
-         }
-       
-         LOG("Test %d, retrieving a 5MB file via HTTP.", _testCaseNumber);
-         if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) {
-            LOG("Got \"%s\"",msgBuffer);
-            char c = 0;
-            for(int i=0; i<100; i++) {
-               if(msgBuffer[i]!=c) {
-                  LOG("Strings do not match at char %d (%x,%x)",i,c,msgBuffer[i]);
-                  outcome = false;
-                  break;
-               }
-               c++;
-               if(c==256)
-                  c = 0;
-            }
-         } else {
-            LOG("HTTP get failure");
-            outcome = false;
-         }
-         _modem->disconnect();
-         return outcome;
-      }
-      
-      virtual void endTest() {
-         
-      }
-      
-   private:
-      
+      Test10(VodafoneUSBModem *m);
+      virtual void setupTest();
+      virtual bool execute();
+      virtual void endTest();
 };
\ No newline at end of file
--- a/Tests/Test12.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test12.h	Fri Sep 14 12:16:09 2012 +0000
@@ -1,8 +1,6 @@
 #pragma once
 #include "VodafoneTestCase.h"
 
-
-
 // this test case will wait to receive an SMS from the modem.
 // if the method that reports a message waiting returns an error it will fail.
 // if the method that returns the message from the mailbox returns an error it will fai.
@@ -11,6 +9,7 @@
 // TODO: this should wait for a set time before failing.
 
 extern const char *gTest12Description;
+extern const char *gAlphabetNumbersMessage;
 
 class Test12 : public VodafoneTestCase {
    public: 
@@ -50,7 +49,7 @@
                             return false;
                         }
                     LOG("The message is from number: %s and the message is: \"%s\"", num, msg);
-                    if (strcmp (msg, alphabetNumbersMessage) ==0)
+                    if (strcmp (msg, gAlphabetNumbersMessage) ==0)
                         {
                             LOG("Success receiving alphabet message matches the sent message");
                             return true;
--- a/Tests/Test13.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test13.h	Fri Sep 14 12:16:09 2012 +0000
@@ -11,6 +11,7 @@
 // TODO: this should wait for a set time before failing.
 
 extern const char *gTest13Description;
+extern const char *gIrregularMessage;
 
 class Test13 : public VodafoneTestCase {
    public: 
@@ -50,7 +51,7 @@
                             return false;
                         }
                     LOG("The message is from number: %s and the message is: \"%s\"", num, msg);
-                    if (strcmp (msg, irregularMessage) ==0)
+                    if (strcmp (msg, gIrregularMessage) ==0)
                         {
                             LOG("Success receiving alphabet message matches the sent message");
                             return true;
--- a/Tests/Test14.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test14.h	Fri Sep 14 12:16:09 2012 +0000
@@ -1,86 +1,88 @@
-#pragma once
-#include "VodafoneTestCase.h"
-//#define __DEBUG__ 1
-
-// this test case will wait to send an SMS from the modem.
-// if the method that sends a message returns an error it will fail.
-// it will report the test as failed if any of the above happens.
-// it does not wait after it has succesfully sent an SMS.
-// this test basic characters and numbers can be sent via SMS.
-
-extern const char *gTest14Description;
-
-class Test14 : public VodafoneTestCase {
-   public: 
-
-
-      Test14(VodafoneUSBModem *m) : VodafoneTestCase(m) {
-         _description = gTest14Description;
-         _testCaseNumber = 14;
-      }
-      
-   
-      virtual bool execute() {
-            
-         LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_UNKNOWN;
-         LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN;
-         int rssi = -1000;
-         if(_modem->getLinkState(&rssi, &regState, &bearer)==0) 
-            {
-                if(rssi==-1000) 
-                    { LOG("Checking signal strength - RSSI: Error."); return false;} 
-               else 
-                { LOG("Signal strength is: RSSI: %d",rssi);}
-            
-            
-               switch(regState) {
-                  case LinkMonitor::REGISTRATION_STATE_UNKNOWN:
-                     LOG("regState: UNKNOWN. Failing.");
-                     return false;
-                  case LinkMonitor::REGISTRATION_STATE_REGISTERING:
-                     LOG("regState: REGISTERING");
-                     break;
-                  case LinkMonitor::REGISTRATION_STATE_DENIED:
-                     LOG("regState: DENIED");
-                     return false;
-                  case LinkMonitor::REGISTRATION_STATE_NO_SIGNAL:
-                     LOG("regState: NO SIGNAL");
-                     return false;
-                  case LinkMonitor::REGISTRATION_STATE_HOME_NETWORK:
-                     LOG("regState: HOME NETWORK");
-                     break;
-                  case LinkMonitor::REGISTRATION_STATE_ROAMING:
-                     LOG("regState: ROAMING");
-                     break;
-                  default:
-                     LOG("regState: ERROR. Failing.");
-                     return false;
-               }
-            }
-  
-                         
-         LOG("Test %d sending an SMS message...", _testCaseNumber);
-         LOG("Sending SMS:' %s ' to test phone: %s , waiting for response.", irregularMessage, testPhoneNumber);
-         
-         int ret = _modem->sendSM(testPhoneNumber, irregularMessage);
-         
-         if (ret)
-            {
-                LOG("Error in sending the SMS message. The return values is: %d", ret);
-                
-                switch(ret){
-                    case(NET_INVALID): LOG("Error message is: 'phone number is invalid size, must be less than 16 digits'.");break;
-                    case(NET_PROTOCOL): LOG("Error message is: 'protocol error from the modem'.");break;
-                    default: LOG("Undefined error message.");         
-
-                }
-                return false;
-            }
-         LOG("Test %d passed...", _testCaseNumber);
-         return true;                
-      }
-
-   private:
-     
-
+#pragma once
+#include "VodafoneTestCase.h"
+//#define __DEBUG__ 1
+
+// this test case will wait to send an SMS from the modem.
+// if the method that sends a message returns an error it will fail.
+// it will report the test as failed if any of the above happens.
+// it does not wait after it has succesfully sent an SMS.
+// this test basic characters and numbers can be sent via SMS.
+
+extern const char *gTest14Description;
+extern const char *gTestPhoneNumber;
+extern const char *gAlphabetNumbersMessage;
+
+class Test14 : public VodafoneTestCase {
+   public: 
+
+
+      Test14(VodafoneUSBModem *m) : VodafoneTestCase(m) {
+         _description = gTest14Description;
+         _testCaseNumber = 14;
+      }
+      
+   
+      virtual bool execute() {
+            
+         LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_UNKNOWN;
+         LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN;
+         int rssi = -1000;
+         if(_modem->getLinkState(&rssi, &regState, &bearer)==0) 
+            {
+                if(rssi==-1000) 
+                    { LOG("Checking signal strength - RSSI: Error."); return false;} 
+               else 
+                { LOG("Signal strength is: RSSI: %d",rssi);}
+            
+            
+               switch(regState) {
+                  case LinkMonitor::REGISTRATION_STATE_UNKNOWN:
+                     LOG("regState: UNKNOWN. Failing.");
+                     return false;
+                  case LinkMonitor::REGISTRATION_STATE_REGISTERING:
+                     LOG("regState: REGISTERING");
+                     break;
+                  case LinkMonitor::REGISTRATION_STATE_DENIED:
+                     LOG("regState: DENIED");
+                     return false;
+                  case LinkMonitor::REGISTRATION_STATE_NO_SIGNAL:
+                     LOG("regState: NO SIGNAL");
+                     return false;
+                  case LinkMonitor::REGISTRATION_STATE_HOME_NETWORK:
+                     LOG("regState: HOME NETWORK");
+                     break;
+                  case LinkMonitor::REGISTRATION_STATE_ROAMING:
+                     LOG("regState: ROAMING");
+                     break;
+                  default:
+                     LOG("regState: ERROR. Failing.");
+                     return false;
+               }
+            }
+  
+                         
+         LOG("Test %d sending an SMS message...", _testCaseNumber);
+         LOG("Sending SMS:' %s ' to test phone: %s , waiting for response.", gIrregularMessage, gTestPhoneNumber);
+         
+         int ret = _modem->sendSM(gTestPhoneNumber, gIrregularMessage);
+         
+         if (ret)
+            {
+                LOG("Error in sending the SMS message. The return values is: %d", ret);
+                
+                switch(ret){
+                    case(NET_INVALID): LOG("Error message is: 'phone number is invalid size, must be less than 16 digits'.");break;
+                    case(NET_PROTOCOL): LOG("Error message is: 'protocol error from the modem'.");break;
+                    default: LOG("Undefined error message.");         
+
+                }
+                return false;
+            }
+         LOG("Test %d passed...", _testCaseNumber);
+         return true;                
+      }
+
+   private:
+     
+
 };
\ No newline at end of file
--- a/Tests/Test16.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test16.h	Fri Sep 14 12:16:09 2012 +0000
@@ -61,9 +61,9 @@
   
                          
          LOG("Test %d sending an SMS message...", _testCaseNumber);
-         LOG("Sending SMS:' %s ' to test phone: %s , waiting for response.", alphabetNumbersMessage, testPhoneNumber);
+         LOG("Sending SMS:' %s ' to test phone: %s , waiting for response.", gAlphabetNumbersMessage, gTestPhoneNumber);
          
-         int ret = _modem->sendSM(testPhoneNumber, alphabetNumbersMessage);
+         int ret = _modem->sendSM(gTestPhoneNumber, gAlphabetNumbersMessage);
          
          if (ret)
             {
--- a/Tests/Test23.cpp	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test23.cpp	Fri Sep 14 12:16:09 2012 +0000
@@ -2,8 +2,9 @@
 #include "Test23.h"
 
 const char gTest23USSDMessage[161] = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
+
 Test23::Test23(VodafoneUSBModem *m) : VodafoneTestCase(m) {
-   _description = gTest23Description;
+   //_description = gTest23Description;
    _testCaseNumber = 23;
 }
       
--- a/Tests/Test56.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Test56.h	Fri Sep 14 12:16:09 2012 +0000
@@ -57,21 +57,23 @@
       
          LOG("Creating GSM test buffer");
          LOG("Test %d sending an SMS message...", _testCaseNumber);
-         LOG("Sending SMS:' %s ' to test phone: %s , waiting for response.", irregularMessage, testPhoneNumber);
+         LOG("Sending SMS:' %s ' to test phone: %s , waiting for response.", gIrregularMessage, gTestPhoneNumber);
          
          // create a buffer and send each character until you can send them all
          char shortBuffer[30];
          
-         for (int i=0; i < sizeof(irregularMessage); i++)
+         // XXX What are you doing here nick? What is the size of gIrregularMessage? It's a pointer!! You're looking for strlen
+         // And gIrregularMessage is longer than shortBuffer so you are goign to kill someone's memory
+         for (int i=0; i < sizeof(gIrregularMessage); i++)
             {
-                shortBuffer[i] = irregularMessage[i];
+                shortBuffer[i] = gIrregularMessage[i];
                 LOG("Buffer is now: %s", shortBuffer);
-                LOG("Irregular message is %s", irregularMessage);
-                int ret = _modem->sendSM(testPhoneNumber, shortBuffer);
+                LOG("Irregular message is %s", gIrregularMessage);
+                int ret = _modem->sendSM(gTestPhoneNumber, shortBuffer);
 
             }
          
-         int ret = _modem->sendSM(testPhoneNumber, irregularMessage);
+         int ret = _modem->sendSM(gTestPhoneNumber, gIrregularMessage);
          
          if (ret)
             {
--- a/Tests/Tests.cpp	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Tests.cpp	Fri Sep 14 12:16:09 2012 +0000
@@ -11,4 +11,14 @@
 const char* gTest25Description = "Retrieve signal strength and print it.";
 const char* gTest26Description = "x30 -> Retrieve signal strength and print it.";
 const char* gTest50Description = "x10 -> Retreive MSISDN and send SMS to self";
-const char* gTest56Description = "Wait for SMS. Send a response.";
\ No newline at end of file
+const char* gTest56Description = "Wait for SMS. Send a response.";
+
+
+// globals used for tests
+const char* gMyMessage              = "myMessage is golden";
+const char* gTestPhoneNumber        = "+447717275049";
+//const char* testPhoneNumber        = "+447785666088";
+const char* gTestMessage            = "this is a test message !";
+const char* gAlphabetNumbersMessage = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+const char* gAllCharsMessage        = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ[]{}()!�$%&*,.':;";
+const char* gIrregularMessage       = "/:[]{}()!�$%&*,.';";
--- a/Tests/Tests.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/Tests/Tests.h	Fri Sep 14 12:16:09 2012 +0000
@@ -44,6 +44,11 @@
 };
 
 /*
+static const char* gTestDescriptions[] = {
+   gTest10Description
+};
+
+
 static const int* gTestDependencies[] = {
    gTest10Depends,
    gTest12Depends,
--- a/VodafoneTestCase.h	Thu Sep 13 15:46:50 2012 +0000
+++ b/VodafoneTestCase.h	Fri Sep 14 12:16:09 2012 +0000
@@ -2,22 +2,12 @@
 #include "VodafoneUSBModem.h"
 #include "LogHeader.h"
 
-const char myMessage[] = "myMessage is golden";
-//const char testPhoneNumber[] = "+447717275049";
-const char testPhoneNumber[] = "+447785666088";
-const char testMessage[] = "this is a test message !";
-const char alphabetNumbersMessage[] = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-const char allCharsMessage[] = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ[]{}()!£$%&*,.':;";
-const char irregularMessage[] = "/:[]{}()!£$%&*,.';";
-
-
 class VodafoneTestCase {
    public:
       VodafoneTestCase(VodafoneUSBModem *m) : _modem(m) , _lastRunTime(0), _lastRunOutcome(false) {
       }
       
       bool run() {
-         _lastRunTime = time(NULL);
          setupTest();
          _lastRunOutcome = execute();
          endTest();
--- a/VodafoneUSBModem_bleedingedge.lib	Thu Sep 13 15:46:50 2012 +0000
+++ b/VodafoneUSBModem_bleedingedge.lib	Fri Sep 14 12:16:09 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#157dd8ce4e55
+http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#b53c619b036d
--- a/main.cpp	Thu Sep 13 15:46:50 2012 +0000
+++ b/main.cpp	Fri Sep 14 12:16:09 2012 +0000
@@ -31,20 +31,11 @@
    }
 }
 
-int* getStack() {
-    int dummy;
-    return &dummy;
-}
-
 void test(void const*) {
   VodafoneUSBModem modem;
   LOG("Constructing TestManager");
+  LOG("Running tests.");
   TestManager *m = new TestManager(&modem);
-  int *heap = (int*)malloc(8*sizeof(int));
-  int *stack = getStack();
-  
-  LOG("heap: %d, stack: %d, size: %d",heap,stack,stack-heap);
-  LOG("Running tests.");
   int numPassed = m->executeTestProfile(TESTS_AUTOMATED);
   loopForever();
 }