public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: devel@edk2.groups.io
Cc: Chris Johnson <chris.n.johnson@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>
Subject: [Patch 06/12] MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example
Date: Sat, 25 Mar 2023 11:45:34 -0700	[thread overview]
Message-ID: <20230325184541.596-7-michael.d.kinney@intel.com> (raw)
In-Reply-To: <20230325184541.596-1-michael.d.kinney@intel.com>

From: Chris Johnson <chris.n.johnson@intel.com>

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>
---
 .../MockUefiRuntimeServicesTableLib.inf       |  4 +-
 .../GoogleTest/UefiSortLibGoogleTest.cpp      | 57 +++++++++++++++++++
 .../GoogleTest/UefiSortLibGoogleTest.inf      | 31 ++++++++++
 MdeModulePkg/Test/MdeModulePkgHostTest.dsc    |  6 ++
 4 files changed, 96 insertions(+), 2 deletions(-)
 create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp
 create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf

diff --git a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf
index e716b855a31a..15eb646d7c38 100644
--- a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf
+++ b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf
@@ -10,9 +10,9 @@ [Defines]
   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 000000000000..7ac1231c6f87
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp
@@ -0,0 +1,57 @@
+/** @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(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(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 000000000000..ac5ffb3bc29d
--- /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
diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
index c9ec835df65d..a2bbbe8adf44 100644
--- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
+++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
@@ -47,3 +47,9 @@ [Components]
       UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
       DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
   }
+
+  MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf {
+    <LibraryClasses>
+      UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+      DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+  }
-- 
2.39.1.windows.1


  parent reply	other threads:[~2023-03-25 18:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-25 18:45 [Patch 00/12] Add gmock support for host-based unit testing Michael D Kinney
2023-03-25 18:45 ` [Patch 01/12] UnitTestFrameworkPkg: Add subhook submodule required for gmock Michael D Kinney
2023-03-25 18:45 ` [Patch 02/12] .pytool/CISettings.py: Add subhook submodule Michael D Kinney
2023-03-25 18:45 ` [Patch 03/12] UnitTestFrameworkPkg: Add gmock support to GoogleTestLib Michael D Kinney
2023-03-25 18:45 ` [Patch 04/12] UnitTestFrameworkPkg/ReadMe.md: Add gmock documentation Michael D Kinney
2023-03-28 18:23   ` Johnson, Chris N
2023-03-25 18:45 ` [Patch 05/12] MdePkg: Add gmock examples Michael D Kinney
2023-03-25 18:45 ` Michael D Kinney [this message]
2023-03-25 18:45 ` [Patch 07/12] SecurityPkg: Add gmock example Michael D Kinney
2023-03-26  2:51   ` Yao, Jiewen
2023-03-25 18:45 ` [Patch 08/12] SecurityPkg/Library/SecureBootVariableLib: Fix VS20xx 4122 errors Michael D Kinney
2023-03-26  2:50   ` Yao, Jiewen
2023-03-25 18:45 ` [Patch 09/12] SecurityPkg/Library/SecureBootVariableLib: HOST_APPLICATION IA32/X64 only Michael D Kinney
2023-03-26  2:50   ` Yao, Jiewen
2023-03-25 18:45 ` [Patch 10/12] MdePkg/Library/BaseLib: " Michael D Kinney
2023-03-25 18:45 ` [Patch 11/12] MdeModulePkg: " Michael D Kinney
2023-03-25 18:45 ` [Patch 12/12] PrmPkg/Library: " Michael D Kinney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230325184541.596-7-michael.d.kinney@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox