test: Add tests for verifyOffset
Added unit tests for verifyOffset in fruUtil.
Signed-off-by: Vijay Khemka <vijaykhemkalinux@gmail.com>
Change-Id: I799acaef087676b3d50aa93c076a698226aaff61
diff --git a/test/test_fru-utils.cpp b/test/test_fru-utils.cpp
index 4f4f57a..028a0d6 100644
--- a/test/test_fru-utils.cpp
+++ b/test/test_fru-utils.cpp
@@ -18,3 +18,49 @@
EXPECT_FALSE(validateHeader(fru_header));
}
+
+TEST(VerifyOffsetTest, EmptyFruDataReturnsFalse)
+{
+ // Validates the FruData size is checked for non empty.
+ std::vector<uint8_t> fru_data = {};
+
+ EXPECT_FALSE(verifyOffset(fru_data, fruAreas::fruAreaChassis, 0));
+}
+
+TEST(VerifyOffsetTest, AreaOutOfRangeReturnsFalse)
+{
+ // Validates the FruArea value, check if it is within range.
+ const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
+
+ unsigned int areaOutOfRange = 8;
+ EXPECT_FALSE(
+ verifyOffset(fru_data, static_cast<fruAreas>(areaOutOfRange), 0));
+}
+
+TEST(VerifyOffsetTest, OverlapNextAreaReturnsFalse)
+{
+ // Validates the Overlap of offsets with overlapped values.
+ const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x00, 0x00, 0x00};
+
+ EXPECT_FALSE(verifyOffset(fru_data, fruAreas::fruAreaChassis, 2));
+}
+
+TEST(VerifyOffsetTest, OverlapPrevAreaReturnsFalse)
+{
+ // Validates the Overlap of offsets with overlapped values.
+ const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x01, 0x03, 0x02,
+ 0x07, 0x00, 0x00, 0x00};
+
+ EXPECT_FALSE(verifyOffset(fru_data, fruAreas::fruAreaProduct, 2));
+}
+
+TEST(VerifyOffsetTest, ValidInputDataNoOverlapReturnsTrue)
+{
+ // Validates all inputs with expected value and no overlap.
+ const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x00, 0x00, 0x00};
+
+ EXPECT_TRUE(verifyOffset(fru_data, fruAreas::fruAreaChassis, 1));
+}