getCSVFromVector: optimize and add tests
Optimization: avoid copy; simpifiled unnessary branches; reduced
temperary string being created when doing string concatenation.
Added unit test for this function.
Tested: unit test
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I8c334dc4f087e262bb3e8613e86cfc2a93d525a0
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index a7801ae..22a8837 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -1,4 +1,5 @@
#include "mock_user_mgr.hpp"
+#include "user_mgr.hpp"
#include <sdbusplus/test/sdbus_mock.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -146,5 +147,18 @@
EXPECT_EQ(true, std::get<bool>(userInfo["RemoteUser"]));
EXPECT_EQ("", std::get<std::string>(userInfo["UserPrivilege"]));
}
+
+TEST(GetCSVFromVector, EmptyVectorReturnsEmptyString)
+{
+ EXPECT_EQ(getCSVFromVector({}), "");
+}
+
+TEST(GetCSVFromVector, ElementsAreJoinedByComma)
+{
+ EXPECT_EQ(getCSVFromVector(std::vector<std::string>{"123"}), "123");
+ EXPECT_EQ(getCSVFromVector(std::vector<std::string>{"123", "456"}),
+ "123,456");
+}
+
} // namespace user
} // namespace phosphor