Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Files at this revision

API Documentation at this revision

Comitter:
ashleymills
Date:
Wed Aug 22 13:27:34 2012 +0000
Parent:
1:0d63e4db8503
Child:
3:28336c2e94e4
Commit message:
Added TestManager class and LogHeader

Changed in this revision

ExampleTest.h Show annotated file Show diff for this revision Revisions of this file
LogHeader.h Show annotated file Show diff for this revision Revisions of this file
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
VodafoneTestCase.h 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/ExampleTest.h	Wed Aug 22 10:17:54 2012 +0000
+++ b/ExampleTest.h	Wed Aug 22 13:27:34 2012 +0000
@@ -1,19 +1,19 @@
-#pragma once
-#include "VodafoneTestCase.h"
-class ExampleTest : public VodafoneTestCase {
-   public: 
-      ExampleTest(VodafoneUSBModem *m) : VodafoneTestCase(m) {
-      }
-   
-      bool runTest() {
-         DBG("Running USSD test 1212");
-         char ussdResponse[64];
-         if(_modem->sendUSSD("*#100#",ussdResponse,64)!=0) {
-            DBG("Error sending USSD");
-            return false;
-         }
-         
-         DBG("Received USSD response: \"%s\"",ussdResponse);
-         return true;
-      }
+#pragma once
+#include "VodafoneTestCase.h"
+class ExampleTest : public VodafoneTestCase {
+   public: 
+      ExampleTest(VodafoneUSBModem *m) : VodafoneTestCase(m) {
+      }
+   
+      virtual bool runTest() {
+         LOG("Running USSD test 1212");
+         char ussdResponse[64];
+         if(_modem->sendUSSD("*#100#",ussdResponse,64)!=0) {
+            LOG("Error sending USSD");
+            return false;
+         }
+         
+         LOG("Received USSD response: \"%s\"",ussdResponse);
+         return true;
+      }
 };
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LogHeader.h	Wed Aug 22 13:27:34 2012 +0000
@@ -0,0 +1,9 @@
+#pragma once
+#define LOGGER
+#ifdef LOGGER
+	#define LOG(...) { fprintf(stdout,"[LOG] "); fprintf(stdout,__VA_ARGS__); fprintf(stdout,"\r\n"); }
+	#define LOGX(...) { fprintf(stdout,"[LOG] "); fprintf(stdout,__VA_ARGS__) }
+#else
+	#define LOG(...)
+	#define LOGX(...)
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestManager.cpp	Wed Aug 22 13:27:34 2012 +0000
@@ -0,0 +1,24 @@
+#include "TestManager.h"
+#include "ExampleTest.h"
+TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { 
+   _tests.push_back((VodafoneTestCase*)new ExampleTest(_modem));
+}
+
+int TestManager::runAll() {
+   int successfullTests = 0;
+   LOG("Running %d tests...",_tests.size());
+   for(int i=0; i<_tests.size(); i++) {
+      LOG("Running test %d...",i);
+      if(_tests[i]->runTest()) {
+         LOG("...OK");
+         successfullTests++;
+      } else {
+         LOG("...FAIL");
+      }
+   }
+   return successfullTests;
+}
+
+int TestManager::getNumTests() {
+   return _tests.size();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestManager.h	Wed Aug 22 13:27:34 2012 +0000
@@ -0,0 +1,16 @@
+#pragma once
+#include "VodafoneUSBModem.h"
+#include "VodafoneTestCase.h"
+#include <vector>
+class TestManager {
+
+   public:
+      TestManager(VodafoneUSBModem *m);
+      void addTest(VodafoneTestCase *tc);
+      int runAll();
+      int getNumTests();
+      
+   private:
+      VodafoneUSBModem *_modem;
+      vector<VodafoneTestCase*> _tests;
+};
\ No newline at end of file
--- a/VodafoneTestCase.h	Wed Aug 22 10:17:54 2012 +0000
+++ b/VodafoneTestCase.h	Wed Aug 22 13:27:34 2012 +0000
@@ -1,14 +1,15 @@
-#pragma once
-#include "VodafoneUSBModem.h"
-class VodafoneTestCase {
-   public:
-      VodafoneTestCase(VodafoneUSBModem *m) : _modem(m) {
-         
-      }
-      
-      virtual bool runTest() {}
-      
-   protected:
-      VodafoneUSBModem *_modem;
-      
+#pragma once
+#include "VodafoneUSBModem.h"
+#include "LogHeader.h"
+class VodafoneTestCase {
+   public:
+      VodafoneTestCase(VodafoneUSBModem *m) : _modem(m) {
+         
+      }
+      
+      virtual bool runTest() { LOG("Base class runTest called!"); return true; }
+      
+   protected:
+      VodafoneUSBModem *_modem;
+      
 };
\ No newline at end of file
--- a/main.cpp	Wed Aug 22 10:17:54 2012 +0000
+++ b/main.cpp	Wed Aug 22 13:27:34 2012 +0000
@@ -3,12 +3,15 @@
 #define __MODULE__ "net_3g_basic_http_test.cpp"
 #endif
 
+#include "LogHeader.h"
+
 #include "mbed.h"
 #include "socket/bsd_socket.h"
 #include "rtos.h"
 #include "VodafoneUSBModem.h"
 #include "VodafoneTestCase.h"
 #include "ExampleTest.h"
+#include "TestManager.h"
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -19,10 +22,10 @@
 
 void test(void const*) {
   VodafoneUSBModem modem;
-  
-  
-  ExampleTest t(&modem);
-  t.runTest();
+  LOG("Constructing TestManager");
+  TestManager *m = new TestManager(&modem);
+  int numPassed = m->runAll();
+  LOG("Tests complete: %d passes and %d failures.",numPassed,m->getNumTests()-numPassed);
   
   while(1) {
      Thread::wait(1000);