You've already forked edk2-upstream
mirror of
https://github.com/Dasharo/edk2-upstream.git
synced 2026-03-06 15:03:57 -08:00
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
267 lines
5.8 KiB
C
267 lines
5.8 KiB
C
/** @file MockShellCommandLib.h
|
|
Google Test mocks for ShellCommandLib
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
#include <Library/GoogleTestLib.h>
|
|
#include <Library/FunctionMockLib.h>
|
|
extern "C" {
|
|
#include <Uefi.h>
|
|
#include <Library/ShellCommandLib.h>
|
|
}
|
|
|
|
struct MockShellCommandLib {
|
|
MOCK_INTERFACE_DECLARATION (MockShellCommandLib);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
RETURN_STATUS,
|
|
ShellCommandRegisterCommandName,
|
|
(IN CONST CHAR16 *CommandString,
|
|
IN SHELL_RUN_COMMAND CommandHandler,
|
|
IN SHELL_GET_MAN_FILENAME GetManFileName,
|
|
IN UINT32 ShellMinSupportLevel,
|
|
IN CONST CHAR16 *ProfileName,
|
|
IN CONST BOOLEAN CanAffectLE,
|
|
IN CONST EFI_HII_HANDLE HiiHandle,
|
|
IN CONST EFI_STRING_ID ManFormatHelp)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
RETURN_STATUS,
|
|
ShellCommandRunCommandHandler,
|
|
(IN CONST CHAR16 *CommandString,
|
|
IN OUT SHELL_STATUS *RetVal,
|
|
IN OUT BOOLEAN *CanAffectLE OPTIONAL)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CONST CHAR16 *,
|
|
ShellCommandGetManFileNameHandler,
|
|
(IN CONST CHAR16 *CommandString)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CONST COMMAND_LIST *,
|
|
ShellCommandGetCommandList,
|
|
(IN CONST BOOLEAN Sort)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
RETURN_STATUS,
|
|
ShellCommandRegisterAlias,
|
|
(IN CONST CHAR16 *Command,
|
|
IN CONST CHAR16 *Alias)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CONST ALIAS_LIST *,
|
|
ShellCommandGetInitAliasList,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellCommandIsOnAliasList,
|
|
(IN CONST CHAR16 *Alias)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellCommandIsCommandOnList,
|
|
(IN CONST CHAR16 *CommandString)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CHAR16 *,
|
|
ShellCommandGetCommandHelp,
|
|
(IN CONST CHAR16 *CommandString)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
CommandInit,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellCommandGetEchoState,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
VOID,
|
|
ShellCommandSetEchoState,
|
|
(IN BOOLEAN State)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
VOID,
|
|
ShellCommandRegisterExit,
|
|
(IN BOOLEAN ScriptOnly,
|
|
IN CONST UINT64 ErrorCode)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
UINT64,
|
|
ShellCommandGetExitCode,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellCommandGetExit,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellCommandGetScriptExit,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
SCRIPT_FILE *,
|
|
ShellCommandGetCurrentScriptFile,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
SCRIPT_FILE *,
|
|
ShellCommandSetNewScript,
|
|
(IN SCRIPT_FILE *Script OPTIONAL)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
VOID,
|
|
DeleteScriptFileStruct,
|
|
(IN SCRIPT_FILE *Script)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CONST CHAR16 *,
|
|
ShellCommandGetProfileList,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CHAR16 *,
|
|
ShellCommandCreateNewMappingName,
|
|
(IN CONST SHELL_MAPPING_TYPE Type)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
ShellCommandConsistMappingInitialize,
|
|
(EFI_DEVICE_PATH_PROTOCOL ***Table)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
ShellCommandConsistMappingUnInitialize,
|
|
(EFI_DEVICE_PATH_PROTOCOL **Table)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CHAR16 *,
|
|
ShellCommandConsistMappingGenMappingName,
|
|
(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
|
IN EFI_DEVICE_PATH_PROTOCOL **Table)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
SHELL_MAP_LIST *,
|
|
ShellCommandFindMapItem,
|
|
(IN CONST CHAR16 *MapKey)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
ShellCommandAddMapItemAndUpdatePath,
|
|
(IN CONST CHAR16 *Name,
|
|
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
|
IN CONST UINT64 Flags,
|
|
IN CONST BOOLEAN Path)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
ShellCommandCreateInitialMappingsAndPaths,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
ShellCommandUpdateMapping,
|
|
()
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_FILE_PROTOCOL *,
|
|
ConvertShellHandleToEfiFileProtocol,
|
|
(IN CONST SHELL_FILE_HANDLE Handle)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellFileHandleRemove,
|
|
(IN CONST SHELL_FILE_HANDLE Handle)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
SHELL_FILE_HANDLE,
|
|
ConvertEfiFileProtocolToShellHandle,
|
|
(IN CONST EFI_FILE_PROTOCOL *Handle,
|
|
IN CONST CHAR16 *Path)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CONST CHAR16 *,
|
|
ShellFileHandleGetPath,
|
|
(IN CONST SHELL_FILE_HANDLE Handle)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
BOOLEAN,
|
|
ShellFileHandleEof,
|
|
(IN SHELL_FILE_HANDLE Handle)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
VOID,
|
|
FreeBufferList,
|
|
(IN BUFFER_LIST *List)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
VOID,
|
|
DumpHex,
|
|
(IN UINTN Indent,
|
|
IN UINTN Offset,
|
|
IN UINTN DataSize,
|
|
IN VOID *UserData)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
CHAR16 *,
|
|
CatSDumpHex,
|
|
(IN CHAR16 *Buffer,
|
|
IN UINTN Indent,
|
|
IN UINTN Offset,
|
|
IN UINTN DataSize,
|
|
IN VOID *UserData)
|
|
);
|
|
|
|
MOCK_FUNCTION_DECLARATION (
|
|
EFI_STATUS,
|
|
ShellSortFileList,
|
|
(IN OUT EFI_SHELL_FILE_INFO **FileList,
|
|
OUT EFI_SHELL_FILE_INFO **Duplicates OPTIONAL,
|
|
IN SHELL_SORT_FILE_LIST Order)
|
|
);
|
|
};
|