diff --git a/test/test_parse_id_list.cpp b/test/test_parse_id_list.cpp index ee656ceeb..a3acc7fca 100644 --- a/test/test_parse_id_list.cpp +++ b/test/test_parse_id_list.cpp @@ -1,6 +1,7 @@ #include "cgimap/api06/handler_utils.hpp" #include #include +#include #include #include @@ -40,26 +41,47 @@ struct test_request : public request { std::map m_params; }; -} // anonymous namespace - -int main(int argc, char *argv[]) { - std::string query_str = "nodes=1,1,1,1"; +std::vector parse_query_str(std::string query_str) { test_request req; req.set_header("REQUEST_METHOD", "GET"); req.set_header("QUERY_STRING", query_str); req.set_header("PATH_INFO", "/api/0.6/nodes"); + return api06::parse_id_list_params(req, "nodes"); +} + +void test_parse_returns_no_duplicates() { + std::string query_str = "nodes=1,1,1,1"; + // the container returned from parse_id_list_params should not contain // any duplicates. - std::vector ids = api06::parse_id_list_params(req, "nodes"); + std::vector ids = parse_query_str(query_str); + if (ids.size() != 1) { - std::cerr << "Parsing " << query_str << " as a list of nodes should " - << "discard duplicates, but got: {"; + std::ostringstream err; + err << "Parsing " << query_str << " as a list of nodes should " + << "discard duplicates, but got: {"; BOOST_FOREACH(osm_nwr_id_t id, ids) { - std::cerr << id << ", "; + err << id << ", "; } - std::cerr << "}\n"; + err << "}\n"; + throw std::runtime_error(err.str()); + } +} + +} // anonymous namespace + +int main(int argc, char *argv[]) { + try { + test_parse_returns_no_duplicates(); + + } catch (const std::exception &e) { + std::cout << "Error: " << e.what() << std::endl; return 1; + + } catch (...) { + std::cout << "Unknown exception type." << std::endl; + return 99; } return 0;