File: GEOSGeomToWKTTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (162 lines) | stat: -rw-r--r-- 2,810 bytes parent folder | download
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
//
// Test Suite for C-API GEOSGeomToWKT

#include <tut/tut.hpp>
// geos
#include <geos_c.h>
// std
#include <string>
#include <cstdlib>

#include "capi_test_utils.h"

namespace tut {
//
// Test Group
//

// Common data used in test cases.
struct test_capigeosgeomtowkt_data : public capitest::utility {
    void
    test_wkt(std::string const& wkt)
    {
        GEOSGeometry* geom1 = GEOSGeomFromWKT(wkt.c_str());
        ensure(nullptr != geom1);

        char* wkt_c = GEOSGeomToWKT(geom1);
        std::string out(wkt_c);
        free(wkt_c);
        GEOSGeom_destroy(geom1);

        ensure_equals(out, wkt);
    }

    void
    test_wkt(std::string const& wkt, std::string::size_type n)
    {
        GEOSGeometry* geom1 = GEOSGeomFromWKT(wkt.c_str());
        ensure(nullptr != geom1);

        char* wkt_c = GEOSGeomToWKT(geom1);
        std::string out(wkt_c);
        free(wkt_c);
        GEOSGeom_destroy(geom1);

        ensure_equals(out.substr(0, n), wkt.substr(0, n));
    }
};

typedef test_group<test_capigeosgeomtowkt_data> group;
typedef group::object object;

group test_capigeosgeomtowkt_group("capi::GEOSGeomToWKT");

//
// Test Cases
//

template<>
template<>
void object::test<1>
()
{
    test_wkt("POINT EMPTY");
}

template<>
template<>
void object::test<2>
()
{
    test_wkt("LINESTRING EMPTY");
}

template<>
template<>
void object::test<3>
()
{
    test_wkt("POLYGON EMPTY");
}

template<>
template<>
void object::test<4>
()
{
    test_wkt("MULTIPOINT EMPTY");
}

template<>
template<>
void object::test<5>
()
{
    test_wkt("MULTILINESTRING EMPTY");
}

template<>
template<>
void object::test<6>
()
{
    test_wkt("MULTIPOLYGON EMPTY");
}

// Comparing string based on float-point numbers does not make sense,
// so make poor-man comparison of WKT type tag and first few numbers

template<>
template<>
void object::test<7>
()
{
    test_wkt("POINT (1.234000 5.678)", 15);

    // check default OutputDimension(2) with higher dimension points
    test_wkt("POINT (1.234000 5.678 9)", 15); // POINT Z
    test_wkt("POINT (1.234000 5.678 9 10)", 15); // POINT ZM
}

template<>
template<>
void object::test<8>
()
{
    test_wkt("LINESTRING (0.000 0, 5 5, 10 5, 10 10)", 17);
}

template<>
template<>
void object::test<9>
()
{
    test_wkt("POLYGON ((0.000 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))", 15);
}

template<>
template<>
void object::test<10>
()
{
    test_wkt("MULTIPOINT ((0.000 0), (5 5), (10 10), (15 15), (20 20))", 17);
}

template<>
template<>
void object::test<11>
()
{
    test_wkt("MULTILINESTRING ((0.000 0, 10 0, 10 10, 0 10, 10 20),(2 2, 2 6, 6 4, 20 2))", 23);
}

template<>
template<>
void object::test<12>
()
{
    test_wkt("MULTIPOLYGON (((0.000 0, 10 0, 10 10, 0 10, 0 0),(2 2, 2 6, 6 4, 2 2)),((60 60, 60 50, 70 40, 60 60)))", 21);
}

} // namespace tut