2015-04-24 12:40:22 +00:00
|
|
|
|
|
|
|
#include <mapnik/layer.hpp>
|
|
|
|
#include <mapnik/map.hpp>
|
|
|
|
#include <mapnik/color.hpp>
|
|
|
|
#include <mapnik/datasource.hpp>
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
2015-07-01 00:04:48 +00:00
|
|
|
#include <mapnik/util/fs.hpp>
|
2015-04-24 12:40:22 +00:00
|
|
|
|
|
|
|
#include "catch.hpp"
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
TEST_CASE("copy")
|
|
|
|
{
|
|
|
|
SECTION("layers")
|
2015-04-24 12:40:22 +00:00
|
|
|
{
|
2022-01-26 22:25:53 +00:00
|
|
|
try
|
2015-07-01 00:04:48 +00:00
|
|
|
{
|
2022-01-26 22:25:53 +00:00
|
|
|
mapnik::Map m0(100, 100);
|
|
|
|
mapnik::Map m2(200, 100);
|
|
|
|
std::string shape_plugin("./plugins/input/shape.input");
|
|
|
|
if (mapnik::util::exists(shape_plugin))
|
|
|
|
{
|
|
|
|
mapnik::parameters p;
|
|
|
|
p["type"] = "shape";
|
|
|
|
p["file"] = "demo/data/boundaries";
|
|
|
|
p["encoding"] = "latin1";
|
|
|
|
auto ds0 = mapnik::datasource_cache::instance().create(p);
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
auto ds1 = ds0; // shared ptr copy
|
|
|
|
REQUIRE((ds1 == ds0));
|
|
|
|
REQUIRE(!(*ds1 != *ds0));
|
|
|
|
REQUIRE((ds1.get() == ds0.get()));
|
|
|
|
ds1 = mapnik::datasource_cache::instance().create(p); // new with the same parameters
|
|
|
|
REQUIRE((ds1 != ds0));
|
|
|
|
REQUIRE((*ds1 == *ds0));
|
|
|
|
auto ds2 = std::move(ds1);
|
|
|
|
REQUIRE((ds2 != ds0));
|
|
|
|
REQUIRE((*ds2 == *ds0));
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
// mapnik::layer
|
|
|
|
mapnik::layer l0("test-layer");
|
|
|
|
l0.set_datasource(ds0);
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
mapnik::layer l1 = l0; // copy assignment
|
|
|
|
REQUIRE((l1 == l0));
|
|
|
|
mapnik::layer l2(l0); // copy ctor
|
|
|
|
REQUIRE((l2 == l0));
|
|
|
|
mapnik::layer l3(mapnik::layer("test-layer")); // move ctor
|
|
|
|
l3.set_datasource(ds2);
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE((l3 == l0));
|
|
|
|
mapnik::layer l4 = std::move(l3);
|
|
|
|
REQUIRE((l4 == l0)); // move assignment
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
m0.add_layer(l4);
|
|
|
|
m0.set_background(mapnik::color("skyblue"));
|
|
|
|
m2.set_background(mapnik::color("skyblue"));
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
auto m1 = m0; // copy
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE((m0 == m1));
|
|
|
|
REQUIRE((m0 != m2));
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
m2 = m1; // copy
|
|
|
|
REQUIRE((m2 == m1));
|
|
|
|
m2 = std::move(m1);
|
|
|
|
REQUIRE((m2 == m0));
|
|
|
|
REQUIRE((m1 != m0));
|
2015-07-01 00:04:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE((m0 == m2));
|
|
|
|
}
|
|
|
|
} catch (std::exception const& ex)
|
|
|
|
{
|
|
|
|
std::clog << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
2015-07-01 00:04:48 +00:00
|
|
|
}
|
2015-04-24 12:40:22 +00:00
|
|
|
}
|
2017-05-05 11:02:01 +00:00
|
|
|
}
|