query_param_test: fix namespaces
Put all test cases into the anonymous namespace. It's shown that a lot
of codes (namespaces) are not needed anymore
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: Ib9866272d2d05103b2b792b361cb4c20fee67004
diff --git a/redfish-core/include/utils/query_param_test.cpp b/redfish-core/include/utils/query_param_test.cpp
index 626d573..05abcfd 100644
--- a/redfish-core/include/utils/query_param_test.cpp
+++ b/redfish-core/include/utils/query_param_test.cpp
@@ -5,7 +5,6 @@
#include <nlohmann/json.hpp>
#include <cstddef>
-#include <iostream>
#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
@@ -15,6 +14,8 @@
namespace
{
+using ::testing::UnorderedElementsAre;
+
TEST(Delegate, OnlyPositive)
{
Query query{
@@ -149,18 +150,12 @@
"?$expand=.($levels=1)");
}
-} // namespace
-} // namespace redfish::query_param
-
TEST(QueryParams, ParseParametersOnly)
{
auto ret = boost::urls::parse_relative_ref("/redfish/v1?only");
ASSERT_TRUE(ret);
crow::Response res;
-
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query != std::nullopt);
EXPECT_TRUE(query->isOnly);
@@ -173,8 +168,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
if constexpr (bmcwebInsecureEnableQueryParams)
{
@@ -195,8 +188,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query != std::nullopt);
EXPECT_EQ(query->top, 1);
@@ -209,8 +200,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query == std::nullopt);
}
@@ -222,8 +211,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query == std::nullopt);
}
@@ -235,8 +222,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query != std::nullopt);
EXPECT_EQ(query->skip, 1);
@@ -249,8 +234,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_EQ(query, std::nullopt);
}
@@ -262,8 +245,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query != std::nullopt);
}
@@ -275,8 +256,6 @@
crow::Response res;
- using redfish::query_param::parseParameters;
- using redfish::query_param::Query;
std::optional<Query> query = parseParameters(ret->params(), res);
ASSERT_TRUE(query == std::nullopt);
EXPECT_EQ(res.result(), boost::beast::http::status::not_implemented);
@@ -284,7 +263,7 @@
TEST(QueryParams, GetExpandType)
{
- redfish::query_param::Query query{};
+ Query query{};
EXPECT_FALSE(getExpandType("", query));
EXPECT_FALSE(getExpandType(".(", query));
@@ -292,11 +271,11 @@
EXPECT_FALSE(getExpandType(".($levels=1", query));
EXPECT_TRUE(getExpandType("*", query));
- EXPECT_EQ(query.expandType, redfish::query_param::ExpandType::Both);
+ EXPECT_EQ(query.expandType, ExpandType::Both);
EXPECT_TRUE(getExpandType(".", query));
- EXPECT_EQ(query.expandType, redfish::query_param::ExpandType::NotLinks);
+ EXPECT_EQ(query.expandType, ExpandType::NotLinks);
EXPECT_TRUE(getExpandType("~", query));
- EXPECT_EQ(query.expandType, redfish::query_param::ExpandType::Links);
+ EXPECT_EQ(query.expandType, ExpandType::Links);
// Per redfish specification, level defaults to 1
EXPECT_TRUE(getExpandType(".", query));
@@ -315,32 +294,21 @@
EXPECT_FALSE(getExpandType(".($levels=a)", query));
}
-namespace redfish::query_param
-{
-// NOLINTNEXTLINE(readability-identifier-naming)
-static void PrintTo(const ExpandNode& value, ::std::ostream* os)
-{
- *os << "ExpandNode: " << value.location << " " << value.uri;
-}
-}; // namespace redfish::query_param
-
TEST(QueryParams, FindNavigationReferencesNonLink)
{
using nlohmann::json;
- using redfish::query_param::ExpandType;
- using redfish::query_param::findNavigationReferences;
- using ::testing::UnorderedElementsAre;
+
json singleTreeNode = R"({"Foo" : {"@odata.id": "/foobar"}})"_json;
// Parsing as the root should net one entry
EXPECT_THAT(findNavigationReferences(ExpandType::Both, singleTreeNode),
- UnorderedElementsAre(redfish::query_param::ExpandNode{
- json::json_pointer("/Foo"), "/foobar"}));
+ UnorderedElementsAre(
+ ExpandNode{json::json_pointer("/Foo"), "/foobar"}));
// Parsing in Non-hyperlinks mode should net one entry
EXPECT_THAT(findNavigationReferences(ExpandType::NotLinks, singleTreeNode),
- UnorderedElementsAre(redfish::query_param::ExpandNode{
- json::json_pointer("/Foo"), "/foobar"}));
+ UnorderedElementsAre(
+ ExpandNode{json::json_pointer("/Foo"), "/foobar"}));
// Searching for not types should return empty set
EXPECT_TRUE(
@@ -354,26 +322,24 @@
R"({"Links": {"@odata.id": "/links"}, "Foo" : {"@odata.id": "/foobar"}})"_json;
// Should still find Foo
EXPECT_THAT(findNavigationReferences(ExpandType::NotLinks, multiTreeNodes),
- UnorderedElementsAre(redfish::query_param::ExpandNode{
- json::json_pointer("/Foo"), "/foobar"}));
+ UnorderedElementsAre(
+ ExpandNode{json::json_pointer("/Foo"), "/foobar"}));
}
TEST(QueryParams, FindNavigationReferencesLink)
{
using nlohmann::json;
- using redfish::query_param::ExpandType;
- using redfish::query_param::findNavigationReferences;
- using ::testing::UnorderedElementsAre;
+
json singleLinkNode =
R"({"Links" : {"Sessions": {"@odata.id": "/foobar"}}})"_json;
// Parsing as the root should net one entry
EXPECT_THAT(findNavigationReferences(ExpandType::Both, singleLinkNode),
- UnorderedElementsAre(redfish::query_param::ExpandNode{
+ UnorderedElementsAre(ExpandNode{
json::json_pointer("/Links/Sessions"), "/foobar"}));
// Parsing in hyperlinks mode should net one entry
EXPECT_THAT(findNavigationReferences(ExpandType::Links, singleLinkNode),
- UnorderedElementsAre(redfish::query_param::ExpandNode{
+ UnorderedElementsAre(ExpandNode{
json::json_pointer("/Links/Sessions"), "/foobar"}));
// Searching for not types should return empty set
@@ -384,3 +350,6 @@
EXPECT_TRUE(
findNavigationReferences(ExpandType::NotLinks, singleLinkNode).empty());
}
+
+} // namespace
+} // namespace redfish::query_param
\ No newline at end of file