From c2af4c0cfce85dd1eeb1b0743cc3fe17f0143095 Mon Sep 17 00:00:00 2001 From: "YiTa Wu (AMI US Holdings Inc)" Date: Thu, 5 Sep 2024 00:30:04 +0800 Subject: [PATCH] Add MockDeviceBootManagerLib --- MsCorePkg/MsCorePkg.dec | 1 + .../Library/MockDeviceBootManagerLib.h | 66 +++++++++++++++++++ .../MockDeviceBootManagerLib.cpp | 17 +++++ .../MockDeviceBootManagerLib.inf | 37 +++++++++++ MsCorePkg/UnitTests/MsCorePkgHostTest.dsc | 2 + 5 files changed, 123 insertions(+) create mode 100644 MsCorePkg/UnitTests/Mock/Include/GoogleTest/Library/MockDeviceBootManagerLib.h create mode 100644 MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.cpp create mode 100644 MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.inf diff --git a/MsCorePkg/MsCorePkg.dec b/MsCorePkg/MsCorePkg.dec index bcd99e2997..5046d9f998 100644 --- a/MsCorePkg/MsCorePkg.dec +++ b/MsCorePkg/MsCorePkg.dec @@ -18,6 +18,7 @@ [Includes] Include + UnitTests/Mock/Include [LibraryClasses] diff --git a/MsCorePkg/UnitTests/Mock/Include/GoogleTest/Library/MockDeviceBootManagerLib.h b/MsCorePkg/UnitTests/Mock/Include/GoogleTest/Library/MockDeviceBootManagerLib.h new file mode 100644 index 0000000000..e5fc5b7022 --- /dev/null +++ b/MsCorePkg/UnitTests/Mock/Include/GoogleTest/Library/MockDeviceBootManagerLib.h @@ -0,0 +1,66 @@ +/** @file MockDeviceBootManagerLib.h + Google Test mocks for DeviceBootManagerLib. + + Copyright (c) Microsoft Corporation. + Your use of this software is governed by the terms of the Microsoft agreement under which you obtained the software. +**/ + +#ifndef MOCK_DEVICE_BOOT_MANAGER_LIB_H_ +#define MOCK_DEVICE_BOOT_MANAGER_LIB_H_ + +#include +#include + +extern "C" { + #include + #include +} + +struct MockDeviceBootManagerLib { + MOCK_INTERFACE_DECLARATION (MockDeviceBootManagerLib); + + MOCK_FUNCTION_DECLARATION ( + EFI_STATUS, + DeviceBootManagerPriorityBoot, + (EFI_BOOT_MANAGER_LOAD_OPTION *BootOption) + ); + + MOCK_FUNCTION_DECLARATION ( + VOID, + DeviceBootManagerUnableToBoot, + () + ); + + MOCK_FUNCTION_DECLARATION ( + VOID, + DeviceBootManagerProcessBootCompletion, + (EFI_BOOT_MANAGER_LOAD_OPTION *BootOption) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_DEVICE_PATH_PROTOCOL **, + DeviceBootManagerOnDemandConInConnect, + () + ); + + MOCK_FUNCTION_DECLARATION ( + VOID, + DeviceBootManagerBdsEntry, + () + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_HANDLE, + DeviceBootManagerBeforeConsole, + (EFI_DEVICE_PATH_PROTOCOL **DevicePath, + BDS_CONSOLE_CONNECT_ENTRY **PlatformConsoles) + ); + + MOCK_FUNCTION_DECLARATION ( + EFI_DEVICE_PATH_PROTOCOL **, + DeviceBootManagerAfterConsole, + () + ); +}; + +#endif diff --git a/MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.cpp b/MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.cpp new file mode 100644 index 0000000000..ea0e33bb43 --- /dev/null +++ b/MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.cpp @@ -0,0 +1,17 @@ +/** @file MockDeviceBootManagerLib.cpp + Google Test mocks for DeviceBootManagerLib. + + Copyright (c) Microsoft Corporation. + Your use of this software is governed by the terms of the Microsoft agreement under which you obtained the software. +**/ + +#include + +MOCK_INTERFACE_DEFINITION (MockDeviceBootManagerLib); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerPriorityBoot, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerUnableToBoot, 0, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerProcessBootCompletion, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerOnDemandConInConnect, 0, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerBdsEntry, 0, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerBeforeConsole, 2, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockDeviceBootManagerLib, DeviceBootManagerAfterConsole, 0, EFIAPI); diff --git a/MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.inf b/MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.inf new file mode 100644 index 0000000000..b152f0aef5 --- /dev/null +++ b/MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.inf @@ -0,0 +1,37 @@ +## @file MockDeviceBootManagerLib.inf +# Google Test mocks for DeviceBootManagerLib. +# +# Copyright (c) Microsoft Corporation. +# Your use of this software is governed by the terms of the Microsoft agreement under which you obtained the software. +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MockDeviceBootManagerLib + FILE_GUID = A19D9B27-21EB-4DCF-A084-0326C2EB0E58 + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + LIBRARY_CLASS = DeviceBootManagerLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MockDeviceBootManagerLib.cpp + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + MsCorePkg/MsCorePkg.dec + PcBdsPkg/PcBdsPkg.dec + BdsPkg/BdsPkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc diff --git a/MsCorePkg/UnitTests/MsCorePkgHostTest.dsc b/MsCorePkg/UnitTests/MsCorePkgHostTest.dsc index 037e4d86c1..af365fe8d6 100644 --- a/MsCorePkg/UnitTests/MsCorePkgHostTest.dsc +++ b/MsCorePkg/UnitTests/MsCorePkgHostTest.dsc @@ -46,5 +46,7 @@ [Components] MsCorePkg/MacAddressEmulationDxe/Test/MacAddressEmulationDxeHostTest.inf + MsCorePkg/UnitTests/Mock/Library/MockDeviceBootManagerLib/MockDeviceBootManagerLib.inf + [BuildOptions] *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES