owlps/owlps-positioner/tests/stock_test.hh

218 lines
7.3 KiB
C++

/*
* This file is part of the Owl Positioning System (OwlPS) project.
* It is subject to the copyright notice and license terms in the
* COPYRIGHT.t2t file found in the top-level directory of this
* distribution and at
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
* No part of the OwlPS Project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
* distributed along with this file, either separately or by replacing
* this notice by the COPYRIGHT.t2t file's contents.
*/
#include <cxxtest/TestSuite.h>
#include "stock.hh"
#include "posexcept.hh"
class Stock_test: public CxxTest::TestSuite
{
public:
// Run before each test
void setUp(void)
{
Stock::clear() ;
}
// Run after each test
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_waypoints(void)
{
Point3D coordinates(42,21,98) ;
const Building &building = Stock::find_create_building("Build") ;
Waypoint wp1(const_cast<Building*>(&building), coordinates) ;
const Waypoint
&wp1_ref1 = Stock::find_create_waypoint(wp1),
&wp1_ref2 = Stock::find_create_waypoint(coordinates) ;
TS_ASSERT_EQUALS(&wp1_ref1, &wp1_ref2) ;
Stock::waypoint_remove_building(wp1_ref1,
const_cast<Building*>(&building)) ;
// TODO: test if the waypoint was removed (needs a function
// Stock::get_waypoint()).
}
void test_mobiles(void)
{
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
element_not_found) ;
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) ;
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") ;
Stock::clear() ;
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
element_not_found) ;
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:01"),
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_cps(void)
{
TS_ASSERT_THROWS(Stock::get_cp("aa:bb:cc:dd:ee:ff"),
element_not_found) ;
CapturePoint ap1 ;
TS_ASSERT_EQUALS(Stock::getw_cp("00:00:00:00:02:01"), ap1) ;
CapturePoint ap2(Point3D(1,2,3), "192.168.2.1", "00:00:00:00:02:02",
8.5, 2.1, 11) ;
Stock::getw_cp("00:00:00:00:02:02") = ap2 ;
TS_ASSERT_EQUALS(Stock::get_cp("00:00:00:00:02:02"), ap2) ;
TS_ASSERT_EQUALS(Stock::getw_cp("00:00:00:00:02:02"), ap2) ;
Stock::clear() ;
TS_ASSERT_THROWS(Stock::get_cp("aa:bb:cc:dd:ee:ff"),
element_not_found) ;
TS_ASSERT_THROWS(Stock::get_cp("00:00:00:00:02:01"),
element_not_found) ;
TS_ASSERT_THROWS(Stock::get_cp("00:00:00:00:02:02"),
element_not_found) ;
}
void test_update_all_friis_indexes(void)
{
// TODO: implement that
}
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_closest_reference_point(void)
{
const CapturePoint &ap1 = Stock::find_create_cp("AA:BB:CC:DD:EE:FF") ;
CalibrationRequest calibrationrequest1 ;
Measurement measurement1(&ap1) ;
measurement1.add_ss(1, -23) ;
std::unordered_map<std::string, Measurement> measurements ;
measurements["AA:BB:CC:DD:EE:FF"] = measurement1 ;
calibrationrequest1.set_measurements(measurements) ;
TS_ASSERT_THROWS(Stock::closest_reference_point(calibrationrequest1),
element_not_found) ;
ReferencePoint referencepoint1(3,5,7) ;
referencepoint1.add_request(&calibrationrequest1) ;
const ReferencePoint &referencepoint1_ref =
Stock::find_create_reference_point(referencepoint1) ;
TS_ASSERT_EQUALS(
&Stock::closest_reference_point(calibrationrequest1),
&referencepoint1_ref) ;
CalibrationRequest calibrationrequest2 ;
Measurement measurement2(&ap1) ;
measurement2.add_ss(1, -78) ;
measurements.clear() ;
measurements["AA:BB:CC:DD:EE:FF"] = measurement2 ;
calibrationrequest2.set_measurements(measurements) ;
ReferencePoint referencepoint2(88,99,111) ;
referencepoint2.add_request(&calibrationrequest2) ;
const ReferencePoint &referencepoint2_ref =
Stock::find_create_reference_point(referencepoint2) ;
TS_ASSERT_EQUALS(
&Stock::closest_reference_point(calibrationrequest1),
&referencepoint1_ref) ;
TS_ASSERT_EQUALS(
&Stock::closest_reference_point(calibrationrequest2),
&referencepoint2_ref) ;
Request request3 ;
Measurement measurement3(&ap1) ;
measurement3.add_ss(1, -75) ;
measurements.clear() ;
measurements["AA:BB:CC:DD:EE:FF"] = measurement3 ;
request3.set_measurements(measurements) ;
TS_ASSERT_EQUALS(
&Stock::closest_reference_point(request3),
&referencepoint2_ref) ;
Request request4 ;
Measurement measurement4(&ap1) ;
measurement4.add_ss(1, -8) ;
measurements.clear() ;
measurements["AA:BB:CC:DD:EE:FF"] = measurement4 ;
request4.set_measurements(measurements) ;
TS_ASSERT_EQUALS(
&Stock::closest_reference_point(request4),
&referencepoint1_ref) ;
}
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) ;
}
} ;