Skip to content

Commit

Permalink
Refactor test in preparation for adding another.
Browse files Browse the repository at this point in the history
  • Loading branch information
zerebubuth committed Jul 19, 2016
1 parent 20bdb68 commit cdba3ff
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions test/test_parse_id_list.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cgimap/api06/handler_utils.hpp"
#include <boost/foreach.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include <map>

Expand Down Expand Up @@ -40,26 +41,47 @@ struct test_request : public request {
std::map<std::string, std::string> m_params;
};

} // anonymous namespace

int main(int argc, char *argv[]) {
std::string query_str = "nodes=1,1,1,1";
std::vector<osm_nwr_id_t> 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<osm_nwr_id_t> ids = api06::parse_id_list_params(req, "nodes");
std::vector<osm_nwr_id_t> 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;
Expand Down

0 comments on commit cdba3ff

Please sign in to comment.