Skip to content

Commit

Permalink
[SQUASH] Fix GoogleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
VivianNK committed Oct 10, 2024
1 parent 99f669d commit dc71a28
Showing 1 changed file with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class DeviceStateBitmaskIsSetTest : public Test {
DEVICE_STATE CurrentDeviceStateMock;
DEVICE_STATE InsecureDeviceStateSettingMock;
CHAR8 Buffer[MAX_INSECURE_DEVICE_STATE_STRING_SIZE];
CHAR8 ExpectedString1[MAX_INSECURE_DEVICE_STATE_STRING_SIZE] = DEVICE_STATE_SOURCE_DEBUG_ENABLED_STRING;
CHAR8 ExpectedString2[MAX_INSECURE_DEVICE_STATE_STRING_SIZE] = "SOURCE_DEBUG_ENABLED UNIT_TEST_MODE ";
UINTN Length;
UINTN StringSize;
UINTN *StrSizePtr = &StringSize;
EFI_STATUS Status;

void
SetUp (
Expand All @@ -41,13 +41,68 @@ class DeviceStateBitmaskIsSetTest : public Test {
}
};

/**
Test GetInsecureDeviceStateString function failures
The tested function calls GetInsecureDeviceStateSetting to get the FixedAtBuild PCD
defined in MdeModulePkg.dec
**/
TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringInvalidParameter) {
CurrentDeviceStateMock |= DEVICE_STATE_SOURCE_DEBUG_ENABLED;

EXPECT_CALL (
PcdLibMock,
LibPcdGet32
)
.Times (4)
.WillRepeatedly (
Return (CurrentDeviceStateMock)
);

Status = GetInsecureDeviceStateString (NULL, MAX_INSECURE_DEVICE_STATE_STRING_SIZE, StrSizePtr);
EXPECT_EQ (Status, EFI_INVALID_PARAMETER);

Status = GetInsecureDeviceStateString (Buffer, 0, StrSizePtr);
EXPECT_EQ (Status, EFI_INVALID_PARAMETER);

Status = GetInsecureDeviceStateString (Buffer, MAX_INSECURE_DEVICE_STATE_STRING_SIZE, NULL);
EXPECT_EQ (Status, EFI_INVALID_PARAMETER);

Status = GetInsecureDeviceStateString (Buffer, 5, StrSizePtr);
EXPECT_EQ (Status, EFI_BUFFER_TOO_SMALL);
}

/**
Test GetInsecureDeviceStateString function with one insecure state
The tested function calls GetInsecureDeviceStateSetting to get the FixedAtBuild PCD
defined in MdeModulePkg.dec
**/
TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringTest1) {
TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringSuccessEmpty) {
CHAR8 ExpectedString1[MAX_INSECURE_DEVICE_STATE_STRING_SIZE] = "";

EXPECT_CALL (
PcdLibMock,
LibPcdGet32
)
.WillOnce (
Return (CurrentDeviceStateMock)
);

Status = GetInsecureDeviceStateString (Buffer, MAX_INSECURE_DEVICE_STATE_STRING_SIZE, StrSizePtr);
EXPECT_EQ (Status, EFI_SUCCESS);
EXPECT_EQ (*StrSizePtr, AsciiStrnSizeS (ExpectedString1, MAX_INSECURE_DEVICE_STATE_STRING_SIZE));
}

/**
Test GetInsecureDeviceStateString function with one insecure state
The tested function calls GetInsecureDeviceStateSetting to get the FixedAtBuild PCD
defined in MdeModulePkg.dec
**/
TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringSuccess1) {
CHAR8 ExpectedString1[MAX_INSECURE_DEVICE_STATE_STRING_SIZE] = DEVICE_STATE_SOURCE_DEBUG_ENABLED_STRING;

CurrentDeviceStateMock |= DEVICE_STATE_SOURCE_DEBUG_ENABLED;

EXPECT_CALL (
Expand All @@ -58,8 +113,9 @@ TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringTest1) {
Return (CurrentDeviceStateMock)
);

Length = GetInsecureDeviceStateString (Buffer, MAX_INSECURE_DEVICE_STATE_STRING_SIZE);
EXPECT_EQ (Length, AsciiStrnLenS (ExpectedString1, MAX_INSECURE_DEVICE_STATE_STRING_SIZE) + 1);
Status = GetInsecureDeviceStateString (Buffer, MAX_INSECURE_DEVICE_STATE_STRING_SIZE, StrSizePtr);
EXPECT_EQ (Status, EFI_SUCCESS);
EXPECT_EQ (*StrSizePtr, AsciiStrnSizeS (ExpectedString1, MAX_INSECURE_DEVICE_STATE_STRING_SIZE));
}

/**
Expand All @@ -68,7 +124,9 @@ TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringTest1) {
The tested function calls GetInsecureDeviceStateSetting to get the FixedAtBuild PCD
defined in MdeModulePkg.dec
**/
TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringTest2) {
TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringSuccess2) {
CHAR8 ExpectedString2[MAX_INSECURE_DEVICE_STATE_STRING_SIZE] = "SOURCE_DEBUG_ENABLED UNIT_TEST_MODE ";

CurrentDeviceStateMock |= DEVICE_STATE_SOURCE_DEBUG_ENABLED;
CurrentDeviceStateMock |= DEVICE_STATE_UNIT_TEST_MODE;

Expand All @@ -80,8 +138,9 @@ TEST_F (DeviceStateBitmaskIsSetTest, GetInsecureDeviceStateStringTest2) {
Return (CurrentDeviceStateMock)
);

Length = GetInsecureDeviceStateString (Buffer, MAX_INSECURE_DEVICE_STATE_STRING_SIZE);
EXPECT_EQ (Length, AsciiStrnLenS (ExpectedString2, MAX_INSECURE_DEVICE_STATE_STRING_SIZE) + 1);
Status = GetInsecureDeviceStateString (Buffer, MAX_INSECURE_DEVICE_STATE_STRING_SIZE, StrSizePtr);
EXPECT_EQ (Status, EFI_SUCCESS);
EXPECT_EQ (*StrSizePtr, AsciiStrnSizeS (ExpectedString2, MAX_INSECURE_DEVICE_STATE_STRING_SIZE));
}

int
Expand Down

0 comments on commit dc71a28

Please sign in to comment.