test treewide: apply namespace best practice

1. put sources into the namespace under test
2. put all test codes into anonymous namespace

It can be proved that this can increase readability and save duplicate
codes.

Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: If0685ca955c9ece5be5e2287ccbde1a302e4dacd
diff --git a/redfish-core/lib/ut/service_root_test.cpp b/redfish-core/lib/ut/service_root_test.cpp
index 80918d2..06a7c21 100644
--- a/redfish-core/lib/ut/service_root_test.cpp
+++ b/redfish-core/lib/ut/service_root_test.cpp
@@ -11,7 +11,12 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
-static void assertServiceRootGet(crow::Response& res)
+namespace redfish
+{
+namespace
+{
+
+void assertServiceRootGet(crow::Response& res)
 {
     nlohmann::json& json = res.jsonValue;
     EXPECT_EQ(json["@odata.id"], "/redfish/v1");
@@ -105,5 +110,8 @@
 
     shareAsyncResp->res.setCompleteRequestHandler(assertServiceRootGet);
 
-    redfish::handleServiceRootGet(shareAsyncResp);
+    handleServiceRootGet(shareAsyncResp);
 }
+
+} // namespace
+} // namespace redfish
\ No newline at end of file
diff --git a/redfish-core/ut/hex_utils_test.cpp b/redfish-core/ut/hex_utils_test.cpp
index 21387c6..05bcb9e 100644
--- a/redfish-core/ut/hex_utils_test.cpp
+++ b/redfish-core/ut/hex_utils_test.cpp
@@ -2,6 +2,9 @@
 
 #include <gmock/gmock.h>
 
+namespace
+{
+
 TEST(ToHexString, uint64)
 {
     EXPECT_EQ(intToHexString(0xFFFFFFFFFFFFFFFFULL, 16), "FFFFFFFFFFFFFFFF");
@@ -65,3 +68,5 @@
     EXPECT_TRUE(hexStringToBytes("`").empty());
     EXPECT_TRUE(hexStringToBytes("012").empty());
 }
+
+} // namespace
\ No newline at end of file
diff --git a/redfish-core/ut/ip_utils_test.cpp b/redfish-core/ut/ip_utils_test.cpp
index 455433b..c27ec99 100644
--- a/redfish-core/ut/ip_utils_test.cpp
+++ b/redfish-core/ut/ip_utils_test.cpp
@@ -2,8 +2,12 @@
 
 #include "gtest/gtest.h"
 
-using boost::asio::ip::make_address;
-using redfish::ip_util::toString;
+namespace redfish::ip_util
+{
+namespace
+{
+
+using ::boost::asio::ip::make_address;
 
 TEST(IpToString, v4mapped)
 {
@@ -18,3 +22,5 @@
               "fd03:f9ab:25de:89ec:1234:5678:90ab:cdef");
     EXPECT_EQ(toString(make_address("::ffff:127.0.0.1")), "127.0.0.1");
 }
+} // namespace
+} // namespace redfish::ip_util
\ No newline at end of file
diff --git a/redfish-core/ut/json_utils_test.cpp b/redfish-core/ut/json_utils_test.cpp
index ed8a79a..cd5504c 100644
--- a/redfish-core/ut/json_utils_test.cpp
+++ b/redfish-core/ut/json_utils_test.cpp
@@ -5,9 +5,10 @@
 
 #include <gmock/gmock.h>
 
-using redfish::json_util::readJson;
-using redfish::json_util::readJsonAction;
-using redfish::json_util::readJsonPatch;
+namespace redfish::json_util
+{
+namespace
+{
 
 TEST(readJson, ValidElements)
 {
@@ -327,3 +328,6 @@
     EXPECT_EQ(res.result(), boost::beast::http::status::ok);
     EXPECT_TRUE(res.jsonValue.empty());
 }
+
+} // namespace
+} // namespace redfish::json_util
\ No newline at end of file
diff --git a/redfish-core/ut/lock_test.cpp b/redfish-core/ut/lock_test.cpp
index 7ee2b71..10c51d3 100644
--- a/redfish-core/ut/lock_test.cpp
+++ b/redfish-core/ut/lock_test.cpp
@@ -4,10 +4,11 @@
 
 #include "gmock/gmock.h"
 
