OmniSciDB  c07336695a
GeoTypesTest.cpp File Reference
#include <Shared/geo_types.h>
#include "Tests/TestHelpers.h"
#include <gtest/gtest.h>
+ Include dependency graph for GeoTypesTest.cpp:

Go to the source code of this file.

Classes

struct  SamplePointData
 
struct  SampleLineStringData
 
struct  SamplePolygonData
 
struct  SampleMultiPolygonData
 

Namespaces

 anonymous_namespace{GeoTypesTest.cpp}
 

Functions

template<class T >
void anonymous_namespace{GeoTypesTest.cpp}::compare_arrays (const std::vector< T > &a, const std::vector< T > &b)
 
 TEST (GeoPoint, EmptyWKT)
 
 TEST (GeoPoint, EmptyCoords)
 
 TEST (GeoPoint, ImportWKT)
 
 TEST (GeoPoint, ExportWKT)
 
 TEST (GeoPoint, ExportColumns)
 
 TEST (GeoPoint, EqualsOperator)
 
 TEST (GeoPoint, OGRError)
 
 TEST (GeoPoint, BadWktType)
 
 TEST (GeoLineString, EmptyWKT)
 
 TEST (GeoLineString, EmptyCoords)
 
 TEST (GeoLineString, ImportWKT)
 
 TEST (GeoLineString, ExportWKT)
 
 TEST (GeoLineString, ExportColumns)
 
 TEST (GeoLineString, EqualsOperator)
 
 TEST (GeoLineString, OGRError)
 
 TEST (GeoLineString, BadWktType)
 
 TEST (GeoPolygon, EmptyWKT)
 
 TEST (GeoPolygon, EmptyCoords)
 
 TEST (GeoPolygon, ImportWKT)
 
 TEST (GeoPolygon, ExportWKT)
 
 TEST (GeoPolygon, ExportColumns)
 
 TEST (GeoPolygon, EqualsOperator)
 
 TEST (GeoPolygon, OGRError)
 
 TEST (GeoPolygon, BadWktType)
 
 TEST (GeoMultiPolygon, EmptyWKT)
 
 TEST (GeoMultiPolygon, EmptyCoords)
 
 TEST (GeoMultiPolygon, ImportWKT)
 
 TEST (GeoMultiPolygon, ExportWKT)
 
 TEST (GeoMultiPolygon, ExportColumns)
 
 TEST (GeoMultiPolygon, EqualsOperator)
 
 TEST (GeoMultiPolygon, OGRError)
 
 TEST (GeoMultiPolygon, BadWktType)
 
 TEST (GeoMisc, Inequality)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 309 of file GeoTypesTest.cpp.

References logger::ERROR, TestHelpers::init_logger_stderr_only(), and LOG.

309  {
311  testing::InitGoogleTest(&argc, argv);
312 
313  int err{0};
314  try {
315  err = RUN_ALL_TESTS();
316  } catch (const std::exception& e) {
317  LOG(ERROR) << e.what();
318  }
319  return err;
320 }
#define LOG(tag)
Definition: Logger.h:182
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
+ Here is the call graph for this function:

◆ TEST() [1/33]

TEST ( GeoPoint  ,
EmptyWKT   
)

Definition at line 41 of file GeoTypesTest.cpp.

41  {
42  const auto gdal_wkt_pt = GeoPoint("POINT EMPTY");
43  const auto wkt_str = gdal_wkt_pt.getWktString();
44  ASSERT_EQ(wkt_str, "POINT EMPTY");
45 }

◆ TEST() [2/33]

TEST ( GeoPoint  ,
EmptyCoords   
)

Definition at line 47 of file GeoTypesTest.cpp.

47  {
48  EXPECT_THROW(GeoPoint(std::vector<double>()), GeoTypesError);
49 }

◆ TEST() [3/33]

TEST ( GeoPoint  ,
ImportWKT   
)

Definition at line 51 of file GeoTypesTest.cpp.

51  {
52  const auto sample_pt = SamplePointData();
53  const auto gdal_pt = GeoPoint(sample_pt.wkt);
54  const auto wkt_str = gdal_pt.getWktString();
55  ASSERT_EQ(wkt_str, sample_pt.wkt);
56 }

◆ TEST() [4/33]

TEST ( GeoPoint  ,
ExportWKT   
)

Definition at line 58 of file GeoTypesTest.cpp.

58  {
59  const auto sample_pt = SamplePointData();
60  const auto gdal_pt = GeoPoint(sample_pt.coords);
61  const auto wkt_str = gdal_pt.getWktString();
62  ASSERT_EQ(wkt_str, sample_pt.wkt);
63 }

◆ TEST() [5/33]

