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
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-04-02 15:49:22 +02:00
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
|
|
#include "topologyreadercsv.hh"
|
|
|
|
|
|
|
|
class TopologyReaderCSV_test: public CxxTest::TestSuite
|
|
|
|
{
|
|
|
|
private:
|
2010-04-13 10:47:10 +02:00
|
|
|
std::string areas_file_name ;
|
|
|
|
std::string waypoints_file_name ;
|
2010-04-02 15:49:22 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
TopologyReaderCSV_test(void):
|
2010-04-13 10:47:10 +02:00
|
|
|
areas_file_name("/tmp/TopologyReaderCSV_areas_file.csv"),
|
|
|
|
waypoints_file_name("/tmp/TopologyReaderCSV_waypoints_file.csv")
|
2010-04-02 15:49:22 +02:00
|
|
|
{
|
2010-04-13 10:47:10 +02:00
|
|
|
std::ofstream areas_file(areas_file_name.c_str()) ;
|
|
|
|
areas_file
|
2010-04-02 15:49:22 +02:00
|
|
|
<< "My building;My room #1;1;2;3;9;8;7\n"
|
|
|
|
<< "My building;Room #2;4;5;6;6;5;4\n"
|
|
|
|
<< "Building #2;My room #1;1;2;3;9;8;7\n"
|
|
|
|
<< "My building;Room #2;4;5;6;6;5;4\n"
|
|
|
|
<< "My building;Room #2;4;5;6;6;5;4\n" ;
|
2010-04-13 10:47:10 +02:00
|
|
|
areas_file.close() ;
|
|
|
|
|
|
|
|
std::ofstream waypoints_file(waypoints_file_name.c_str()) ;
|
|
|
|
waypoints_file
|
|
|
|
<< "1;2;3;My building\n"
|
|
|
|
<< "4;5;6;My building\n"
|
|
|
|
<< "1;2;3;Building #2\n"
|
|
|
|
<< "4;5;6;My building\n"
|
|
|
|
<< "9;8;7;Building #2;My building\n"
|
|
|
|
<< "4;5;6;My building\n" ;
|
|
|
|
waypoints_file.close() ;
|
|
|
|
|
|
|
|
TS_ASSERT_THROWS_NOTHING(
|
|
|
|
TopologyReaderCSV toporeader(areas_file_name,
|
|
|
|
waypoints_file_name)) ;
|
2010-04-02 15:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~TopologyReaderCSV_test(void)
|
|
|
|
{
|
2010-04-13 10:47:10 +02:00
|
|
|
TestUtil::remove_file(areas_file_name) ;
|
|
|
|
TestUtil::remove_file(waypoints_file_name) ;
|
2010-04-02 15:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static TopologyReaderCSV_test* createSuite(void)
|
|
|
|
{
|
|
|
|
return new TopologyReaderCSV_test() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void destroySuite(TopologyReaderCSV_test *suite)
|
|
|
|
{
|
|
|
|
delete suite ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
void test_areas(void)
|
2010-04-02 15:49:22 +02:00
|
|
|
{
|
2013-06-22 23:10:38 +02:00
|
|
|
Building *building1 = NULL ;
|
2010-04-02 15:49:22 +02:00
|
|
|
TS_ASSERT_THROWS_NOTHING(
|
|
|
|
building1 = const_cast<Building*>(
|
|
|
|
&Stock::get_building("My building"))) ;
|
2013-06-22 23:10:38 +02:00
|
|
|
Building *building2 = NULL ;
|
2010-04-02 15:49:22 +02:00
|
|
|
TS_ASSERT_THROWS_NOTHING(
|
|
|
|
building2 = const_cast<Building*>(
|
|
|
|
&Stock::get_building("Building #2"))) ;
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(building1->get_areas().size(), 2u) ;
|
|
|
|
|
|
|
|
Area *area_ptr ;
|
|
|
|
area_ptr = building1->get_areas().find("My room #1")->second ;
|
|
|
|
Area area1(building1, "My room #1",
|
|
|
|
Point3D(1,2,3), Point3D(9,8,7)) ;
|
|
|
|
assert(area_ptr) ;
|
|
|
|
TS_ASSERT_EQUALS(*area_ptr, area1) ;
|
|
|
|
|
|
|
|
area_ptr = building1->get_areas().find("Room #2")->second ;
|
|
|
|
assert(area_ptr) ;
|
|
|
|
Area area2(building1, "Room #2",
|
|
|
|
Point3D(4,5,6), Point3D(6,5,4)) ;
|
|
|
|
TS_ASSERT_EQUALS(*area_ptr, area2) ;
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(building2->get_areas().size(), 1u) ;
|
|
|
|
area1.set_building(building2) ;
|
|
|
|
area_ptr = building2->get_areas().find("My room #1")->second ;
|
|
|
|
assert(area_ptr) ;
|
|
|
|
TS_ASSERT_EQUALS(*area_ptr, area1) ;
|
|
|
|
}
|
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
|
|
|
|
void test_waypoints(void)
|
|
|
|
{
|
2013-06-22 23:10:38 +02:00
|
|
|
Building *building1 = NULL ;
|
2010-04-13 10:47:10 +02:00
|
|
|
TS_ASSERT_THROWS_NOTHING(
|
|
|
|
building1 = const_cast<Building*>(
|
|
|
|
&Stock::get_building("My building"))) ;
|
2013-06-22 23:10:38 +02:00
|
|
|
Building *building2 = NULL ;
|
2010-04-13 10:47:10 +02:00
|
|
|
TS_ASSERT_THROWS_NOTHING(
|
|
|
|
building2 = const_cast<Building*>(
|
|
|
|
&Stock::get_building("Building #2"))) ;
|
|
|
|
|
|
|
|
Waypoint *w, *waypoint_ptr ;
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(building1->get_waypoints().size(), 3u) ;
|
|
|
|
|
|
|
|
const Waypoint &waypoint1 =
|
|
|
|
Stock::find_create_waypoint(Waypoint(building1, 1,2,3)) ;
|
|
|
|
w = const_cast<Waypoint*>(&waypoint1) ;
|
|
|
|
|
|
|
|
TS_ASSERT(building1->get_waypoints().find(w) !=
|
|
|
|
building1->get_waypoints().end()) ;
|
|
|
|
waypoint_ptr = *building1->get_waypoints().find(
|
|
|
|
const_cast<Waypoint*>(&waypoint1)) ;
|
|
|
|
TS_ASSERT_EQUALS(waypoint_ptr, w) ;
|
|
|
|
|
|
|
|
const Waypoint &waypoint2 =
|
|
|
|
Stock::find_create_waypoint(Waypoint(building1, 4,5,6)) ;
|
|
|
|
w = const_cast<Waypoint*>(&waypoint2) ;
|
|
|
|
|
|
|
|
TS_ASSERT(building1->get_waypoints().find(w) !=
|
|
|
|
building1->get_waypoints().end()) ;
|
|
|
|
waypoint_ptr = *building1->get_waypoints().find(
|
|
|
|
const_cast<Waypoint*>(&waypoint2)) ;
|
|
|
|
TS_ASSERT_EQUALS(waypoint_ptr, w) ;
|
|
|
|
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(building2->get_waypoints().size(), 2u) ;
|
|
|
|
|
|
|
|
const Waypoint &waypoint3 =
|
|
|
|
Stock::find_create_waypoint(Waypoint(building2, 1,2,3)) ;
|
|
|
|
w = const_cast<Waypoint*>(&waypoint3) ;
|
|
|
|
|
|
|
|
TS_ASSERT(building2->get_waypoints().find(w) !=
|
|
|
|
building2->get_waypoints().end()) ;
|
|
|
|
waypoint_ptr = *building2->get_waypoints().find(
|
|
|
|
const_cast<Waypoint*>(&waypoint3)) ;
|
|
|
|
TS_ASSERT_EQUALS(waypoint_ptr, w) ;
|
|
|
|
}
|
|
|
|
|
2010-04-02 15:49:22 +02:00
|
|
|
} ;
|