2012-03-24 03:04:42 +00:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
|
|
#include <iostream>
|
2013-01-13 05:00:45 +00:00
|
|
|
#include <mapnik/value_types.hpp>
|
2012-03-24 03:04:42 +00:00
|
|
|
#include <mapnik/params.hpp>
|
|
|
|
#include <mapnik/boolean.hpp>
|
2013-05-25 00:21:55 +00:00
|
|
|
#include <vector>
|
2013-05-25 23:04:40 +00:00
|
|
|
#include <algorithm>
|
2013-01-13 05:00:45 +00:00
|
|
|
|
2015-01-23 02:25:37 +00:00
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
class string_holder {
|
|
|
|
public:
|
|
|
|
string_holder() :
|
|
|
|
member_("member") {}
|
|
|
|
std::string const& get_string() const
|
|
|
|
{
|
|
|
|
return member_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::string member_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-25 00:21:55 +00:00
|
|
|
int main(int argc, char** argv)
|
2012-03-24 03:04:42 +00:00
|
|
|
{
|
2013-05-25 00:21:55 +00:00
|
|
|
std::vector<std::string> args;
|
|
|
|
for (int i=1;i<argc;++i)
|
|
|
|
{
|
|
|
|
args.push_back(argv[i]);
|
|
|
|
}
|
|
|
|
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
// true
|
|
|
|
params["bool"] = mapnik::value_integer(true);
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "true";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = mapnik::value_integer(1);
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "1";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "True";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "on";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "yes";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
// false
|
|
|
|
params["bool"] = mapnik::value_integer(false);
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false) );
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "false";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false) );
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = mapnik::value_integer(0);
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "0";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "False";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "off";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 03:04:42 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
params["bool"] = "no";
|
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-04-06 21:20:04 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
// strings
|
|
|
|
params["string"] = "hello";
|
|
|
|
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
|
2012-04-06 21:20:04 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
// int
|
|
|
|
params["int"] = mapnik::value_integer(1);
|
|
|
|
BOOST_TEST( (params.get<mapnik::value_integer>("int") && *params.get<mapnik::value_integer>("int") == 1) );
|
2012-04-06 21:20:04 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
// double
|
|
|
|
params["double"] = 1.5;
|
|
|
|
BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) );
|
2012-04-06 21:20:04 +00:00
|
|
|
|
2014-10-21 02:55:11 +00:00
|
|
|
// value_null
|
|
|
|
params["null"] = mapnik::value_null();
|
|
|
|
// https://github.com/mapnik/mapnik/issues/2471
|
|
|
|
//BOOST_TEST( (params.get<mapnik::value_null>("null") && *params.get<mapnik::value_null>("null") == mapnik::value_null()) );
|
2015-01-23 02:25:37 +00:00
|
|
|
|
2015-01-28 11:54:33 +00:00
|
|
|
std::string value("value");
|
|
|
|
params["value"] = value;
|
|
|
|
BOOST_TEST(params.get<std::string>("value") == std::string("value"));
|
|
|
|
BOOST_TEST(value == std::string("value"));
|
2015-01-23 02:25:37 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
BOOST_TEST(params.get<std::string>("member") == std::string("member"));
|
|
|
|
BOOST_TEST(holder_member == std::string("member"));
|
2014-10-21 02:55:11 +00:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
|
|
|
{
|
|
|
|
std::cerr << ex.what() << "\n";
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2012-04-17 05:33:37 +00:00
|
|
|
|
|
|
|
if (!::boost::detail::test_errors()) {
|
2013-05-25 00:21:55 +00:00
|
|
|
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
|
|
|
|
else std::clog << "C++ parameters: \x1b[1;32m✓ \x1b[0m\n";
|
2012-05-15 18:45:55 +00:00
|
|
|
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
2012-04-17 05:33:37 +00:00
|
|
|
} else {
|
|
|
|
return ::boost::report_errors();
|
|
|
|
}
|
2012-03-24 03:04:42 +00:00
|
|
|
}
|