MdePkg: Add gmock examples

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Chris Johnson <chris.n.johnson@intel.com>
Acked-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
Chris Johnson
2023-03-24 16:10:22 -07:00
committed by mergify[bot]
parent e4af282e9f
commit 09458c2b0b
8 changed files with 202 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
/** @file
Google Test mocks for UefiLib
Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <GoogleTest/Library/MockUefiLib.h>
MOCK_INTERFACE_DEFINITION(MockUefiLib);
MOCK_FUNCTION_DEFINITION(MockUefiLib, GetVariable2, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION(MockUefiLib, GetEfiGlobalVariable2, 3, EFIAPI);

View File

@@ -0,0 +1,33 @@
## @file
# Google Test mocks for UefiLib
#
# Copyright (c) 2022, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockUefiLib
FILE_GUID = 47211F7A-6D90-4DFB-BDF9-610B69197C2E
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = UefiLib
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#
[Sources]
MockUefiLib.cpp
[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
[LibraryClasses]
GoogleTestLib
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc

View File

@@ -0,0 +1,40 @@
/** @file
Google Test mocks for UefiRuntimeServicesTableLib
Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h>
MOCK_INTERFACE_DEFINITION(MockUefiRuntimeServicesTableLib);
MOCK_FUNCTION_DEFINITION(MockUefiRuntimeServicesTableLib, gRT_GetVariable, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION(MockUefiRuntimeServicesTableLib, gRT_SetVariable, 5, EFIAPI);
static EFI_RUNTIME_SERVICES localRt = {
{0}, // EFI_TABLE_HEADER
NULL, // EFI_GET_TIME
NULL, // EFI_SET_TIME
NULL, // EFI_GET_WAKEUP_TIME
NULL, // EFI_SET_WAKEUP_TIME
NULL, // EFI_SET_VIRTUAL_ADDRESS_MAP
NULL, // EFI_CONVERT_POINTER
gRT_GetVariable, // EFI_GET_VARIABLE
NULL, // EFI_GET_NEXT_VARIABLE_NAME
gRT_SetVariable, // EFI_SET_VARIABLE
NULL, // EFI_GET_NEXT_HIGH_MONO_COUNT
NULL, // EFI_RESET_SYSTEM
NULL, // EFI_UPDATE_CAPSULE
NULL, // EFI_QUERY_CAPSULE_CAPABILITIES
NULL, // EFI_QUERY_VARIABLE_INFO
};
extern "C" {
EFI_RUNTIME_SERVICES* gRT = &localRt;
}

View File

@@ -0,0 +1,33 @@
## @file
# Google Test mocks for UefiRuntimeServicesTableLib
#
# Copyright (c) 2022, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockUefiRuntimeServicesTableLib
FILE_GUID = 0A0E13C2-4176-4293-89C7-C2497AA31B92
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = UefiRuntimeServicesTableLib
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#
[Sources]
MockUefiRuntimeServicesTableLib.cpp
[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
[LibraryClasses]
GoogleTestLib
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc