Update get_routes to use trie for efficiency
This commit updates the behavior of request_routes to actually use the
trie data structure to find the appropriate routes. This function was
originaly intended for debugging, but now with redfish, it is being
used to look up routes.
Also, update the prototype so it returns a string pointer to the main
route in the trie instead of copying the whole list of stings.
A future optimization should also give the ability to pick a "stop at"
character, or a depth so that users can decide how deep into the tree
they want to iterate, instead of getting the whole subtree and
filtering after the fact.
Change-Id: I8b98fb3f19f59a043ae6aa583ed62ab89be10eb8
diff --git a/src/crow_getroutes_test.cpp b/src/crow_getroutes_test.cpp
index 6a9f538..d89c7c1 100644
--- a/src/crow_getroutes_test.cpp
+++ b/src/crow_getroutes_test.cpp
@@ -18,7 +18,8 @@
decltype(app)::server_t server(&app, "127.0.0.1", 45451);
CROW_ROUTE(app, "/")([]() { return 200; });
- EXPECT_THAT(app.get_routes(), testing::ElementsAre("/"));
+ EXPECT_THAT(app.get_routes(),
+ testing::ElementsAre(testing::Pointee(std::string("/"))));
}
// Tests that static urls are correctly passed
@@ -32,7 +33,11 @@
CROW_ROUTE(app, "/boo")([]() { return 200; });
CROW_ROUTE(app, "/moo")([]() { return 200; });
- EXPECT_THAT(app.get_routes(),
- testing::UnorderedElementsAre("/", "/foo", "/bar", "/baz", "/boo",
- "/moo"));
+ EXPECT_THAT(app.get_routes(), testing::UnorderedElementsAre(
+ testing::Pointee(std::string("/")),
+ testing::Pointee(std::string("/foo")),
+ testing::Pointee(std::string("/bar")),
+ testing::Pointee(std::string("/baz")),
+ testing::Pointee(std::string("/boo")),
+ testing::Pointee(std::string("/moo"))));
}
\ No newline at end of file