TEST ( GeoPoint  ,
ExportColumns   
)

Definition at line 65 of file GeoTypesTest.cpp.

References anonymous_namespace{GeoTypesTest.cpp}::compare_arrays().

65  {
66  const auto sample_pt = SamplePointData();
67  const auto gdal_pt = GeoPoint(sample_pt.wkt);
68  std::vector<double> coords;
69  gdal_pt.getColumns(coords);
70  compare_arrays(coords, sample_pt.coords);
71 }
void compare_arrays(const std::vector< T > &a, const std::vector< T > &b)
+ Here is the call graph for this function:

◆ TEST() [6/33]

TEST ( GeoPoint  ,
EqualsOperator   
)

Definition at line 73 of file GeoTypesTest.cpp.

73  {
74  const auto sample_pt = SamplePointData();
75  ASSERT_TRUE(GeoPoint(sample_pt.coords) == GeoPoint(sample_pt.wkt));
76 }

◆ TEST() [7/33]

TEST ( GeoPoint  ,
OGRError   
)

Definition at line 78 of file GeoTypesTest.cpp.

78  {
79  EXPECT_THROW(GeoPoint("POINT (0)"), GeoTypesError);
80 }

◆ TEST() [8/33]

TEST ( GeoPoint  ,
BadWktType   
)

Definition at line 82 of file GeoTypesTest.cpp.

82  {
83  try {
84  auto pt = GeoPoint("LINESTRING (1 1)");
85  } catch (const GeoTypesError& e) {
86  ASSERT_STREQ("GeoPoint Error: Unexpected geometry type from WKT string: Line String",
87  e.what());
88  } catch (...) {
89  FAIL();
90  }
91 }

◆ TEST() [9/33]

TEST ( GeoLineString  ,
EmptyWKT   
)

Definition at line 99 of file GeoTypesTest.cpp.

99  {
100  const auto gdal_wkt_linestr = GeoLineString("LINESTRING EMPTY");
101  const auto wkt_str = gdal_wkt_linestr.getWktString();
102  ASSERT_EQ(wkt_str, "LINESTRING EMPTY");
103 }

◆ TEST() [10/33]

TEST ( GeoLineString  ,
EmptyCoords   
)

Definition at line 105 of file GeoTypesTest.cpp.

105  {
106  const auto gdal_linestr = GeoLineString(std::vector<double>());
107  const auto wkt_str = gdal_linestr.getWktString();
108  ASSERT_EQ(wkt_str, "LINESTRING EMPTY");
109 }

◆ TEST() [11/33]

TEST ( GeoLineString  ,
ImportWKT   
)

Definition at line 111 of file GeoTypesTest.cpp.

111  {
112  const auto sample_linestr = SampleLineStringData();
113  const auto gdal_linestr = GeoLineString(sample_linestr.wkt);
114  const auto wkt_str = gdal_linestr.getWktString();
115  ASSERT_EQ(wkt_str, sample_linestr.wkt);
116 }

◆ TEST() [12/33]

TEST ( GeoLineString  ,
ExportWKT   
)

Definition at line 118 of file GeoTypesTest.cpp.

118  {
119  const auto sample_linestr = SampleLineStringData();
120  const auto gdal_linestr = GeoLineString(sample_linestr.coords);
121  const auto wkt_str = gdal_linestr.getWktString();
122  ASSERT_EQ(wkt_str, sample_linestr.wkt);
123 }

◆ TEST() [13/33]

TEST ( GeoLineString  ,
ExportColumns   
)

Definition at line 125 of file GeoTypesTest.cpp.

References anonymous_namespace{GeoTypesTest.cpp}::compare_arrays().

125  {
126  const auto sample_linestr = SampleLineStringData();
127  const auto gdal_linestr = GeoLineString(sample_linestr.wkt);
128  std::vector<double> coords;
129  std::vector<double> bounds;
130  gdal_linestr.getColumns(coords, bounds);
131  compare_arrays(coords, sample_linestr.coords);
132  compare_arrays(bounds, sample_linestr.bounds);
133 }
void compare_arrays(const std::vector< T > &a, const std::vector< T > &b)
+ Here is the call graph for this function:

◆ TEST() [14/33]

TEST ( GeoLineString  ,
EqualsOperator   
)

Definition at line 135 of file GeoTypesTest.cpp.

135  {
136  const auto sample_linestr = SampleLineStringData();
137  ASSERT_TRUE(GeoLineString(sample_linestr.coords) == GeoLineString(sample_linestr.wkt));
138 }

◆ TEST() [15/33]

TEST ( GeoLineString  ,
OGRError   
)

Definition at line 140 of file GeoTypesTest.cpp.

