diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
| commit | 6232d13f5321b87ddf12a1aa36b4545da45f173d (patch) | |
| tree | 23f3316470a14136debd9d02f9e920ca2b06f4cc /test/test_geo_json.cc | |
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in
memroy.
Diffstat (limited to 'test/test_geo_json.cc')
| -rw-r--r-- | test/test_geo_json.cc | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/test/test_geo_json.cc b/test/test_geo_json.cc new file mode 100644 index 0000000..e466e75 --- /dev/null +++ b/test/test_geo_json.cc @@ -0,0 +1,123 @@ +#include "common.hh" + +#include "file_test.hh" +#include "geo_json.hh" +#include "logger.hh" + +#include <gtest/gtest.h> + +namespace { + +class GeoJsonTest : public FileTest { +public: + std::unique_ptr<GeoJson> load(std::string_view data) { + write(data); + close(); + return GeoJson::create(logger_, path()); + } + +private: + std::shared_ptr<Logger> logger_{Logger::create_null()}; +}; + +} // namespace + +TEST_F(GeoJsonTest, empty) { + auto geo_json = load(""); + + auto opt = geo_json->get_data(0.0, 0.0, "prop0"); + EXPECT_FALSE(opt.has_value()); +} + +TEST_F(GeoJsonTest, sanity) { + auto geo_json = load( + "{" + " \"type\": \"FeatureCollection\"," + " \"features\": [" + " {" + " \"type\": \"Feature\"," + " \"geometry\": {" + " \"type\": \"Polygon\"," + " \"coordinates\": [" + " [" + " [100.0, 0.0], [101.0, 0.0], [101.0, 1.0]," + " [100.0, 1.0], [100.0, 0.0]" + " ]" + " ]" + " }," + " \"properties\": {" + " \"prop0\": \"value0\"," + " \"prop1\": { \"this\": \"that\" }" + " }" + " }" + " ]" + "}"); + + auto opt = geo_json->get_data(0.0, 0.0, "prop0"); + EXPECT_FALSE(opt.has_value()); + + opt = geo_json->get_data(0.5, 100.5, "prop0"); + EXPECT_TRUE(opt.has_value()); + if (opt.has_value()) { + EXPECT_EQ("value0", opt.value()); + } + + opt = geo_json->get_data(0.0, 100.0, "prop0"); + EXPECT_TRUE(opt.has_value()); + if (opt.has_value()) { + EXPECT_EQ("value0", opt.value()); + } + + opt = geo_json->get_data(0.5, 100.5, "prop1"); + EXPECT_FALSE(opt.has_value()); +} + +TEST_F(GeoJsonTest, hole) { + auto geo_json = load( + "{" + " \"type\": \"FeatureCollection\"," + " \"features\": [" + " {" + " \"type\": \"Feature\"," + " \"geometry\": {" + " \"type\": \"Polygon\"," + " \"coordinates\": [" + " [" + " [100.0, 0.0], [101.0, 0.0], [101.0, 1.0]," + " [100.0, 1.0], [100.0, 0.0]" + " ]," + " [" + " [100.25, 0.25], [100.75, 0.25], [100.75, 0.75]," + " [100.25, 0.75], [100.25, 0.25]" + " ]" + " ]" + " }," + " \"properties\": {" + " \"prop0\": \"value0\"" + " }" + " }" + " ]" + "}"); + + auto opt = geo_json->get_data(0.5, 100.5, "prop0"); + EXPECT_FALSE(opt.has_value()); + + opt = geo_json->get_data(0.0, 100.0, "prop0"); + EXPECT_TRUE(opt.has_value()); + if (opt.has_value()) { + EXPECT_EQ("value0", opt.value()); + } + + opt = geo_json->get_data(0.1, 100.20, "prop0"); + EXPECT_TRUE(opt.has_value()); + if (opt.has_value()) { + EXPECT_EQ("value0", opt.value()); + } +} + +TEST_F(GeoJsonTest, bad) { + auto geo_json = load(std::string(1000, '{')); + + auto opt = geo_json->get_data(0.0, 0.0, "prop0"); + EXPECT_FALSE(opt.has_value()); +} |