-namespace crow
+namespace crow::ibm_mc_lock
 {
-namespace ibm_mc_lock
+namespace
 {
+
 using SType = std::string;
 using LockRequest = std::tuple<SType, SType, SType, uint64_t, SegmentFlags>;
 using LockRequests = std::vector<LockRequest>;
@@ -354,5 +355,5 @@
     ASSERT_EQ(1, result.size());
 }
 
-} // namespace ibm_mc_lock
-} // namespace crow
+} // namespace
+} // namespace crow::ibm_mc_lock
diff --git a/redfish-core/ut/privileges_test.cpp b/redfish-core/ut/privileges_test.cpp
index 1613fbb..3813b54 100644
--- a/redfish-core/ut/privileges_test.cpp
+++ b/redfish-core/ut/privileges_test.cpp
@@ -6,7 +6,10 @@
 
 #include "gmock/gmock.h"
 
-using namespace redfish;
+namespace redfish
+{
+namespace
+{
 
 TEST(PrivilegeTest, PrivilegeConstructor)
 {
@@ -121,3 +124,5 @@
                     expectedPrivileges[2], expectedPrivileges[3],
                     expectedPrivileges[4]));
 }
+} // namespace
+} // namespace redfish
\ No newline at end of file
diff --git a/redfish-core/ut/registries_test.cpp b/redfish-core/ut/registries_test.cpp
index b75883c..c324fee 100644
--- a/redfish-core/ut/registries_test.cpp
+++ b/redfish-core/ut/registries_test.cpp
@@ -2,9 +2,13 @@
 
 #include "gmock/gmock.h"
 
+namespace redfish::registries
+{
+namespace
+{
+
 TEST(RedfishRegistries, fillMessageArgs)
 {
-    using redfish::registries::fillMessageArgs;
     std::string toFill("%1");
     fillMessageArgs({{"foo"}}, toFill);
     EXPECT_EQ(toFill, "foo");
@@ -17,3 +21,5 @@
     fillMessageArgs({{"foo", "bar"}}, toFill);
     EXPECT_EQ(toFill, "foo, bar");
 }
+} // namespace
+} // namespace redfish::registries
\ No newline at end of file
diff --git a/redfish-core/ut/stl_utils_test.cpp b/redfish-core/ut/stl_utils_test.cpp
index a5115bd..02a9c15 100644
--- a/redfish-core/ut/stl_utils_test.cpp
+++ b/redfish-core/ut/stl_utils_test.cpp
@@ -1,16 +1,21 @@
 #include "utils/stl_utils.hpp"
 
-#include <gmock/gmock.h>
+#include <string>
 
+#include <gtest/gtest.h>
+
+namespace redfish::stl_utils
+{
+namespace
+{
 TEST(STLUtilesTest, RemoveDuplicates)
 {
     std::vector<std::string> strVec = {"s1", "s4", "s1", "s2", "", "s3", "s3"};
 
-    auto iter =
-        redfish::stl_utils::firstDuplicate(strVec.begin(), strVec.end());
+    auto iter = firstDuplicate(strVec.begin(), strVec.end());
     EXPECT_EQ(*iter, "s3");
 
-    redfish::stl_utils::removeDuplicate(strVec);
+    removeDuplicate(strVec);
 
     EXPECT_EQ(strVec.size(), 5);
     EXPECT_EQ(strVec[0], "s1");
@@ -19,3 +24,5 @@
     EXPECT_EQ(strVec[3], "");
     EXPECT_EQ(strVec[4], "s3");
 }
+} // namespace
+} // namespace redfish::stl_utils
diff --git a/redfish-core/ut/time_utils_test.cpp b/redfish-core/ut/time_utils_test.cpp
index 0a88e65..ee2e037 100644
--- a/redfish-core/ut/time_utils_test.cpp
+++ b/redfish-core/ut/time_utils_test.cpp
@@ -2,24 +2,29 @@
 
 #include <gmock/gmock.h>
 
