From 287ece64bf9a8ee0c42f77cefce559054b488ae7 Mon Sep 17 00:00:00 2001 From: George Liu Date: Thu, 30 Sep 2021 20:24:46 +0800 Subject: Remove NTPServers duplicate values and null values When saving the set NTPServers values from webUI, NTPServer may contain duplicate values and null values and update them to D-Bus. Now, need to parse and verify the value of the ntpServers attribute,and remove duplicate values and null values. Tested:save NTP and check it via D-Bus without this patch: NTPServers property as 3 "" "10.164.29.2" "10.164.29.2" with this patch: NTPServers property as 2 "" "10.164.29.2" Signed-off-by: George Liu Change-Id: I52291e4608efd635b179f3934c3d3e805afd2209 --- redfish-core/ut/stl_utils_test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 redfish-core/ut/stl_utils_test.cpp (limited to 'redfish-core/ut') diff --git a/redfish-core/ut/stl_utils_test.cpp b/redfish-core/ut/stl_utils_test.cpp new file mode 100644 index 0000000000..a5115bd910 --- /dev/null +++ b/redfish-core/ut/stl_utils_test.cpp @@ -0,0 +1,21 @@ +#include "utils/stl_utils.hpp" + +#include + +TEST(STLUtilesTest, RemoveDuplicates) +{ + std::vector strVec = {"s1", "s4", "s1", "s2", "", "s3", "s3"}; + + auto iter = + redfish::stl_utils::firstDuplicate(strVec.begin(), strVec.end()); + EXPECT_EQ(*iter, "s3"); + + redfish::stl_utils::removeDuplicate(strVec); + + EXPECT_EQ(strVec.size(), 5); + EXPECT_EQ(strVec[0], "s1"); + EXPECT_EQ(strVec[1], "s4"); + EXPECT_EQ(strVec[2], "s2"); + EXPECT_EQ(strVec[3], ""); + EXPECT_EQ(strVec[4], "s3"); +} -- cgit v1.2.3