accountUnlockTimeout: add unit test

This commit added several unit tests for the |accountUnlockTimeout|
function.

Tested: unit test passed

Coverage:
  lines......: 80.7% (1874 of 2323 lines)
  functions..: 93.7% (387 of 413 functions)
  branches...: 32.2% (2930 of 9096 branches)

Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I1dfb134d54f4086920f41c9020104e64af71f1f9
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 239dbeb..693f18c 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -209,7 +209,7 @@
 # See the pam_unix manpage for other options.
 
 # here are the per-package modules (the "Primary" block)
-password	[success=ok default=die]	pam_tally2.so debug enforce_for_root reject_username minlen=8 difok=0 lcredit=0 ocredit=0 dcredit=0 ucredit=0 deny=2 #some comments
+password	[success=ok default=die]	pam_tally2.so debug enforce_for_root reject_username minlen=8 difok=0 lcredit=0 ocredit=0 dcredit=0 ucredit=0 deny=2 unlock_time=3 #some comments
 password	[success=ok default=die]	pam_cracklib.so debug enforce_for_root reject_username minlen=8 difok=0 lcredit=0 ocredit=0 dcredit=0 ucredit=0 #some comments
 password	[success=ok default=die]	pam_ipmicheck.so spec_grp_name=ipmi use_authtok
 password	[success=ok ignore=ignore default=die]	pam_pwhistory.so debug enforce_for_root remember=0 use_authtok
@@ -645,5 +645,31 @@
     EXPECT_EQ(AccountPolicyIface::rememberOldPasswordTimes(), 0);
 }
 
+TEST_F(UserMgrInTest, AccountUnlockTimeoutReturnsIfValueIsTheSame)
+{
+    initializeAccountPolicy();
+    EXPECT_EQ(AccountPolicyIface::accountUnlockTimeout(), 3);
+    UserMgr::accountUnlockTimeout(3);
+    EXPECT_EQ(AccountPolicyIface::accountUnlockTimeout(), 3);
+}
+
+TEST_F(UserMgrInTest, AccountUnlockTimeoutOnSuccess)
+{
+    initializeAccountPolicy();
+    EXPECT_EQ(AccountPolicyIface::accountUnlockTimeout(), 3);
+    UserMgr::accountUnlockTimeout(16);
+    EXPECT_EQ(AccountPolicyIface::accountUnlockTimeout(), 16);
+}
+
+TEST_F(UserMgrInTest, AccountUnlockTimeoutOnFailure)
+{
+    initializeAccountPolicy();
+    EXPECT_NO_THROW(dumpStringToFile("whatever", tempPamConfigFile));
+    EXPECT_THROW(
+        UserMgr::accountUnlockTimeout(16),
+        sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure);
+    EXPECT_EQ(AccountPolicyIface::accountUnlockTimeout(), 3);
+}
+
 } // namespace user
 } // namespace phosphor