summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Library
diff options
context:
space:
mode:
authorChris Johnson <chris.n.johnson@intel.com>2023-03-24 16:16:01 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-04-10 05:59:02 +0000
commit1a24843ecb84d8258a613568122fa33fb872ecbc (patch)
tree41cc488da40257c3926079e152c8899431da265d /MdeModulePkg/Library
parent09458c2b0bc531478337ceb37cb30a4b5d550c13 (diff)
downloadedk2-1a24843ecb84d8258a613568122fa33fb872ecbc.tar.gz
edk2-1a24843ecb84d8258a613568122fa33fb872ecbc.tar.bz2
edk2-1a24843ecb84d8258a613568122fa33fb872ecbc.zip
MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Chris Johnson <chris.n.johnson@intel.com> Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Diffstat (limited to 'MdeModulePkg/Library')
-rw-r--r--MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf4
-rw-r--r--MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp61
-rw-r--r--MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf31
3 files changed, 94 insertions, 2 deletions
diff --git a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf
index e716b855a3..15eb646d7c 100644
--- a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf
+++ b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf
@@ -10,9 +10,9 @@
INF_VERSION = 0x00010005
BASE_NAME = MockUefiRuntimeServicesTableLib
FILE_GUID = 4EA215EE-85C1-4A0A-847F-D2A8DE20805F
- MODULE_TYPE = UEFI_DRIVER
+ MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
- LIBRARY_CLASS = UefiRuntimeServicesTableLib|HOST_APPLICATION
+ LIBRARY_CLASS = UefiRuntimeServicesTableLib
#
# VALID_ARCHITECTURES = IA32 X64 EBC
diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp
new file mode 100644
index 0000000000..23f6e9cc06
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp
@@ -0,0 +1,61 @@
+/** @file
+ Unit tests for the implementation of UefiSortLib.
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include <Library/GoogleTestLib.h>
+
+extern "C" {
+ #include <Uefi.h>
+ #include <Library/SortLib.h>
+}
+
+using namespace testing;
+
+INTN
+EFIAPI
+CompareUint32 (
+ IN CONST VOID *Left,
+ IN CONST VOID *Right
+ )
+{
+ if (*(UINT32*)Right > *(UINT32*)Left) {
+ return 1;
+ } else if (*(UINT32*)Right < *(UINT32*)Left) {
+ return -1;
+ }
+
+ return 0;
+}
+
+// Test PerformQuickSort() API from UefiSortLib to verify a UINT32 array
+// with 9 elements in ascending order is sorted into descending order.
+TEST(PerformQuickSortTest, SortUint32AscendingArray_Size9) {
+ CONST UINT32 ArraySize = 9;
+ UINT32 BuffActual[ArraySize];
+ UINT32 BuffExpected[ArraySize];
+
+ for (UINT32 Index = 0; Index < ArraySize; Index++) {
+ BuffActual[Index] = Index + 1;
+ BuffExpected[Index] = ArraySize - Index;
+ }
+
+ PerformQuickSort (BuffActual, (UINTN)ArraySize, sizeof(UINT32), (SORT_COMPARE)CompareUint32);
+ EXPECT_THAT(BuffActual, ElementsAreArray(BuffExpected, ArraySize));
+}
+
+// Test StringCompare() API from UefiSortLib to verify the comparison
+// succeeds when the same buffer is compared with itself.
+TEST(StringCompareTest, CompareSameBuffer) {
+ INTN RetVal;
+ CONST CHAR16 *Buffer = (CHAR16*)L"abcdefg";
+
+ RetVal = StringCompare (&Buffer, &Buffer);
+ EXPECT_EQ(RetVal, 0);
+}
+
+int main(int argc, char* argv[]) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf
new file mode 100644
index 0000000000..ac5ffb3bc2
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf
@@ -0,0 +1,31 @@
+## @file
+# Unit test suite for the UefiSortLib using Google Test
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UefiSortLibGoogleTest
+ FILE_GUID = 78FB0BEE-D0EA-4E1A-BD38-67458C8ECDEF
+ VERSION_STRING = 1.0
+ MODULE_TYPE = HOST_APPLICATION
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ UefiSortLibGoogleTest.cpp
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ GoogleTestLib
+ UefiSortLib