File: GEOSGeomFromWKBTest.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 (134 lines) | stat: -rw-r--r-- 3,243 bytes parent folder | download | duplicates (2)
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
//
// Test Suite for C-API GEOSGeomFromWKB

#include <tut/tut.hpp>
#include <utility.h> // wkb_hex_decoder

#include "capi_test_utils.h"

namespace tut {
//
// Test Group
//

// Common data used in test cases.
struct test_capigeosgeomfromwkb_data : public capitest::utility {
    GEOSWKTReader* reader_;

    test_capigeosgeomfromwkb_data() : reader_(nullptr)
    {
        reader_ = GEOSWKTReader_create();
    }

    ~test_capigeosgeomfromwkb_data()
    {
        GEOSWKTReader_destroy(reader_);
        reader_ = nullptr;
    }

    void
    test_wkb(const std::string& wkbhex, const std::string& wkt)
    {
        wkb_hex_decoder::binary_type wkb;
        wkb_hex_decoder::decode(wkbhex, wkb);

        geom1_ = GEOSGeomFromWKB_buf(&wkb[0], wkb.size());
        ensure("GEOSGeomFromWKB_buf failed to create geometry", nullptr != geom1_);

        geom2_ = GEOSWKTReader_read(reader_, wkt.c_str());
        ensure ("GEOSWKTReader_read failed to create geometry", nullptr != geom2_ );
        ensure_geometry_equals(geom1_, geom2_);
    }
};

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

group test_capigeosgeomfromwkb_group("capi::GEOSGeomFromWKB");

//
// Test Cases
//

template<>
template<>
void object::test<1>
()
{
    // POINT(1.234 5.678)
    std::string wkt("POINT (1.234 5.678)");
    std::string wkb("01010000005839B4C876BEF33F83C0CAA145B61640");
    test_wkb(wkb, wkt);
}

template<>
template<>
void object::test<2>
()
{
    // SRID=4;POINT(0 0)
    std::string wkt("POINT(0 0)");
    std::string ewkb("01010000200400000000000000000000000000000000000000");
    test_wkb(ewkb, wkt);
}

template<>
template<>
void object::test<3>
()
{
    // SRID=32632;POINT(1.234 5.678)
    std::string wkt("POINT (1.234 5.678)");
    std::string ewkb("0101000020787F00005839B4C876BEF33F83C0CAA145B61640");
    test_wkb(ewkb, wkt);
}

template<>
template<>
void object::test<4>
()
{
    // POINT (1.234 5.678 15 79) -- XYZM
    std::string wkt("POINT (1.234 5.678 15 79)");
    std::string ewkb("01010000C05839B4C876BEF33F83C0CAA145B616400000000000002E400000000000C05340");
    test_wkb(ewkb, wkt);
}

template<>
template<>
void object::test<5>
()
{
    std::string wkt("MULTIPOINT ((1.123 1.456), (2.123 2.456), (3.123 3.456))");
    std::string
    ewkb("01040000000300000001010000002b8716d9cef7f13fb29defa7c64bf73f010100000096438b6ce7fb0040d9cef753e3a50340010100000096438b6ce7fb0840d9cef753e3a50b40");
    test_wkb(ewkb, wkt);
}

// Check force close on unclosed rings
template<>
template<>
void object::test<6>
()
{
    geom1_ = GEOSWKTReader_read(reader_, "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))");
    ensure("geom1_ not null", geom1_ != nullptr);
    GEOSWKTReader_setFixStructure(reader_, 1);
    geom2_ = GEOSWKTReader_read(reader_, "POLYGON((0 0, 0 1, 1 1, 1 0))");
    ensure("geom2_ not null", geom2_ != nullptr);
    ensure_geometry_equals(geom1_, geom2_);
}

// Supply EWKB input
template<>
template<>
void object::test<7>()
{
    test_wkb(
        "01040000C00200000001010000C000000000000000000000000000000000000000000000F03F000000000000F03F01010000C0000000000000084000000000000000400000000000000040000000000000F03F",
        "MULTIPOINT((0 0 1 1), (3 2 2 1))"
    );
}

} // namespace tut