140  {
141  EXPECT_THROW(GeoLineString("LINESTRING (0)"), GeoTypesError);
142 }

◆ TEST() [16/33]

TEST ( GeoLineString  ,
BadWktType   
)

Definition at line 144 of file GeoTypesTest.cpp.

144  {
145  try {
146  auto pt = GeoLineString("POINT (1 1)");
147  } catch (const GeoTypesError& e) {
148  ASSERT_STREQ("GeoLineString Error: Unexpected geometry type from WKT string: Point",
149  e.what());
150  } catch (...) {
151  FAIL();
152  }
153 }

◆ TEST() [17/33]

TEST ( GeoPolygon  ,
EmptyWKT   
)

Definition at line 164 of file GeoTypesTest.cpp.

164  {
165  const auto gdal_wkt_poly = GeoPolygon("POLYGON EMPTY");
166  const auto wkt_str = gdal_wkt_poly.getWktString();
167  ASSERT_EQ(wkt_str, "POLYGON EMPTY");
168 }

◆ TEST() [18/33]

TEST ( GeoPolygon  ,
EmptyCoords   
)

Definition at line 170 of file GeoTypesTest.cpp.

170  {
171  const auto gdal_poly = GeoPolygon(std::vector<double>(), std::vector<int32_t>());
172  const auto wkt_str = gdal_poly.getWktString();
173  ASSERT_EQ(wkt_str, "POLYGON EMPTY");
174 }

◆ TEST() [19/33]

TEST ( GeoPolygon  ,
ImportWKT   
)

Definition at line 176 of file GeoTypesTest.cpp.

176  {
177  const auto sample_poly = SamplePolygonData();
178  const auto gdal_poly = GeoPolygon(sample_poly.wkt);
179  const auto wkt_str = gdal_poly.getWktString();
180  ASSERT_EQ(wkt_str, sample_poly.wkt);
181 }

◆ TEST() [20/33]

TEST ( GeoPolygon  ,
ExportWKT   
)

Definition at line 183 of file GeoTypesTest.cpp.

183  {
184  const auto sample_poly = SamplePolygonData();
185  const auto gdal_poly = GeoPolygon(sample_poly.coords, sample_poly.ring_sizes);
186  const auto wkt_str = gdal_poly.getWktString();
187  ASSERT_EQ(wkt_str, sample_poly.wkt);
188 }

◆ TEST() [21/33]

TEST ( GeoPolygon  ,
ExportColumns   
)

Definition at line 190 of file GeoTypesTest.cpp.

References anonymous_namespace{GeoTypesTest.cpp}::compare_arrays().

190  {
191  const auto sample_poly = SamplePolygonData();
192  const auto gdal_poly = GeoPolygon(sample_poly.coords, sample_poly.ring_sizes);
193  std::vector<double> coords;
194  std::vector<int32_t> ring_sizes;
195  std::vector<double> bounds;
196  gdal_poly.getColumns(coords, ring_sizes, bounds);
197  compare_arrays(coords, sample_poly.coords);
198  compare_arrays(ring_sizes, sample_poly.ring_sizes);
199  compare_arrays(bounds, sample_poly.bounds);
200 }
void compare_arrays(const std::vector< T > &a, const std::vector< T > &b)
+ Here is the call graph for this function:

◆ TEST() [22/33]

TEST ( GeoPolygon  ,
EqualsOperator   
)

Definition at line 202 of file GeoTypesTest.cpp.

202  {
203  const auto sample_poly = SamplePolygonData();
204  ASSERT_TRUE(GeoPolygon(sample_poly.coords, sample_poly.ring_sizes) ==
205  GeoPolygon(sample_poly.wkt));
206 }

◆ TEST() [23/33]

TEST ( GeoPolygon  ,
OGRError   
)

Definition at line 208 of file GeoTypesTest.cpp.

208  {
209  EXPECT_THROW(GeoPolygon("POYLGON ((0))"), GeoTypesError);
210 }

◆ TEST() [24/33]

TEST ( GeoPolygon  ,
BadWktType   
)

Definition at line 212 of file GeoTypesTest.cpp.

212  {
213  try {
214  auto pt = GeoPolygon("POINT (1 1)");
215  } catch (const GeoTypesError& e) {
216  ASSERT_STREQ("GeoPolygon Error: Unexpected geometry type from WKT string: Point",
217  e.what());
218  } catch (...) {
219  FAIL();
220  }
221 }

◆ TEST() [25/33]

TEST ( GeoMultiPolygon  ,
EmptyWKT   
)

Definition at line 234 of file GeoTypesTest.cpp.

234  {
235  const auto gdal_wkt_mpoly = GeoMultiPolygon("MULTIPOLYGON EMPTY");
236  const auto wkt_str = gdal_wkt_mpoly.getWktString();
237  ASSERT_EQ(wkt_str, "MULTIPOLYGON EMPTY");
238 }