+namespace redfish::time_utils
+{
+namespace
+{
+
 TEST(FromDurationTest, PositiveTests)
 {
-    using redfish::time_utils::fromDurationString;
-    using std::chrono::milliseconds;
-    EXPECT_EQ(fromDurationString("PT12S"), milliseconds(12000));
-    EXPECT_EQ(fromDurationString("PT0.204S"), milliseconds(204));
-    EXPECT_EQ(fromDurationString("PT0.2S"), milliseconds(200));
-    EXPECT_EQ(fromDurationString("PT50M"), milliseconds(3000000));
-    EXPECT_EQ(fromDurationString("PT23H"), milliseconds(82800000));
-    EXPECT_EQ(fromDurationString("P51D"), milliseconds(4406400000));
-    EXPECT_EQ(fromDurationString("PT2H40M10.1S"), milliseconds(9610100));
-    EXPECT_EQ(fromDurationString("P20DT2H40M10.1S"), milliseconds(1737610100));
-    EXPECT_EQ(fromDurationString(""), milliseconds(0));
+    EXPECT_EQ(fromDurationString("PT12S"), std::chrono::milliseconds(12000));
+    EXPECT_EQ(fromDurationString("PT0.204S"), std::chrono::milliseconds(204));
+    EXPECT_EQ(fromDurationString("PT0.2S"), std::chrono::milliseconds(200));
+    EXPECT_EQ(fromDurationString("PT50M"), std::chrono::milliseconds(3000000));
+    EXPECT_EQ(fromDurationString("PT23H"), std::chrono::milliseconds(82800000));
+    EXPECT_EQ(fromDurationString("P51D"),
+              std::chrono::milliseconds(4406400000));
+    EXPECT_EQ(fromDurationString("PT2H40M10.1S"),
+              std::chrono::milliseconds(9610100));
+    EXPECT_EQ(fromDurationString("P20DT2H40M10.1S"),
+              std::chrono::milliseconds(1737610100));
+    EXPECT_EQ(fromDurationString(""), std::chrono::milliseconds(0));
 }
 
 TEST(FromDurationTest, NegativeTests)
 {
-    using redfish::time_utils::fromDurationString;
     EXPECT_EQ(fromDurationString("PTS"), std::nullopt);
     EXPECT_EQ(fromDurationString("P1T"), std::nullopt);
     EXPECT_EQ(fromDurationString("PT100M1000S100"), std::nullopt);
@@ -32,28 +37,25 @@
 }
 TEST(ToDurationTest, PositiveTests)
 {
-    using redfish::time_utils::toDurationString;
-    using std::chrono::milliseconds;
-    EXPECT_EQ(toDurationString(milliseconds(12000)), "PT12.000S");
-    EXPECT_EQ(toDurationString(milliseconds(204)), "PT0.204S");
-    EXPECT_EQ(toDurationString(milliseconds(200)), "PT0.200S");
-    EXPECT_EQ(toDurationString(milliseconds(3000000)), "PT50M");
-    EXPECT_EQ(toDurationString(milliseconds(82800000)), "PT23H");
-    EXPECT_EQ(toDurationString(milliseconds(4406400000)), "P51DT");
-    EXPECT_EQ(toDurationString(milliseconds(9610100)), "PT2H40M10.100S");
-    EXPECT_EQ(toDurationString(milliseconds(1737610100)), "P20DT2H40M10.100S");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(12000)), "PT12.000S");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(204)), "PT0.204S");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(200)), "PT0.200S");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(3000000)), "PT50M");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(82800000)), "PT23H");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(4406400000)), "P51DT");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(9610100)),
+              "PT2H40M10.100S");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(1737610100)),
+              "P20DT2H40M10.100S");
 }
 
 TEST(ToDurationTest, NegativeTests)
 {
-    using redfish::time_utils::toDurationString;
-    using std::chrono::milliseconds;
-    EXPECT_EQ(toDurationString(milliseconds(-250)), "");
+    EXPECT_EQ(toDurationString(std::chrono::milliseconds(-250)), "");
 }
 
 TEST(ToDurationStringFromUintTest, PositiveTests)
 {
-    using redfish::time_utils::toDurationStringFromUint;
     uint64_t maxAcceptedTimeMs =
         static_cast<uint64_t>(std::chrono::milliseconds::max().count());
 
@@ -66,7 +68,6 @@
 
 TEST(ToDurationStringFromUintTest, NegativeTests)
 {
-    using redfish::time_utils::toDurationStringFromUint;
     uint64_t minNotAcceptedTimeMs =
         static_cast<uint64_t>(std::chrono::milliseconds::max().count()) + 1;
 
@@ -74,3 +75,6 @@
     EXPECT_EQ(toDurationStringFromUint(static_cast<uint64_t>(-1)),
               std::nullopt);
 }
+
+} // namespace
+} // namespace redfish::time_utils