#include "catch.hpp" #include #include #include #include #include #include #include namespace detail { class string_holder { public: string_holder() : member_("member") {} std::string const& get_string() const { return member_; } private: std::string member_; }; } TEST_CASE("parameters") { SECTION("get/set") { try { mapnik::parameters params; // true params["bool"] = mapnik::value_integer(true); REQUIRE( (params.get("bool") && *params.get("bool") == true)); params["bool"] = "true"; REQUIRE( (params.get("bool") && *params.get("bool") == true)); params["bool"] = mapnik::value_integer(1); REQUIRE( (params.get("bool") && *params.get("bool") == true)); params["bool"] = "1"; REQUIRE( (params.get("bool") && *params.get("bool") == true)); params["bool"] = "True"; REQUIRE( (params.get("bool") && *params.get("bool") == true)); params["bool"] = "on"; REQUIRE( (params.get("bool") && *params.get("bool") == true)); params["bool"] = "yes"; REQUIRE( (params.get("bool") && *params.get("bool") == true)); // false params["bool"] = mapnik::value_integer(false); REQUIRE( (params.get("bool") && *params.get("bool") == false) ); params["bool"] = "false"; REQUIRE( (params.get("bool") && *params.get("bool") == false) ); params["bool"] = mapnik::value_integer(0); REQUIRE( (params.get("bool") && *params.get("bool") == false)); params["bool"] = "0"; REQUIRE( (params.get("bool") && *params.get("bool") == false)); params["bool"] = "False"; REQUIRE( (params.get("bool") && *params.get("bool") == false)); params["bool"] = "off"; REQUIRE( (params.get("bool") && *params.get("bool") == false)); params["bool"] = "no"; REQUIRE( (params.get("bool") && *params.get("bool") == false)); // strings params["string"] = "hello"; REQUIRE( (params.get("string") && *params.get("string") == "hello") ); // int params["int"] = mapnik::value_integer(1); REQUIRE( (params.get("int") && *params.get("int") == 1) ); // double params["double"] = 1.5; REQUIRE( (params.get("double") && *params.get("double") == 1.5) ); // value_null params["null"] = mapnik::value_null(); // https://github.com/mapnik/mapnik/issues/2471 //REQUIRE( (params.get("null") && *params.get("null") == mapnik::value_null()) ); std::string value("value"); params["value"] = value; REQUIRE( (params.get("value") == std::string("value")) ) ; REQUIRE(value == std::string("value")); // ensure that const member is not moved incorrectly when added to params detail::string_holder holder; std::string const& holder_member = holder.get_string(); params["member"] = holder_member; REQUIRE( (params.get("member") == std::string("member")) ); REQUIRE( (holder_member == std::string("member")) ); } catch (std::exception const& ex) { std::cerr << ex.what() << "\n"; REQUIRE(false); } } }