◆ TEST() [26/33]

TEST ( GeoMultiPolygon  ,
EmptyCoords   
)

Definition at line 240 of file GeoTypesTest.cpp.

240  {
241  const auto gdal_mpoly = GeoMultiPolygon(
242  std::vector<double>(), std::vector<int32_t>(), std::vector<int32_t>());
243  const auto wkt_str = gdal_mpoly.getWktString();
244  ASSERT_EQ(wkt_str, "MULTIPOLYGON EMPTY");
245 }

◆ TEST() [27/33]

TEST ( GeoMultiPolygon  ,
ImportWKT   
)

Definition at line 247 of file GeoTypesTest.cpp.

247  {
248  const auto sample_mpoly = SampleMultiPolygonData();
249  const auto gdal_mpoly = GeoMultiPolygon(sample_mpoly.wkt);
250  const auto wkt_str = gdal_mpoly.getWktString();
251  ASSERT_EQ(wkt_str, sample_mpoly.wkt);
252 }

◆ TEST() [28/33]

TEST ( GeoMultiPolygon  ,
ExportWKT   
)

Definition at line 254 of file GeoTypesTest.cpp.

254  {
255  const auto sample_mpoly = SampleMultiPolygonData();
256  const auto gdal_mpoly = GeoMultiPolygon(
257  sample_mpoly.coords, sample_mpoly.ring_sizes, sample_mpoly.poly_rings);
258  const auto wkt_str = gdal_mpoly.getWktString();
259  ASSERT_EQ(wkt_str, sample_mpoly.wkt);
260 }

◆ TEST() [29/33]

TEST ( GeoMultiPolygon  ,
ExportColumns   
)

Definition at line 262 of file GeoTypesTest.cpp.

References anonymous_namespace{GeoTypesTest.cpp}::compare_arrays().

262  {
263  const auto sample_mpoly = SampleMultiPolygonData();
264  const auto gdal_mpoly = GeoMultiPolygon(sample_mpoly.wkt);
265  std::vector<double> coords;
266  std::vector<int32_t> ring_sizes;
267  std::vector<int32_t> poly_rings;
268  std::vector<double> bounds;
269  gdal_mpoly.getColumns(coords, ring_sizes, poly_rings, bounds);
270  compare_arrays(coords, sample_mpoly.coords);
271  compare_arrays(ring_sizes, sample_mpoly.ring_sizes);
272  compare_arrays(poly_rings, sample_mpoly.poly_rings);
273  compare_arrays(bounds, sample_mpoly.bounds);
274 }
void compare_arrays(const std::vector< T > &a, const std::vector< T > &b)
+ Here is the call graph for this function:

◆ TEST() [30/33]

TEST ( GeoMultiPolygon  ,
EqualsOperator   
)

Definition at line 276 of file GeoTypesTest.cpp.

276  {
277  const auto sample_mpoly = SampleMultiPolygonData();
278  ASSERT_TRUE(GeoMultiPolygon(sample_mpoly.coords,
279  sample_mpoly.ring_sizes,
280  sample_mpoly.poly_rings) ==
281  GeoMultiPolygon(sample_mpoly.wkt));
282 }

◆ TEST() [31/33]

TEST ( GeoMultiPolygon  ,
OGRError   
)

Definition at line 284 of file GeoTypesTest.cpp.

284  {
285  EXPECT_THROW(GeoMultiPolygon("MULTIPOYLGON ((0))"), GeoTypesError);
286 }

◆ TEST() [32/33]

TEST ( GeoMultiPolygon  ,
BadWktType   
)

Definition at line 288 of file GeoTypesTest.cpp.

288  {
289  try {
290  auto pt = GeoMultiPolygon("POINT (1 1)");
291  } catch (const GeoTypesError& e) {
292  ASSERT_STREQ("GeoMultiPolygon Error: Unexpected geometry type from WKT string: Point",
293  e.what());
294  } catch (...) {
295  FAIL();
296  }
297 }

◆ TEST() [33/33]

TEST ( GeoMisc  ,
Inequality   
)

Definition at line 299 of file GeoTypesTest.cpp.

299  {
300  const auto sample_pt = SamplePointData();
301  const auto sample_linestring = SampleLineStringData();
302  ASSERT_FALSE(GeoPoint(sample_pt.wkt) == GeoLineString(sample_linestring.wkt));
303 
304  const auto sample_mpoly = SampleMultiPolygonData();
305  ASSERT_FALSE(GeoLineString(sample_linestring.coords) ==
306  GeoMultiPolygon(sample_mpoly.wkt));
307 }