2012-03-24 04:04:42 +01:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
|
|
#include <iostream>
|
2013-01-13 06:00:45 +01:00
|
|
|
#include <mapnik/value_types.hpp>
|
2012-03-24 04:04:42 +01:00
|
|
|
#include <mapnik/params.hpp>
|
|
|
|
#include <mapnik/boolean.hpp>
|
2013-05-25 02:21:55 +02:00
|
|
|
#include <vector>
|
2013-05-26 01:04:40 +02:00
|
|
|
#include <algorithm>
|
2013-01-13 06:00:45 +01:00
|
|
|
#include <boost/variant.hpp>
|
|
|
|
|
2013-05-25 02:21:55 +02:00
|
|
|
int main(int argc, char** argv)
|
2012-03-24 04:04:42 +01:00
|
|
|
{
|
2013-05-25 02:21:55 +02: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 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
mapnik::parameters params;
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
// true
|
2013-10-09 16:52:53 +02:00
|
|
|
params["bool"] = mapnik::value_integer(true);
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "true";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2013-10-09 16:52:53 +02:00
|
|
|
params["bool"] = mapnik::value_integer(1);
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2013-10-09 16:52:53 +02:00
|
|
|
params["bool"] = "1";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "True";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "on";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "yes";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
// false
|
2013-10-09 16:32:47 +02:00
|
|
|
params["bool"] = mapnik::value_integer(false);
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false) );
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "false";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false) );
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2013-10-09 16:52:53 +02:00
|
|
|
params["bool"] = mapnik::value_integer(0);
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2013-10-09 16:52:53 +02:00
|
|
|
params["bool"] = "0";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "False";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "off";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-03-24 04:04:42 +01:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
params["bool"] = "no";
|
2014-07-29 04:46:49 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
2012-04-06 23:20:04 +02:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
// strings
|
|
|
|
params["string"] = "hello";
|
|
|
|
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
|
2012-04-06 23:20:04 +02:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
// int
|
2012-12-18 21:34:27 +01:00
|
|
|
params["int"] = mapnik::value_integer(1);
|
|
|
|
BOOST_TEST( (params.get<mapnik::value_integer>("int") && *params.get<mapnik::value_integer>("int") == 1) );
|
2012-04-06 23:20:04 +02:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
// double
|
|
|
|
params["double"] = 1.5;
|
|
|
|
BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) );
|
2012-04-06 23:20:04 +02:00
|
|
|
|
2012-04-17 07:33:37 +02:00
|
|
|
// value_null
|
|
|
|
params["null"] = mapnik::value_null();
|
2013-10-09 16:32:47 +02:00
|
|
|
BOOST_TEST( (params.get<mapnik::value_null>("null") && *params.get<mapnik::value_null>("null") == mapnik::value_null()) );
|
2012-04-17 07:33:37 +02:00
|
|
|
|
|
|
|
if (!::boost::detail::test_errors()) {
|
2013-05-25 02:21:55 +02:00
|
|
|
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
|
|
|
|
else std::clog << "C++ parameters: \x1b[1;32m✓ \x1b[0m\n";
|
2012-05-15 20:45:55 +02:00
|
|
|
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
2012-04-17 07:33:37 +02:00
|
|
|
} else {
|
|
|
|
return ::boost::report_errors();
|
|
|
|
}
|
2012-03-24 04:04:42 +01:00
|
|
|
}
|