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-02-02 12:51:50 +01:00
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
|
|
#include "building.hh"
|
|
|
|
#include "waypoint.hh"
|
|
|
|
#include "area.hh"
|
2013-06-16 03:11:21 +02:00
|
|
|
#include "stock.hh"
|
2010-02-02 12:51:50 +01:00
|
|
|
|
|
|
|
class Building_test: public CxxTest::TestSuite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void test_constructors(void)
|
|
|
|
{
|
|
|
|
// Default constructor
|
|
|
|
Building b1 ;
|
|
|
|
Building b2("Unnamed building") ;
|
|
|
|
TS_ASSERT_EQUALS(b1, b2) ;
|
|
|
|
|
|
|
|
// Copy constructor
|
|
|
|
Building b3("My Enormous Building") ;
|
|
|
|
Building b4(b3) ;
|
|
|
|
TS_ASSERT_EQUALS(b3, b4) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test_accessors(void)
|
|
|
|
{
|
|
|
|
// Simple read accessors
|
|
|
|
Building b1 ;
|
|
|
|
TS_ASSERT_EQUALS(b1.get_name(), "Unnamed building") ;
|
2013-05-30 20:13:44 +02:00
|
|
|
std::unordered_map<std::string, Area*> areas1 ;
|
2010-04-02 10:56:52 +02:00
|
|
|
TS_ASSERT_EQUALS(b1.get_areas(), areas1) ;
|
2013-05-30 20:13:44 +02:00
|
|
|
std::unordered_set<Waypoint*> waypoints1 ;
|
2010-04-02 10:56:52 +02:00
|
|
|
TS_ASSERT_EQUALS(b1.get_waypoints(), waypoints1) ;
|
2010-02-02 12:51:50 +01:00
|
|
|
|
|
|
|
// Write & read accessors
|
|
|
|
Building b2("My Building") ;
|
|
|
|
TS_ASSERT_EQUALS(b2.get_name(), "My Building") ;
|
|
|
|
b2.set_name("My Second Building") ;
|
|
|
|
TS_ASSERT_EQUALS(b2.get_name(), "My Second Building") ;
|
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
const Waypoint &wp1 =
|
|
|
|
Stock::find_create_waypoint(Waypoint(&b2, 43,45,909)) ;
|
|
|
|
const Waypoint &wp2 =
|
|
|
|
Stock::find_create_waypoint(Waypoint(&b2, 12,78,2)) ;
|
|
|
|
b2.add_waypoint(&wp1) ;
|
|
|
|
b2.add_waypoint(&wp2) ;
|
|
|
|
waypoints1.insert(const_cast<Waypoint*>(&wp1)) ;
|
|
|
|
waypoints1.insert(const_cast<Waypoint*>(&wp2)) ;
|
2010-04-02 10:56:52 +02:00
|
|
|
TS_ASSERT_EQUALS(b2.get_waypoints(), waypoints1) ;
|
2010-02-02 12:51:50 +01:00
|
|
|
|
2010-04-02 10:56:52 +02:00
|
|
|
Area *a1 = new Area(&b2, "area1") ;
|
|
|
|
Area *a2 = new Area(&b2, "area2") ;
|
2010-02-02 12:51:50 +01:00
|
|
|
b2.add_area(a1) ;
|
|
|
|
b2.add_area(a2) ;
|
2010-04-02 10:56:52 +02:00
|
|
|
areas1["area1"] = a1 ;
|
|
|
|
areas1["area2"] = a2 ;
|
|
|
|
TS_ASSERT_EQUALS(b2.get_areas(), areas1) ;
|
2010-04-13 10:47:10 +02:00
|
|
|
|
|
|
|
// TODO: test deletion of waypoints from Stock after deletion of b2
|
2010-02-02 12:51:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test_operators(void)
|
|
|
|
{
|
|
|
|
// ==
|
|
|
|
Building b1("Build") ;
|
|
|
|
Building b2("Build") ;
|
|
|
|
TS_ASSERT_EQUALS(b1, b2) ;
|
|
|
|
|
|
|
|
// !=
|
|
|
|
Building b3("B2") ;
|
2010-03-05 09:30:29 +01:00
|
|
|
TS_ASSERT(b1 != b3) ;
|
2010-02-02 12:51:50 +01:00
|
|
|
|
|
|
|
// =
|
|
|
|
b2 = b3 ;
|
|
|
|
TS_ASSERT_EQUALS(b2, b3) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
} ;
|