2013-06-22 23:30:17 +02:00
|
|
|
/*
|
|
|
|
* 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
|
2016-11-03 05:10:34 +01:00
|
|
|
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
|
2013-06-22 23:30:17 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-02-02 12:51:50 +01:00
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
2016-11-05 03:02:30 +01:00
|
|
|
#include "calibrationrequest.hh"
|
2010-02-02 12:51:50 +01:00
|
|
|
#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:
|
|
|
|
|
2013-06-22 23:10:38 +02:00
|
|
|
// Run before each test
|
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
|
|
|
|
2013-06-22 23:10:38 +02:00
|
|
|
// Run after each test
|
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) ;
|
|
|
|
}
|
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
void test_waypoints(void)
|
|
|
|
{
|
|
|
|
Point3D coordinates(42,21,98) ;
|
|
|
|
const Building &building = Stock::find_create_building("Build") ;
|
2013-10-02 20:38:45 +02:00
|
|
|
Waypoint wp1(const_cast<Building*>(&building), coordinates) ;
|
2010-04-13 10:47:10 +02:00
|
|
|
const Waypoint
|
|
|
|
&wp1_ref1 = Stock::find_create_waypoint(wp1),
|
|
|
|
&wp1_ref2 = Stock::find_create_waypoint(coordinates) ;
|
|
|
|
TS_ASSERT_EQUALS(&wp1_ref1, &wp1_ref2) ;
|
|
|
|
|
2013-10-02 20:38:45 +02:00
|
|
|
Stock::waypoint_remove_building(wp1_ref1,
|
|
|
|
const_cast<Building*>(&building)) ;
|
2010-04-13 10:47:10 +02:00
|
|
|
// TODO: test if the waypoint was removed (needs a function
|
|
|
|
// Stock::get_waypoint()).
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
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) ;
|
|
|
|
}
|
|
|
|
|
2013-06-16 03:02:40 +02:00
|
|
|
void test_cps(void)
|
2010-04-02 14:03:55 +02:00
|
|
|
{
|
2013-06-16 03:02:40 +02:00
|
|
|
TS_ASSERT_THROWS(Stock::get_cp("aa:bb:cc:dd:ee:ff"),
|
2010-04-02 14:03:55 +02:00
|
|
|
element_not_found) ;
|
|
|
|
|
2013-06-16 03:02:40 +02:00
|
|
|
CapturePoint ap1 ;
|
|
|
|
TS_ASSERT_EQUALS(Stock::getw_cp("00:00:00:00:02:01"), ap1) ;
|
2010-04-02 14:03:55 +02:00
|
|
|
|
2013-06-16 03:02:40 +02:00
|
|
|
CapturePoint ap2(Point3D(1,2,3), "192.168.2.1", "00:00:00:00:02:02",
|
2013-06-22 23:10:38 +02:00
|
|
|
8.5, 2.1, 11) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
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) ;
|
2010-04-02 14:03:55 +02:00
|
|
|
|
|
|
|
Stock::clear() ;
|
2013-06-16 03:02:40 +02:00
|
|
|
TS_ASSERT_THROWS(Stock::get_cp("aa:bb:cc:dd:ee:ff"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
TS_ASSERT_THROWS(Stock::get_cp("00:00:00:00:02:01"),
|
2010-02-11 18:33:45 +01:00
|
|
|
element_not_found) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
TS_ASSERT_THROWS(Stock::get_cp("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-06-10 15:57:03 +02:00
|
|
|
void test_update_all_friis_indexes(void)
|
|
|
|
{
|
|
|
|
// TODO: implement that
|
|
|
|
}
|
|
|
|
|
2016-11-05 03:02:30 +01:00
|
|
|
/*
|
|
|
|
* This test creates a ReferencePoint, then retrieves it from its
|
|
|
|
* coordinates (Point3D).
|
|
|
|
*/
|
|
|
|
void test_reference_points_1(void)
|
2010-04-02 14:03:55 +02:00
|
|
|
{
|
2016-11-05 03:02:30 +01:00
|
|
|
Point3D point1(3,5,7);
|
|
|
|
ReferencePoint referencepoint1(point1);
|
|
|
|
CalibrationRequest cr1(42); // 42 is obviously not a valid request type
|
|
|
|
referencepoint1.add_request(&cr1);
|
|
|
|
|
|
|
|
TS_ASSERT_THROWS(Stock::get_reference_point(point1), element_not_found);
|
|
|
|
TS_ASSERT_THROWS(Stock::get_reference_point(referencepoint1),
|
|
|
|
element_not_found);
|
2010-04-02 14:03:55 +02:00
|
|
|
|
|
|
|
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) ;
|
2016-11-05 03:02:30 +01:00
|
|
|
|
|
|
|
const ReferencePoint &referencepoint1_ref3 =
|
|
|
|
Stock::get_reference_point(referencepoint1);
|
|
|
|
TS_ASSERT_EQUALS(referencepoint1, referencepoint1_ref3) ;
|
|
|
|
TS_ASSERT_DIFFERS(&referencepoint1, &referencepoint1_ref3) ;
|
|
|
|
|
|
|
|
/* Now let's use the Point3D to look up the ReferencePoint */
|
|
|
|
|
|
|
|
const ReferencePoint &referencepoint1_ref4 =
|
|
|
|
Stock::get_reference_point(point1);
|
|
|
|
TS_ASSERT_EQUALS(referencepoint1, referencepoint1_ref4);
|
|
|
|
|
|
|
|
const ReferencePoint &referencepoint1_ref5 =
|
|
|
|
Stock::find_create_reference_point(point1);
|
|
|
|
TS_ASSERT_EQUALS(referencepoint1, referencepoint1_ref5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This test creates a ReferencePoint using a Point3D in the first
|
|
|
|
* place, and compares to a ReferencePoint created from a
|
|
|
|
* ReferencePoint.
|
|
|
|
*/
|
|
|
|
void test_reference_points_2(void)
|
|
|
|
{
|
|
|
|
// Create with Point3D, retrieve with ReferencePoint
|
|
|
|
Point3D p1(1,2,3);
|
|
|
|
const ReferencePoint &rp1_ref1 = Stock::find_create_reference_point(p1);
|
|
|
|
ReferencePoint rp1(1,2,3);
|
|
|
|
const ReferencePoint &rp1_ref2 = Stock::get_reference_point(rp1);
|
|
|
|
const ReferencePoint &rp1_ref3 = Stock::find_create_reference_point(rp1);
|
|
|
|
TS_ASSERT_EQUALS(&rp1_ref1, &rp1_ref2);
|
|
|
|
TS_ASSERT_EQUALS(&rp1_ref1, &rp1_ref3);
|
|
|
|
TS_ASSERT_EQUALS(rp1, rp1_ref1);
|
|
|
|
|
|
|
|
// Create with ReferencePoint, retrieve with Point3D
|
|
|
|
ReferencePoint rp2(4,5,6);
|
|
|
|
const ReferencePoint &rp2_ref1 = Stock::find_create_reference_point(rp2);
|
|
|
|
Point3D p2(4,5,6);
|
|
|
|
const ReferencePoint &rp2_ref2 = Stock::get_reference_point(p2);
|
|
|
|
const ReferencePoint &rp2_ref3 = Stock::find_create_reference_point(p2);
|
|
|
|
TS_ASSERT_EQUALS(&rp2_ref1, &rp2_ref2);
|
|
|
|
TS_ASSERT_EQUALS(&rp2_ref1, &rp2_ref3);
|
|
|
|
TS_ASSERT_EQUALS(rp2, rp2_ref1);
|
|
|
|
|
|
|
|
/* Now with a request in the reference point */
|
|
|
|
|
|
|
|
// Create with Point3D, retrieve with ReferencePoint
|
|
|
|
Point3D p3(7,8,9);
|
|
|
|
const ReferencePoint &rp3_ref1 = Stock::find_create_reference_point(p3);
|
|
|
|
ReferencePoint rp3(7,8,9);
|
|
|
|
CalibrationRequest cr3(42); // 42 is obviously not a valid request type
|
|
|
|
rp3.add_request(&cr3);
|
|
|
|
const ReferencePoint &rp3_ref2 = Stock::get_reference_point(rp3);
|
|
|
|
const ReferencePoint &rp3_ref3 = Stock::find_create_reference_point(rp3);
|
|
|
|
TS_ASSERT_EQUALS(&rp3_ref1, &rp3_ref2);
|
|
|
|
TS_ASSERT_EQUALS(&rp3_ref1, &rp3_ref3);
|
|
|
|
TS_ASSERT_DIFFERS(rp3, rp3_ref1); /* the ReferencePoint in the stock doesn't
|
|
|
|
* have the CalibrationRequest */
|
|
|
|
ReferencePoint &rp3_ref_rw =
|
|
|
|
const_cast<ReferencePoint&>(Stock::get_reference_point(rp3));
|
|
|
|
rp3_ref_rw.add_request(&cr3);
|
|
|
|
TS_ASSERT_EQUALS(rp3, rp3_ref1);
|
2010-04-02 14:03:55 +02:00
|
|
|
}
|
|
|
|
|
2010-06-02 12:37:43 +02:00
|
|
|
void test_closest_reference_point(void)
|
|
|
|
{
|
2013-06-17 18:19:38 +02:00
|
|
|
const CapturePoint &ap1 = Stock::find_create_cp("AA:BB:CC:DD:EE:FF") ;
|
2010-06-02 12:37:43 +02:00
|
|
|
CalibrationRequest calibrationrequest1 ;
|
|
|
|
Measurement measurement1(&ap1) ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -23) ;
|
2013-05-30 20:13:44 +02:00
|
|
|
std::unordered_map<std::string, Measurement> measurements ;
|
2013-06-22 23:10:38 +02:00
|
|
|
measurements["AA:BB:CC:DD:EE:FF"] = measurement1 ;
|
2010-06-02 12:37:43 +02:00
|
|
|
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) ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement2.add_ss(1, -78) ;
|
2010-06-02 12:37:43 +02:00
|
|
|
measurements.clear() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
measurements["AA:BB:CC:DD:EE:FF"] = measurement2 ;
|
2010-06-02 12:37:43 +02:00
|
|
|
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) ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement3.add_ss(1, -75) ;
|
2010-06-02 12:37:43 +02:00
|
|
|
measurements.clear() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
measurements["AA:BB:CC:DD:EE:FF"] = measurement3 ;
|
2010-06-02 12:37:43 +02:00
|
|
|
request3.set_measurements(measurements) ;
|
|
|
|
TS_ASSERT_EQUALS(
|
|
|
|
&Stock::closest_reference_point(request3),
|
|
|
|
&referencepoint2_ref) ;
|
|
|
|
|
|
|
|
Request request4 ;
|
|
|
|
Measurement measurement4(&ap1) ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement4.add_ss(1, -8) ;
|
2010-06-02 12:37:43 +02:00
|
|
|
measurements.clear() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
measurements["AA:BB:CC:DD:EE:FF"] = measurement4 ;
|
2010-06-02 12:37:43 +02:00
|
|
|
request4.set_measurements(measurements) ;
|
|
|
|
TS_ASSERT_EQUALS(
|
|
|
|
&Stock::closest_reference_point(request4),
|
|
|
|
&referencepoint1_ref) ;
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
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
|
|
|
} ;
|