owlps/owlps-positioner/tests/building_test.hh

94 lines
2.6 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 "building.hh"
#include "waypoint.hh"
#include "area.hh"
#include "stock.hh"
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") ;
std::unordered_map<std::string, Area*> areas1 ;
TS_ASSERT_EQUALS(b1.get_areas(), areas1) ;
std::unordered_set<Waypoint*> waypoints1 ;
TS_ASSERT_EQUALS(b1.get_waypoints(), waypoints1) ;
// 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") ;
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(const_cast<Waypoint*>(&wp1)) ;
b2.add_waypoint(const_cast<Waypoint*>(&wp2)) ;
waypoints1.insert(const_cast<Waypoint*>(&wp1)) ;
waypoints1.insert(const_cast<Waypoint*>(&wp2)) ;
TS_ASSERT_EQUALS(b2.get_waypoints(), waypoints1) ;
Area *a1 = new Area(&b2, "area1") ;
Area *a2 = new Area(&b2, "area2") ;
b2.add_area(a1) ;
b2.add_area(a2) ;
areas1["area1"] = a1 ;
areas1["area2"] = a2 ;
TS_ASSERT_EQUALS(b2.get_areas(), areas1) ;
// TODO: test deletion of waypoints from Stock after deletion of b2
}
void test_operators(void)
{
// ==
Building b1("Build") ;
Building b2("Build") ;
TS_ASSERT_EQUALS(b1, b2) ;
// !=
Building b3("B2") ;
TS_ASSERT(b1 != b3) ;
// =
b2 = b3 ;
TS_ASSERT_EQUALS(b2, b3) ;
}
} ;