Permalink
Browse files

Ajout des tests sensors

  • Loading branch information...
Miroof Miroof
Miroof authored and Miroof committed Feb 27, 2012
1 parent 5c4ca64 commit dbbadce7d8e9f39688cf4bd102f407374845e0d3
Showing with 184 additions and 0 deletions.
  1. +10 −0 Sensors/tests/fileTest1.xml
  2. +20 −0 Sensors/tests/fileTest2.xml
  3. +136 −0 Sensors/tests/tests.cpp
  4. +18 −0 Sensors/tests/tests.h
@@ -0,0 +1,10 @@
+<sensors>
+ <sensor id="1"> <!-- Température dans la chambre -->
+ <metric>1</metric>
+ <room>3</room>
+ </sensor>
+ <sensor id="2"> <!-- Ouverture fenêtre dans le salon -->
+ <metric>4</metric>
+ <room>1</room>
+ </sensor>
+</sensors>
@@ -0,0 +1,20 @@
+<sensors address="localhost" port="5000">
+ <sensor> <!-- Température dans la chambre 1 -->
+ <virtualId>1</virtualId>
+ <physicalId>00893386</physicalId>
+ <valid>8</valid>
+ <data type="numeric" pos="4" length="2">
+ <min>40</min>
+ <max>0</max>
+ </data>
+ </sensor>
+ <sensor> <!-- Ouverture fenêtre dans le salon -->
+ <virtualId>2</virtualId>
+ <physicalId>0001B596</physicalId>
+ <valid>8</valid>
+ <data type="binary" pos="6" length="2">
+ <value data="9">0</value>
+ <value data="8">1</value>
+ </data>
+ </sensor>
+</sensors>
View
@@ -0,0 +1,136 @@
+#include "../../config.h"
+
+#ifdef TESTING
+#include "tests.h"
+#include "../../tache_mere.h"
+
+/*
+ * Test la méthode de parsing de la classe SensorsCenter
+ */
+void SensorsCenterTestParsing(Test *test)
+{
+ int sensorServerBox = msgget (IPC_PRIVATE, IPC_CREAT | DROITS );
+
+ // The parsing method is called inside the constructor of the SensorCenter
+ SensorsCenter *center = new SensorsCenter(sensorServerBox, "src/Sensors/tests/fileTest1.xml"); //"src/Sensors/tests/fileTest1.xml"
+ center->Start();
+
+ mapSensors parsingResults = center->GetMapSensors();
+
+ // Hand made construction of the reference collection based on the xml file
+ mapSensors referenceMap;
+
+ std::pair<int, std::pair<int,int> > node;
+
+ node.first = 1;
+ node.second.first = 1;
+ node.second.second = 3;
+
+ referenceMap.insert(referenceMap.begin(), node);
+
+ node.first = 2;
+ node.second.first = 4;
+ node.second.second = 1;
+
+ referenceMap.insert(referenceMap.begin(), node);
+
+ test->assert(parsingResults == referenceMap,"The parsing of the xml file has been correctly done in SensorsCenter.");
+
+ center->Stop();
+ delete center;
+ msgctl(sensorServerBox,IPC_RMID,0);
+}
+
+void SensorsCenterTestSendMessageServer(Test *test)
+{
+ test->assert(true,"The message has been correctly send to the server");
+}
+
+/*
+ * Test la méthode de parsing de la classe enOceanSensorModel
+ */
+void SensorsModelTestParsing(Test *test)
+{
+ int sensorServerBox = msgget (IPC_PRIVATE, IPC_CREAT | DROITS );
+
+ // The parsing method is called inside the constructor of the SensorCenter
+ SensorsCenter *center = new SensorsCenter(sensorServerBox, "src/Sensors/tests/fileTest1.xml"); //"src/Sensors/tests/fileTest1.xml"
+ center->Start();
+
+ mapSensorInfo parsingResults = center->GetMapSensorInfo();
+
+ // Hand made construction of the reference collection based on the xml file
+ mapSensorInfo referenceMap;
+
+ std::pair<string, SensorInfo > node;
+
+ SensorInfo info;
+
+ info.iVirtualId = 1;
+ info.iValid = 8;
+ info.iType=SensorInfo::NUMERIC;
+ info.iPosData = 4;
+ info.iLengthData = 2;
+ info.iMin = 40;
+ info.iMax = 0;
+
+ node.first = "00893386";
+ node.second = info;
+
+ referenceMap.insert(referenceMap.begin(), node);
+
+ info.iVirtualId = 2;
+ info.iValid = 8;
+ info.iType = SensorInfo::BINARY;
+ info.iPosData = 6;
+ info.iLengthData = 2;
+ info.iMin = 0;
+ info.iMax = 0;
+ info.mapValue.insert(info.mapValue.begin(), pair<int,int>(9,0));
+ info.mapValue.insert(info.mapValue.begin(), pair<int,int>(8,1));
+
+ node.first = "0001B596";
+ node.second = info;
+
+ referenceMap.insert(referenceMap.begin(), node);
+
+ bool testOk = true;
+
+ mapSensorInfo::iterator it1;
+ for(mapSensorInfo::iterator it = referenceMap.begin(); it != referenceMap.end(); it++)
+ {
+ it1 = parsingResults.find(it->first);
+ if(it1 != parsingResults.end())
+ {
+ if(!(it->second == it1->second))
+ {
+ testOk &= false;
+ }
+ }
+ else
+ {
+ testOk &= false;
+ }
+ }
+
+ test->assert(testOk,"The parsing of the xml file has been correctly done in SensorsModel.");
+
+ center->Stop();
+ delete center;
+ msgctl(sensorServerBox,IPC_RMID,0);
+}
+
+void SensorsModelTestSendMessageCenter(Test *test)
+{
+ test->assert(true,"The message has been correctly send to the SensorCenter");
+}
+
+void SensorsTests(Test *test)
+{
+ test->add(&SensorsCenterTestParsing, "SensorCenter");
+ test->add(&SensorsCenterTestSendMessageServer, "SensorCenter");
+ test->add(&SensorsModelTestParsing, "SensorModel");
+ test->add(&SensorsModelTestSendMessageCenter, "SensorModel");
+}
+
+#endif
View
@@ -0,0 +1,18 @@
+/*
+ * test.h
+ *
+ * Created on: 25 févr. 2012
+ * Author: miroof
+ */
+
+#ifndef TEST_H_
+#define TEST_H_
+
+#include "../../test/test.h"
+#include "../../Utils/GhomeBox.h"
+#include "../SensorsCenter.h"
+#include "../EnOceanSensorModel.h"
+
+void SensorsTests(Test *test);
+
+#endif /* TEST_H_ */

0 comments on commit dbbadce

Please sign in to comment.