2010-02-02 12:51:50 +01:00
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
|
|
#include "stock.hh"
|
2010-02-11 18:33:45 +01:00
|
|
|
#include "posexcept.hh"
|
2010-02-02 12:51:50 +01:00
|
|
|
|
|
|
|
class Stock_test: public CxxTest::TestSuite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
void setUp(void)
|
2010-02-02 12:51:50 +01:00
|
|
|
{
|
2010-02-02 17:34:58 +01:00
|
|
|
Stock::clear() ;
|
2010-04-02 14:03:55 +02:00
|
|
|
}
|
2010-02-02 17:34:58 +01:00
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
void tearDown(void)
|
|
|
|
{
|
|
|
|
Stock::clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_buildings(void)
|
|
|
|
{
|
|
|
|
TS_ASSERT_THROWS(Stock::get_building("My building"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-04-02 14:03:55 +02:00
|
|
|
|
|
|
|
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"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-02-02 12:51:50 +01:00
|
|
|
|
|
|
|
Mobile m1 ;
|
|
|
|
TS_ASSERT_EQUALS(Stock::getw_mobile("00:00:00:00:01:01"), m1) ;
|
|
|
|
|
|
|
|
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) ;
|
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
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") ;
|
2010-02-02 17:34:58 +01:00
|
|
|
|
|
|
|
Stock::clear() ;
|
|
|
|
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-02-02 17:34:58 +01:00
|
|
|
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:01"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-02-02 17:34:58 +01:00
|
|
|
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:02"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-04-02 14:03:55 +02:00
|
|
|
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() ;
|
2010-02-02 17:34:58 +01:00
|
|
|
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-02-02 17:34:58 +01:00
|
|
|
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:01"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-02-02 17:34:58 +01:00
|
|
|
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:02"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2010-02-02 12:51:50 +01:00
|
|
|
}
|
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
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) ;
|
|
|
|
}
|
|
|
|
|
2010-02-02 12:51:50 +01:00
|
|
|
} ;
|