[Positioning] Stock: add Building list & complete tests
This commit is contained in:
parent
f4e8d7a1b7
commit
a30b08ac3c
|
@ -15,6 +15,8 @@ size_t hash_value(const ReferencePoint &object)
|
|||
|
||||
/* *** Attribute definitions *** */
|
||||
|
||||
unordered_map<string, Building> Stock::buildings ;
|
||||
|
||||
unordered_map<string, Mobile> Stock::mobiles ;
|
||||
|
||||
unordered_map<string, AccessPoint> Stock::aps ;
|
||||
|
@ -28,6 +30,39 @@ unordered_set<CalibrationRequest> Stock::calibration_requests ;
|
|||
/* *** Accessors *** */
|
||||
|
||||
|
||||
/**
|
||||
* The name of the Building is initialised.
|
||||
*/
|
||||
const Building& Stock::find_create_building(const string &name)
|
||||
{
|
||||
unordered_map<string, Building>::const_iterator i =
|
||||
buildings.find(name) ;
|
||||
if (i != buildings.end())
|
||||
return i->second ;
|
||||
|
||||
Building &building = buildings[name] ;
|
||||
building.set_name(name) ;
|
||||
return building ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name The name of the Building to search for.
|
||||
* It must be a valid name, as no check is performed.
|
||||
* @return A const reference to the Building.
|
||||
* @throw element_not_found is thrown if the Building corresponding
|
||||
* to \em name does not exist.
|
||||
*/
|
||||
const Building& Stock::get_building(const string &name)
|
||||
{
|
||||
unordered_map<string, Building>::const_iterator i =
|
||||
buildings.find(name) ;
|
||||
if (i != buildings.end())
|
||||
return i->second ;
|
||||
throw element_not_found("No Building with name « " + name + " »!") ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mac The MAC address of the Mobile to search for.
|
||||
* It must be a valid MAC address, as no check is performed.
|
||||
|
@ -40,7 +75,8 @@ const Mobile& Stock::get_mobile(const string &mac)
|
|||
unordered_map<string, Mobile>::const_iterator i = mobiles.find(mac) ;
|
||||
if (i != mobiles.end())
|
||||
return i->second ;
|
||||
throw element_not_found("No Mobile with MAC address « " + mac + " »!") ;
|
||||
throw element_not_found("No Mobile with MAC address « " +
|
||||
mac + " »!") ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,6 +149,7 @@ find_create_calibration_request(const CalibrationRequest &request)
|
|||
|
||||
void Stock::clear()
|
||||
{
|
||||
buildings.clear() ;
|
||||
mobiles.clear() ;
|
||||
aps.clear() ;
|
||||
reference_points.clear() ;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _OWLPS_POSITIONING_STOCK_HH_
|
||||
#define _OWLPS_POSITIONING_STOCK_HH_
|
||||
|
||||
#include "building.hh"
|
||||
#include "mobile.hh"
|
||||
#include "accesspoint.hh"
|
||||
#include "referencepoint.hh"
|
||||
|
@ -13,6 +14,9 @@
|
|||
class Stock
|
||||
{
|
||||
private:
|
||||
/// List of known Building
|
||||
static std::tr1::unordered_map<std::string, Building> buildings ;
|
||||
|
||||
/// List of known Mobile
|
||||
static std::tr1::unordered_map<std::string, Mobile> mobiles ;
|
||||
|
||||
|
@ -26,6 +30,11 @@ private:
|
|||
static std::tr1::unordered_set<CalibrationRequest> calibration_requests ;
|
||||
|
||||
public:
|
||||
/// Read the Building corresponding to a given name
|
||||
static const Building& get_building(const std::string &name) ;
|
||||
/// Look for a Building and create it if it does not exist
|
||||
static const Building& find_create_building(const std::string &name) ;
|
||||
|
||||
/// Read the Mobile corresponding to a given MAC address
|
||||
static const Mobile& get_mobile(const std::string &mac) ;
|
||||
/// Look for a Mobile and create it if it does not exist
|
||||
|
@ -40,11 +49,11 @@ public:
|
|||
/// Get a reference to the AccessPoint corresponding to a given MAC address
|
||||
static AccessPoint& getw_ap(const std::string &mac) ;
|
||||
|
||||
/// Look for a ReferencePoint and create it if it does not exist
|
||||
/// Look for a ReferencePoint and add it if it does not exist
|
||||
static const ReferencePoint&
|
||||
find_create_reference_point(const ReferencePoint &point) ;
|
||||
|
||||
/// Get a reference to a CalibrationRequest
|
||||
/// Look for a CalibrationRequest and add it if it does not exist
|
||||
static const CalibrationRequest&
|
||||
find_create_calibration_request(const CalibrationRequest &request) ;
|
||||
|
||||
|
|
|
@ -7,36 +7,51 @@ class Stock_test: public CxxTest::TestSuite
|
|||
{
|
||||
public:
|
||||
|
||||
void test_accessors(void)
|
||||
void setUp(void)
|
||||
{
|
||||
// Clear the stock, in case other test classes filled it
|
||||
Stock::clear() ;
|
||||
}
|
||||
|
||||
// Non-existing elements
|
||||
void tearDown(void)
|
||||
{
|
||||
Stock::clear() ;
|
||||
}
|
||||
|
||||
void test_buildings(void)
|
||||
{
|
||||
TS_ASSERT_THROWS(Stock::get_building("My building"),
|
||||
element_not_found) ;
|
||||
|
||||
const Building &building1 =
|
||||
Stock::find_create_building("My building") ;
|
||||
TS_ASSERT(&building1) ;
|
||||
|
||||
const Building &building2 = Stock::get_building("My building") ;
|
||||
TS_ASSERT_EQUALS(&building1, &building2) ;
|
||||
|
||||
Stock::clear() ;
|
||||
TS_ASSERT_THROWS(Stock::get_building("My building"),
|
||||
element_not_found) ;
|
||||
}
|
||||
|
||||
void test_mobiles(void)
|
||||
{
|
||||
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
||||
element_not_found) ;
|
||||
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
||||
element_not_found) ;
|
||||
|
||||
// Creation of empty elements
|
||||
Mobile m1 ;
|
||||
AccessPoint ap1 ;
|
||||
TS_ASSERT_EQUALS(Stock::getw_mobile("00:00:00:00:01:01"), m1) ;
|
||||
TS_ASSERT_EQUALS(Stock::getw_ap("00:00:00:00:02:01"), ap1) ;
|
||||
|
||||
// Creation of elements and access
|
||||
Mobile m2("192.168.1.1", "00:00:00:00:01:02", 1.5, 20) ;
|
||||
Stock::getw_mobile("00:00:00:00:01:02") = m2 ;
|
||||
TS_ASSERT_EQUALS(Stock::get_mobile("00:00:00:00:01:02"), m2) ;
|
||||
TS_ASSERT_EQUALS(Stock::getw_mobile("00:00:00:00:01:02"), m2) ;
|
||||
|
||||
AccessPoint ap2(Point3D(1,2,3), "192.168.2.1", "00:00:00:00:02:02",
|
||||
8.5, 2.1, 11) ;
|
||||
Stock::getw_ap("00:00:00:00:02:02") = ap2 ;
|
||||
TS_ASSERT_EQUALS(Stock::get_ap("00:00:00:00:02:02"), ap2) ;
|
||||
TS_ASSERT_EQUALS(Stock::getw_ap("00:00:00:00:02:02"), ap2) ;
|
||||
const Mobile &mobile3 =
|
||||
Stock::find_create_mobile("00:00:00:00:01:03") ;
|
||||
TS_ASSERT(&mobile3) ;
|
||||
TS_ASSERT_EQUALS(mobile3.get_mac_addr(), "00:00:00:00:01:03") ;
|
||||
|
||||
// clear()
|
||||
Stock::clear() ;
|
||||
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
||||
element_not_found) ;
|
||||
|
@ -44,6 +59,25 @@ public:
|
|||
element_not_found) ;
|
||||
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:02"),
|
||||
element_not_found) ;
|
||||
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:03"),
|
||||
element_not_found) ;
|
||||
}
|
||||
|
||||
void test_aps(void)
|
||||
{
|
||||
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
||||
element_not_found) ;
|
||||
|
||||
AccessPoint ap1 ;
|
||||
TS_ASSERT_EQUALS(Stock::getw_ap("00:00:00:00:02:01"), ap1) ;
|
||||
|
||||
AccessPoint ap2(Point3D(1,2,3), "192.168.2.1", "00:00:00:00:02:02",
|
||||
8.5, 2.1, 11) ;
|
||||
Stock::getw_ap("00:00:00:00:02:02") = ap2 ;
|
||||
TS_ASSERT_EQUALS(Stock::get_ap("00:00:00:00:02:02"), ap2) ;
|
||||
TS_ASSERT_EQUALS(Stock::getw_ap("00:00:00:00:02:02"), ap2) ;
|
||||
|
||||
Stock::clear() ;
|
||||
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
||||
element_not_found) ;
|
||||
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:01"),
|
||||
|
@ -52,4 +86,38 @@ public:
|
|||
element_not_found) ;
|
||||
}
|
||||
|
||||
void test_reference_points(void)
|
||||
{
|
||||
ReferencePoint referencepoint1(3,5,7) ;
|
||||
|
||||
const ReferencePoint &referencepoint1_ref1 =
|
||||
Stock::find_create_reference_point(referencepoint1) ;
|
||||
TS_ASSERT_EQUALS(referencepoint1, referencepoint1_ref1) ;
|
||||
TS_ASSERT_DIFFERS(&referencepoint1, &referencepoint1_ref1) ;
|
||||
|
||||
const ReferencePoint &referencepoint1_ref2 =
|
||||
Stock::find_create_reference_point(referencepoint1) ;
|
||||
TS_ASSERT_EQUALS(referencepoint1, referencepoint1_ref2) ;
|
||||
TS_ASSERT_DIFFERS(&referencepoint1, &referencepoint1_ref2) ;
|
||||
|
||||
TS_ASSERT_EQUALS(&referencepoint1_ref1, &referencepoint1_ref2) ;
|
||||
}
|
||||
|
||||
void test_calibration_requests(void)
|
||||
{
|
||||
CalibrationRequest calibrationrequest1 ;
|
||||
|
||||
const CalibrationRequest &calibrationrequest1_ref1 =
|
||||
Stock::find_create_calibration_request(calibrationrequest1) ;
|
||||
TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest1_ref1) ;
|
||||
TS_ASSERT_DIFFERS(&calibrationrequest1, &calibrationrequest1_ref1) ;
|
||||
|
||||
const CalibrationRequest &calibrationrequest1_ref2 =
|
||||
Stock::find_create_calibration_request(calibrationrequest1) ;
|
||||
TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest1_ref2) ;
|
||||
TS_ASSERT_DIFFERS(&calibrationrequest1, &calibrationrequest1_ref2) ;
|
||||
|
||||
TS_ASSERT_EQUALS(&calibrationrequest1_ref1, &calibrationrequest1_ref2) ;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
|
Loading…
Reference in New Issue