-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MdePkg/GoogleTest: Add HASH2 Protocol mock interface (#630)
# Preface ## Description Adds the HASH2 Protocol to the Mock library implementation For each item, place an "x" in between `[` and `]` if true. Example: `[x]`. _(you can also check items in the GitHub UI)_ - [ ] Impacts functionality? - Adds Hash2 to the Mock library for Unit Testing - [ ] Impacts security? - [ ] Breaking change? - no - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested Currently private unit tests that depend on these hash2 protocols ## Integration Instructions N/A
- Loading branch information
1 parent
b68c17d
commit a3b31b7
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** @file | ||
This file declares a mock of Hash2 Protocol. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef MOCK_HASH2_H | ||
#define MOCK_HASH2_H | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Protocol\Hash2.h> | ||
} | ||
|
||
struct MockHash2 { | ||
MOCK_INTERFACE_DECLARATION (MockHash2); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
GetHashSize, | ||
(IN CONST EFI_HASH2_PROTOCOL *This, | ||
IN CONST EFI_GUID *HashAlgorithm, | ||
OUT UINTN *HashSize) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
Hash, | ||
(IN CONST EFI_HASH2_PROTOCOL *This, | ||
IN CONST EFI_GUID *HashAlgorithm, | ||
IN CONST UINT8 *Message, | ||
IN UINTN MessageSize, | ||
IN OUT EFI_HASH2_OUTPUT *Hash) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
HashInit, | ||
(IN CONST EFI_HASH2_PROTOCOL *This, | ||
IN CONST EFI_GUID *HashAlgorithm) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
HashUpdate, | ||
(IN CONST EFI_HASH2_PROTOCOL *This, | ||
IN CONST UINT8 *Message, | ||
IN UINTN MessageSize) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
HashFinal, | ||
(IN CONST EFI_HASH2_PROTOCOL *This, | ||
IN OUT EFI_HASH2_OUTPUT *Hash) | ||
); | ||
}; | ||
|
||
extern "C" { | ||
extern EFI_HASH2_PROTOCOL *gHash2Protocol; | ||
} | ||
|
||
#endif // MOCK_HASH2_H |
27 changes: 27 additions & 0 deletions
27
MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** @file MockHash2.cpp | ||
Google Test mock for Hash2 Protocol | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <GoogleTest/Protocol/MockHash2.h> | ||
|
||
MOCK_INTERFACE_DEFINITION (MockHash2); | ||
MOCK_FUNCTION_DEFINITION (MockHash2, GetHashSize, 3, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockHash2, Hash, 5, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockHash2, HashInit, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockHash2, HashUpdate, 3, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockHash2, HashFinal, 2, EFIAPI); | ||
|
||
EFI_HASH2_PROTOCOL HASH2_PROTOCOL_INSTANCE = { | ||
GetHashSize, // EFI_HASH2_GET_HASH_SIZE | ||
Hash, // EFI_HASH2_HASH | ||
HashInit, // EFI_HASH2_HASH_INIT | ||
HashUpdate, // EFI_HASH2_HASH_UPDATE | ||
HashFinal // EFI_HASH2_HASH_FINAL | ||
}; | ||
|
||
extern "C" { | ||
EFI_HASH2_PROTOCOL *gHash2Protocol = &HASH2_PROTOCOL_INSTANCE; | ||
} |