summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorCeline Buret2011-11-22 15:23:28 +0100
committerCeline Buret2012-01-13 11:22:50 +0100
commit9a113d140555f2e027308f77da407dbd691d7509 (patch)
treeaac2797b7c8347d20de888a007a4435f75845819 /cesar
parent82368c7168e9e5905783a77a6f3eb8b26cea69af (diff)
cesar/maximus: test hide_sta (), refs #2826
Diffstat (limited to 'cesar')
-rw-r--r--cesar/maximus/coreengine/inc/MaximusTest.h86
-rw-r--r--cesar/maximus/coreengine/src/MaximusTest.cpp62
-rw-r--r--cesar/maximus/python/test/test_interface.py8
-rw-r--r--cesar/maximus/system/inc/StationTest.h20
-rw-r--r--cesar/maximus/system/inc/SystemManagerTest.h34
-rw-r--r--cesar/maximus/system/src/StationTest.cpp36
-rw-r--r--cesar/maximus/system/src/SystemManagerTest.cpp66
7 files changed, 245 insertions, 67 deletions
diff --git a/cesar/maximus/coreengine/inc/MaximusTest.h b/cesar/maximus/coreengine/inc/MaximusTest.h
index 726cbc24d8..7833dad157 100644
--- a/cesar/maximus/coreengine/inc/MaximusTest.h
+++ b/cesar/maximus/coreengine/inc/MaximusTest.h
@@ -5,62 +5,66 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+class CoreEngine;
class Maximus;
class MaximusTest : public CPPUNIT_NS::TestFixture
{
- CPPUNIT_TEST_SUITE (MaximusTest);
- CPPUNIT_TEST (init_test);
- CPPUNIT_TEST (init_phy_test);
- CPPUNIT_TEST (init_ether_test);
- CPPUNIT_TEST (process_test);
- CPPUNIT_TEST (create_sta_test);
- CPPUNIT_TEST (create_fc_test);
- CPPUNIT_TEST (create_probe_test);
- CPPUNIT_TEST (create_mpdu_test);
- CPPUNIT_TEST (send_mpdu_test);
- CPPUNIT_TEST (create_ether_test);
- CPPUNIT_TEST (send_ether_test);
- CPPUNIT_TEST (wait_test);
- CPPUNIT_TEST (disturb_channel_test);
- CPPUNIT_TEST (get_date_test);
- CPPUNIT_TEST (set_freq_test);
- CPPUNIT_TEST (activate_false_alarm_test);
- CPPUNIT_TEST (deactivate_false_alarm_test);
- CPPUNIT_TEST (is_station_idle_test);
- CPPUNIT_TEST_SUITE_END ();
+ CPPUNIT_TEST_SUITE (MaximusTest);
+ CPPUNIT_TEST (init_test);
+ CPPUNIT_TEST (init_phy_test);
+ CPPUNIT_TEST (init_ether_test);
+ CPPUNIT_TEST (process_test);
+ CPPUNIT_TEST (create_sta_test);
+ CPPUNIT_TEST (create_fc_test);
+ CPPUNIT_TEST (create_probe_test);
+ CPPUNIT_TEST (create_mpdu_test);
+ CPPUNIT_TEST (send_mpdu_test);
+ CPPUNIT_TEST (create_ether_test);
+ CPPUNIT_TEST (send_ether_test);
+ CPPUNIT_TEST (wait_test);
+ CPPUNIT_TEST (disturb_channel_test);
+ CPPUNIT_TEST (get_date_test);
+ CPPUNIT_TEST (set_freq_test);
+ CPPUNIT_TEST (activate_false_alarm_test);
+ CPPUNIT_TEST (deactivate_false_alarm_test);
+ CPPUNIT_TEST (is_station_idle_test);
+ CPPUNIT_TEST (hide_sta_test);
+ CPPUNIT_TEST_SUITE_END ();
public:
- void setUp (void);
- void tearDown (void);
+ void setUp (void);
+ void tearDown (void);
protected:
- void init_test (void);
- void init_phy_test (void);
- void init_ether_test (void);
- void process_test (void);
- void create_sta_test (void);
- void create_fc_test (void);
- void create_probe_test (void);
- void create_mpdu_test (void);
- void send_mpdu_test (void);
- void create_ether_test (void);
- void send_ether_test (void);
- void wait_test (void);
- void disturb_channel_test (void);
- void get_date_test (void);
- void set_freq_test (void);
- void activate_false_alarm_test (void);
- void deactivate_false_alarm_test (void);
- void is_station_idle_test (void);
+ void init_test (void);
+ void init_phy_test (void);
+ void init_ether_test (void);
+ void process_test (void);
+ void create_sta_test (void);
+ void create_fc_test (void);
+ void create_probe_test (void);
+ void create_mpdu_test (void);
+ void send_mpdu_test (void);
+ void create_ether_test (void);
+ void send_ether_test (void);
+ void wait_test (void);
+ void disturb_channel_test (void);
+ void get_date_test (void);
+ void set_freq_test (void);
+ void activate_false_alarm_test (void);
+ void deactivate_false_alarm_test (void);
+ void is_station_idle_test (void);
+ void hide_sta_test (void);
private:
- Maximus * mpMaximus;
+ CoreEngine *mpCoreEngine;
+ Maximus *mpMaximus;
};
diff --git a/cesar/maximus/coreengine/src/MaximusTest.cpp b/cesar/maximus/coreengine/src/MaximusTest.cpp
index f308081266..449c4a6d61 100644
--- a/cesar/maximus/coreengine/src/MaximusTest.cpp
+++ b/cesar/maximus/coreengine/src/MaximusTest.cpp
@@ -8,6 +8,9 @@
#include "PhySciMsgFc.h"
#include "PhySciMsgMpdu.h"
#include "EtherSciMsg.h"
+#include "Station.h"
+#include "ISystem.h"
+#include "CoreEngine.h"
#include "Logger.h"
@@ -33,7 +36,8 @@ void MaximusTest::setUp (void)
{
logTest();
- mpMaximus = new Maximus ();
+ mpCoreEngine = new CoreEngine ();
+ mpMaximus = new Maximus (mpCoreEngine);
}
@@ -443,3 +447,59 @@ void MaximusTest::is_station_idle_test (void)
}
}
+
+void MaximusTest::hide_sta_test (void)
+{
+ logTest ();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta1 = mpMaximus->create_sta ();
+ Sta sta2 = mpMaximus->create_sta ();
+
+ mpMaximus->hide_sta (sta1, sta2, true);
+
+ /* retrieve stations 1 and 2 */
+ Station *pStation1 = NULL, *pStation2 = NULL;
+ for (StationsList::const_iterator it = mpCoreEngine->getSystem ()->getListOfStations ()->begin ();
+ it != mpCoreEngine->getSystem ()->getListOfStations ()->end (); ++it)
+ {
+ if (NULL != *it)
+ {
+ Sci_Msg_Station_Id id = (*it)->getStationId ();
+ if (sta1.getStationId () == id)
+ pStation1 = *it;
+ else if (sta2.getStationId () == id)
+ pStation2 = *it;
+ }
+ }
+ CPPUNIT_ASSERT_MESSAGE ("Cannot retrieve stations",
+ (pStation1 != NULL)
+ && (pStation2 != NULL));
+
+ set<Sci_Msg_Station_Id>::iterator it1, it2;
+ /* check that station 2 is hidden from station 1 */
+ it2 = pStation1->getHiddenStationsList ().find (sta2.getStationId ());
+ CPPUNIT_ASSERT_MESSAGE ("hide_sta 2 from 1 failed", *it2 == sta2.getStationId ());
+ /* check that station 1 is hidden from station 2 */
+ it1 = pStation2->getHiddenStationsList ().find (sta1.getStationId ());
+ CPPUNIT_ASSERT_MESSAGE ("hide_sta 1 from 2 failed", *it1 == sta1.getStationId ());
+
+ mpMaximus->hide_sta (sta1, sta2, false);
+ /* check that stations are visible from each other */
+ it2 = pStation1->getHiddenStationsList ().find (sta2.getStationId ());
+ CPPUNIT_ASSERT_MESSAGE ("hide_sta FALSE failed", it2 == pStation1->getHiddenStationsList ().end ());
+ /* check that station 1 is hidden from station 2 */
+ it1 = pStation2->getHiddenStationsList ().find (sta1.getStationId ());
+ CPPUNIT_ASSERT_MESSAGE ("hide_sta FALSE failed", it1 == pStation2->getHiddenStationsList ().end ());
+
+ /* clean */
+ sta1.remove ();
+ sta2.remove ();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
diff --git a/cesar/maximus/python/test/test_interface.py b/cesar/maximus/python/test/test_interface.py
index 112e5e6807..61685e1ef6 100644
--- a/cesar/maximus/python/test/test_interface.py
+++ b/cesar/maximus/python/test/test_interface.py
@@ -185,6 +185,14 @@ class TestInterfaceFunctions(unittest.TestCase):
self.station.deactivate()
self.assert_(not self.m.is_station_idle(self.station.get_station_id()))
+ def test_hide_sta (self):
+ sta1 = self.m.create_sta ()
+ sta2 = self.m.create_sta ()
+ self.m.hide_sta (sta1, sta2, True)
+ self.m.hide_sta (sta1, sta2, False)
+ sta1.remove ()
+ sta2.remove ()
+
def test_remove(self):
# Remove station
diff --git a/cesar/maximus/system/inc/StationTest.h b/cesar/maximus/system/inc/StationTest.h
index 67eb7b874f..43b465e11f 100644
--- a/cesar/maximus/system/inc/StationTest.h
+++ b/cesar/maximus/system/inc/StationTest.h
@@ -11,23 +11,27 @@ class Station;
class StationTest : public CPPUNIT_NS::TestFixture
{
- CPPUNIT_TEST_SUITE (StationTest);
- CPPUNIT_TEST (setStationNameTest);
- CPPUNIT_TEST_SUITE_END ();
+ CPPUNIT_TEST_SUITE (StationTest);
+ CPPUNIT_TEST (setStationNameTest);
+ CPPUNIT_TEST (setHiddenStationsListTest);
+ CPPUNIT_TEST (hideStationTest);
+ CPPUNIT_TEST_SUITE_END ();
public:
- void setUp (void);
- void tearDown (void);
+ void setUp (void);
+ void tearDown (void);
protected:
- void setStationNameTest (void);
+ void setStationNameTest (void);
+ void setHiddenStationsListTest (void);
+ void hideStationTest (void);
private:
- Station * mpStation;
-
+ Station * mpStation;
+
};
diff --git a/cesar/maximus/system/inc/SystemManagerTest.h b/cesar/maximus/system/inc/SystemManagerTest.h
index 6c902dc679..6e0a0f5788 100644
--- a/cesar/maximus/system/inc/SystemManagerTest.h
+++ b/cesar/maximus/system/inc/SystemManagerTest.h
@@ -16,30 +16,32 @@ class INetworkClock;
class SystemManagerTest : public CPPUNIT_NS::TestFixture
{
- CPPUNIT_TEST_SUITE (SystemManagerTest);
- CPPUNIT_TEST (createStationTest);
- CPPUNIT_TEST (removeStationTest);
- CPPUNIT_TEST (areAllActiveStationsIdleTest);
- CPPUNIT_TEST (setNetworkClockTest);
- CPPUNIT_TEST (setStationNameTest);
- CPPUNIT_TEST_SUITE_END ();
+ CPPUNIT_TEST_SUITE (SystemManagerTest);
+ CPPUNIT_TEST (createStationTest);
+ CPPUNIT_TEST (removeStationTest);
+ CPPUNIT_TEST (areAllActiveStationsIdleTest);
+ CPPUNIT_TEST (setNetworkClockTest);
+ CPPUNIT_TEST (setStationNameTest);
+ CPPUNIT_TEST (hideStationTest);
+ CPPUNIT_TEST_SUITE_END ();
public:
- void setUp (void);
- void tearDown (void);
+ void setUp (void);
+ void tearDown (void);
protected:
- void createStationTest (void);
- void removeStationTest (void);
- void areAllActiveStationsIdleTest (void);
- void setNetworkClockTest (void);
- void setStationNameTest (void);
+ void createStationTest (void);
+ void removeStationTest (void);
+ void areAllActiveStationsIdleTest (void);
+ void setNetworkClockTest (void);
+ void setStationNameTest (void);
+ void hideStationTest (void);
- private:
+ private:
- SystemManager * mpSystemManager;
+ SystemManager * mpSystemManager;
SciServer * mpSciServer;
IFunctionCall * mpFunctionCall;
IPhy * mpPhy;
diff --git a/cesar/maximus/system/src/StationTest.cpp b/cesar/maximus/system/src/StationTest.cpp
index d0ca985293..cfa5234ec6 100644
--- a/cesar/maximus/system/src/StationTest.cpp
+++ b/cesar/maximus/system/src/StationTest.cpp
@@ -36,7 +36,7 @@ void StationTest::tearDown (void)
if (NULL != mpStation)
{
- delete (mpStation);
+ delete (mpStation);
mpStation = NULL;
}
}
@@ -59,3 +59,37 @@ void StationTest::setStationNameTest (void)
}
}
+
+void StationTest::setHiddenStationsListTest (void)
+{
+ logTest ();
+
+ HiddenStationsList hiddenStationsList;
+ /* set some initial values: 10 20 30 40 50 */
+ for (int i = 1; i <= 5; i++)
+ hiddenStationsList.insert (i*10);
+
+ CPPUNIT_ASSERT_MESSAGE ("setHiddenStationsList failed",
+ mpStation->setHiddenStationsList (hiddenStationsList));
+ CPPUNIT_ASSERT_MESSAGE ("getHiddenStationsList failed",
+ hiddenStationsList == mpStation->getHiddenStationsList ());
+}
+
+
+void StationTest::hideStationTest (void)
+{
+ logTest ();
+
+ /* hide a station */
+ Sci_Msg_Station_Id stationId = 111;
+ CPPUNIT_ASSERT_MESSAGE ("hideStation TRUE failed",
+ mpStation->hideStation (stationId, true));
+ set<Sci_Msg_Station_Id>::iterator it = mpStation->getHiddenStationsList ().find (stationId);
+ CPPUNIT_ASSERT_MESSAGE ("hideStation failed", *it == stationId);
+
+ /* make the station visible */
+ CPPUNIT_ASSERT_MESSAGE ("hideStation FALSE failed",
+ mpStation->hideStation (stationId, false)
+ && mpStation->getHiddenStationsList ().empty ());
+}
+
diff --git a/cesar/maximus/system/src/SystemManagerTest.cpp b/cesar/maximus/system/src/SystemManagerTest.cpp
index a19a0941ee..70fe94b206 100644
--- a/cesar/maximus/system/src/SystemManagerTest.cpp
+++ b/cesar/maximus/system/src/SystemManagerTest.cpp
@@ -7,6 +7,7 @@
#include "NetworkClockProcessor.h"
#include "FunctionCallManager.h"
#include "EthernetProcessor.h"
+#include "Station.h"
#include "Error.h"
#include "Logger.h"
@@ -205,3 +206,68 @@ void SystemManagerTest::setStationNameTest (void)
}
}
+
+void SystemManagerTest::hideStationTest (void)
+{
+ logTest ();
+
+ try
+ {
+ /* create 3 stations */
+ Sci_Msg_Station_Id stationId1 = mpSystemManager->createStation \
+ (mpSystemManager->getDefaultStationExecutable ());
+ Sci_Msg_Station_Id stationId2 = mpSystemManager->createStation \
+ (mpSystemManager->getDefaultStationExecutable ());
+ Sci_Msg_Station_Id stationId3 = mpSystemManager->createStation \
+ (mpSystemManager->getDefaultStationExecutable ());
+
+ /* hide station 1 from stations 2 and 3 and vice versa */
+ CPPUNIT_ASSERT_MESSAGE ("hideStation failed",
+ mpSystemManager->hideStation \
+ (stationId1, stationId2, true)
+ && mpSystemManager->hideStation \
+ (stationId1, stationId3, true));
+
+ /* retrieve stations 1, 2, 3 */
+ Station *pStation1 = NULL, *pStation2 = NULL, *pStation3 = NULL;
+ for (StationsList::const_iterator it = mpSystemManager->getListOfStations ()->begin ();
+ it != mpSystemManager->getListOfStations ()->end (); ++it)
+ {
+ if (NULL != *it)
+ {
+ Sci_Msg_Station_Id id = (*it)->getStationId ();
+ if (stationId1 == id)
+ pStation1 = *it;
+ else if (stationId2 == id)
+ pStation2 = *it;
+ else if (stationId3 == id)
+ pStation3 = *it;
+ }
+ }
+ CPPUNIT_ASSERT_MESSAGE ("Cannot retrieve stations",
+ (pStation1 != NULL)
+ && (pStation2 != NULL)
+ && (pStation3 != NULL));
+
+ set<Sci_Msg_Station_Id>::iterator it1, it2, it3;
+ /* check that stations 2 and 3 are hidden from station 1 */
+ it2 = pStation1->getHiddenStationsList ().find (stationId2);
+ it3 = pStation1->getHiddenStationsList ().find (stationId3);
+ CPPUNIT_ASSERT_MESSAGE ("hideStation 2 from 1 failed", *it2 == stationId2);
+ CPPUNIT_ASSERT_MESSAGE ("hideStation 3 from 1 failed", *it3 == stationId3);
+ /* check that station 1 is hidden from station 2 */
+ it1 = pStation2->getHiddenStationsList ().find (stationId1);
+ CPPUNIT_ASSERT_MESSAGE ("hideStation 1 from 2 failed", *it1 == stationId1);
+ /* check that station 1 is hidden from station 3 */
+ it1 = pStation3->getHiddenStationsList ().find (stationId1);
+ CPPUNIT_ASSERT_MESSAGE ("hideStation 1 from 3 failed", *it1 == stationId1);
+
+ /* clean */
+ mpSystemManager->removeAllStations ();
+ }
+ catch (Error &e)
+ {
+ e.display ();
+ }
+}
+