1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//
// Test Suite for geos::noding::BasicSegmentString class.
#include <tut/tut.hpp>
// geos
#include <geos/noding/BasicSegmentString.h>
#include <geos/noding/Octant.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/util.h>
// std
#include <memory>
namespace tut {
//
// Test Group
//
// Common data used by tests
struct test_basicsegmentstring_data {
typedef std::unique_ptr<geos::geom::CoordinateSequence> \
CoordinateSequenceAutoPtr;
typedef std::unique_ptr<geos::noding::BasicSegmentString> \
SegmentStringAutoPtr;
SegmentStringAutoPtr
makeSegmentString(geos::geom::CoordinateSequence* cs, void* d = nullptr)
{
return SegmentStringAutoPtr(
new geos::noding::BasicSegmentString(cs, d)
);
}
test_basicsegmentstring_data()
{
}
~test_basicsegmentstring_data()
{
}
};
typedef test_group<test_basicsegmentstring_data> group;
typedef group::object object;
group test_basicsegmentstring_group("geos::noding::BasicSegmentString");
//
// Test Cases
//
// test constructor with 2 equal points
template<>
template<>
void object::test<1>
()
{
auto cs = geos::detail::make_unique<geos::geom::CoordinateSequence>(0u, 2u);
ensure(nullptr != cs.get());
geos::geom::Coordinate c0(0, 0);
geos::geom::Coordinate c1(0, 0);
cs->add(c0);
cs->add(c1);
ensure_equals(cs->size(), 2u);
SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
ensure(nullptr != ss.get());
ensure_equals(ss->size(), 2u);
ensure_equals(ss->getData(), (void*)nullptr);
ensure_equals(ss->getCoordinates(), cs.get());
ensure_equals(ss->getCoordinate(0), c0);
ensure_equals(ss->getCoordinate(1), c1);
ensure_equals(ss->isClosed(), true);
// this would throw an exception
bool octant_failed = false;
try {
ss->getSegmentOctant(0);
}
catch(...) {
octant_failed = true;
}
ensure(octant_failed);
}
// test constructor with 2 different points
template<>
template<>
void object::test<2>
()
{
auto cs = geos::detail::make_unique<geos::geom::CoordinateSequence>(0u, 2u);
ensure(nullptr != cs.get());
geos::geom::Coordinate c0(0, 0);
geos::geom::Coordinate c1(1, 0);
cs->add(c0);
cs->add(c1);
ensure_equals(cs->size(), 2u);
SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
ensure(nullptr != ss.get());
ensure_equals(ss->size(), 2u);
ensure_equals(ss->getData(), (void*)nullptr);
ensure_equals(ss->getCoordinates(), cs.get());
ensure_equals(ss->getCoordinate(0), c0);
ensure_equals(ss->getCoordinate(1), c1);
ensure_equals(ss->isClosed(), false);
ensure_equals(ss->getSegmentOctant(0), 0);
}
// test constructor with 4 different points forming a ring
template<>
template<>
void object::test<3>
()
{
auto cs = geos::detail::make_unique<geos::geom::CoordinateSequence>(0u, 2u);
ensure(nullptr != cs.get());
geos::geom::Coordinate c0(0, 0);
geos::geom::Coordinate c1(1, 0);
geos::geom::Coordinate c2(1, 1);
cs->add(c0);
cs->add(c1);
cs->add(c2);
cs->add(c0);
ensure_equals(cs->size(), 4u);
SegmentStringAutoPtr ss(makeSegmentString(cs.get()));
ensure(nullptr != ss.get());
ensure_equals(ss->size(), 4u);
ensure_equals(ss->getData(), (void*)nullptr);
ensure_equals(ss->getCoordinates(), cs.get());
ensure_equals(ss->getCoordinate(0), c0);
ensure_equals(ss->getCoordinate(1), c1);
ensure_equals(ss->getCoordinate(2), c2);
ensure_equals(ss->getCoordinate(3), c0);
ensure_equals(ss->isClosed(), true);
ensure_equals(ss->getSegmentOctant(2), 4);
ensure_equals(ss->getSegmentOctant(1), 1);
ensure_equals(ss->getSegmentOctant(0), 0);
}
// test Octant class
template<>
template<>
void object::test<4>
()
{
geos::geom::Coordinate p0(0, 0);
geos::geom::Coordinate p1(5, -5);
int octant_rc1 = 0;
int octant_rc2 = 0;
int testPassed = true;
try {
octant_rc1 = geos::noding::Octant::octant(p0, p1);
octant_rc2 = geos::noding::Octant::octant(&p0, &p1);
testPassed = (octant_rc1 == octant_rc2);
}
catch(...) {
testPassed = false;
}
ensure(0 != testPassed);
}
} // namespace tut
|