1 //
2 // Test Suite for C-API GEOSRelateBoundaryNodeRule
3 
4 #include <tut/tut.hpp>
5 // geos
6 #include <geos_c.h>
7 // std
8 #include <cstdarg>
9 #include <cstdio>
10 #include <cstdlib>
11 
12 namespace tut {
13 //
14 // Test Group
15 //
16 
17 // Common data used in test cases.
18 struct test_capigeosrelateboundarynoderule_data {
19     GEOSGeometry* geom1_;
20     GEOSGeometry* geom2_;
21     char* pat_;
22 
23     static void
noticetut::test_capigeosrelateboundarynoderule_data24     notice(const char* fmt, ...)
25     {
26         std::fprintf(stdout, "NOTICE: ");
27 
28         va_list ap;
29         va_start(ap, fmt);
30         std::vfprintf(stdout, fmt, ap);
31         va_end(ap);
32 
33         std::fprintf(stdout, "\n");
34     }
35 
test_capigeosrelateboundarynoderule_datatut::test_capigeosrelateboundarynoderule_data36     test_capigeosrelateboundarynoderule_data()
37         : geom1_(nullptr), geom2_(nullptr), pat_(nullptr)
38     {
39         initGEOS(notice, notice);
40     }
41 
~test_capigeosrelateboundarynoderule_datatut::test_capigeosrelateboundarynoderule_data42     ~test_capigeosrelateboundarynoderule_data()
43     {
44         GEOSGeom_destroy(geom1_);
45         GEOSGeom_destroy(geom2_);
46         GEOSFree(pat_);
47         finishGEOS();
48     }
49 
50 };
51 
52 typedef test_group<test_capigeosrelateboundarynoderule_data> group;
53 typedef group::object object;
54 
55 group test_capigeosrelateboundarynoderule_group("capi::GEOSRelateBoundaryNodeRule");
56 
57 //
58 // Test Cases
59 //
60 
61 // Closed line touching open line on endpoint with OGC rule
62 template<>
63 template<>
test()64 void object::test<1>
65 ()
66 {
67     geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0, 10 10, 0 0)");
68     geom2_ = GEOSGeomFromWKT("LINESTRING(0 0, 0 -10)");
69     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_, GEOSRELATE_BNR_OGC);
70     ensure_equals(std::string(pat_), std::string("F01FFF102"));
71 }
72 
73 // Closed line touching open line on endpoint with MOD2 rule
74 template<>
75 template<>
test()76 void object::test<2>
77 ()
78 {
79     geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0, 10 10, 0 0)");
80     geom2_ = GEOSGeomFromWKT("LINESTRING(0 0, 0 -10)");
81     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_, GEOSRELATE_BNR_MOD2);
82     ensure_equals(std::string(pat_), std::string("F01FFF102"));
83 }
84 
85 // Closed line touching open line on endpoint with ENDPOINT rule
86 template<>
87 template<>
test()88 void object::test<3>
89 ()
90 {
91     geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0, 10 10, 0 0)");
92     geom2_ = GEOSGeomFromWKT("LINESTRING(0 0, 0 -10)");
93     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_,
94                                       GEOSRELATE_BNR_ENDPOINT);
95     ensure_equals(std::string(pat_), std::string("FF1F0F102"));
96 }
97 
98 // Noded multiline touching line on node , MOD2 rule
99 template<>
100 template<>
test()101 void object::test<4>
102 ()
103 {
104     geom1_ = GEOSGeomFromWKT("MULTILINESTRING((0 0, 10 0),(10 0, 10 10))");
105     geom2_ = GEOSGeomFromWKT("LINESTRING(10 0, 10 -10)");
106     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_,
107                                       GEOSRELATE_BNR_MOD2);
108     ensure_equals(std::string(pat_), std::string("F01FF0102"));
109 }
110 
111 // Noded multiline touching line on node , ENDPOINT rule
112 template<>
113 template<>
test()114 void object::test<5>
115 ()
116 {
117     geom1_ = GEOSGeomFromWKT("MULTILINESTRING((0 0, 10 0),(10 0, 10 10))");
118     geom2_ = GEOSGeomFromWKT("LINESTRING(10 0, 10 -10)");
119     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_,
120                                       GEOSRELATE_BNR_ENDPOINT);
121     ensure_equals(std::string(pat_), std::string("FF1F00102"));
122 }
123 
124 // Noded multiline touching line on node , MULTIVALENT ENDPOINT rule
125 // NOTE: the single line has no boundary !
126 template<>
127 template<>
test()128 void object::test<6>
129 ()
130 {
131     geom1_ = GEOSGeomFromWKT("MULTILINESTRING((0 0, 10 0),(10 0, 10 10))");
132     geom2_ = GEOSGeomFromWKT("LINESTRING(10 0, 10 -10)");
133     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_,
134                                       GEOSRELATE_BNR_MULTIVALENT_ENDPOINT);
135     ensure_equals(std::string(pat_), std::string("0F1FFF1F2"));
136 }
137 
138 // Noded multiline touching line on node , MONOVALENT ENDPOINT rule
139 template<>
140 template<>
test()141 void object::test<7>
142 ()
143 {
144     geom1_ = GEOSGeomFromWKT("MULTILINESTRING((0 0, 10 0),(10 0, 10 10))");
145     geom2_ = GEOSGeomFromWKT("LINESTRING(10 0, 10 -10)");
146     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_,
147                                       GEOSRELATE_BNR_MONOVALENT_ENDPOINT);
148     ensure_equals(std::string(pat_), std::string("F01FF0102"));
149 }
150 
151 // Invalid/unknown rule
152 template<>
153 template<>
test()154 void object::test<8>
155 ()
156 {
157     geom1_ = GEOSGeomFromWKT("MULTILINESTRING((0 0, 10 0),(10 0, 10 10))");
158     geom2_ = GEOSGeomFromWKT("LINESTRING(10 0, 10 -10)");
159     pat_ = GEOSRelateBoundaryNodeRule(geom1_, geom2_, 5);
160     ensure(nullptr == pat_);
161 }
162 
163 
164 
165 } // namespace tut
166 
167