libpldm: bios: implement en/decode for SetDateTime
Add encode/decode functions.
Add unit-test.
Signed-off-by: Xiaochao Ma <maxiaochao@inspur.com>
Change-Id: Ide5563ea5b6446b7300e0d1a9f2b64275217c820
diff --git a/test/libpldm_utils_test.cpp b/test/libpldm_utils_test.cpp
index b391f79..a40aec1 100644
--- a/test/libpldm_utils_test.cpp
+++ b/test/libpldm_utils_test.cpp
@@ -65,4 +65,19 @@
EXPECT_EQ(0x9999, dec2bcd16(9999));
EXPECT_EQ(0x12345678, dec2bcd32(12345678));
EXPECT_EQ(0x99999999, dec2bcd32(99999999));
+}
+
+TEST(TimeLegal, TimeLegal)
+{
+ EXPECT_EQ(true, is_time_legal(30, 25, 16, 18, 8, 2019));
+ EXPECT_EQ(true, is_time_legal(30, 25, 16, 29, 2, 2020)); // leap year
+
+ EXPECT_EQ(false, is_time_legal(30, 25, 16, 18, 8, 1960)); // year illegal
+ EXPECT_EQ(false, is_time_legal(30, 25, 16, 18, 15, 2019)); // month illegal
+ EXPECT_EQ(false, is_time_legal(30, 25, 16, 18, 0, 2019)); // month illegal
+ EXPECT_EQ(false, is_time_legal(30, 25, 16, 0, 8, 2019)); // day illegal
+ EXPECT_EQ(false, is_time_legal(30, 25, 16, 29, 2, 2019)); // day illegal
+ EXPECT_EQ(false, is_time_legal(30, 25, 25, 18, 8, 2019)); // hours illegal
+ EXPECT_EQ(false, is_time_legal(30, 70, 16, 18, 8, 2019)); // minutes illegal
+ EXPECT_EQ(false, is_time_legal(80, 25, 16, 18, 8, 2019)); // seconds illegal
}
\ No newline at end of file