From nobody Thu May 2 04:22:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513728977735756.9933074681707; Tue, 19 Dec 2017 16:16:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 48C5C221C193B; Tue, 19 Dec 2017 16:11:28 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 82E2B21CB865F for ; Tue, 19 Dec 2017 16:11:26 -0800 (PST) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2017 16:16:13 -0800 Received: from mdkinney-mobl2.amr.corp.intel.com ([10.241.98.58]) by fmsmga007.fm.intel.com with ESMTP; 19 Dec 2017 16:16:12 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=michael.d.kinney@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,429,1508828400"; d="scan'208";a="3742581" From: "Kinney, Michael D" To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 16:16:06 -0800 Message-Id: <20171220001607.22736-2-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.14.2.windows.3 In-Reply-To: <20171220001607.22736-1-michael.d.kinney@intel.com> References: <20171220001607.22736-1-michael.d.kinney@intel.com> Subject: [edk2] [staging/edk2-test Patch 1/2] MdePkgUnitTest: Add unit test package for MdePkg X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Michael D Kinney Initial version of a unit test package for the MdePkg that uses services from the MsUnitTestPkg to implement test cases for the SafeIntLib in the MdePkg. The initial version of these tests is from the following branch and commit: https://github.com/Microsoft/MS_UEFI/tree/share/intsafelib/MdeModulePkg/Uni= tTests/IntSafeLib https://github.com/Microsoft/MS_UEFI/commit/cc2e9d229d4e876ab64d75dee16761a= 297582fd9 Updates from original content: * Update test cases to be compatible with all supported CPU types * Add unit test cases to verify that Result is set to the correct error value when RETURN_BUFFER_TOO_SMALL is returned to indicate an overflow or an undeflow condition. * Add unit test cases to pass in a Result parameter of NULL and verify that RETURN_INVALID_PARAMETER is returned. * Add SafeChar8Add() unit tests * Add SafeChar8Sub() unit tests * Add SafeChar8Mult() unit tests * Add SafeInt8ToChar8() unit tests * Update ToChar8() unit tests to perform success tests on positive values in range 0..127 and failure tests in ranges -128..-1 and 128..255. * Replace "UIntN" with "Uintn" * Replace "IntN" with "Intn" * Replace "UIntxx" with "Uintxx" * Fix EDK II code style issues Cc: Sean Brogan Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney Reviewed-by: Sean Brogan --- MdePkgUnitTest/MdePkgUnitTest.dec | 20 + MdePkgUnitTest/MdePkgUnitTest.dsc | 57 + .../SafeIntLib/SafeIntLibUintnIntnUnitTests32.c | 54 + .../SafeIntLib/SafeIntLibUintnIntnUnitTests64.c | 54 + .../SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c | 65 + MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c | 3450 ++++++++++++++++= ++++ MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.h | 155 + MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.inf | 69 + MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c | 595 ++++ MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c | 599 ++++ 10 files changed, 5118 insertions(+) create mode 100644 MdePkgUnitTest/MdePkgUnitTest.dec create mode 100644 MdePkgUnitTest/MdePkgUnitTest.dsc create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests3= 2.c create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests6= 4.c create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsE= bc.c create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.h create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.inf create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c create mode 100644 MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c diff --git a/MdePkgUnitTest/MdePkgUnitTest.dec b/MdePkgUnitTest/MdePkgUnitT= est.dec new file mode 100644 index 0000000000..9ea59192fb --- /dev/null +++ b/MdePkgUnitTest/MdePkgUnitTest.dec @@ -0,0 +1,20 @@ +## @file +# This Package provides unit tests for the MdePkg +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials are licensed and made availa= ble under +# the terms and conditions of the BSD License which accompanies this distr= ibution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. +# +## + +[Defines] + DEC_SPECIFICATION =3D 0x00010005 + PACKAGE_NAME =3D MdePkgUnitTest + PACKAGE_GUID =3D 42038d8f-d911-11e7-a7f4-f8597177a00a + PACKAGE_VERSION =3D 0.1 diff --git a/MdePkgUnitTest/MdePkgUnitTest.dsc b/MdePkgUnitTest/MdePkgUnitT= est.dsc new file mode 100644 index 0000000000..d98483020b --- /dev/null +++ b/MdePkgUnitTest/MdePkgUnitTest.dsc @@ -0,0 +1,57 @@ +## @file +# This Package provides unit tests for the MdePkg +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials are licensed and made availa= ble under +# the terms and conditions of the BSD License which accompanies this distr= ibution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. +# +## + +[Defines] + PLATFORM_NAME =3D MdePkgUnitTest + PLATFORM_GUID =3D 44be67cf-d911-11e7-bf44-f8597177a00a + PLATFORM_VERSION =3D 0.1 + DSC_SPECIFICATION =3D 0x00010005 + OUTPUT_DIRECTORY =3D Build/MdePkgUnitTest + SUPPORTED_ARCHITECTURES =3D IA32|IPF|X64|EBC|ARM|AARCH64 + BUILD_TARGETS =3D DEBUG|RELEASE + SKUID_IDENTIFIER =3D DEFAULT + +[LibraryClasses] + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + DebugLib|MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseD= ebugPrintErrorLevelLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + + UnitTestLib|MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf + UnitTestAssertLib|MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssert= Lib.inf + UnitTestLogLib|MsUnitTestPkg/Library/UnitTestLogLib/UnitTestLogLib.inf + UnitTestPersistenceLib|MsUnitTestPkg/Library/UnitTestPersistenceFileSyst= emLib/UnitTestPersistenceFileSystemLib.inf + UnitTestBootUsbLib|MsUnitTestPkg/Library/UnitTestBootUsbMicrosoftLib/Uni= tTestBootUsbMicrosoftLib.inf + UnitTestResultReportLib|MsUnitTestPkg/Library/UnitTestResultReportPlainT= extOutputLib/UnitTestResultReportLib.inf + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + +[Components] + MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.inf { + + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + } diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c b/M= dePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c new file mode 100644 index 0000000000..632ddbbfef --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c @@ -0,0 +1,54 @@ +/** @file + + 32-bit specific functions for unit-testing INTN and UINTN functions in + SafeIntLib. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "SafeIntLibUnitTests.h" + +#define _UNIT_TEST_32_BIT(CaseName) \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_32 ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ); \ +\ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ) \ +{ \ + return CaseName##_32(Framework, Context); \ +} + +_UNIT_TEST_32_BIT(TestSafeInt32ToUintn) +_UNIT_TEST_32_BIT(TestSafeUint32ToIntn) +_UNIT_TEST_32_BIT(TestSafeIntnToInt32) +_UNIT_TEST_32_BIT(TestSafeIntnToUint32) +_UNIT_TEST_32_BIT(TestSafeUintnToUint32) +_UNIT_TEST_32_BIT(TestSafeUintnToIntn) +_UNIT_TEST_32_BIT(TestSafeUintnToInt64) +_UNIT_TEST_32_BIT(TestSafeInt64ToIntn) +_UNIT_TEST_32_BIT(TestSafeInt64ToUintn) +_UNIT_TEST_32_BIT(TestSafeUint64ToIntn) +_UNIT_TEST_32_BIT(TestSafeUint64ToUintn) +_UNIT_TEST_32_BIT(TestSafeUintnAdd) +_UNIT_TEST_32_BIT(TestSafeIntnAdd) +_UNIT_TEST_32_BIT(TestSafeUintnSub) +_UNIT_TEST_32_BIT(TestSafeIntnSub) +_UNIT_TEST_32_BIT(TestSafeUintnMult) +_UNIT_TEST_32_BIT(TestSafeIntnMult) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c b/M= dePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c new file mode 100644 index 0000000000..462f93e351 --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c @@ -0,0 +1,54 @@ +/** @file + + 64-bit specific functions for unit-testing INTN and UINTN functions in + SafeIntLib. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "SafeIntLibUnitTests.h" + +#define _UNIT_TEST_64_BIT(CaseName) \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_64 ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ); \ +\ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ) \ +{ \ + return CaseName##_64(Framework, Context); \ +} + +_UNIT_TEST_64_BIT(TestSafeInt32ToUintn) +_UNIT_TEST_64_BIT(TestSafeUint32ToIntn) +_UNIT_TEST_64_BIT(TestSafeIntnToInt32) +_UNIT_TEST_64_BIT(TestSafeIntnToUint32) +_UNIT_TEST_64_BIT(TestSafeUintnToUint32) +_UNIT_TEST_64_BIT(TestSafeUintnToIntn) +_UNIT_TEST_64_BIT(TestSafeUintnToInt64) +_UNIT_TEST_64_BIT(TestSafeInt64ToIntn) +_UNIT_TEST_64_BIT(TestSafeInt64ToUintn) +_UNIT_TEST_64_BIT(TestSafeUint64ToIntn) +_UNIT_TEST_64_BIT(TestSafeUint64ToUintn) +_UNIT_TEST_64_BIT(TestSafeUintnAdd) +_UNIT_TEST_64_BIT(TestSafeIntnAdd) +_UNIT_TEST_64_BIT(TestSafeUintnSub) +_UNIT_TEST_64_BIT(TestSafeIntnSub) +_UNIT_TEST_64_BIT(TestSafeUintnMult) +_UNIT_TEST_64_BIT(TestSafeIntnMult) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c b/= MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c new file mode 100644 index 0000000000..e91811bc2f --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c @@ -0,0 +1,65 @@ +/** @file + + EBC-specific functions for unit-testing INTN and UINTN functions in + SafeIntLib. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include "SafeIntLibUnitTests.h" + +#define _EBC_UNIT_TEST(CaseName) \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_32 ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ); \ +\ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_64 ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ); \ +\ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ) \ +{ \ + if (sizeof (UINTN) =3D=3D sizeof (UINT32)) { \ + return CaseName##_32(Framework, Context); \ + } else { \ + return CaseName##_64(Framework, Context); \ + } \ +} + +_EBC_UNIT_TEST(TestSafeInt32ToUintn) +_EBC_UNIT_TEST(TestSafeUint32ToIntn) +_EBC_UNIT_TEST(TestSafeIntnToInt32) +_EBC_UNIT_TEST(TestSafeIntnToUint32) +_EBC_UNIT_TEST(TestSafeUintnToUint32) +_EBC_UNIT_TEST(TestSafeUintnToIntn) +_EBC_UNIT_TEST(TestSafeUintnToInt64) +_EBC_UNIT_TEST(TestSafeInt64ToIntn) +_EBC_UNIT_TEST(TestSafeInt64ToUintn) +_EBC_UNIT_TEST(TestSafeUint64ToIntn) +_EBC_UNIT_TEST(TestSafeUint64ToUintn) +_EBC_UNIT_TEST(TestSafeUintnAdd) +_EBC_UNIT_TEST(TestSafeIntnAdd) +_EBC_UNIT_TEST(TestSafeUintnSub) +_EBC_UNIT_TEST(TestSafeIntnSub) +_EBC_UNIT_TEST(TestSafeUintnMult) +_EBC_UNIT_TEST(TestSafeIntnMult) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c b/MdePkgUnitTe= st/SafeIntLib/SafeIntLibUnitTests.c new file mode 100644 index 0000000000..475c10c728 --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c @@ -0,0 +1,3450 @@ +/** @file + UEFI Shell based application for unit testing the SafeIntLib. + + Copyright (c) 2017, Microsoft Corporation + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are m= et: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright not= ice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS = IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IM= PLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE D= ISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY= DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCL= UDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF= USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY TH= EORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEG= LIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include "SafeIntLibUnitTests.h" + +#define UNIT_TEST_APP_NAME L"Int Safe Lib Unit Test Application" +#define UNIT_TEST_APP_VERSION L"0.1" + +// +// Conversion function tests: +// +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Operand =3D 0x5b; + UINT8 Result =3D 0; + + // + // Positive UINT8 should result in just a cast + // + Status =3D SafeInt8ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Negative number should result in an error status + // + Operand =3D (-56); + Status =3D SafeInt8ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeInt8ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // + // Positive INT8 should result in just a cast + // + Status =3D SafeInt8ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Negative number should result in an error status + // + Operand =3D (-56); + Status =3D SafeInt8ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeInt8ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8ToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Operand =3D 0x5b; + UINT16 Result =3D 0; + + // + // Positive UINT8 should result in just a cast + // + Status =3D SafeInt8ToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Negative number should result in an error status + // + Operand =3D (-56); + Status =3D SafeInt8ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeInt8ToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8ToUint32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Operand =3D 0x5b; + UINT32 Result =3D 0; + + // + // Positive UINT8 should result in just a cast + // + Status =3D SafeInt8ToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Negative number should result in an error status + // + Operand =3D (-56); + Status =3D SafeInt8ToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeInt8ToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8ToUintn ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Operand =3D 0x5b; + UINTN Result =3D 0; + + // + // Positive UINT8 should result in just a cast + // + Status =3D SafeInt8ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Negative number should result in an error status + // + Operand =3D (-56); + Status =3D SafeInt8ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeInt8ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8ToUint64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Operand =3D 0x5b; + UINT64 Result =3D 0; + + // + // Positive UINT8 should result in just a cast + // + Status =3D SafeInt8ToUint64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Negative number should result in an error status + // + Operand =3D (-56); + Status =3D SafeInt8ToUint64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeInt8ToUint64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint8ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT8 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // Operand <=3D 0x7F (MAX_INT8) should result in a cast + // + Status =3D SafeUint8ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Operand larger than 0x7f should result in an error status + // + Operand =3D 0xaf; + Status =3D SafeUint8ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeUint8ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint8ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT8 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + // + + // + // Operand <=3D 0x7F (MAX_INT8) should result in a cast + // + Status =3D SafeUint8ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Operand larger than 0x7f should result in an error status + // + Operand =3D 0xaf; + Status =3D SafeUint8ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeUint8ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st + // + Status =3D SafeInt16ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + Operand =3D (-35); + Status =3D SafeInt16ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-35), Result); + + // + // Otherwise should result in an error status + // + Operand =3D 0x1234; + Status =3D SafeInt16ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Operand =3D (-17835); + Status =3D SafeInt16ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeInt16ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + // + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st + // + Status =3D SafeInt16ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-35); + Status =3D SafeInt16ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D 0x1234; + Status =3D SafeInt16ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (-17835); + Status =3D SafeInt16ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeInt16ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b; + UINT8 Result =3D 0; + + // + // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast + // + Status =3D SafeInt16ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D 0x1234; + Status =3D SafeInt16ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Operand =3D (-17835); + Status =3D SafeInt16ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeInt16ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b5b; + UINT16 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt16ToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-17835); + Status =3D SafeInt16ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeInt16ToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToUint32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b5b; + UINT32 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt16ToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-17835); + Status =3D SafeInt16ToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeInt16ToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToUintn ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b5b; + UINTN Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt16ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-17835); + Status =3D SafeInt16ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeInt16ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16ToUint64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Operand =3D 0x5b5b; + UINT64 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt16ToUint64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-17835); + Status =3D SafeInt16ToUint64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeInt16ToUint64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is <=3D MAX_INT8, it's a cast + // + Status =3D SafeUint16ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5b5b); + Status =3D SafeUint16ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeUint16ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is <=3D MAX_INT8, it's a cast + // + Status =3D SafeUint16ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5b5b); + Status =3D SafeUint16ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeUint16ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Operand =3D 0xab; + UINT8 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT8 (0xff), it's a cast + // + Status =3D SafeUint16ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5b5b); + Status =3D SafeUint16ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUint16ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16ToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Operand =3D 0x5b5b; + INT16 Result =3D 0; + + // + // If Operand is <=3D MAX_INT16 (0x7fff), it's a cast + // + Status =3D SafeUint16ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabab); + Status =3D SafeUint16ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeUint16ToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st + // + Status =3D SafeInt32ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + Operand =3D (-57); + Status =3D SafeInt32ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-57), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeInt32ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt32ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeInt32ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st + // + Status =3D SafeInt32ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-57); + Status =3D SafeInt32ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (0x5bababab); + Status =3D SafeInt32ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt32ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeInt32ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5b; + UINT8 Result =3D 0; + + // + // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast + // + Status =3D SafeInt32ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-57); + Status =3D SafeInt32ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Operand =3D (0x5bababab); + Status =3D SafeInt32ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt32ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeInt32ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5b5b; + INT16 Result =3D 0; + + // + // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a = cast + // + Status =3D SafeInt32ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b5b, Result); + + Operand =3D (-17857); + Status =3D SafeInt32ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-17857), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeInt32ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt32ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeInt32ToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0xabab; + UINT16 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast + // + Status =3D SafeInt32ToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-17857); + Status =3D SafeInt32ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Operand =3D (0x5bababab); + Status =3D SafeInt32ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt32ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeInt32ToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUint32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5bababab; + UINT32 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt32ToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeInt32ToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeInt32ToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUint64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5bababab; + UINT64 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt32ToUint64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeInt32ToUint64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeInt32ToUint64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is <=3D MAX_INT8, then it's a cast + // + Status =3D SafeUint32ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeUint32ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeUint32ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is <=3D MAX_INT8, then it's a cast + // + Status =3D SafeUint32ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeUint32ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeUint32ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0xab; + UINT8 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT8, then it's a cast + // + Status =3D SafeUint32ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUint32ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUint32ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0x5bab; + INT16 Result =3D 0; + + // + // If Operand is <=3D MAX_INT16, then it's a cast + // + Status =3D SafeUint32ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUint32ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeUint32ToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0xabab; + UINT16 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT16, then it's a cast + // + Status =3D SafeUint32ToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUint32ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeUint32ToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToInt32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0x5bababab; + INT32 Result =3D 0; + + // + // If Operand is <=3D MAX_INT32, then it's a cast + // + Status =3D SafeUint32ToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUint32ToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeUint32ToInt32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st + // + Status =3D SafeIntnToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + Operand =3D (-53); + Status =3D SafeIntnToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-53), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeIntnToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeIntnToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeIntnToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st + // + Status =3D SafeIntnToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-53); + Status =3D SafeIntnToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (0x5bababab); + Status =3D SafeIntnToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeIntnToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeIntnToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0xab; + UINT8 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT8 inclusive, then it's a cast + // + Status =3D SafeIntnToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeIntnToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeIntnToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeIntnToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5bab; + INT16 Result =3D 0; + + // + // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a = cast + // + Status =3D SafeIntnToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bab, Result); + + Operand =3D (-23467); + Status =3D SafeIntnToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-23467), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeIntnToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeIntnToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeIntnToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0xabab; + UINT16 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast + // + Status =3D SafeIntnToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5bababab); + Status =3D SafeIntnToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Operand =3D (-1537977259); + Status =3D SafeIntnToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeIntnToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUintn ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5bababab; + UINTN Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeIntnToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeIntnToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeIntnToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUint64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5bababab; + UINT64 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeIntnToUint64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeIntnToUint64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeIntnToUint64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is <=3D MAX_INT8, then it's a cast + // + Status =3D SafeUintnToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabab); + Status =3D SafeUintnToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeUintnToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is <=3D MAX_INT8, then it's a cast + // + Status =3D SafeUintnToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabab); + Status =3D SafeUintnToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeUintnToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0xab; + UINT8 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT8, then it's a cast + // + Status =3D SafeUintnToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabab); + Status =3D SafeUintnToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUintnToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5bab; + INT16 Result =3D 0; + + // + // If Operand is <=3D MAX_INT16, then it's a cast + // + Status =3D SafeUintnToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabab); + Status =3D SafeUintnToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeUintnToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0xabab; + UINT16 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT16, then it's a cast + // + Status =3D SafeUintnToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUintnToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeUintnToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToInt32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5bababab; + INT32 Result =3D 0; + + // + // If Operand is <=3D MAX_INT32, then it's a cast + // + Status =3D SafeUintnToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUintnToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeUintnToInt32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a c= ast + // + Status =3D SafeInt64ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + Operand =3D (-37); + Status =3D SafeInt64ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-37), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeInt64ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast + // + Status =3D SafeInt64ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-37); + Status =3D SafeInt64ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeInt64ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0xab; + UINT8 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT8 inclusive, then it's a cast + // + Status =3D SafeInt64ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeInt64ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5bab; + INT16 Result =3D 0; + + // + // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a= cast + // + Status =3D SafeInt64ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bab, Result); + + Operand =3D (-23467); + Status =3D SafeInt64ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-23467), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeInt64ToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0xabab; + UINT16 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast + // + Status =3D SafeInt64ToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeInt64ToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToInt32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5bababab; + INT32 Result =3D 0; + + // + // If Operand is between MIN_INT32 and MAX_INT32 inclusive, then it's a= cast + // + Status =3D SafeInt64ToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt64ToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-1537977259), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeInt64ToInt32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUint32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0xabababab; + UINT32 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT32 inclusive, then it's a cast + // + Status =3D SafeInt64ToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeInt64ToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUint64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5babababefefefef; + UINT64 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt64ToUint64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToUint64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeInt64ToUint64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToInt8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5b; + INT8 Result =3D 0; + + // + // If Operand is <=3D MAX_INT8, then it's a cast + // + Status =3D SafeUint64ToInt8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToInt8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeUint64ToInt8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToChar8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5b; + CHAR8 Result =3D 0; + + // CHAR8 is typedefed as char, which by default is signed, but is + // also allowed to be unsigned. + + // + // If Operand is <=3D MAX_INT8, then it's a cast + // + Status =3D SafeUint64ToChar8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5b, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToChar8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeUint64ToChar8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToUint8 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0xab; + UINT8 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT8, then it's a cast + // + Status =3D SafeUint64ToUint8(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToUint8(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUint64ToUint8(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToInt16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5bab; + INT16 Result =3D 0; + + // + // If Operand is <=3D MAX_INT16, then it's a cast + // + Status =3D SafeUint64ToInt16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToInt16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeUint64ToInt16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToUint16 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0xabab; + UINT16 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT16, then it's a cast + // + Status =3D SafeUint64ToUint16(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToUint16(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeUint64ToUint16(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToInt32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5bababab; + INT32 Result =3D 0; + + // + // If Operand is <=3D MAX_INT32, then it's a cast + // + Status =3D SafeUint64ToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeUint64ToInt32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToUint32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0xabababab; + UINT32 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT32, then it's a cast + // + Status =3D SafeUint64ToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeUint64ToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToInt64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5babababefefefef; + INT64 Result =3D 0; + + // + // If Operand is <=3D MAX_INT64, then it's a cast + // + Status =3D SafeUint64ToInt64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToInt64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Status =3D SafeUint64ToInt64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +// +// Addition function tests: +// +UNIT_TEST_STATUS +EFIAPI +TestSafeUint8Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT8 Augend =3D 0x3a; + UINT8 Addend =3D 0x3a; + UINT8 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_UINT8, then it's addit= ion + // + Status =3D SafeUint8Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0xab; + Addend =3D 0xbc; + Status =3D SafeUint8Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUint8Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Augend =3D 0x3a3a; + UINT16 Addend =3D 0x3a3a; + UINT16 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_UINT16, then it's addi= tion + // + Status =3D SafeUint16Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7474, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0xabab; + Addend =3D 0xbcbc; + Status =3D SafeUint16Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeUint16Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Augend =3D 0x3a3a3a3a; + UINT32 Addend =3D 0x3a3a3a3a; + UINT32 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_UINT32, then it's addi= tion + // + Status =3D SafeUint32Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74747474, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0xabababab; + Addend =3D 0xbcbcbcbc; + Status =3D SafeUint32Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeUint32Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Augend =3D 0x3a3a3a3a12121212; + UINT64 Addend =3D 0x3a3a3a3a12121212; + UINT64 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_UINT64, then it's addi= tion + // + Status =3D SafeUint64Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7474747424242424, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0xababababefefefef; + Addend =3D 0xbcbcbcbcdededede; + Status =3D SafeUint64Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeUint64Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Augend =3D 0x3a; + INT8 Addend =3D 0x3a; + INT8 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INT8 + // and doesn't underflow MIN_INT8, then it's addition + // + Status =3D SafeInt8Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74, Result); + + Augend =3D (-58); + Addend =3D (-58); + Status =3D SafeInt8Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-116), Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a; + Addend =3D 0x5a; + Status =3D SafeInt8Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Augend =3D (-90); + Addend =3D (-90); + Status =3D SafeInt8Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeInt8Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; + +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeChar8Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + CHAR8 Augend =3D 0x3a; + CHAR8 Addend =3D 0x3a; + CHAR8 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INT8 + // and doesn't underflow MIN_INT8, then it's addition + // + Status =3D SafeChar8Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a; + Addend =3D 0x5a; + Status =3D SafeChar8Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Augend =3D 0x85; + Addend =3D 58; + Status =3D SafeChar8Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Augend =3D 58; + Addend =3D 0x85; + Status =3D SafeChar8Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeChar8Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; + +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Augend =3D 0x3a3a; + INT16 Addend =3D 0x3a3a; + INT16 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INT16 + // and doesn't underflow MIN_INT16, then it's addition + // + Status =3D SafeInt16Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7474, Result); + + Augend =3D (-14906); + Addend =3D (-14906); + Status =3D SafeInt16Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-29812), Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a5a; + Addend =3D 0x5a5a; + Status =3D SafeInt16Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Augend =3D (-23130); + Addend =3D (-23130); + Status =3D SafeInt16Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeInt16Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Augend =3D 0x3a3a3a3a; + INT32 Addend =3D 0x3a3a3a3a; + INT32 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INT32 + // and doesn't underflow MIN_INT32, then it's addition + // + Status =3D SafeInt32Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74747474, Result); + + Augend =3D (-976894522); + Addend =3D (-976894522); + Status =3D SafeInt32Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-1953789044), Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a5a5a5a; + Addend =3D 0x5a5a5a5a; + Status =3D SafeInt32Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Augend =3D (-1515870810); + Addend =3D (-1515870810); + Status =3D SafeInt32Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeInt32Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64Add ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Augend =3D 0x3a3a3a3a3a3a3a3a; + INT64 Addend =3D 0x3a3a3a3a3a3a3a3a; + INT64 Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INT64 + // and doesn't underflow MIN_INT64, then it's addition + // + Status =3D SafeInt64Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7474747474747474, Result); + + Augend =3D (-4195730024608447034); + Addend =3D (-4195730024608447034); + Status =3D SafeInt64Add(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-8391460049216894068), Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a5a5a5a5a5a5a5a; + Addend =3D 0x5a5a5a5a5a5a5a5a; + Status =3D SafeInt64Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Augend =3D (-6510615555426900570); + Addend =3D (-6510615555426900570); + Status =3D SafeInt64Add(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Status =3D SafeInt64Add(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +// +// Subtraction function tests: +// +UNIT_TEST_STATUS +EFIAPI +TestSafeUint8Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT8 Minuend =3D 0x5a; + UINT8 Subtrahend =3D 0x3b; + UINT8 Result =3D 0; + + // + // If Minuend >=3D Subtrahend, then it's subtraction + // + Status =3D SafeUint8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x1f, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 0x5a; + Subtrahend =3D 0x6d; + Status =3D SafeUint8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUint8Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Minuend =3D 0x5a5a; + UINT16 Subtrahend =3D 0x3b3b; + UINT16 Result =3D 0; + + // + // If Minuend >=3D Subtrahend, then it's subtraction + // + Status =3D SafeUint16Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x1f1f, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 0x5a5a; + Subtrahend =3D 0x6d6d; + Status =3D SafeUint16Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeUint16Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Minuend =3D 0x5a5a5a5a; + UINT32 Subtrahend =3D 0x3b3b3b3b; + UINT32 Result =3D 0; + + // + // If Minuend >=3D Subtrahend, then it's subtraction + // + Status =3D SafeUint32Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x1f1f1f1f, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 0x5a5a5a5a; + Subtrahend =3D 0x6d6d6d6d; + Status =3D SafeUint32Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeUint32Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Minuend =3D 0x5a5a5a5a5a5a5a5a; + UINT64 Subtrahend =3D 0x3b3b3b3b3b3b3b3b; + UINT64 Result =3D 0; + + // + // If Minuend >=3D Subtrahend, then it's subtraction + // + Status =3D SafeUint64Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x1f1f1f1f1f1f1f1f, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 0x5a5a5a5a5a5a5a5a; + Subtrahend =3D 0x6d6d6d6d6d6d6d6d; + Status =3D SafeUint64Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeUint64Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Minuend =3D 0x5a; + INT8 Subtrahend =3D 0x3a; + INT8 Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INT8 or + // underflow MIN_INT8, then it's subtraction + // + Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x20, Result); + + Minuend =3D 58; + Subtrahend =3D 78; + Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-20), Result); + + // + // Otherwise should result in an error status + // + Minuend =3D (-80); + Subtrahend =3D 80; + Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Minuend =3D (80); + Subtrahend =3D (-80); + Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeInt8Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeChar8Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + CHAR8 Minuend =3D 0x5a; + CHAR8 Subtrahend =3D 0x3a; + CHAR8 Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INT8 or + // underflow MIN_INT8, then it's subtraction + // + Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x20, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 58; + Subtrahend =3D 78; + Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Minuend =3D 0x85; + Subtrahend =3D 80; + Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Minuend =3D (80); + Subtrahend =3D 0x85; + Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeChar8Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Minuend =3D 0x5a5a; + INT16 Subtrahend =3D 0x3a3a; + INT16 Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INT16 or + // underflow MIN_INT16, then it's subtraction + // + Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x2020, Result); + + Minuend =3D 0x3a3a; + Subtrahend =3D 0x5a5a; + Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-8224), Result); + + // + // Otherwise should result in an error status + // + Minuend =3D (-31354); + Subtrahend =3D 31354; + Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Minuend =3D (31354); + Subtrahend =3D (-31354); + Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeInt16Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Minuend =3D 0x5a5a5a5a; + INT32 Subtrahend =3D 0x3a3a3a3a; + INT32 Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INT32 or + // underflow MIN_INT32, then it's subtraction + // + Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x20202020, Result); + + Minuend =3D 0x3a3a3a3a; + Subtrahend =3D 0x5a5a5a5a; + Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-538976288), Result); + + // + // Otherwise should result in an error status + // + Minuend =3D (-2054847098); + Subtrahend =3D 2054847098; + Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Minuend =3D (2054847098); + Subtrahend =3D (-2054847098); + Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeInt32Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64Sub ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Minuend =3D 0x5a5a5a5a5a5a5a5a; + INT64 Subtrahend =3D 0x3a3a3a3a3a3a3a3a; + INT64 Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INT64 or + // underflow MIN_INT64, then it's subtraction + // + Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x2020202020202020, Result); + + Minuend =3D 0x3a3a3a3a3a3a3a3a; + Subtrahend =3D 0x5a5a5a5a5a5a5a5a; + Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-2314885530818453536), Result); + + // + // Otherwise should result in an error status + // + Minuend =3D (-8825501086245354106); + Subtrahend =3D 8825501086245354106; + Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Minuend =3D (8825501086245354106); + Subtrahend =3D (-8825501086245354106); + Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Status =3D SafeInt64Sub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +// +// Multiplication function tests: +// +UNIT_TEST_STATUS +EFIAPI +TestSafeUint8Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT8 Multiplicand =3D 0x12; + UINT8 Multiplier =3D 0xa; + UINT8 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_UINT8, it will s= ucceed + // + Status =3D SafeUint8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xb4, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x12; + Multiplier =3D 0x23; + Status =3D SafeUint8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT8_ERROR, Result); + + Status =3D SafeUint8Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint16Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT16 Multiplicand =3D 0x212; + UINT16 Multiplier =3D 0x7a; + UINT16 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_UINT16, it will = succeed + // + Status =3D SafeUint16Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xfc94, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x1234; + Multiplier =3D 0x213; + Status =3D SafeUint16Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT16_ERROR, Result); + + Status =3D SafeUint16Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Multiplicand =3D 0xa122a; + UINT32 Multiplier =3D 0xd23; + UINT32 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_UINT32, it will = succeed + // + Status =3D SafeUint32Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x844c9dbe, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0xa122a; + Multiplier =3D 0xed23; + Status =3D SafeUint32Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeUint32Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Multiplicand =3D 0x123456789a; + UINT64 Multiplier =3D 0x1234567; + UINT64 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_UINT64, it will = succeed + // + Status =3D SafeUint64Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x14b66db9745a07f6, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123456789a; + Multiplier =3D 0x12345678; + Status =3D SafeUint64Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT64_ERROR, Result); + + Status =3D SafeUint64Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt8Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT8 Multiplicand =3D 0x12; + INT8 Multiplier =3D 0x7; + INT8 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INT8 and doesn't + // underflow MIN_UINT8, it will succeed + // + Status =3D SafeInt8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7e, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x12; + Multiplier =3D 0xa; + Status =3D SafeInt8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT8_ERROR, Result); + + Status =3D SafeInt8Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeChar8Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + CHAR8 Multiplicand =3D 0x12; + CHAR8 Multiplier =3D 0x7; + CHAR8 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INT8 and doesn't + // underflow MIN_UINT8, it will succeed + // + Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7e, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x12; + Multiplier =3D 0xa; + Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Multiplicand =3D 0x85; + Multiplier =3D 5; + Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Multiplicand =3D 5; + Multiplier =3D 0x85; + Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + + Status =3D SafeChar8Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt16Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT16 Multiplicand =3D 0x123; + INT16 Multiplier =3D 0x67; + INT16 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INT16 and doesn't + // underflow MIN_UINT16, it will succeed + // + Status =3D SafeInt16Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7515, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123; + Multiplier =3D 0xab; + Status =3D SafeInt16Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT16_ERROR, Result); + + Status =3D SafeInt16Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Multiplicand =3D 0x123456; + INT32 Multiplier =3D 0x678; + INT32 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INT32 and doesn't + // underflow MIN_UINT32, it will succeed + // + Status =3D SafeInt32Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x75c28c50, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123456; + Multiplier =3D 0xabc; + Status =3D SafeInt32Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeInt32Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64Mult ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Multiplicand =3D 0x123456789; + INT64 Multiplier =3D 0x6789abcd; + INT64 Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INT64 and doesn't + // underflow MIN_UINT64, it will succeed + // + Status =3D SafeInt64Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x75cd9045220d6bb5, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123456789; + Multiplier =3D 0xa789abcd; + Status =3D SafeInt64Mult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Status =3D SafeInt64Mult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + + + +/** + + Main fuction sets up the unit test environment + +**/ +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE* SystemTable + ) +{ + EFI_STATUS Status; + UNIT_TEST_FRAMEWORK *Fw =3D NULL; + UNIT_TEST_SUITE *ConversionTestSuite; + UNIT_TEST_SUITE *AdditionSubtractionTestSuite; + UNIT_TEST_SUITE *MultiplicationTestSuite; + CHAR16 ShortName[100]; + ShortName[0] =3D L'\0'; + + UnicodeSPrint(&ShortName[0], sizeof(ShortName), L"%a", gEfiCallerBaseNam= e); + DEBUG((DEBUG_INFO, "%s v%s\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION= )); + + // + // Start setting up the test framework for running the tests. + // + Status =3D InitUnitTestFramework(&Fw, UNIT_TEST_APP_NAME, ShortName, UNI= T_TEST_APP_VERSION); + if (EFI_ERROR(Status)) + { + DEBUG((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r\n"= , Status)); + goto EXIT; + } + + /// + // Test the conversion functions + // + Status =3D CreateUnitTestSuite(&ConversionTestSuite, Fw, L"Int Safe Conv= ersions Test Suite", L"Common.IntSafe.Convert", NULL, NULL); + if (EFI_ERROR(Status)) + { + DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Conversions Tes= t Suite\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint8", L"Common.In= tSafe.Convert.TestSafeInt8ToUint8", TestSafeInt8ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt8ToChar8", L"Common.In= tSafe.Convert.TestSafeInt8ToChar8", TestSafeInt8ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint16", L"Common.In= tSafe.Convert.TestSafeInt8ToUint16", TestSafeInt8ToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint32", L"Common.In= tSafe.Convert.TestSafeInt8ToUint32", TestSafeInt8ToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUintn", L"Common.In= tSafe.Convert.TestSafeInt8ToUintn", TestSafeInt8ToUintn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint64", L"Common.In= tSafe.Convert.TestSafeInt8ToUint64", TestSafeInt8ToUint64, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint8ToInt8", L"Common.In= tSafe.Convert.TestSafeUint8ToInt8", TestSafeUint8ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint8ToChar8", L"Common.In= tSafe.Convert.TestSafeUint8ToChar8", TestSafeUint8ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToInt8", L"Common.In= tSafe.Convert.TestSafeInt16ToInt8", TestSafeInt16ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToChar8", L"Common.In= tSafe.Convert.TestSafeInt16ToChar8", TestSafeInt16ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint8", L"Common.In= tSafe.Convert.TestSafeInt16ToUint8", TestSafeInt16ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint16", L"Common.In= tSafe.Convert.TestSafeInt16ToUint16", TestSafeInt16ToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint32", L"Common.In= tSafe.Convert.TestSafeInt16ToUint32", TestSafeInt16ToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUintn", L"Common.In= tSafe.Convert.TestSafeInt16ToUintn", TestSafeInt16ToUintn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint64", L"Common.In= tSafe.Convert.TestSafeInt16ToUint64", TestSafeInt16ToUint64, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint16ToInt8", L"Common.In= tSafe.Convert.TestSafeUint16ToInt8", TestSafeUint16ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint16ToChar8", L"Common.In= tSafe.Convert.TestSafeUint16ToChar8", TestSafeUint16ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint16ToUint8", L"Common.In= tSafe.Convert.TestSafeUint16ToUint8", TestSafeUint16ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint16ToInt16", L"Common.In= tSafe.Convert.TestSafeUint16ToInt16", TestSafeUint16ToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToInt8", L"Common.In= tSafe.Convert.TestSafeInt32ToInt8", TestSafeInt32ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToChar8", L"Common.In= tSafe.Convert.TestSafeInt32ToChar8", TestSafeInt32ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint8", L"Common.In= tSafe.Convert.TestSafeInt32ToUint8", TestSafeInt32ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToInt16", L"Common.In= tSafe.Convert.TestSafeInt32ToInt16", TestSafeInt32ToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint16", L"Common.In= tSafe.Convert.TestSafeInt32ToUint16", TestSafeInt32ToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint32", L"Common.In= tSafe.Convert.TestSafeInt32ToUint32", TestSafeInt32ToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUintn", L"Common.In= tSafe.Convert.TestSafeInt32ToUintn", TestSafeInt32ToUintn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint64", L"Common.In= tSafe.Convert.TestSafeInt32ToUint64", TestSafeInt32ToUint64, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToInt8", L"Common.In= tSafe.Convert.TestSafeUint32ToInt8", TestSafeUint32ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToChar8", L"Common.In= tSafe.Convert.TestSafeUint32ToChar8", TestSafeUint32ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToUint8", L"Common.In= tSafe.Convert.TestSafeUint32ToUint8", TestSafeUint32ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToInt16", L"Common.In= tSafe.Convert.TestSafeUint32ToInt16", TestSafeUint32ToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToUint16", L"Common.In= tSafe.Convert.TestSafeUint32ToUint16", TestSafeUint32ToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToInt32", L"Common.In= tSafe.Convert.TestSafeUint32ToInt32", TestSafeUint32ToInt32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint32ToIntn", L"Common.In= tSafe.Convert.TestSafeUint32ToIntn", TestSafeUint32ToIntn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToInt8", L"Common.In= tSafe.Convert.TestSafeIntnToInt8", TestSafeIntnToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToChar8", L"Common.In= tSafe.Convert.TestSafeIntnToChar8", TestSafeIntnToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint8", L"Common.In= tSafe.Convert.TestSafeIntnToUint8", TestSafeIntnToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToInt16", L"Common.In= tSafe.Convert.TestSafeIntnToInt16", TestSafeIntnToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint16", L"Common.In= tSafe.Convert.TestSafeIntnToUint16", TestSafeIntnToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToInt32", L"Common.In= tSafe.Convert.TestSafeIntnToInt32", TestSafeIntnToInt32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint32", L"Common.In= tSafe.Convert.TestSafeIntnToUint32", TestSafeIntnToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToUintn", L"Common.In= tSafe.Convert.TestSafeIntnToUintn", TestSafeIntnToUintn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint64", L"Common.In= tSafe.Convert.TestSafeIntnToUint64", TestSafeIntnToUint64, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt8", L"Common.In= tSafe.Convert.TestSafeUintnToInt8", TestSafeUintnToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToChar8", L"Common.In= tSafe.Convert.TestSafeUintnToChar8", TestSafeUintnToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToUint8", L"Common.In= tSafe.Convert.TestSafeUintnToUint8", TestSafeUintnToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt16", L"Common.In= tSafe.Convert.TestSafeUintnToInt16", TestSafeUintnToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToUint16", L"Common.In= tSafe.Convert.TestSafeUintnToUint16", TestSafeUintnToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt32", L"Common.In= tSafe.Convert.TestSafeUintnToInt32", TestSafeUintnToInt32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToUint32", L"Common.In= tSafe.Convert.TestSafeUintnToUint32", TestSafeUintnToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToIntn", L"Common.In= tSafe.Convert.TestSafeUintnToIntn", TestSafeUintnToIntn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt64", L"Common.In= tSafe.Convert.TestSafeUintnToInt64", TestSafeUintnToInt64, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToInt8", L"Common.In= tSafe.Convert.TestSafeInt64ToInt8", TestSafeInt64ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToChar8", L"Common.In= tSafe.Convert.TestSafeInt64ToChar8", TestSafeInt64ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint8", L"Common.In= tSafe.Convert.TestSafeInt64ToUint8", TestSafeInt64ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToInt16", L"Common.In= tSafe.Convert.TestSafeInt64ToInt16", TestSafeInt64ToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint16", L"Common.In= tSafe.Convert.TestSafeInt64ToUint16", TestSafeInt64ToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToInt32", L"Common.In= tSafe.Convert.TestSafeInt64ToInt32", TestSafeInt64ToInt32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint32", L"Common.In= tSafe.Convert.TestSafeInt64ToUint32", TestSafeInt64ToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToIntn", L"Common.In= tSafe.Convert.TestSafeInt64ToIntn", TestSafeInt64ToIntn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUintn", L"Common.In= tSafe.Convert.TestSafeInt64ToUintn", TestSafeInt64ToUintn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint64", L"Common.In= tSafe.Convert.TestSafeInt64ToUint64", TestSafeInt64ToUint64, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt8", L"Common.In= tSafe.Convert.TestSafeUint64ToInt8", TestSafeUint64ToInt8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToChar8", L"Common.In= tSafe.Convert.TestSafeUint64ToChar8", TestSafeUint64ToChar8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUint8", L"Common.In= tSafe.Convert.TestSafeUint64ToUint8", TestSafeUint64ToUint8, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt16", L"Common.In= tSafe.Convert.TestSafeUint64ToInt16", TestSafeUint64ToInt16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUint16", L"Common.In= tSafe.Convert.TestSafeUint64ToUint16", TestSafeUint64ToUint16, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt32", L"Common.In= tSafe.Convert.TestSafeUint64ToInt32", TestSafeUint64ToInt32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUint32", L"Common.In= tSafe.Convert.TestSafeUint64ToUint32", TestSafeUint64ToUint32, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToIntn", L"Common.In= tSafe.Convert.TestSafeUint64ToIntn", TestSafeUint64ToIntn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUintn", L"Common.In= tSafe.Convert.TestSafeUint64ToUintn", TestSafeUint64ToUintn, NULL, NULL, = NULL); + AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt64", L"Common.In= tSafe.Convert.TestSafeUint64ToInt64", TestSafeUint64ToInt64, NULL, NULL, = NULL); + + // + // Test the addition and subtraction functions + // + Status =3D CreateUnitTestSuite(&AdditionSubtractionTestSuite, Fw, L"Int = Safe Add/Subtract Test Suite", L"Common.IntSafe.AddSubtract", NULL, NULL); + if (EFI_ERROR(Status)) + { + DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Add/Su= btract Test Suite\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint8Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint8Add", TestSafeUint8Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint16Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint16Add", TestSafeUint16Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint32Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint32Add", TestSafeUint32Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUintnAdd", L"Commo= n.IntSafe.AddSubtract.TestSafeUintnAdd", TestSafeUintnAdd, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint64Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint64Add", TestSafeUint64Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt8Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt8Add", TestSafeInt8Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeChar8Add", L"Commo= n.IntSafe.AddSubtract.TestSafeChar8Add", TestSafeChar8Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt16Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt16Add", TestSafeInt16Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt32Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt32Add", TestSafeInt32Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeIntnAdd", L"Commo= n.IntSafe.AddSubtract.TestSafeIntnAdd", TestSafeIntnAdd, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt64Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt64Add", TestSafeInt64Add, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint8Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint8Sub", TestSafeUint8Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint16Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint16Sub", TestSafeUint16Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint32Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint32Sub", TestSafeUint32Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUintnSub", L"Commo= n.IntSafe.AddSubtract.TestSafeUintnSub", TestSafeUintnSub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint64Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint64Sub", TestSafeUint64Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt8Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt8Sub", TestSafeInt8Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeChar8Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeChar8Sub", TestSafeChar8Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt16Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt16Sub", TestSafeInt16Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt32Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt32Sub", TestSafeInt32Sub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeIntnSub", L"Commo= n.IntSafe.AddSubtract.TestSafeIntnSub", TestSafeIntnSub, NULL, NULL, NU= LL); + AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt64Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt64Sub", TestSafeInt64Sub, NULL, NULL, NU= LL); + + // + // Test the multiplication functions + // + Status =3D CreateUnitTestSuite(&MultiplicationTestSuite, Fw, L"Int Safe = Multiply Test Suite", L"Common.IntSafe.Multiply", NULL, NULL); + if (EFI_ERROR(Status)) + { + DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Multip= ly Test Suite\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + AddTestCase(MultiplicationTestSuite, L"Test SafeUint8Mult", L"Common.In= tSafe.Multiply.TestSafeUint8Mult", TestSafeUint8Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeUint16Mult", L"Common.In= tSafe.Multiply.TestSafeUint16Mult", TestSafeUint16Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeUint32Mult", L"Common.In= tSafe.Multiply.TestSafeUint32Mult", TestSafeUint32Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeUintnMult", L"Common.In= tSafe.Multiply.TestSafeUintnMult", TestSafeUintnMult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeUint64Mult", L"Common.In= tSafe.Multiply.TestSafeUint64Mult", TestSafeUint64Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeInt8Mult", L"Common.In= tSafe.Multiply.TestSafeInt8Mult", TestSafeInt8Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeChar8Mult", L"Common.In= tSafe.Multiply.TestSafeChar8Mult", TestSafeChar8Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeInt16Mult", L"Common.In= tSafe.Multiply.TestSafeInt16Mult", TestSafeInt16Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeInt32Mult", L"Common.In= tSafe.Multiply.TestSafeInt32Mult", TestSafeInt32Mult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeIntnMult", L"Common.In= tSafe.Multiply.TestSafeIntnMult", TestSafeIntnMult, NULL, NULL, NULL); + AddTestCase(MultiplicationTestSuite, L"Test SafeInt64Mult", L"Common.In= tSafe.Multiply.TestSafeInt64Mult", TestSafeInt64Mult, NULL, NULL, NULL); + + // + // Execute the tests. + // + Status =3D RunAllTestSuites(Fw); + +EXIT: + if (Fw) + { + FreeUnitTestFramework(Fw); + } + + return Status; +} diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.h b/MdePkgUnitTe= st/SafeIntLib/SafeIntLibUnitTests.h new file mode 100644 index 0000000000..749e9cd7b1 --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.h @@ -0,0 +1,155 @@ +/** @file + UEFI Shell based application for unit testing the SafeIntLib. + + Copyright (c) 2017, Microsoft Corporation + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are m= et: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright not= ice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS = IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IM= PLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE D= ISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY= DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCL= UDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF= USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY TH= EORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEG= LIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUintn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToIntn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToInt32( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUint32( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToUint32( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToIntn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToInt64( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToIntn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUintn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToIntn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToUintn( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnAdd( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnAdd( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnSub( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnSub( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnMult( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnMult( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ); diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.inf b/MdePkgUnit= Test/SafeIntLib/SafeIntLibUnitTests.inf new file mode 100644 index 0000000000..ce16773ba0 --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.inf @@ -0,0 +1,69 @@ +## @file +# Uefi Shell based Application that Unit Tests the SafeIntLib +# +# Copyright (c) 2017, Microsoft Corporation + +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are m= et: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright not= ice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS = IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IM= PLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE D= ISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY= DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCL= UDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF= USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY TH= EORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEG= LIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SafeIntLibUnitTestApp + FILE_GUID =3D 9D783A1B-4593-49BA-8511-363FE72156D1 + MODULE_TYPE =3D UEFI_APPLICATION + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D UefiMain + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + SafeIntLibUnitTests.c + SafeIntLibUnitTests.h + +[Sources.IA32, Sources.ARM] + SafeIntLibUnitTests32.c + SafeIntLibUintnIntnUnitTests32.c + +[Sources.X64, Sources.IPF, Sources.AARCH64] + SafeIntLibUnitTests64.c + SafeIntLibUintnIntnUnitTests64.c + +[Sources.EBC] + SafeIntLibUnitTests32.c + SafeIntLibUnitTests64.c + SafeIntLibUintnIntnUnitTestsEbc.c + +[Packages] + MdePkg/MdePkg.dec + MsUnitTestPkg/MsUnitTestPkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + BaseLib + SafeIntLib + UnitTestLib + UnitTestAssertLib + PrintLib diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c b/MdePkgUnit= Test/SafeIntLib/SafeIntLibUnitTests32.c new file mode 100644 index 0000000000..242773b487 --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c @@ -0,0 +1,595 @@ +/** @file + 32-bit specific functions for unit-testing INTN and UINTN functions in + SafeIntLib. + + Copyright (c) 2017, Microsoft Corporation + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are m= et: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright not= ice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS = IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IM= PLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE D= ISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY= DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCL= UDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF= USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY TH= EORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEG= LIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include "SafeIntLibUnitTests.h" + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUintn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5bababab; + UINTN Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt32ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeInt32ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeInt32ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToIntn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0x5bababab; + INTN Result =3D 0; + + // + // If Operand is <=3D MAX_INTN, then it's a cast + // + Status =3D SafeUint32ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUint32ToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeUint32ToIntn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToInt32_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5bababab; + INT32 Result =3D 0; + + // + // INTN is same as INT32 in IA32, so this is just a cast + // + Status =3D SafeIntnToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUint32_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5bababab; + UINT32 Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeIntnToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeIntnToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeIntnToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToUint32_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0xabababab; + UINT32 Result =3D 0; + + // + // UINTN is same as UINT32 in IA32, so this is just a cast + // + Status =3D SafeUintnToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToIntn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5bababab; + INTN Result =3D 0; + + // + // If Operand is <=3D MAX_INTN, then it's a cast + // + Status =3D SafeUintnToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xabababab); + Status =3D SafeUintnToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeUintnToIntn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToInt64_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0xabababab; + INT64 Result =3D 0; + + // + // UINTN is same as UINT32 in IA32, and UINT32 is a subset of + // INT64, so this is just a cast + // + Status =3D SafeUintnToInt64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToIntn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5bababab; + INTN Result =3D 0; + + // + // If Operand is between MIN_INTN and MAX_INTN2 inclusive, then it's a = cast + // + Status =3D SafeInt64ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + Operand =3D (-1537977259); + Status =3D SafeInt64ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-1537977259), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeInt64ToIntn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUintn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0xabababab; + UINTN Result =3D 0; + + // + // If Operand is between 0 and MAX_UINTN inclusive, then it's a cast + // + Status =3D SafeInt64ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeInt64ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeInt64ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToIntn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5bababab; + INTN Result =3D 0; + + // + // If Operand is <=3D MAX_INTN, then it's a cast + // + Status =3D SafeUint64ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeUint64ToIntn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToUintn_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0xabababab; + UINTN Result =3D 0; + + // + // If Operand is <=3D MAX_UINTN, then it's a cast + // + Status =3D SafeUint64ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUint64ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnAdd_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Augend =3D 0x3a3a3a3a; + UINTN Addend =3D 0x3a3a3a3a; + UINTN Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_UINTN, then it's addit= ion + // + Status =3D SafeUintnAdd(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74747474, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0xabababab; + Addend =3D 0xbcbcbcbc; + Status =3D SafeUintnAdd(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUintnAdd(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnAdd_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Augend =3D 0x3a3a3a3a; + INTN Addend =3D 0x3a3a3a3a; + INTN Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INTN + // and doesn't underflow MIN_INTN, then it's addition + // + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x74747474, Result); + + Augend =3D (-976894522); + Addend =3D (-976894522); + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-1953789044), Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a5a5a5a; + Addend =3D 0x5a5a5a5a; + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Augend =3D (-1515870810); + Addend =3D (-1515870810); + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeIntnAdd(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnSub_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Minuend =3D 0x5a5a5a5a; + UINTN Subtrahend =3D 0x3b3b3b3b; + UINTN Result =3D 0; + + // + // If Minuend >=3D Subtrahend, then it's subtraction + // + Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x1f1f1f1f, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 0x5a5a5a5a; + Subtrahend =3D 0x6d6d6d6d; + Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUintnSub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnSub_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Minuend =3D 0x5a5a5a5a; + INTN Subtrahend =3D 0x3a3a3a3a; + INTN Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INTN or + // underflow MIN_INTN, then it's subtraction + // + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x20202020, Result); + + Minuend =3D 0x3a3a3a3a; + Subtrahend =3D 0x5a5a5a5a; + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-538976288), Result); + + // + // Otherwise should result in an error status + // + Minuend =3D (-2054847098); + Subtrahend =3D 2054847098; + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Minuend =3D (2054847098); + Subtrahend =3D (-2054847098); + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeIntnSub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnMult_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Multiplicand =3D 0xa122a; + UINTN Multiplier =3D 0xd23; + UINTN Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_UINTN, it will s= ucceed + // + Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x844c9dbe, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0xa122a; + Multiplier =3D 0xed23; + Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUintnMult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnMult_32 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Multiplicand =3D 0x123456; + INTN Multiplier =3D 0x678; + INTN Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INTN and doesn't + // underflow MIN_UINTN, it will succeed + // + Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x75c28c50, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123456; + Multiplier =3D 0xabc; + Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeIntnMult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c b/MdePkgUnit= Test/SafeIntLib/SafeIntLibUnitTests64.c new file mode 100644 index 0000000000..59eb4f72d6 --- /dev/null +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c @@ -0,0 +1,599 @@ +/** @file + 64-bit specific functions for unit-testing INTN and UINTN functions in + SafeIntLib. + + Copyright (c) 2017, Microsoft Corporation + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are m= et: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright not= ice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS = IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IM= PLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE D= ISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY= DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCL= UDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF= USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY TH= EORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEG= LIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include "SafeIntLibUnitTests.h" + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt32ToUintn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT32 Operand =3D 0x5bababab; + UINTN Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt32ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-1537977259); + Status =3D SafeInt32ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeInt32ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint32ToIntn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT32 Operand =3D 0xabababab; + INTN Result =3D 0; + + // + // For x64, INTN is same as INT64 which is a superset of INT32 + // This is just a cast then, and it'll never fail + // + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeUint32ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToInt32_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0x5bababab; + INT32 Result =3D 0; + + // + // If Operand is between MIN_INT32 and MAX_INT32 inclusive, then it's a= cast + // + Status =3D SafeIntnToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5bababab, Result); + + Operand =3D (-1537977259); + Status =3D SafeIntnToInt32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-1537977259), Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeIntnToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeIntnToInt32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT32_ERROR, Result); + + Status =3D SafeIntnToInt32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnToUint32_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Operand =3D 0xabababab; + UINT32 Result =3D 0; + + // + // If Operand is between 0 and MAX_UINT32 inclusive, then it's a cast + // + Status =3D SafeIntnToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0x5babababefefefef); + Status =3D SafeIntnToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Operand =3D (-6605562033422200815); + Status =3D SafeIntnToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeIntnToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToUint32_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0xabababab; + UINT32 Result =3D 0; + + // + // If Operand is <=3D MAX_UINT32, then it's a cast + // + Status =3D SafeUintnToUint32(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xabababab, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUintnToUint32(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINT32_ERROR, Result); + + Status =3D SafeUintnToUint32(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToIntn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5babababefefefef; + INTN Result =3D 0; + + // + // If Operand is <=3D MAX_INTN (0x7fff_ffff_ffff_ffff), then it's a cast + // + Status =3D SafeUintnToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUintnToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeUintnToIntn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnToInt64_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Operand =3D 0x5babababefefefef; + INT64 Result =3D 0; + + // + // If Operand is <=3D MAX_INT64, then it's a cast + // + Status =3D SafeUintnToInt64(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUintnToInt64(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INT64_ERROR, Result); + + Status =3D SafeUintnToInt64(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToIntn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5babababefefefef; + INTN Result =3D 0; + + // + // INTN is same as INT64 in x64, so this is just a cast + // + Status =3D SafeInt64ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeInt64ToUintn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INT64 Operand =3D 0x5babababefefefef; + UINTN Result =3D 0; + + // + // If Operand is non-negative, then it's a cast + // + Status =3D SafeInt64ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (-6605562033422200815); + Status =3D SafeInt64ToUintn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeInt64ToUintn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToIntn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0x5babababefefefef; + INTN Result =3D 0; + + // + // If Operand is <=3D MAX_INTN (0x7fff_ffff_ffff_ffff), then it's a cast + // + Status =3D SafeUint64ToIntn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x5babababefefefef, Result); + + // + // Otherwise should result in an error status + // + Operand =3D (0xababababefefefef); + Status =3D SafeUint64ToIntn(Operand, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeUint64ToIntn(Operand, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUint64ToUintn_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINT64 Operand =3D 0xababababefefefef; + UINTN Result =3D 0; + + // + // UINTN is same as UINT64 in x64, so this is just a cast + // + Status =3D SafeUint64ToUintn(Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0xababababefefefef, Result); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnAdd_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Augend =3D 0x3a3a3a3a12121212; + UINTN Addend =3D 0x3a3a3a3a12121212; + UINTN Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_UINTN, then it's addit= ion + // + Status =3D SafeUintnAdd(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7474747424242424, Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0xababababefefefef; + Addend =3D 0xbcbcbcbcdededede; + Status =3D SafeUintnAdd(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUintnAdd(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnAdd_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Augend =3D 0x3a3a3a3a3a3a3a3a; + INTN Addend =3D 0x3a3a3a3a3a3a3a3a; + INTN Result =3D 0; + + // + // If the result of addition doesn't overflow MAX_INTN + // and doesn't underflow MIN_INTN, then it's addition + // + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x7474747474747474, Result); + + Augend =3D (-4195730024608447034); + Addend =3D (-4195730024608447034); + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-8391460049216894068), Result); + + // + // Otherwise should result in an error status + // + Augend =3D 0x5a5a5a5a5a5a5a5a; + Addend =3D 0x5a5a5a5a5a5a5a5a; + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Augend =3D (-6510615555426900570); + Addend =3D (-6510615555426900570); + Status =3D SafeIntnAdd(Augend, Addend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeIntnAdd(Augend, Addend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnSub_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Minuend =3D 0x5a5a5a5a5a5a5a5a; + UINTN Subtrahend =3D 0x3b3b3b3b3b3b3b3b; + UINTN Result =3D 0; + + // + // If Minuend >=3D Subtrahend, then it's subtraction + // + Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x1f1f1f1f1f1f1f1f, Result); + + // + // Otherwise should result in an error status + // + Minuend =3D 0x5a5a5a5a5a5a5a5a; + Subtrahend =3D 0x6d6d6d6d6d6d6d6d; + Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUintnSub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnSub_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Minuend =3D 0x5a5a5a5a5a5a5a5a; + INTN Subtrahend =3D 0x3a3a3a3a3a3a3a3a; + INTN Result =3D 0; + + // + // If the result of subtractions doesn't overflow MAX_INTN or + // underflow MIN_INTN, then it's subtraction + // + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x2020202020202020, Result); + + Minuend =3D 0x3a3a3a3a3a3a3a3a; + Subtrahend =3D 0x5a5a5a5a5a5a5a5a; + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL((-2314885530818453536), Result); + + // + // Otherwise should result in an error status + // + Minuend =3D (-8825501086245354106); + Subtrahend =3D 8825501086245354106; + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Minuend =3D (8825501086245354106); + Subtrahend =3D (-8825501086245354106); + Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeIntnSub(Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeUintnMult_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN Multiplicand =3D 0x123456789a; + UINTN Multiplier =3D 0x1234567; + UINTN Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_UINTN, it will s= ucceed + // + Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x14b66db9745a07f6, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123456789a; + Multiplier =3D 0x12345678; + Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(UINTN_ERROR, Result); + + Status =3D SafeUintnMult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +TestSafeIntnMult_64 ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + INTN Multiplicand =3D 0x123456789; + INTN Multiplier =3D 0x6789abcd; + INTN Result =3D 0; + + // + // If the result of multiplication doesn't overflow MAX_INTN and doesn't + // underflow MIN_UINTN, it will succeed + // + Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR(Status); + UT_ASSERT_EQUAL(0x75cd9045220d6bb5, Result); + + // + // Otherwise should result in an error status + // + Multiplicand =3D 0x123456789; + Multiplier =3D 0xa789abcd; + Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL(INTN_ERROR, Result); + + Status =3D SafeIntnMult(Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + + return UNIT_TEST_PASSED; +} --=20 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 04:22:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513728980437683.0503325596289; Tue, 19 Dec 2017 16:16:20 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A7D93221C1945; Tue, 19 Dec 2017 16:11:29 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5B1A021CB867E for ; Tue, 19 Dec 2017 16:11:27 -0800 (PST) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2017 16:16:13 -0800 Received: from mdkinney-mobl2.amr.corp.intel.com ([10.241.98.58]) by fmsmga007.fm.intel.com with ESMTP; 19 Dec 2017 16:16:12 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=michael.d.kinney@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,429,1508828400"; d="scan'208";a="3742585" From: "Kinney, Michael D" To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 16:16:07 -0800 Message-Id: <20171220001607.22736-3-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.14.2.windows.3 In-Reply-To: <20171220001607.22736-1-michael.d.kinney@intel.com> References: <20171220001607.22736-1-michael.d.kinney@intel.com> Subject: [edk2] [staging/edk2-test Patch 2/2] MdePkgUnitTest: Fix EDK II style issues X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Sean Brogan Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney Reviewed-by: Sean Brogan --- .../SafeIntLib/SafeIntLibUintnIntnUnitTests32.c | 60 +- .../SafeIntLib/SafeIntLibUintnIntnUnitTests64.c | 60 +- .../SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c | 84 +- MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c | 2625 +++++++++++-----= ---- MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c | 404 +-- MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c | 404 +-- 6 files changed, 1967 insertions(+), 1670 deletions(-) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c b/M= dePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c index 632ddbbfef..2e39ee23ea 100644 --- a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests32.c @@ -17,38 +17,38 @@ =20 #include "SafeIntLibUnitTests.h" =20 -#define _UNIT_TEST_32_BIT(CaseName) \ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName##_32 ( \ +#define _UNIT_TEST_32_BIT(CaseName) \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_32 ( \ IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ); \ -\ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName ( \ + IN UNIT_TEST_CONTEXT Context \ + ); \ + \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName ( \ IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ) \ -{ \ + IN UNIT_TEST_CONTEXT Context \ + ) \ +{ \ return CaseName##_32(Framework, Context); \ } =20 -_UNIT_TEST_32_BIT(TestSafeInt32ToUintn) -_UNIT_TEST_32_BIT(TestSafeUint32ToIntn) -_UNIT_TEST_32_BIT(TestSafeIntnToInt32) -_UNIT_TEST_32_BIT(TestSafeIntnToUint32) -_UNIT_TEST_32_BIT(TestSafeUintnToUint32) -_UNIT_TEST_32_BIT(TestSafeUintnToIntn) -_UNIT_TEST_32_BIT(TestSafeUintnToInt64) -_UNIT_TEST_32_BIT(TestSafeInt64ToIntn) -_UNIT_TEST_32_BIT(TestSafeInt64ToUintn) -_UNIT_TEST_32_BIT(TestSafeUint64ToIntn) -_UNIT_TEST_32_BIT(TestSafeUint64ToUintn) -_UNIT_TEST_32_BIT(TestSafeUintnAdd) -_UNIT_TEST_32_BIT(TestSafeIntnAdd) -_UNIT_TEST_32_BIT(TestSafeUintnSub) -_UNIT_TEST_32_BIT(TestSafeIntnSub) -_UNIT_TEST_32_BIT(TestSafeUintnMult) -_UNIT_TEST_32_BIT(TestSafeIntnMult) +_UNIT_TEST_32_BIT (TestSafeInt32ToUintn) +_UNIT_TEST_32_BIT (TestSafeUint32ToIntn) +_UNIT_TEST_32_BIT (TestSafeIntnToInt32) +_UNIT_TEST_32_BIT (TestSafeIntnToUint32) +_UNIT_TEST_32_BIT (TestSafeUintnToUint32) +_UNIT_TEST_32_BIT (TestSafeUintnToIntn) +_UNIT_TEST_32_BIT (TestSafeUintnToInt64) +_UNIT_TEST_32_BIT (TestSafeInt64ToIntn) +_UNIT_TEST_32_BIT (TestSafeInt64ToUintn) +_UNIT_TEST_32_BIT (TestSafeUint64ToIntn) +_UNIT_TEST_32_BIT (TestSafeUint64ToUintn) +_UNIT_TEST_32_BIT (TestSafeUintnAdd) +_UNIT_TEST_32_BIT (TestSafeIntnAdd) +_UNIT_TEST_32_BIT (TestSafeUintnSub) +_UNIT_TEST_32_BIT (TestSafeIntnSub) +_UNIT_TEST_32_BIT (TestSafeUintnMult) +_UNIT_TEST_32_BIT (TestSafeIntnMult) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c b/M= dePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c index 462f93e351..7d62b599ad 100644 --- a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTests64.c @@ -17,38 +17,38 @@ =20 #include "SafeIntLibUnitTests.h" =20 -#define _UNIT_TEST_64_BIT(CaseName) \ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName##_64 ( \ +#define _UNIT_TEST_64_BIT(CaseName) \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_64 ( \ IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ); \ -\ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName ( \ + IN UNIT_TEST_CONTEXT Context \ + ); \ + \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName ( \ IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ) \ -{ \ + IN UNIT_TEST_CONTEXT Context \ + ) \ +{ \ return CaseName##_64(Framework, Context); \ } =20 -_UNIT_TEST_64_BIT(TestSafeInt32ToUintn) -_UNIT_TEST_64_BIT(TestSafeUint32ToIntn) -_UNIT_TEST_64_BIT(TestSafeIntnToInt32) -_UNIT_TEST_64_BIT(TestSafeIntnToUint32) -_UNIT_TEST_64_BIT(TestSafeUintnToUint32) -_UNIT_TEST_64_BIT(TestSafeUintnToIntn) -_UNIT_TEST_64_BIT(TestSafeUintnToInt64) -_UNIT_TEST_64_BIT(TestSafeInt64ToIntn) -_UNIT_TEST_64_BIT(TestSafeInt64ToUintn) -_UNIT_TEST_64_BIT(TestSafeUint64ToIntn) -_UNIT_TEST_64_BIT(TestSafeUint64ToUintn) -_UNIT_TEST_64_BIT(TestSafeUintnAdd) -_UNIT_TEST_64_BIT(TestSafeIntnAdd) -_UNIT_TEST_64_BIT(TestSafeUintnSub) -_UNIT_TEST_64_BIT(TestSafeIntnSub) -_UNIT_TEST_64_BIT(TestSafeUintnMult) -_UNIT_TEST_64_BIT(TestSafeIntnMult) +_UNIT_TEST_64_BIT (TestSafeInt32ToUintn) +_UNIT_TEST_64_BIT (TestSafeUint32ToIntn) +_UNIT_TEST_64_BIT (TestSafeIntnToInt32) +_UNIT_TEST_64_BIT (TestSafeIntnToUint32) +_UNIT_TEST_64_BIT (TestSafeUintnToUint32) +_UNIT_TEST_64_BIT (TestSafeUintnToIntn) +_UNIT_TEST_64_BIT (TestSafeUintnToInt64) +_UNIT_TEST_64_BIT (TestSafeInt64ToIntn) +_UNIT_TEST_64_BIT (TestSafeInt64ToUintn) +_UNIT_TEST_64_BIT (TestSafeUint64ToIntn) +_UNIT_TEST_64_BIT (TestSafeUint64ToUintn) +_UNIT_TEST_64_BIT (TestSafeUintnAdd) +_UNIT_TEST_64_BIT (TestSafeIntnAdd) +_UNIT_TEST_64_BIT (TestSafeUintnSub) +_UNIT_TEST_64_BIT (TestSafeIntnSub) +_UNIT_TEST_64_BIT (TestSafeUintnMult) +_UNIT_TEST_64_BIT (TestSafeIntnMult) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c b/= MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c index e91811bc2f..98426f1c05 100644 --- a/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUintnIntnUnitTestsEbc.c @@ -17,49 +17,49 @@ =20 #include "SafeIntLibUnitTests.h" =20 -#define _EBC_UNIT_TEST(CaseName) \ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName##_32 ( \ - IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ); \ -\ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName##_64 ( \ - IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ); \ -\ -UNIT_TEST_STATUS \ -EFIAPI \ -CaseName ( \ - IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ - IN UNIT_TEST_CONTEXT Context \ - ) \ -{ \ - if (sizeof (UINTN) =3D=3D sizeof (UINT32)) { \ +#define _EBC_UNIT_TEST(CaseName) \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_32 ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ); \ + \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName##_64 ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ); \ + \ +UNIT_TEST_STATUS \ +EFIAPI \ +CaseName ( \ + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, \ + IN UNIT_TEST_CONTEXT Context \ + ) \ +{ \ + if (sizeof (UINTN) =3D=3D sizeof (UINT32)) { \ return CaseName##_32(Framework, Context); \ - } else { \ + } else { \ return CaseName##_64(Framework, Context); \ - } \ + } \ } =20 -_EBC_UNIT_TEST(TestSafeInt32ToUintn) -_EBC_UNIT_TEST(TestSafeUint32ToIntn) -_EBC_UNIT_TEST(TestSafeIntnToInt32) -_EBC_UNIT_TEST(TestSafeIntnToUint32) -_EBC_UNIT_TEST(TestSafeUintnToUint32) -_EBC_UNIT_TEST(TestSafeUintnToIntn) -_EBC_UNIT_TEST(TestSafeUintnToInt64) -_EBC_UNIT_TEST(TestSafeInt64ToIntn) -_EBC_UNIT_TEST(TestSafeInt64ToUintn) -_EBC_UNIT_TEST(TestSafeUint64ToIntn) -_EBC_UNIT_TEST(TestSafeUint64ToUintn) -_EBC_UNIT_TEST(TestSafeUintnAdd) -_EBC_UNIT_TEST(TestSafeIntnAdd) -_EBC_UNIT_TEST(TestSafeUintnSub) -_EBC_UNIT_TEST(TestSafeIntnSub) -_EBC_UNIT_TEST(TestSafeUintnMult) -_EBC_UNIT_TEST(TestSafeIntnMult) +_EBC_UNIT_TEST (TestSafeInt32ToUintn) +_EBC_UNIT_TEST (TestSafeUint32ToIntn) +_EBC_UNIT_TEST (TestSafeIntnToInt32) +_EBC_UNIT_TEST (TestSafeIntnToUint32) +_EBC_UNIT_TEST (TestSafeUintnToUint32) +_EBC_UNIT_TEST (TestSafeUintnToIntn) +_EBC_UNIT_TEST (TestSafeUintnToInt64) +_EBC_UNIT_TEST (TestSafeInt64ToIntn) +_EBC_UNIT_TEST (TestSafeInt64ToUintn) +_EBC_UNIT_TEST (TestSafeUint64ToIntn) +_EBC_UNIT_TEST (TestSafeUint64ToUintn) +_EBC_UNIT_TEST (TestSafeUintnAdd) +_EBC_UNIT_TEST (TestSafeIntnAdd) +_EBC_UNIT_TEST (TestSafeUintnSub) +_EBC_UNIT_TEST (TestSafeIntnSub) +_EBC_UNIT_TEST (TestSafeUintnMult) +_EBC_UNIT_TEST (TestSafeIntnMult) diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c b/MdePkgUnitTe= st/SafeIntLib/SafeIntLibUnitTests.c index 475c10c728..6640e3283a 100644 --- a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.c @@ -41,26 +41,28 @@ TestSafeInt8ToUint8 ( ) { EFI_STATUS Status; - INT8 Operand =3D 0x5b; - UINT8 Result =3D 0; + INT8 Operand; + UINT8 Result; =20 // // Positive UINT8 should result in just a cast // - Status =3D SafeInt8ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt8ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Negative number should result in an error status // Operand =3D (-56); - Status =3D SafeInt8ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt8ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeInt8ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -73,26 +75,28 @@ TestSafeInt8ToChar8 ( ) { EFI_STATUS Status; - INT8 Operand =3D 0x5b; - CHAR8 Result =3D 0; + INT8 Operand; + CHAR8 Result; =20 // // Positive INT8 should result in just a cast // - Status =3D SafeInt8ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt8ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Negative number should result in an error status // Operand =3D (-56); - Status =3D SafeInt8ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt8ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeInt8ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -105,26 +109,28 @@ TestSafeInt8ToUint16 ( ) { EFI_STATUS Status; - INT8 Operand =3D 0x5b; - UINT16 Result =3D 0; + INT8 Operand; + UINT16 Result; =20 // // Positive UINT8 should result in just a cast // - Status =3D SafeInt8ToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt8ToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Negative number should result in an error status // Operand =3D (-56); - Status =3D SafeInt8ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt8ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeInt8ToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8ToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -137,26 +143,28 @@ TestSafeInt8ToUint32 ( ) { EFI_STATUS Status; - INT8 Operand =3D 0x5b; - UINT32 Result =3D 0; + INT8 Operand; + UINT32 Result; =20 // // Positive UINT8 should result in just a cast // - Status =3D SafeInt8ToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt8ToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Negative number should result in an error status // Operand =3D (-56); - Status =3D SafeInt8ToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeInt8ToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeInt8ToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8ToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -169,26 +177,28 @@ TestSafeInt8ToUintn ( ) { EFI_STATUS Status; - INT8 Operand =3D 0x5b; - UINTN Result =3D 0; + INT8 Operand; + UINTN Result; =20 // // Positive UINT8 should result in just a cast // - Status =3D SafeInt8ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt8ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Negative number should result in an error status // Operand =3D (-56); - Status =3D SafeInt8ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt8ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeInt8ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -201,26 +211,28 @@ TestSafeInt8ToUint64 ( ) { EFI_STATUS Status; - INT8 Operand =3D 0x5b; - UINT64 Result =3D 0; + INT8 Operand; + UINT64 Result; =20 // // Positive UINT8 should result in just a cast // - Status =3D SafeInt8ToUint64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt8ToUint64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Negative number should result in an error status // Operand =3D (-56); - Status =3D SafeInt8ToUint64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeInt8ToUint64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeInt8ToUint64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8ToUint64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -233,26 +245,28 @@ TestSafeUint8ToInt8 ( ) { EFI_STATUS Status; - UINT8 Operand =3D 0x5b; - INT8 Result =3D 0; + UINT8 Operand; + INT8 Result; =20 // // Operand <=3D 0x7F (MAX_INT8) should result in a cast // - Status =3D SafeUint8ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint8ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Operand larger than 0x7f should result in an error status // Operand =3D 0xaf; - Status =3D SafeUint8ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeUint8ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeUint8ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint8ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -265,8 +279,8 @@ TestSafeUint8ToChar8 ( ) { EFI_STATUS Status; - UINT8 Operand =3D 0x5b; - CHAR8 Result =3D 0; + UINT8 Operand; + CHAR8 Result; =20 // // CHAR8 is typedefed as char, which by default is signed, but is @@ -276,20 +290,22 @@ TestSafeUint8ToChar8 ( // // Operand <=3D 0x7F (MAX_INT8) should result in a cast // - Status =3D SafeUint8ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint8ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Operand larger than 0x7f should result in an error status // Operand =3D 0xaf; - Status =3D SafeUint8ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeUint8ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeUint8ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint8ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -302,36 +318,38 @@ TestSafeInt16ToInt8 ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b; - INT8 Result =3D 0; + INT16 Operand; + INT8 Result; =20 // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st // - Status =3D SafeInt16ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt16ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 Operand =3D (-35); - Status =3D SafeInt16ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-35), Result); + Status =3D SafeInt16ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-35), Result); =20 // // Otherwise should result in an error status // Operand =3D 0x1234; - Status =3D SafeInt16ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt16ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 Operand =3D (-17835); - Status =3D SafeInt16ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt16ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeInt16ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -344,8 +362,8 @@ TestSafeInt16ToChar8 ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b; - CHAR8 Result =3D 0; + INT16 Operand; + CHAR8 Result; =20 // // CHAR8 is typedefed as char, which by default is signed, but is @@ -355,30 +373,32 @@ TestSafeInt16ToChar8 ( // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st // - Status =3D SafeInt16ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt16ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-35); - Status =3D SafeInt16ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt16ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D 0x1234; - Status =3D SafeInt16ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt16ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (-17835); - Status =3D SafeInt16ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt16ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeInt16ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -391,31 +411,33 @@ TestSafeInt16ToUint8 ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b; - UINT8 Result =3D 0; + INT16 Operand; + UINT8 Result; =20 // // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast // - Status =3D SafeInt16ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt16ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D 0x1234; - Status =3D SafeInt16ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt16ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 Operand =3D (-17835); - Status =3D SafeInt16ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt16ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeInt16ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -428,26 +450,28 @@ TestSafeInt16ToUint16 ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b5b; - UINT16 Result =3D 0; + INT16 Operand; + UINT16 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt16ToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b5b, Result); + Result =3D 0; + Operand =3D 0x5b5b; + Status =3D SafeInt16ToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-17835); - Status =3D SafeInt16ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt16ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeInt16ToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -460,26 +484,28 @@ TestSafeInt16ToUint32 ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b5b; - UINT32 Result =3D 0; + INT16 Operand; + UINT32 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt16ToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b5b, Result); + Result =3D 0; + Operand =3D 0x5b5b; + Status =3D SafeInt16ToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-17835); - Status =3D SafeInt16ToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeInt16ToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeInt16ToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -492,26 +518,28 @@ TestSafeInt16ToUintn ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b5b; - UINTN Result =3D 0; + INT16 Operand; + UINTN Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt16ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b5b, Result); + Result =3D 0; + Operand =3D 0x5b5b; + Status =3D SafeInt16ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-17835); - Status =3D SafeInt16ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt16ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeInt16ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -524,26 +552,28 @@ TestSafeInt16ToUint64 ( ) { EFI_STATUS Status; - INT16 Operand =3D 0x5b5b; - UINT64 Result =3D 0; + INT16 Operand; + UINT64 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt16ToUint64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b5b, Result); + Result =3D 0; + Operand =3D 0x5b5b; + Status =3D SafeInt16ToUint64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-17835); - Status =3D SafeInt16ToUint64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeInt16ToUint64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeInt16ToUint64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16ToUint64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -556,26 +586,28 @@ TestSafeUint16ToInt8 ( ) { EFI_STATUS Status; - UINT16 Operand =3D 0x5b; - INT8 Result =3D 0; + UINT16 Operand; + INT8 Result; =20 // // If Operand is <=3D MAX_INT8, it's a cast // - Status =3D SafeUint16ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint16ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5b5b); - Status =3D SafeUint16ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeUint16ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeUint16ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -588,8 +620,8 @@ TestSafeUint16ToChar8 ( ) { EFI_STATUS Status; - UINT16 Operand =3D 0x5b; - CHAR8 Result =3D 0; + UINT16 Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -597,20 +629,22 @@ TestSafeUint16ToChar8 ( // // If Operand is <=3D MAX_INT8, it's a cast // - Status =3D SafeUint16ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint16ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5b5b); - Status =3D SafeUint16ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeUint16ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeUint16ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -623,26 +657,28 @@ TestSafeUint16ToUint8 ( ) { EFI_STATUS Status; - UINT16 Operand =3D 0xab; - UINT8 Result =3D 0; + UINT16 Operand; + UINT8 Result; =20 // // If Operand is <=3D MAX_UINT8 (0xff), it's a cast // - Status =3D SafeUint16ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xab, Result); + Result =3D 0; + Operand =3D 0xab; + Status =3D SafeUint16ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5b5b); - Status =3D SafeUint16ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUint16ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUint16ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -655,26 +691,28 @@ TestSafeUint16ToInt16 ( ) { EFI_STATUS Status; - UINT16 Operand =3D 0x5b5b; - INT16 Result =3D 0; + UINT16 Operand; + INT16 Result; =20 // // If Operand is <=3D MAX_INT16 (0x7fff), it's a cast // - Status =3D SafeUint16ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b5b, Result); + Result =3D 0; + Operand =3D 0x5b5b; + Status =3D SafeUint16ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabab); - Status =3D SafeUint16ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeUint16ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeUint16ToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16ToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -687,36 +725,38 @@ TestSafeInt32ToInt8 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5b; - INT8 Result =3D 0; + INT32 Operand; + INT8 Result; =20 // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st // - Status =3D SafeInt32ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt32ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 Operand =3D (-57); - Status =3D SafeInt32ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-57), Result); + Status =3D SafeInt32ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-57), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeInt32ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt32ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt32ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt32ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeInt32ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -729,8 +769,8 @@ TestSafeInt32ToChar8 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5b; - CHAR8 Result =3D 0; + INT32 Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -738,30 +778,32 @@ TestSafeInt32ToChar8 ( // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st // - Status =3D SafeInt32ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt32ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-57); - Status =3D SafeInt32ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt32ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (0x5bababab); - Status =3D SafeInt32ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt32ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt32ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt32ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeInt32ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -774,36 +816,38 @@ TestSafeInt32ToUint8 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5b; - UINT8 Result =3D 0; + INT32 Operand; + UINT8 Result; =20 // // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast // - Status =3D SafeInt32ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt32ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-57); - Status =3D SafeInt32ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt32ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 Operand =3D (0x5bababab); - Status =3D SafeInt32ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt32ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt32ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt32ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeInt32ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -816,36 +860,38 @@ TestSafeInt32ToInt16 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5b5b; - INT16 Result =3D 0; + INT32 Operand; + INT16 Result; =20 // // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a = cast // - Status =3D SafeInt32ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b5b, Result); + Result =3D 0; + Operand =3D 0x5b5b; + Status =3D SafeInt32ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b5b, Result); =20 Operand =3D (-17857); - Status =3D SafeInt32ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-17857), Result); + Status =3D SafeInt32ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-17857), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeInt32ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt32ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt32ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt32ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeInt32ToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -858,36 +904,38 @@ TestSafeInt32ToUint16 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0xabab; - UINT16 Result =3D 0; + INT32 Operand; + UINT16 Result; =20 // // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast // - Status =3D SafeInt32ToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabab, Result); + Result =3D 0; + Operand =3D 0xabab; + Status =3D SafeInt32ToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-17857); - Status =3D SafeInt32ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt32ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 Operand =3D (0x5bababab); - Status =3D SafeInt32ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt32ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt32ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt32ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeInt32ToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -900,26 +948,28 @@ TestSafeInt32ToUint32 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5bababab; - UINT32 Result =3D 0; + INT32 Operand; + UINT32 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt32ToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeInt32ToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeInt32ToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeInt32ToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeInt32ToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -932,26 +982,28 @@ TestSafeInt32ToUint64 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5bababab; - UINT64 Result =3D 0; + INT32 Operand; + UINT64 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt32ToUint64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeInt32ToUint64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeInt32ToUint64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeInt32ToUint64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeInt32ToUint64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToUint64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -964,26 +1016,28 @@ TestSafeUint32ToInt8 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0x5b; - INT8 Result =3D 0; + UINT32 Operand; + INT8 Result; =20 // // If Operand is <=3D MAX_INT8, then it's a cast // - Status =3D SafeUint32ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint32ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeUint32ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeUint32ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeUint32ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -996,8 +1050,8 @@ TestSafeUint32ToChar8 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0x5b; - CHAR8 Result =3D 0; + UINT32 Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -1005,20 +1059,22 @@ TestSafeUint32ToChar8 ( // // If Operand is <=3D MAX_INT8, then it's a cast // - Status =3D SafeUint32ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint32ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeUint32ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeUint32ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeUint32ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1031,26 +1087,28 @@ TestSafeUint32ToUint8 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0xab; - UINT8 Result =3D 0; + UINT32 Operand; + UINT8 Result; =20 // // If Operand is <=3D MAX_UINT8, then it's a cast // - Status =3D SafeUint32ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xab, Result); + Result =3D 0; + Operand =3D 0xab; + Status =3D SafeUint32ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUint32ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUint32ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUint32ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1063,26 +1121,28 @@ TestSafeUint32ToInt16 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0x5bab; - INT16 Result =3D 0; + UINT32 Operand; + INT16 Result; =20 // // If Operand is <=3D MAX_INT16, then it's a cast // - Status =3D SafeUint32ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bab, Result); + Result =3D 0; + Operand =3D 0x5bab; + Status =3D SafeUint32ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUint32ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeUint32ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeUint32ToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1095,26 +1155,28 @@ TestSafeUint32ToUint16 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0xabab; - UINT16 Result =3D 0; + UINT32 Operand; + UINT16 Result; =20 // // If Operand is <=3D MAX_UINT16, then it's a cast // - Status =3D SafeUint32ToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabab, Result); + Result =3D 0; + Operand =3D 0xabab; + Status =3D SafeUint32ToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUint32ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeUint32ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeUint32ToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1127,26 +1189,28 @@ TestSafeUint32ToInt32 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0x5bababab; - INT32 Result =3D 0; + UINT32 Operand; + INT32 Result; =20 // // If Operand is <=3D MAX_INT32, then it's a cast // - Status =3D SafeUint32ToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeUint32ToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUint32ToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeUint32ToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeUint32ToInt32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToInt32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1159,36 +1223,38 @@ TestSafeIntnToInt8 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5b; - INT8 Result =3D 0; + INTN Operand; + INT8 Result; =20 // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st // - Status =3D SafeIntnToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeIntnToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 Operand =3D (-53); - Status =3D SafeIntnToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-53), Result); + Status =3D SafeIntnToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-53), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeIntnToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeIntnToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeIntnToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeIntnToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeIntnToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1201,8 +1267,8 @@ TestSafeIntnToChar8 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5b; - CHAR8 Result =3D 0; + INTN Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -1210,30 +1276,32 @@ TestSafeIntnToChar8 ( // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a ca= st // - Status =3D SafeIntnToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeIntnToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-53); - Status =3D SafeIntnToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeIntnToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (0x5bababab); - Status =3D SafeIntnToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeIntnToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeIntnToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeIntnToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeIntnToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1246,31 +1314,33 @@ TestSafeIntnToUint8 ( ) { EFI_STATUS Status; - INTN Operand =3D 0xab; - UINT8 Result =3D 0; + INTN Operand; + UINT8 Result; =20 // // If Operand is between 0 and MAX_UINT8 inclusive, then it's a cast // - Status =3D SafeIntnToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xab, Result); + Result =3D 0; + Operand =3D 0xab; + Status =3D SafeIntnToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeIntnToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeIntnToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeIntnToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeIntnToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeIntnToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1283,36 +1353,38 @@ TestSafeIntnToInt16 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5bab; - INT16 Result =3D 0; + INTN Operand; + INT16 Result; =20 // // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a = cast // - Status =3D SafeIntnToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bab, Result); + Result =3D 0; + Operand =3D 0x5bab; + Status =3D SafeIntnToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bab, Result); =20 Operand =3D (-23467); - Status =3D SafeIntnToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-23467), Result); + Status =3D SafeIntnToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-23467), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeIntnToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeIntnToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeIntnToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeIntnToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeIntnToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1325,31 +1397,33 @@ TestSafeIntnToUint16 ( ) { EFI_STATUS Status; - INTN Operand =3D 0xabab; - UINT16 Result =3D 0; + INTN Operand; + UINT16 Result; =20 // // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast // - Status =3D SafeIntnToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabab, Result); + Result =3D 0; + Operand =3D 0xabab; + Status =3D SafeIntnToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5bababab); - Status =3D SafeIntnToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeIntnToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 Operand =3D (-1537977259); - Status =3D SafeIntnToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeIntnToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeIntnToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1362,26 +1436,28 @@ TestSafeIntnToUintn ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5bababab; - UINTN Result =3D 0; + INTN Operand; + UINTN Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeIntnToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeIntnToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeIntnToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeIntnToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeIntnToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1394,26 +1470,28 @@ TestSafeIntnToUint64 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5bababab; - UINT64 Result =3D 0; + INTN Operand; + UINT64 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeIntnToUint64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeIntnToUint64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeIntnToUint64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeIntnToUint64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeIntnToUint64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToUint64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1426,26 +1504,28 @@ TestSafeUintnToInt8 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5b; - INT8 Result =3D 0; + UINTN Operand; + INT8 Result; =20 // // If Operand is <=3D MAX_INT8, then it's a cast // - Status =3D SafeUintnToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUintnToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabab); - Status =3D SafeUintnToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeUintnToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeUintnToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1458,8 +1538,8 @@ TestSafeUintnToChar8 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5b; - CHAR8 Result =3D 0; + UINTN Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -1467,20 +1547,22 @@ TestSafeUintnToChar8 ( // // If Operand is <=3D MAX_INT8, then it's a cast // - Status =3D SafeUintnToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUintnToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabab); - Status =3D SafeUintnToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeUintnToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeUintnToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1493,26 +1575,28 @@ TestSafeUintnToUint8 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0xab; - UINT8 Result =3D 0; + UINTN Operand; + UINT8 Result; =20 // // If Operand is <=3D MAX_UINT8, then it's a cast // - Status =3D SafeUintnToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xab, Result); + Result =3D 0; + Operand =3D 0xab; + Status =3D SafeUintnToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabab); - Status =3D SafeUintnToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUintnToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUintnToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1525,26 +1609,28 @@ TestSafeUintnToInt16 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5bab; - INT16 Result =3D 0; + UINTN Operand; + INT16 Result; =20 // // If Operand is <=3D MAX_INT16, then it's a cast // - Status =3D SafeUintnToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bab, Result); + Result =3D 0; + Operand =3D 0x5bab; + Status =3D SafeUintnToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabab); - Status =3D SafeUintnToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeUintnToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeUintnToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1557,26 +1643,28 @@ TestSafeUintnToUint16 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0xabab; - UINT16 Result =3D 0; + UINTN Operand; + UINT16 Result; =20 // // If Operand is <=3D MAX_UINT16, then it's a cast // - Status =3D SafeUintnToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabab, Result); + Result =3D 0; + Operand =3D 0xabab; + Status =3D SafeUintnToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUintnToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeUintnToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeUintnToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1589,26 +1677,28 @@ TestSafeUintnToInt32 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5bababab; - INT32 Result =3D 0; + UINTN Operand; + INT32 Result; =20 // // If Operand is <=3D MAX_INT32, then it's a cast // - Status =3D SafeUintnToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeUintnToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUintnToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeUintnToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeUintnToInt32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToInt32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1621,36 +1711,38 @@ TestSafeInt64ToInt8 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5b; - INT8 Result =3D 0; + INT64 Operand; + INT8 Result; =20 // // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a c= ast // - Status =3D SafeInt64ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt64ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 Operand =3D (-37); - Status =3D SafeInt64ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-37), Result); + Status =3D SafeInt64ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-37), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt64ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt64ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeInt64ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1663,8 +1755,8 @@ TestSafeInt64ToChar8 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5b; - CHAR8 Result =3D 0; + INT64 Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -1672,30 +1764,32 @@ TestSafeInt64ToChar8 ( // // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast // - Status =3D SafeInt64ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeInt64ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (-37); - Status =3D SafeInt64ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt64ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt64ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeInt64ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeInt64ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1708,31 +1802,33 @@ TestSafeInt64ToUint8 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0xab; - UINT8 Result =3D 0; + INT64 Operand; + UINT8 Result; =20 // // If Operand is between 0 and MAX_UINT8 inclusive, then it's a cast // - Status =3D SafeInt64ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xab, Result); + Result =3D 0; + Operand =3D 0xab; + Status =3D SafeInt64ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt64ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeInt64ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeInt64ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1745,36 +1841,38 @@ TestSafeInt64ToInt16 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5bab; - INT16 Result =3D 0; + INT64 Operand; + INT16 Result; =20 // // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a= cast // - Status =3D SafeInt64ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bab, Result); + Result =3D 0; + Operand =3D 0x5bab; + Status =3D SafeInt64ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bab, Result); =20 Operand =3D (-23467); - Status =3D SafeInt64ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-23467), Result); + Status =3D SafeInt64ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-23467), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt64ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt64ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeInt64ToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1787,31 +1885,33 @@ TestSafeInt64ToUint16 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0xabab; - UINT16 Result =3D 0; + INT64 Operand; + UINT16 Result; =20 // // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast // - Status =3D SafeInt64ToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabab, Result); + Result =3D 0; + Operand =3D 0xabab; + Status =3D SafeInt64ToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt64ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeInt64ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeInt64ToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1824,36 +1924,38 @@ TestSafeInt64ToInt32 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5bababab; - INT32 Result =3D 0; + INT64 Operand; + INT32 Result; =20 // // If Operand is between MIN_INT32 and MAX_INT32 inclusive, then it's a= cast // - Status =3D SafeInt64ToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeInt64ToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt64ToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-1537977259), Result); + Status =3D SafeInt64ToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-1537977259), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt64ToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt64ToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeInt64ToInt32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToInt32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1866,31 +1968,33 @@ TestSafeInt64ToUint32 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0xabababab; - UINT32 Result =3D 0; + INT64 Operand; + UINT32 Result; =20 // // If Operand is between 0 and MAX_UINT32 inclusive, then it's a cast // - Status =3D SafeInt64ToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeInt64ToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeInt64ToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeInt64ToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeInt64ToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1903,26 +2007,28 @@ TestSafeInt64ToUint64 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5babababefefefef; - UINT64 Result =3D 0; + INT64 Operand; + UINT64 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt64ToUint64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeInt64ToUint64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 // // Otherwise should result in an error status // Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToUint64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeInt64ToUint64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeInt64ToUint64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToUint64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1935,26 +2041,28 @@ TestSafeUint64ToInt8 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5b; - INT8 Result =3D 0; + UINT64 Operand; + INT8 Result; =20 // // If Operand is <=3D MAX_INT8, then it's a cast // - Status =3D SafeUint64ToInt8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint64ToInt8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToInt8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeUint64ToInt8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeUint64ToInt8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToInt8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -1967,8 +2075,8 @@ TestSafeUint64ToChar8 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5b; - CHAR8 Result =3D 0; + UINT64 Operand; + CHAR8 Result; =20 // CHAR8 is typedefed as char, which by default is signed, but is // also allowed to be unsigned. @@ -1976,20 +2084,22 @@ TestSafeUint64ToChar8 ( // // If Operand is <=3D MAX_INT8, then it's a cast // - Status =3D SafeUint64ToChar8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5b, Result); + Result =3D 0; + Operand =3D 0x5b; + Status =3D SafeUint64ToChar8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5b, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToChar8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeUint64ToChar8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeUint64ToChar8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToChar8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2002,26 +2112,28 @@ TestSafeUint64ToUint8 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0xab; - UINT8 Result =3D 0; + UINT64 Operand; + UINT8 Result; =20 // // If Operand is <=3D MAX_UINT8, then it's a cast // - Status =3D SafeUint64ToUint8(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xab, Result); + Result =3D 0; + Operand =3D 0xab; + Status =3D SafeUint64ToUint8 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToUint8(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUint64ToUint8 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUint64ToUint8(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToUint8 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2034,26 +2146,28 @@ TestSafeUint64ToInt16 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5bab; - INT16 Result =3D 0; + UINT64 Operand; + INT16 Result; =20 // // If Operand is <=3D MAX_INT16, then it's a cast // - Status =3D SafeUint64ToInt16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bab, Result); + Result =3D 0; + Operand =3D 0x5bab; + Status =3D SafeUint64ToInt16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToInt16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeUint64ToInt16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeUint64ToInt16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToInt16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2066,26 +2180,28 @@ TestSafeUint64ToUint16 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0xabab; - UINT16 Result =3D 0; + UINT64 Operand; + UINT16 Result; =20 // // If Operand is <=3D MAX_UINT16, then it's a cast // - Status =3D SafeUint64ToUint16(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabab, Result); + Result =3D 0; + Operand =3D 0xabab; + Status =3D SafeUint64ToUint16 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToUint16(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeUint64ToUint16 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeUint64ToUint16(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToUint16 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2098,26 +2214,28 @@ TestSafeUint64ToInt32 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5bababab; - INT32 Result =3D 0; + UINT64 Operand; + INT32 Result; =20 // // If Operand is <=3D MAX_INT32, then it's a cast // - Status =3D SafeUint64ToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeUint64ToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeUint64ToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeUint64ToInt32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToInt32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2130,26 +2248,28 @@ TestSafeUint64ToUint32 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0xabababab; - UINT32 Result =3D 0; + UINT64 Operand; + UINT32 Result; =20 // // If Operand is <=3D MAX_UINT32, then it's a cast // - Status =3D SafeUint64ToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeUint64ToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeUint64ToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeUint64ToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2162,26 +2282,28 @@ TestSafeUint64ToInt64 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5babababefefefef; - INT64 Result =3D 0; + UINT64 Operand; + INT64 Result; =20 // // If Operand is <=3D MAX_INT64, then it's a cast // - Status =3D SafeUint64ToInt64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeUint64ToInt64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToInt64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeUint64ToInt64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 - Status =3D SafeUint64ToInt64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToInt64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2197,28 +2319,31 @@ TestSafeUint8Add ( ) { EFI_STATUS Status; - UINT8 Augend =3D 0x3a; - UINT8 Addend =3D 0x3a; - UINT8 Result =3D 0; + UINT8 Augend; + UINT8 Addend; + UINT8 Result; =20 // // If the result of addition doesn't overflow MAX_UINT8, then it's addit= ion // - Status =3D SafeUint8Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74, Result); + Result =3D 0; + Augend =3D 0x3a; + Addend =3D 0x3a; + Status =3D SafeUint8Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74, Result); =20 // // Otherwise should result in an error status // Augend =3D 0xab; Addend =3D 0xbc; - Status =3D SafeUint8Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUint8Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUint8Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint8Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2231,28 +2356,31 @@ TestSafeUint16Add ( ) { EFI_STATUS Status; - UINT16 Augend =3D 0x3a3a; - UINT16 Addend =3D 0x3a3a; - UINT16 Result =3D 0; + UINT16 Augend; + UINT16 Addend; + UINT16 Result; =20 // // If the result of addition doesn't overflow MAX_UINT16, then it's addi= tion // - Status =3D SafeUint16Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7474, Result); + Result =3D 0; + Augend =3D 0x3a3a; + Addend =3D 0x3a3a; + Status =3D SafeUint16Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7474, Result); =20 // // Otherwise should result in an error status // Augend =3D 0xabab; Addend =3D 0xbcbc; - Status =3D SafeUint16Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeUint16Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeUint16Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2265,28 +2393,31 @@ TestSafeUint32Add ( ) { EFI_STATUS Status; - UINT32 Augend =3D 0x3a3a3a3a; - UINT32 Addend =3D 0x3a3a3a3a; - UINT32 Result =3D 0; + UINT32 Augend; + UINT32 Addend; + UINT32 Result; =20 // // If the result of addition doesn't overflow MAX_UINT32, then it's addi= tion // - Status =3D SafeUint32Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74747474, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a; + Addend =3D 0x3a3a3a3a; + Status =3D SafeUint32Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74747474, Result); =20 // // Otherwise should result in an error status // Augend =3D 0xabababab; Addend =3D 0xbcbcbcbc; - Status =3D SafeUint32Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeUint32Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeUint32Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2299,28 +2430,31 @@ TestSafeUint64Add ( ) { EFI_STATUS Status; - UINT64 Augend =3D 0x3a3a3a3a12121212; - UINT64 Addend =3D 0x3a3a3a3a12121212; - UINT64 Result =3D 0; + UINT64 Augend; + UINT64 Addend; + UINT64 Result; =20 // // If the result of addition doesn't overflow MAX_UINT64, then it's addi= tion // - Status =3D SafeUint64Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7474747424242424, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a12121212; + Addend =3D 0x3a3a3a3a12121212; + Status =3D SafeUint64Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7474747424242424, Result); =20 // // Otherwise should result in an error status // Augend =3D 0xababababefefefef; Addend =3D 0xbcbcbcbcdededede; - Status =3D SafeUint64Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeUint64Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeUint64Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2333,41 +2467,44 @@ TestSafeInt8Add ( ) { EFI_STATUS Status; - INT8 Augend =3D 0x3a; - INT8 Addend =3D 0x3a; - INT8 Result =3D 0; + INT8 Augend; + INT8 Addend; + INT8 Result; =20 // // If the result of addition doesn't overflow MAX_INT8 // and doesn't underflow MIN_INT8, then it's addition // - Status =3D SafeInt8Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74, Result); + Result =3D 0; + Augend =3D 0x3a; + Addend =3D 0x3a; + Status =3D SafeInt8Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74, Result); =20 Augend =3D (-58); Addend =3D (-58); - Status =3D SafeInt8Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-116), Result); + Status =3D SafeInt8Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-116), Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a; Addend =3D 0x5a; - Status =3D SafeInt8Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt8Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 Augend =3D (-90); Addend =3D (-90); - Status =3D SafeInt8Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt8Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeInt8Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; =20 @@ -2381,41 +2518,44 @@ TestSafeChar8Add ( ) { EFI_STATUS Status; - CHAR8 Augend =3D 0x3a; - CHAR8 Addend =3D 0x3a; - CHAR8 Result =3D 0; + CHAR8 Augend; + CHAR8 Addend; + CHAR8 Result; =20 // // If the result of addition doesn't overflow MAX_INT8 // and doesn't underflow MIN_INT8, then it's addition // - Status =3D SafeChar8Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74, Result); + Result =3D 0; + Augend =3D 0x3a; + Addend =3D 0x3a; + Status =3D SafeChar8Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74, Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a; Addend =3D 0x5a; - Status =3D SafeChar8Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Augend =3D 0x85; Addend =3D 58; - Status =3D SafeChar8Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Augend =3D 58; Addend =3D 0x85; - Status =3D SafeChar8Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeChar8Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeChar8Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; =20 @@ -2429,41 +2569,44 @@ TestSafeInt16Add ( ) { EFI_STATUS Status; - INT16 Augend =3D 0x3a3a; - INT16 Addend =3D 0x3a3a; - INT16 Result =3D 0; + INT16 Augend; + INT16 Addend; + INT16 Result; =20 // // If the result of addition doesn't overflow MAX_INT16 // and doesn't underflow MIN_INT16, then it's addition // - Status =3D SafeInt16Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7474, Result); + Result =3D 0; + Augend =3D 0x3a3a; + Addend =3D 0x3a3a; + Status =3D SafeInt16Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7474, Result); =20 Augend =3D (-14906); Addend =3D (-14906); - Status =3D SafeInt16Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-29812), Result); + Status =3D SafeInt16Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-29812), Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a5a; Addend =3D 0x5a5a; - Status =3D SafeInt16Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt16Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 Augend =3D (-23130); Addend =3D (-23130); - Status =3D SafeInt16Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt16Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeInt16Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2476,41 +2619,44 @@ TestSafeInt32Add ( ) { EFI_STATUS Status; - INT32 Augend =3D 0x3a3a3a3a; - INT32 Addend =3D 0x3a3a3a3a; - INT32 Result =3D 0; + INT32 Augend; + INT32 Addend; + INT32 Result; =20 // // If the result of addition doesn't overflow MAX_INT32 // and doesn't underflow MIN_INT32, then it's addition // - Status =3D SafeInt32Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74747474, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a; + Addend =3D 0x3a3a3a3a; + Status =3D SafeInt32Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74747474, Result); =20 Augend =3D (-976894522); Addend =3D (-976894522); - Status =3D SafeInt32Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-1953789044), Result); + Status =3D SafeInt32Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-1953789044), Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a5a5a5a; Addend =3D 0x5a5a5a5a; - Status =3D SafeInt32Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt32Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 Augend =3D (-1515870810); Addend =3D (-1515870810); - Status =3D SafeInt32Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt32Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeInt32Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2523,41 +2669,44 @@ TestSafeInt64Add ( ) { EFI_STATUS Status; - INT64 Augend =3D 0x3a3a3a3a3a3a3a3a; - INT64 Addend =3D 0x3a3a3a3a3a3a3a3a; - INT64 Result =3D 0; + INT64 Augend; + INT64 Addend; + INT64 Result; =20 // // If the result of addition doesn't overflow MAX_INT64 // and doesn't underflow MIN_INT64, then it's addition // - Status =3D SafeInt64Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7474747474747474, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a3a3a3a3a; + Addend =3D 0x3a3a3a3a3a3a3a3a; + Status =3D SafeInt64Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7474747474747474, Result); =20 Augend =3D (-4195730024608447034); Addend =3D (-4195730024608447034); - Status =3D SafeInt64Add(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-8391460049216894068), Result); + Status =3D SafeInt64Add (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-8391460049216894068), Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a5a5a5a5a5a5a5a; Addend =3D 0x5a5a5a5a5a5a5a5a; - Status =3D SafeInt64Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeInt64Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 Augend =3D (-6510615555426900570); Addend =3D (-6510615555426900570); - Status =3D SafeInt64Add(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeInt64Add (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 - Status =3D SafeInt64Add(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64Add (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2573,28 +2722,31 @@ TestSafeUint8Sub ( ) { EFI_STATUS Status; - UINT8 Minuend =3D 0x5a; - UINT8 Subtrahend =3D 0x3b; - UINT8 Result =3D 0; + UINT8 Minuend; + UINT8 Subtrahend; + UINT8 Result; =20 // // If Minuend >=3D Subtrahend, then it's subtraction // - Status =3D SafeUint8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x1f, Result); + Result =3D 0; + Minuend =3D 0x5a; + Subtrahend =3D 0x3b; + Status =3D SafeUint8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x1f, Result); =20 // // Otherwise should result in an error status // Minuend =3D 0x5a; Subtrahend =3D 0x6d; - Status =3D SafeUint8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUint8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUint8Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint8Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2607,28 +2759,31 @@ TestSafeUint16Sub ( ) { EFI_STATUS Status; - UINT16 Minuend =3D 0x5a5a; - UINT16 Subtrahend =3D 0x3b3b; - UINT16 Result =3D 0; + UINT16 Minuend; + UINT16 Subtrahend; + UINT16 Result; =20 // // If Minuend >=3D Subtrahend, then it's subtraction // - Status =3D SafeUint16Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x1f1f, Result); + Result =3D 0; + Minuend =3D 0x5a5a; + Subtrahend =3D 0x3b3b; + Status =3D SafeUint16Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x1f1f, Result); =20 // // Otherwise should result in an error status // Minuend =3D 0x5a5a; Subtrahend =3D 0x6d6d; - Status =3D SafeUint16Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeUint16Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeUint16Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2641,28 +2796,31 @@ TestSafeUint32Sub ( ) { EFI_STATUS Status; - UINT32 Minuend =3D 0x5a5a5a5a; - UINT32 Subtrahend =3D 0x3b3b3b3b; - UINT32 Result =3D 0; + UINT32 Minuend; + UINT32 Subtrahend; + UINT32 Result; =20 // // If Minuend >=3D Subtrahend, then it's subtraction // - Status =3D SafeUint32Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x1f1f1f1f, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a; + Subtrahend =3D 0x3b3b3b3b; + Status =3D SafeUint32Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x1f1f1f1f, Result); =20 // // Otherwise should result in an error status // Minuend =3D 0x5a5a5a5a; Subtrahend =3D 0x6d6d6d6d; - Status =3D SafeUint32Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeUint32Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeUint32Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2675,28 +2833,31 @@ TestSafeUint64Sub ( ) { EFI_STATUS Status; - UINT64 Minuend =3D 0x5a5a5a5a5a5a5a5a; - UINT64 Subtrahend =3D 0x3b3b3b3b3b3b3b3b; - UINT64 Result =3D 0; + UINT64 Minuend; + UINT64 Subtrahend; + UINT64 Result; =20 // // If Minuend >=3D Subtrahend, then it's subtraction // - Status =3D SafeUint64Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x1f1f1f1f1f1f1f1f, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a5a5a5a5a; + Subtrahend =3D 0x3b3b3b3b3b3b3b3b; + Status =3D SafeUint64Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x1f1f1f1f1f1f1f1f, Result); =20 // // Otherwise should result in an error status // Minuend =3D 0x5a5a5a5a5a5a5a5a; Subtrahend =3D 0x6d6d6d6d6d6d6d6d; - Status =3D SafeUint64Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeUint64Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeUint64Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2709,41 +2870,44 @@ TestSafeInt8Sub ( ) { EFI_STATUS Status; - INT8 Minuend =3D 0x5a; - INT8 Subtrahend =3D 0x3a; - INT8 Result =3D 0; + INT8 Minuend; + INT8 Subtrahend; + INT8 Result; =20 // // If the result of subtractions doesn't overflow MAX_INT8 or // underflow MIN_INT8, then it's subtraction // - Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x20, Result); + Result =3D 0; + Minuend =3D 0x5a; + Subtrahend =3D 0x3a; + Status =3D SafeInt8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x20, Result); =20 Minuend =3D 58; Subtrahend =3D 78; - Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-20), Result); + Status =3D SafeInt8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-20), Result); =20 // // Otherwise should result in an error status // Minuend =3D (-80); Subtrahend =3D 80; - Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 Minuend =3D (80); Subtrahend =3D (-80); - Status =3D SafeInt8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeInt8Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2756,41 +2920,44 @@ TestSafeChar8Sub ( ) { EFI_STATUS Status; - CHAR8 Minuend =3D 0x5a; - CHAR8 Subtrahend =3D 0x3a; - CHAR8 Result =3D 0; + CHAR8 Minuend; + CHAR8 Subtrahend; + CHAR8 Result; =20 // // If the result of subtractions doesn't overflow MAX_INT8 or // underflow MIN_INT8, then it's subtraction // - Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x20, Result); + Result =3D 0; + Minuend =3D 0x5a; + Subtrahend =3D 0x3a; + Status =3D SafeChar8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x20, Result); =20 // // Otherwise should result in an error status // Minuend =3D 58; Subtrahend =3D 78; - Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Minuend =3D 0x85; Subtrahend =3D 80; - Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Minuend =3D (80); Subtrahend =3D 0x85; - Status =3D SafeChar8Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeChar8Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeChar8Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2803,41 +2970,44 @@ TestSafeInt16Sub ( ) { EFI_STATUS Status; - INT16 Minuend =3D 0x5a5a; - INT16 Subtrahend =3D 0x3a3a; - INT16 Result =3D 0; + INT16 Minuend; + INT16 Subtrahend; + INT16 Result; =20 // // If the result of subtractions doesn't overflow MAX_INT16 or // underflow MIN_INT16, then it's subtraction // - Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x2020, Result); + Result =3D 0; + Minuend =3D 0x5a5a; + Subtrahend =3D 0x3a3a; + Status =3D SafeInt16Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x2020, Result); =20 Minuend =3D 0x3a3a; Subtrahend =3D 0x5a5a; - Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-8224), Result); + Status =3D SafeInt16Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-8224), Result); =20 // // Otherwise should result in an error status // Minuend =3D (-31354); Subtrahend =3D 31354; - Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt16Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 Minuend =3D (31354); Subtrahend =3D (-31354); - Status =3D SafeInt16Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt16Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeInt16Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2850,41 +3020,44 @@ TestSafeInt32Sub ( ) { EFI_STATUS Status; - INT32 Minuend =3D 0x5a5a5a5a; - INT32 Subtrahend =3D 0x3a3a3a3a; - INT32 Result =3D 0; + INT32 Minuend; + INT32 Subtrahend; + INT32 Result; =20 // // If the result of subtractions doesn't overflow MAX_INT32 or // underflow MIN_INT32, then it's subtraction // - Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x20202020, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a; + Subtrahend =3D 0x3a3a3a3a; + Status =3D SafeInt32Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x20202020, Result); =20 Minuend =3D 0x3a3a3a3a; Subtrahend =3D 0x5a5a5a5a; - Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-538976288), Result); + Status =3D SafeInt32Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-538976288), Result); =20 // // Otherwise should result in an error status // Minuend =3D (-2054847098); Subtrahend =3D 2054847098; - Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt32Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 Minuend =3D (2054847098); Subtrahend =3D (-2054847098); - Status =3D SafeInt32Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt32Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeInt32Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2897,41 +3070,44 @@ TestSafeInt64Sub ( ) { EFI_STATUS Status; - INT64 Minuend =3D 0x5a5a5a5a5a5a5a5a; - INT64 Subtrahend =3D 0x3a3a3a3a3a3a3a3a; - INT64 Result =3D 0; + INT64 Minuend; + INT64 Subtrahend; + INT64 Result; =20 // // If the result of subtractions doesn't overflow MAX_INT64 or // underflow MIN_INT64, then it's subtraction // - Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x2020202020202020, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a5a5a5a5a; + Subtrahend =3D 0x3a3a3a3a3a3a3a3a; + Status =3D SafeInt64Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x2020202020202020, Result); =20 Minuend =3D 0x3a3a3a3a3a3a3a3a; Subtrahend =3D 0x5a5a5a5a5a5a5a5a; - Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-2314885530818453536), Result); + Status =3D SafeInt64Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-2314885530818453536), Result); =20 // // Otherwise should result in an error status // Minuend =3D (-8825501086245354106); Subtrahend =3D 8825501086245354106; - Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeInt64Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 Minuend =3D (8825501086245354106); Subtrahend =3D (-8825501086245354106); - Status =3D SafeInt64Sub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeInt64Sub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 - Status =3D SafeInt64Sub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64Sub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2947,28 +3123,31 @@ TestSafeUint8Mult ( ) { EFI_STATUS Status; - UINT8 Multiplicand =3D 0x12; - UINT8 Multiplier =3D 0xa; - UINT8 Result =3D 0; + UINT8 Multiplicand; + UINT8 Multiplier; + UINT8 Result; =20 // // If the result of multiplication doesn't overflow MAX_UINT8, it will s= ucceed // - Status =3D SafeUint8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xb4, Result); + Result =3D 0; + Multiplicand =3D 0x12; + Multiplier =3D 0xa; + Status =3D SafeUint8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xb4, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x12; Multiplier =3D 0x23; - Status =3D SafeUint8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT8_ERROR, Result); + Status =3D SafeUint8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT8_ERROR, Result); =20 - Status =3D SafeUint8Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint8Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -2981,28 +3160,31 @@ TestSafeUint16Mult ( ) { EFI_STATUS Status; - UINT16 Multiplicand =3D 0x212; - UINT16 Multiplier =3D 0x7a; - UINT16 Result =3D 0; + UINT16 Multiplicand; + UINT16 Multiplier; + UINT16 Result; =20 // // If the result of multiplication doesn't overflow MAX_UINT16, it will = succeed // - Status =3D SafeUint16Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xfc94, Result); + Result =3D 0; + Multiplicand =3D 0x212; + Multiplier =3D 0x7a; + Status =3D SafeUint16Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xfc94, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x1234; Multiplier =3D 0x213; - Status =3D SafeUint16Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT16_ERROR, Result); + Status =3D SafeUint16Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT16_ERROR, Result); =20 - Status =3D SafeUint16Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint16Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3015,28 +3197,31 @@ TestSafeUint32Mult ( ) { EFI_STATUS Status; - UINT32 Multiplicand =3D 0xa122a; - UINT32 Multiplier =3D 0xd23; - UINT32 Result =3D 0; + UINT32 Multiplicand; + UINT32 Multiplier; + UINT32 Result; =20 // // If the result of multiplication doesn't overflow MAX_UINT32, it will = succeed // - Status =3D SafeUint32Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x844c9dbe, Result); + Result =3D 0; + Multiplicand =3D 0xa122a; + Multiplier =3D 0xd23; + Status =3D SafeUint32Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x844c9dbe, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0xa122a; Multiplier =3D 0xed23; - Status =3D SafeUint32Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeUint32Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeUint32Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3049,28 +3234,31 @@ TestSafeUint64Mult ( ) { EFI_STATUS Status; - UINT64 Multiplicand =3D 0x123456789a; - UINT64 Multiplier =3D 0x1234567; - UINT64 Result =3D 0; + UINT64 Multiplicand; + UINT64 Multiplier; + UINT64 Result; =20 // // If the result of multiplication doesn't overflow MAX_UINT64, it will = succeed // - Status =3D SafeUint64Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x14b66db9745a07f6, Result); + Result =3D 0; + Multiplicand =3D 0x123456789a; + Multiplier =3D 0x1234567; + Status =3D SafeUint64Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x14b66db9745a07f6, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123456789a; Multiplier =3D 0x12345678; - Status =3D SafeUint64Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT64_ERROR, Result); + Status =3D SafeUint64Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT64_ERROR, Result); =20 - Status =3D SafeUint64Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3083,29 +3271,32 @@ TestSafeInt8Mult ( ) { EFI_STATUS Status; - INT8 Multiplicand =3D 0x12; - INT8 Multiplier =3D 0x7; - INT8 Result =3D 0; + INT8 Multiplicand; + INT8 Multiplier; + INT8 Result; =20 // // If the result of multiplication doesn't overflow MAX_INT8 and doesn't // underflow MIN_UINT8, it will succeed // - Status =3D SafeInt8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7e, Result); + Result =3D 0; + Multiplicand =3D 0x12; + Multiplier =3D 0x7; + Status =3D SafeInt8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7e, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x12; Multiplier =3D 0xa; - Status =3D SafeInt8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT8_ERROR, Result); + Status =3D SafeInt8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT8_ERROR, Result); =20 - Status =3D SafeInt8Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt8Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3118,41 +3309,44 @@ TestSafeChar8Mult ( ) { EFI_STATUS Status; - CHAR8 Multiplicand =3D 0x12; - CHAR8 Multiplier =3D 0x7; - CHAR8 Result =3D 0; + CHAR8 Multiplicand; + CHAR8 Multiplier; + CHAR8 Result; =20 // // If the result of multiplication doesn't overflow MAX_INT8 and doesn't // underflow MIN_UINT8, it will succeed // - Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7e, Result); + Result =3D 0; + Multiplicand =3D 0x12; + Multiplier =3D 0x7; + Status =3D SafeChar8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7e, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x12; Multiplier =3D 0xa; - Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Multiplicand =3D 0x85; Multiplier =3D 5; - Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 Multiplicand =3D 5; Multiplier =3D 0x85; - Status =3D SafeChar8Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(CHAR8_ERROR, Result); + Status =3D SafeChar8Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (CHAR8_ERROR, Result); =20 - Status =3D SafeChar8Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeChar8Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3165,29 +3359,32 @@ TestSafeInt16Mult ( ) { EFI_STATUS Status; - INT16 Multiplicand =3D 0x123; - INT16 Multiplier =3D 0x67; - INT16 Result =3D 0; + INT16 Multiplicand; + INT16 Multiplier; + INT16 Result; =20 // // If the result of multiplication doesn't overflow MAX_INT16 and doesn't // underflow MIN_UINT16, it will succeed // - Status =3D SafeInt16Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7515, Result); + Multiplicand =3D 0x123; + Multiplier =3D 0x67; + Result =3D 0; + Status =3D SafeInt16Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7515, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123; Multiplier =3D 0xab; - Status =3D SafeInt16Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT16_ERROR, Result); + Status =3D SafeInt16Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT16_ERROR, Result); =20 - Status =3D SafeInt16Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt16Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3200,29 +3397,32 @@ TestSafeInt32Mult ( ) { EFI_STATUS Status; - INT32 Multiplicand =3D 0x123456; - INT32 Multiplier =3D 0x678; - INT32 Result =3D 0; + INT32 Multiplicand; + INT32 Multiplier; + INT32 Result; =20 // // If the result of multiplication doesn't overflow MAX_INT32 and doesn't // underflow MIN_UINT32, it will succeed // - Status =3D SafeInt32Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x75c28c50, Result); + Result =3D 0; + Multiplicand =3D 0x123456; + Multiplier =3D 0x678; + Status =3D SafeInt32Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x75c28c50, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123456; Multiplier =3D 0xabc; - Status =3D SafeInt32Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeInt32Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeInt32Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3235,29 +3435,32 @@ TestSafeInt64Mult ( ) { EFI_STATUS Status; - INT64 Multiplicand =3D 0x123456789; - INT64 Multiplier =3D 0x6789abcd; - INT64 Result =3D 0; + INT64 Multiplicand; + INT64 Multiplier; + INT64 Result; =20 // // If the result of multiplication doesn't overflow MAX_INT64 and doesn't // underflow MIN_UINT64, it will succeed // - Status =3D SafeInt64Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x75cd9045220d6bb5, Result); + Result =3D 0; + Multiplicand =3D 0x123456789; + Multiplier =3D 0x6789abcd; + Status =3D SafeInt64Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x75cd9045220d6bb5, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123456789; Multiplier =3D 0xa789abcd; - Status =3D SafeInt64Mult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeInt64Mult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 - Status =3D SafeInt64Mult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64Mult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -3272,8 +3475,8 @@ TestSafeInt64Mult ( EFI_STATUS EFIAPI UefiMain ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE* SystemTable + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; @@ -3284,166 +3487,180 @@ UefiMain ( CHAR16 ShortName[100]; ShortName[0] =3D L'\0'; =20 - UnicodeSPrint(&ShortName[0], sizeof(ShortName), L"%a", gEfiCallerBaseNam= e); - DEBUG((DEBUG_INFO, "%s v%s\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION= )); + UnicodeSPrint (&ShortName[0], sizeof (ShortName), L"%a", gEfiCallerBaseN= ame); + DEBUG ((DEBUG_INFO, "%s v%s\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSIO= N)); =20 // // Start setting up the test framework for running the tests. // - Status =3D InitUnitTestFramework(&Fw, UNIT_TEST_APP_NAME, ShortName, UNI= T_TEST_APP_VERSION); - if (EFI_ERROR(Status)) - { - DEBUG((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r\n"= , Status)); + Status =3D InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, ShortName, UN= IT_TEST_APP_VERSION); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r\n= ", Status)); goto EXIT; } =20 /// // Test the conversion functions // - Status =3D CreateUnitTestSuite(&ConversionTestSuite, Fw, L"Int Safe Conv= ersions Test Suite", L"Common.IntSafe.Convert", NULL, NULL); - if (EFI_ERROR(Status)) - { - DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Conversions Tes= t Suite\n")); + Status =3D CreateUnitTestSuite ( + &ConversionTestSuite, + Fw, + L"Int Safe Conversions Test Suite", + L"Common.IntSafe.Convert", + NULL, NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Conversions Te= st Suite\n")); Status =3D EFI_OUT_OF_RESOURCES; goto EXIT; } - AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint8", L"Common.In= tSafe.Convert.TestSafeInt8ToUint8", TestSafeInt8ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt8ToChar8", L"Common.In= tSafe.Convert.TestSafeInt8ToChar8", TestSafeInt8ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint16", L"Common.In= tSafe.Convert.TestSafeInt8ToUint16", TestSafeInt8ToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint32", L"Common.In= tSafe.Convert.TestSafeInt8ToUint32", TestSafeInt8ToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUintn", L"Common.In= tSafe.Convert.TestSafeInt8ToUintn", TestSafeInt8ToUintn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt8ToUint64", L"Common.In= tSafe.Convert.TestSafeInt8ToUint64", TestSafeInt8ToUint64, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint8ToInt8", L"Common.In= tSafe.Convert.TestSafeUint8ToInt8", TestSafeUint8ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint8ToChar8", L"Common.In= tSafe.Convert.TestSafeUint8ToChar8", TestSafeUint8ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToInt8", L"Common.In= tSafe.Convert.TestSafeInt16ToInt8", TestSafeInt16ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToChar8", L"Common.In= tSafe.Convert.TestSafeInt16ToChar8", TestSafeInt16ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint8", L"Common.In= tSafe.Convert.TestSafeInt16ToUint8", TestSafeInt16ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint16", L"Common.In= tSafe.Convert.TestSafeInt16ToUint16", TestSafeInt16ToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint32", L"Common.In= tSafe.Convert.TestSafeInt16ToUint32", TestSafeInt16ToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUintn", L"Common.In= tSafe.Convert.TestSafeInt16ToUintn", TestSafeInt16ToUintn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt16ToUint64", L"Common.In= tSafe.Convert.TestSafeInt16ToUint64", TestSafeInt16ToUint64, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint16ToInt8", L"Common.In= tSafe.Convert.TestSafeUint16ToInt8", TestSafeUint16ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint16ToChar8", L"Common.In= tSafe.Convert.TestSafeUint16ToChar8", TestSafeUint16ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint16ToUint8", L"Common.In= tSafe.Convert.TestSafeUint16ToUint8", TestSafeUint16ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint16ToInt16", L"Common.In= tSafe.Convert.TestSafeUint16ToInt16", TestSafeUint16ToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToInt8", L"Common.In= tSafe.Convert.TestSafeInt32ToInt8", TestSafeInt32ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToChar8", L"Common.In= tSafe.Convert.TestSafeInt32ToChar8", TestSafeInt32ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint8", L"Common.In= tSafe.Convert.TestSafeInt32ToUint8", TestSafeInt32ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToInt16", L"Common.In= tSafe.Convert.TestSafeInt32ToInt16", TestSafeInt32ToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint16", L"Common.In= tSafe.Convert.TestSafeInt32ToUint16", TestSafeInt32ToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint32", L"Common.In= tSafe.Convert.TestSafeInt32ToUint32", TestSafeInt32ToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUintn", L"Common.In= tSafe.Convert.TestSafeInt32ToUintn", TestSafeInt32ToUintn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt32ToUint64", L"Common.In= tSafe.Convert.TestSafeInt32ToUint64", TestSafeInt32ToUint64, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToInt8", L"Common.In= tSafe.Convert.TestSafeUint32ToInt8", TestSafeUint32ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToChar8", L"Common.In= tSafe.Convert.TestSafeUint32ToChar8", TestSafeUint32ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToUint8", L"Common.In= tSafe.Convert.TestSafeUint32ToUint8", TestSafeUint32ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToInt16", L"Common.In= tSafe.Convert.TestSafeUint32ToInt16", TestSafeUint32ToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToUint16", L"Common.In= tSafe.Convert.TestSafeUint32ToUint16", TestSafeUint32ToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToInt32", L"Common.In= tSafe.Convert.TestSafeUint32ToInt32", TestSafeUint32ToInt32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint32ToIntn", L"Common.In= tSafe.Convert.TestSafeUint32ToIntn", TestSafeUint32ToIntn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToInt8", L"Common.In= tSafe.Convert.TestSafeIntnToInt8", TestSafeIntnToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToChar8", L"Common.In= tSafe.Convert.TestSafeIntnToChar8", TestSafeIntnToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint8", L"Common.In= tSafe.Convert.TestSafeIntnToUint8", TestSafeIntnToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToInt16", L"Common.In= tSafe.Convert.TestSafeIntnToInt16", TestSafeIntnToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint16", L"Common.In= tSafe.Convert.TestSafeIntnToUint16", TestSafeIntnToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToInt32", L"Common.In= tSafe.Convert.TestSafeIntnToInt32", TestSafeIntnToInt32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint32", L"Common.In= tSafe.Convert.TestSafeIntnToUint32", TestSafeIntnToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToUintn", L"Common.In= tSafe.Convert.TestSafeIntnToUintn", TestSafeIntnToUintn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeIntnToUint64", L"Common.In= tSafe.Convert.TestSafeIntnToUint64", TestSafeIntnToUint64, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt8", L"Common.In= tSafe.Convert.TestSafeUintnToInt8", TestSafeUintnToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToChar8", L"Common.In= tSafe.Convert.TestSafeUintnToChar8", TestSafeUintnToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToUint8", L"Common.In= tSafe.Convert.TestSafeUintnToUint8", TestSafeUintnToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt16", L"Common.In= tSafe.Convert.TestSafeUintnToInt16", TestSafeUintnToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToUint16", L"Common.In= tSafe.Convert.TestSafeUintnToUint16", TestSafeUintnToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt32", L"Common.In= tSafe.Convert.TestSafeUintnToInt32", TestSafeUintnToInt32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToUint32", L"Common.In= tSafe.Convert.TestSafeUintnToUint32", TestSafeUintnToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToIntn", L"Common.In= tSafe.Convert.TestSafeUintnToIntn", TestSafeUintnToIntn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUintnToInt64", L"Common.In= tSafe.Convert.TestSafeUintnToInt64", TestSafeUintnToInt64, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToInt8", L"Common.In= tSafe.Convert.TestSafeInt64ToInt8", TestSafeInt64ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToChar8", L"Common.In= tSafe.Convert.TestSafeInt64ToChar8", TestSafeInt64ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint8", L"Common.In= tSafe.Convert.TestSafeInt64ToUint8", TestSafeInt64ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToInt16", L"Common.In= tSafe.Convert.TestSafeInt64ToInt16", TestSafeInt64ToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint16", L"Common.In= tSafe.Convert.TestSafeInt64ToUint16", TestSafeInt64ToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToInt32", L"Common.In= tSafe.Convert.TestSafeInt64ToInt32", TestSafeInt64ToInt32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint32", L"Common.In= tSafe.Convert.TestSafeInt64ToUint32", TestSafeInt64ToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToIntn", L"Common.In= tSafe.Convert.TestSafeInt64ToIntn", TestSafeInt64ToIntn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUintn", L"Common.In= tSafe.Convert.TestSafeInt64ToUintn", TestSafeInt64ToUintn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeInt64ToUint64", L"Common.In= tSafe.Convert.TestSafeInt64ToUint64", TestSafeInt64ToUint64, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt8", L"Common.In= tSafe.Convert.TestSafeUint64ToInt8", TestSafeUint64ToInt8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToChar8", L"Common.In= tSafe.Convert.TestSafeUint64ToChar8", TestSafeUint64ToChar8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUint8", L"Common.In= tSafe.Convert.TestSafeUint64ToUint8", TestSafeUint64ToUint8, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt16", L"Common.In= tSafe.Convert.TestSafeUint64ToInt16", TestSafeUint64ToInt16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUint16", L"Common.In= tSafe.Convert.TestSafeUint64ToUint16", TestSafeUint64ToUint16, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt32", L"Common.In= tSafe.Convert.TestSafeUint64ToInt32", TestSafeUint64ToInt32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUint32", L"Common.In= tSafe.Convert.TestSafeUint64ToUint32", TestSafeUint64ToUint32, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToIntn", L"Common.In= tSafe.Convert.TestSafeUint64ToIntn", TestSafeUint64ToIntn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToUintn", L"Common.In= tSafe.Convert.TestSafeUint64ToUintn", TestSafeUint64ToUintn, NULL, NULL, = NULL); - AddTestCase(ConversionTestSuite, L"Test SafeUint64ToInt64", L"Common.In= tSafe.Convert.TestSafeUint64ToInt64", TestSafeUint64ToInt64, NULL, NULL, = NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt8ToUint8", L"Common.I= ntSafe.Convert.TestSafeInt8ToUint8", TestSafeInt8ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt8ToChar8", L"Common.I= ntSafe.Convert.TestSafeInt8ToChar8", TestSafeInt8ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt8ToUint16", L"Common.I= ntSafe.Convert.TestSafeInt8ToUint16", TestSafeInt8ToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt8ToUint32", L"Common.I= ntSafe.Convert.TestSafeInt8ToUint32", TestSafeInt8ToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt8ToUintn", L"Common.I= ntSafe.Convert.TestSafeInt8ToUintn", TestSafeInt8ToUintn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt8ToUint64", L"Common.I= ntSafe.Convert.TestSafeInt8ToUint64", TestSafeInt8ToUint64, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint8ToInt8", L"Common.I= ntSafe.Convert.TestSafeUint8ToInt8", TestSafeUint8ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint8ToChar8", L"Common.I= ntSafe.Convert.TestSafeUint8ToChar8", TestSafeUint8ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToInt8", L"Common.I= ntSafe.Convert.TestSafeInt16ToInt8", TestSafeInt16ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToChar8", L"Common.I= ntSafe.Convert.TestSafeInt16ToChar8", TestSafeInt16ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToUint8", L"Common.I= ntSafe.Convert.TestSafeInt16ToUint8", TestSafeInt16ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToUint16", L"Common.I= ntSafe.Convert.TestSafeInt16ToUint16", TestSafeInt16ToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToUint32", L"Common.I= ntSafe.Convert.TestSafeInt16ToUint32", TestSafeInt16ToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToUintn", L"Common.I= ntSafe.Convert.TestSafeInt16ToUintn", TestSafeInt16ToUintn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt16ToUint64", L"Common.I= ntSafe.Convert.TestSafeInt16ToUint64", TestSafeInt16ToUint64, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint16ToInt8", L"Common.I= ntSafe.Convert.TestSafeUint16ToInt8", TestSafeUint16ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint16ToChar8", L"Common.I= ntSafe.Convert.TestSafeUint16ToChar8", TestSafeUint16ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint16ToUint8", L"Common.I= ntSafe.Convert.TestSafeUint16ToUint8", TestSafeUint16ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint16ToInt16", L"Common.I= ntSafe.Convert.TestSafeUint16ToInt16", TestSafeUint16ToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToInt8", L"Common.I= ntSafe.Convert.TestSafeInt32ToInt8", TestSafeInt32ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToChar8", L"Common.I= ntSafe.Convert.TestSafeInt32ToChar8", TestSafeInt32ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToUint8", L"Common.I= ntSafe.Convert.TestSafeInt32ToUint8", TestSafeInt32ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToInt16", L"Common.I= ntSafe.Convert.TestSafeInt32ToInt16", TestSafeInt32ToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToUint16", L"Common.I= ntSafe.Convert.TestSafeInt32ToUint16", TestSafeInt32ToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToUint32", L"Common.I= ntSafe.Convert.TestSafeInt32ToUint32", TestSafeInt32ToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToUintn", L"Common.I= ntSafe.Convert.TestSafeInt32ToUintn", TestSafeInt32ToUintn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt32ToUint64", L"Common.I= ntSafe.Convert.TestSafeInt32ToUint64", TestSafeInt32ToUint64, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToInt8", L"Common.I= ntSafe.Convert.TestSafeUint32ToInt8", TestSafeUint32ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToChar8", L"Common.I= ntSafe.Convert.TestSafeUint32ToChar8", TestSafeUint32ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToUint8", L"Common.I= ntSafe.Convert.TestSafeUint32ToUint8", TestSafeUint32ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToInt16", L"Common.I= ntSafe.Convert.TestSafeUint32ToInt16", TestSafeUint32ToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToUint16", L"Common.I= ntSafe.Convert.TestSafeUint32ToUint16", TestSafeUint32ToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToInt32", L"Common.I= ntSafe.Convert.TestSafeUint32ToInt32", TestSafeUint32ToInt32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint32ToIntn", L"Common.I= ntSafe.Convert.TestSafeUint32ToIntn", TestSafeUint32ToIntn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToInt8", L"Common.I= ntSafe.Convert.TestSafeIntnToInt8", TestSafeIntnToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToChar8", L"Common.I= ntSafe.Convert.TestSafeIntnToChar8", TestSafeIntnToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToUint8", L"Common.I= ntSafe.Convert.TestSafeIntnToUint8", TestSafeIntnToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToInt16", L"Common.I= ntSafe.Convert.TestSafeIntnToInt16", TestSafeIntnToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToUint16", L"Common.I= ntSafe.Convert.TestSafeIntnToUint16", TestSafeIntnToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToInt32", L"Common.I= ntSafe.Convert.TestSafeIntnToInt32", TestSafeIntnToInt32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToUint32", L"Common.I= ntSafe.Convert.TestSafeIntnToUint32", TestSafeIntnToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToUintn", L"Common.I= ntSafe.Convert.TestSafeIntnToUintn", TestSafeIntnToUintn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeIntnToUint64", L"Common.I= ntSafe.Convert.TestSafeIntnToUint64", TestSafeIntnToUint64, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToInt8", L"Common.I= ntSafe.Convert.TestSafeUintnToInt8", TestSafeUintnToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToChar8", L"Common.I= ntSafe.Convert.TestSafeUintnToChar8", TestSafeUintnToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToUint8", L"Common.I= ntSafe.Convert.TestSafeUintnToUint8", TestSafeUintnToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToInt16", L"Common.I= ntSafe.Convert.TestSafeUintnToInt16", TestSafeUintnToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToUint16", L"Common.I= ntSafe.Convert.TestSafeUintnToUint16", TestSafeUintnToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToInt32", L"Common.I= ntSafe.Convert.TestSafeUintnToInt32", TestSafeUintnToInt32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToUint32", L"Common.I= ntSafe.Convert.TestSafeUintnToUint32", TestSafeUintnToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToIntn", L"Common.I= ntSafe.Convert.TestSafeUintnToIntn", TestSafeUintnToIntn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUintnToInt64", L"Common.I= ntSafe.Convert.TestSafeUintnToInt64", TestSafeUintnToInt64, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToInt8", L"Common.I= ntSafe.Convert.TestSafeInt64ToInt8", TestSafeInt64ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToChar8", L"Common.I= ntSafe.Convert.TestSafeInt64ToChar8", TestSafeInt64ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToUint8", L"Common.I= ntSafe.Convert.TestSafeInt64ToUint8", TestSafeInt64ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToInt16", L"Common.I= ntSafe.Convert.TestSafeInt64ToInt16", TestSafeInt64ToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToUint16", L"Common.I= ntSafe.Convert.TestSafeInt64ToUint16", TestSafeInt64ToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToInt32", L"Common.I= ntSafe.Convert.TestSafeInt64ToInt32", TestSafeInt64ToInt32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToUint32", L"Common.I= ntSafe.Convert.TestSafeInt64ToUint32", TestSafeInt64ToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToIntn", L"Common.I= ntSafe.Convert.TestSafeInt64ToIntn", TestSafeInt64ToIntn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToUintn", L"Common.I= ntSafe.Convert.TestSafeInt64ToUintn", TestSafeInt64ToUintn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeInt64ToUint64", L"Common.I= ntSafe.Convert.TestSafeInt64ToUint64", TestSafeInt64ToUint64, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToInt8", L"Common.I= ntSafe.Convert.TestSafeUint64ToInt8", TestSafeUint64ToInt8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToChar8", L"Common.I= ntSafe.Convert.TestSafeUint64ToChar8", TestSafeUint64ToChar8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToUint8", L"Common.I= ntSafe.Convert.TestSafeUint64ToUint8", TestSafeUint64ToUint8, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToInt16", L"Common.I= ntSafe.Convert.TestSafeUint64ToInt16", TestSafeUint64ToInt16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToUint16", L"Common.I= ntSafe.Convert.TestSafeUint64ToUint16", TestSafeUint64ToUint16, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToInt32", L"Common.I= ntSafe.Convert.TestSafeUint64ToInt32", TestSafeUint64ToInt32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToUint32", L"Common.I= ntSafe.Convert.TestSafeUint64ToUint32", TestSafeUint64ToUint32, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToIntn", L"Common.I= ntSafe.Convert.TestSafeUint64ToIntn", TestSafeUint64ToIntn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToUintn", L"Common.I= ntSafe.Convert.TestSafeUint64ToUintn", TestSafeUint64ToUintn, NULL, NULL,= NULL); + AddTestCase (ConversionTestSuite, L"Test SafeUint64ToInt64", L"Common.I= ntSafe.Convert.TestSafeUint64ToInt64", TestSafeUint64ToInt64, NULL, NULL,= NULL); =20 // // Test the addition and subtraction functions // - Status =3D CreateUnitTestSuite(&AdditionSubtractionTestSuite, Fw, L"Int = Safe Add/Subtract Test Suite", L"Common.IntSafe.AddSubtract", NULL, NULL); - if (EFI_ERROR(Status)) - { - DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Add/Su= btract Test Suite\n")); + Status =3D CreateUnitTestSuite ( + &AdditionSubtractionTestSuite, + Fw, + L"Int Safe Add/Subtract Test Suite", + L"Common.IntSafe.AddSubtract", + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Add/S= ubtract Test Suite\n")); Status =3D EFI_OUT_OF_RESOURCES; goto EXIT; } - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint8Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint8Add", TestSafeUint8Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint16Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint16Add", TestSafeUint16Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint32Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint32Add", TestSafeUint32Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUintnAdd", L"Commo= n.IntSafe.AddSubtract.TestSafeUintnAdd", TestSafeUintnAdd, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint64Add", L"Commo= n.IntSafe.AddSubtract.TestSafeUint64Add", TestSafeUint64Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt8Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt8Add", TestSafeInt8Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeChar8Add", L"Commo= n.IntSafe.AddSubtract.TestSafeChar8Add", TestSafeChar8Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt16Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt16Add", TestSafeInt16Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt32Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt32Add", TestSafeInt32Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeIntnAdd", L"Commo= n.IntSafe.AddSubtract.TestSafeIntnAdd", TestSafeIntnAdd, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt64Add", L"Commo= n.IntSafe.AddSubtract.TestSafeInt64Add", TestSafeInt64Add, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint8Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint8Sub", TestSafeUint8Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint16Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint16Sub", TestSafeUint16Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint32Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint32Sub", TestSafeUint32Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUintnSub", L"Commo= n.IntSafe.AddSubtract.TestSafeUintnSub", TestSafeUintnSub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeUint64Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeUint64Sub", TestSafeUint64Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt8Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt8Sub", TestSafeInt8Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeChar8Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeChar8Sub", TestSafeChar8Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt16Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt16Sub", TestSafeInt16Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt32Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt32Sub", TestSafeInt32Sub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeIntnSub", L"Commo= n.IntSafe.AddSubtract.TestSafeIntnSub", TestSafeIntnSub, NULL, NULL, NU= LL); - AddTestCase(AdditionSubtractionTestSuite, L"Test SafeInt64Sub", L"Commo= n.IntSafe.AddSubtract.TestSafeInt64Sub", TestSafeInt64Sub, NULL, NULL, NU= LL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint8Add", L"Comm= on.IntSafe.AddSubtract.TestSafeUint8Add", TestSafeUint8Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint16Add", L"Comm= on.IntSafe.AddSubtract.TestSafeUint16Add", TestSafeUint16Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint32Add", L"Comm= on.IntSafe.AddSubtract.TestSafeUint32Add", TestSafeUint32Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUintnAdd", L"Comm= on.IntSafe.AddSubtract.TestSafeUintnAdd", TestSafeUintnAdd, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint64Add", L"Comm= on.IntSafe.AddSubtract.TestSafeUint64Add", TestSafeUint64Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt8Add", L"Comm= on.IntSafe.AddSubtract.TestSafeInt8Add", TestSafeInt8Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeChar8Add", L"Comm= on.IntSafe.AddSubtract.TestSafeChar8Add", TestSafeChar8Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt16Add", L"Comm= on.IntSafe.AddSubtract.TestSafeInt16Add", TestSafeInt16Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt32Add", L"Comm= on.IntSafe.AddSubtract.TestSafeInt32Add", TestSafeInt32Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeIntnAdd", L"Comm= on.IntSafe.AddSubtract.TestSafeIntnAdd", TestSafeIntnAdd, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt64Add", L"Comm= on.IntSafe.AddSubtract.TestSafeInt64Add", TestSafeInt64Add, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint8Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeUint8Sub", TestSafeUint8Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint16Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeUint16Sub", TestSafeUint16Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint32Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeUint32Sub", TestSafeUint32Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUintnSub", L"Comm= on.IntSafe.AddSubtract.TestSafeUintnSub", TestSafeUintnSub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeUint64Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeUint64Sub", TestSafeUint64Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt8Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeInt8Sub", TestSafeInt8Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeChar8Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeChar8Sub", TestSafeChar8Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt16Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeInt16Sub", TestSafeInt16Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt32Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeInt32Sub", TestSafeInt32Sub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeIntnSub", L"Comm= on.IntSafe.AddSubtract.TestSafeIntnSub", TestSafeIntnSub, NULL, NULL, N= ULL); + AddTestCase (AdditionSubtractionTestSuite, L"Test SafeInt64Sub", L"Comm= on.IntSafe.AddSubtract.TestSafeInt64Sub", TestSafeInt64Sub, NULL, NULL, N= ULL); =20 // // Test the multiplication functions // - Status =3D CreateUnitTestSuite(&MultiplicationTestSuite, Fw, L"Int Safe = Multiply Test Suite", L"Common.IntSafe.Multiply", NULL, NULL); - if (EFI_ERROR(Status)) - { - DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Multip= ly Test Suite\n")); + Status =3D CreateUnitTestSuite ( + &MultiplicationTestSuite, + Fw, + L"Int Safe Multiply Test Suite", + L"Common.IntSafe.Multiply", + NULL, NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Multi= ply Test Suite\n")); Status =3D EFI_OUT_OF_RESOURCES; goto EXIT; } - AddTestCase(MultiplicationTestSuite, L"Test SafeUint8Mult", L"Common.In= tSafe.Multiply.TestSafeUint8Mult", TestSafeUint8Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeUint16Mult", L"Common.In= tSafe.Multiply.TestSafeUint16Mult", TestSafeUint16Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeUint32Mult", L"Common.In= tSafe.Multiply.TestSafeUint32Mult", TestSafeUint32Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeUintnMult", L"Common.In= tSafe.Multiply.TestSafeUintnMult", TestSafeUintnMult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeUint64Mult", L"Common.In= tSafe.Multiply.TestSafeUint64Mult", TestSafeUint64Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeInt8Mult", L"Common.In= tSafe.Multiply.TestSafeInt8Mult", TestSafeInt8Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeChar8Mult", L"Common.In= tSafe.Multiply.TestSafeChar8Mult", TestSafeChar8Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeInt16Mult", L"Common.In= tSafe.Multiply.TestSafeInt16Mult", TestSafeInt16Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeInt32Mult", L"Common.In= tSafe.Multiply.TestSafeInt32Mult", TestSafeInt32Mult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeIntnMult", L"Common.In= tSafe.Multiply.TestSafeIntnMult", TestSafeIntnMult, NULL, NULL, NULL); - AddTestCase(MultiplicationTestSuite, L"Test SafeInt64Mult", L"Common.In= tSafe.Multiply.TestSafeInt64Mult", TestSafeInt64Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeUint8Mult", L"Common.I= ntSafe.Multiply.TestSafeUint8Mult", TestSafeUint8Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeUint16Mult", L"Common.I= ntSafe.Multiply.TestSafeUint16Mult", TestSafeUint16Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeUint32Mult", L"Common.I= ntSafe.Multiply.TestSafeUint32Mult", TestSafeUint32Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeUintnMult", L"Common.I= ntSafe.Multiply.TestSafeUintnMult", TestSafeUintnMult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeUint64Mult", L"Common.I= ntSafe.Multiply.TestSafeUint64Mult", TestSafeUint64Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeInt8Mult", L"Common.I= ntSafe.Multiply.TestSafeInt8Mult", TestSafeInt8Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeChar8Mult", L"Common.I= ntSafe.Multiply.TestSafeChar8Mult", TestSafeChar8Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeInt16Mult", L"Common.I= ntSafe.Multiply.TestSafeInt16Mult", TestSafeInt16Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeInt32Mult", L"Common.I= ntSafe.Multiply.TestSafeInt32Mult", TestSafeInt32Mult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeIntnMult", L"Common.I= ntSafe.Multiply.TestSafeIntnMult", TestSafeIntnMult, NULL, NULL, NULL); + AddTestCase (MultiplicationTestSuite, L"Test SafeInt64Mult", L"Common.I= ntSafe.Multiply.TestSafeInt64Mult", TestSafeInt64Mult, NULL, NULL, NULL); =20 // // Execute the tests. // - Status =3D RunAllTestSuites(Fw); + Status =3D RunAllTestSuites (Fw); =20 EXIT: - if (Fw) - { - FreeUnitTestFramework(Fw); + if (Fw) { + FreeUnitTestFramework (Fw); } =20 return Status; diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c b/MdePkgUnit= Test/SafeIntLib/SafeIntLibUnitTests32.c index 242773b487..d86fa56068 100644 --- a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests32.c @@ -36,26 +36,28 @@ TestSafeInt32ToUintn_32 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5bababab; - UINTN Result =3D 0; + INT32 Operand; + UINTN Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt32ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeInt32ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeInt32ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt32ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeInt32ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -68,26 +70,28 @@ TestSafeUint32ToIntn_32 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0x5bababab; - INTN Result =3D 0; + UINT32 Operand; + INTN Result; =20 // // If Operand is <=3D MAX_INTN, then it's a cast // - Status =3D SafeUint32ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeUint32ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUint32ToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeUint32ToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeUint32ToIntn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint32ToIntn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -100,15 +104,17 @@ TestSafeIntnToInt32_32 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5bababab; - INT32 Result =3D 0; + INTN Operand; + INT32 Result; =20 // // INTN is same as INT32 in IA32, so this is just a cast // - Status =3D SafeIntnToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeIntnToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 return UNIT_TEST_PASSED; } @@ -121,26 +127,28 @@ TestSafeIntnToUint32_32 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5bababab; - UINT32 Result =3D 0; + INTN Operand; + UINT32 Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeIntnToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeIntnToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeIntnToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeIntnToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeIntnToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -153,15 +161,17 @@ TestSafeUintnToUint32_32 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0xabababab; - UINT32 Result =3D 0; + UINTN Operand; + UINT32 Result; =20 // // UINTN is same as UINT32 in IA32, so this is just a cast // - Status =3D SafeUintnToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeUintnToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 return UNIT_TEST_PASSED; } @@ -174,26 +184,28 @@ TestSafeUintnToIntn_32 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5bababab; - INTN Result =3D 0; + UINTN Operand; + INTN Result; =20 // // If Operand is <=3D MAX_INTN, then it's a cast // - Status =3D SafeUintnToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeUintnToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xabababab); - Status =3D SafeUintnToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeUintnToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeUintnToIntn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToIntn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -206,16 +218,18 @@ TestSafeUintnToInt64_32 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0xabababab; - INT64 Result =3D 0; + UINTN Operand; + INT64 Result; =20 // // UINTN is same as UINT32 in IA32, and UINT32 is a subset of // INT64, so this is just a cast // - Status =3D SafeUintnToInt64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeUintnToInt64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 return UNIT_TEST_PASSED; } @@ -228,36 +242,38 @@ TestSafeInt64ToIntn_32 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5bababab; - INTN Result =3D 0; + INT64 Operand; + INTN Result; =20 // // If Operand is between MIN_INTN and MAX_INTN2 inclusive, then it's a = cast // - Status =3D SafeInt64ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeInt64ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 Operand =3D (-1537977259); - Status =3D SafeInt64ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-1537977259), Result); + Status =3D SafeInt64ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-1537977259), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeInt64ToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeInt64ToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeInt64ToIntn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToIntn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -270,31 +286,33 @@ TestSafeInt64ToUintn_32 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0xabababab; - UINTN Result =3D 0; + INT64 Operand; + UINTN Result; =20 // // If Operand is between 0 and MAX_UINTN inclusive, then it's a cast // - Status =3D SafeInt64ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeInt64ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeInt64ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt64ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt64ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeInt64ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -307,26 +325,28 @@ TestSafeUint64ToIntn_32 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5bababab; - INTN Result =3D 0; + UINT64 Operand; + INTN Result; =20 // // If Operand is <=3D MAX_INTN, then it's a cast // - Status =3D SafeUint64ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeUint64ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeUint64ToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeUint64ToIntn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToIntn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -339,26 +359,28 @@ TestSafeUint64ToUintn_32 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0xabababab; - UINTN Result =3D 0; + UINT64 Operand; + UINTN Result; =20 // // If Operand is <=3D MAX_UINTN, then it's a cast // - Status =3D SafeUint64ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeUint64ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUint64ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUint64ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -371,28 +393,31 @@ TestSafeUintnAdd_32 ( ) { EFI_STATUS Status; - UINTN Augend =3D 0x3a3a3a3a; - UINTN Addend =3D 0x3a3a3a3a; - UINTN Result =3D 0; + UINTN Augend; + UINTN Addend; + UINTN Result; =20 // // If the result of addition doesn't overflow MAX_UINTN, then it's addit= ion // - Status =3D SafeUintnAdd(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74747474, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a; + Addend =3D 0x3a3a3a3a; + Status =3D SafeUintnAdd (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74747474, Result); =20 // // Otherwise should result in an error status // Augend =3D 0xabababab; Addend =3D 0xbcbcbcbc; - Status =3D SafeUintnAdd(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUintnAdd (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUintnAdd(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnAdd (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -405,41 +430,44 @@ TestSafeIntnAdd_32 ( ) { EFI_STATUS Status; - INTN Augend =3D 0x3a3a3a3a; - INTN Addend =3D 0x3a3a3a3a; - INTN Result =3D 0; + INTN Augend; + INTN Addend; + INTN Result; =20 // // If the result of addition doesn't overflow MAX_INTN // and doesn't underflow MIN_INTN, then it's addition // - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x74747474, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a; + Addend =3D 0x3a3a3a3a; + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x74747474, Result); =20 Augend =3D (-976894522); Addend =3D (-976894522); - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-1953789044), Result); + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-1953789044), Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a5a5a5a; Addend =3D 0x5a5a5a5a; - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 Augend =3D (-1515870810); Addend =3D (-1515870810); - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeIntnAdd(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnAdd (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -452,28 +480,31 @@ TestSafeUintnSub_32 ( ) { EFI_STATUS Status; - UINTN Minuend =3D 0x5a5a5a5a; - UINTN Subtrahend =3D 0x3b3b3b3b; - UINTN Result =3D 0; + UINTN Minuend; + UINTN Subtrahend; + UINTN Result; =20 // // If Minuend >=3D Subtrahend, then it's subtraction // - Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x1f1f1f1f, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a; + Subtrahend =3D 0x3b3b3b3b; + Status =3D SafeUintnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x1f1f1f1f, Result); =20 // // Otherwise should result in an error status // Minuend =3D 0x5a5a5a5a; Subtrahend =3D 0x6d6d6d6d; - Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUintnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUintnSub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnSub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -486,41 +517,44 @@ TestSafeIntnSub_32 ( ) { EFI_STATUS Status; - INTN Minuend =3D 0x5a5a5a5a; - INTN Subtrahend =3D 0x3a3a3a3a; - INTN Result =3D 0; + INTN Minuend; + INTN Subtrahend; + INTN Result; =20 // // If the result of subtractions doesn't overflow MAX_INTN or // underflow MIN_INTN, then it's subtraction // - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x20202020, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a; + Subtrahend =3D 0x3a3a3a3a; + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x20202020, Result); =20 Minuend =3D 0x3a3a3a3a; Subtrahend =3D 0x5a5a5a5a; - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-538976288), Result); + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-538976288), Result); =20 // // Otherwise should result in an error status // Minuend =3D (-2054847098); Subtrahend =3D 2054847098; - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 Minuend =3D (2054847098); Subtrahend =3D (-2054847098); - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeIntnSub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnSub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -533,28 +567,31 @@ TestSafeUintnMult_32 ( ) { EFI_STATUS Status; - UINTN Multiplicand =3D 0xa122a; - UINTN Multiplier =3D 0xd23; - UINTN Result =3D 0; + UINTN Multiplicand; + UINTN Multiplier; + UINTN Result; =20 // // If the result of multiplication doesn't overflow MAX_UINTN, it will s= ucceed // - Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x844c9dbe, Result); + Result =3D 0; + Multiplicand =3D 0xa122a; + Multiplier =3D 0xd23; + Status =3D SafeUintnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x844c9dbe, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0xa122a; Multiplier =3D 0xed23; - Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUintnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUintnMult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnMult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -567,29 +604,32 @@ TestSafeIntnMult_32 ( ) { EFI_STATUS Status; - INTN Multiplicand =3D 0x123456; - INTN Multiplier =3D 0x678; - INTN Result =3D 0; + INTN Multiplicand; + INTN Multiplier; + INTN Result; =20 // // If the result of multiplication doesn't overflow MAX_INTN and doesn't // underflow MIN_UINTN, it will succeed // - Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x75c28c50, Result); + Result =3D 0; + Multiplicand =3D 0x123456; + Multiplier =3D 0x678; + Status =3D SafeIntnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x75c28c50, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123456; Multiplier =3D 0xabc; - Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeIntnMult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnMult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } diff --git a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c b/MdePkgUnit= Test/SafeIntLib/SafeIntLibUnitTests64.c index 59eb4f72d6..22bbd476ab 100644 --- a/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c +++ b/MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests64.c @@ -36,26 +36,28 @@ TestSafeInt32ToUintn_64 ( ) { EFI_STATUS Status; - INT32 Operand =3D 0x5bababab; - UINTN Result =3D 0; + INT32 Operand; + UINTN Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt32ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeInt32ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (-1537977259); - Status =3D SafeInt32ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt32ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeInt32ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt32ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -68,8 +70,8 @@ TestSafeUint32ToIntn_64 ( ) { EFI_STATUS Status; - UINT32 Operand =3D 0xabababab; - INTN Result =3D 0; + UINT32 Operand; + INTN Result; =20 // // For x64, INTN is same as INT64 which is a superset of INT32 @@ -79,9 +81,11 @@ TestSafeUint32ToIntn_64 ( // // If Operand is non-negative, then it's a cast // - Status =3D SafeUint32ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeUint32ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 return UNIT_TEST_PASSED; } @@ -94,36 +98,38 @@ TestSafeIntnToInt32_64 ( ) { EFI_STATUS Status; - INTN Operand =3D 0x5bababab; - INT32 Result =3D 0; + INTN Operand; + INT32 Result; =20 // // If Operand is between MIN_INT32 and MAX_INT32 inclusive, then it's a= cast // - Status =3D SafeIntnToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5bababab, Result); + Result =3D 0; + Operand =3D 0x5bababab; + Status =3D SafeIntnToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5bababab, Result); =20 Operand =3D (-1537977259); - Status =3D SafeIntnToInt32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-1537977259), Result); + Status =3D SafeIntnToInt32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-1537977259), Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeIntnToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeIntnToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeIntnToInt32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT32_ERROR, Result); + Status =3D SafeIntnToInt32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT32_ERROR, Result); =20 - Status =3D SafeIntnToInt32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToInt32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -136,31 +142,33 @@ TestSafeIntnToUint32_64 ( ) { EFI_STATUS Status; - INTN Operand =3D 0xabababab; - UINT32 Result =3D 0; + INTN Operand; + UINT32 Result; =20 // // If Operand is between 0 and MAX_UINT32 inclusive, then it's a cast // - Status =3D SafeIntnToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeIntnToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0x5babababefefefef); - Status =3D SafeIntnToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeIntnToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 Operand =3D (-6605562033422200815); - Status =3D SafeIntnToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeIntnToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeIntnToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -173,26 +181,28 @@ TestSafeUintnToUint32_64 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0xabababab; - UINT32 Result =3D 0; + UINTN Operand; + UINT32 Result; =20 // // If Operand is <=3D MAX_UINT32, then it's a cast // - Status =3D SafeUintnToUint32(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xabababab, Result); + Result =3D 0; + Operand =3D 0xabababab; + Status =3D SafeUintnToUint32 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xabababab, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUintnToUint32(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINT32_ERROR, Result); + Status =3D SafeUintnToUint32 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINT32_ERROR, Result); =20 - Status =3D SafeUintnToUint32(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToUint32 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -205,26 +215,28 @@ TestSafeUintnToIntn_64 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5babababefefefef; - INTN Result =3D 0; + UINTN Operand; + INTN Result; =20 // // If Operand is <=3D MAX_INTN (0x7fff_ffff_ffff_ffff), then it's a cast // - Status =3D SafeUintnToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeUintnToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUintnToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeUintnToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeUintnToIntn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToIntn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -237,26 +249,28 @@ TestSafeUintnToInt64_64 ( ) { EFI_STATUS Status; - UINTN Operand =3D 0x5babababefefefef; - INT64 Result =3D 0; + UINTN Operand; + INT64 Result; =20 // // If Operand is <=3D MAX_INT64, then it's a cast // - Status =3D SafeUintnToInt64(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeUintnToInt64 (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUintnToInt64(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INT64_ERROR, Result); + Status =3D SafeUintnToInt64 (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INT64_ERROR, Result); =20 - Status =3D SafeUintnToInt64(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnToInt64 (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -269,15 +283,17 @@ TestSafeInt64ToIntn_64 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5babababefefefef; - INTN Result =3D 0; + INT64 Operand; + INTN Result; =20 // // INTN is same as INT64 in x64, so this is just a cast // - Status =3D SafeInt64ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeInt64ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 return UNIT_TEST_PASSED; } @@ -290,26 +306,28 @@ TestSafeInt64ToUintn_64 ( ) { EFI_STATUS Status; - INT64 Operand =3D 0x5babababefefefef; - UINTN Result =3D 0; + INT64 Operand; + UINTN Result; =20 // // If Operand is non-negative, then it's a cast // - Status =3D SafeInt64ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeInt64ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 // // Otherwise should result in an error status // Operand =3D (-6605562033422200815); - Status =3D SafeInt64ToUintn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeInt64ToUintn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeInt64ToUintn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeInt64ToUintn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -322,26 +340,28 @@ TestSafeUint64ToIntn_64 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0x5babababefefefef; - INTN Result =3D 0; + UINT64 Operand; + INTN Result; =20 // // If Operand is <=3D MAX_INTN (0x7fff_ffff_ffff_ffff), then it's a cast // - Status =3D SafeUint64ToIntn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x5babababefefefef, Result); + Result =3D 0; + Operand =3D 0x5babababefefefef; + Status =3D SafeUint64ToIntn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x5babababefefefef, Result); =20 // // Otherwise should result in an error status // Operand =3D (0xababababefefefef); - Status =3D SafeUint64ToIntn(Operand, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeUint64ToIntn (Operand, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeUint64ToIntn(Operand, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUint64ToIntn (Operand, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -354,15 +374,17 @@ TestSafeUint64ToUintn_64 ( ) { EFI_STATUS Status; - UINT64 Operand =3D 0xababababefefefef; - UINTN Result =3D 0; + UINT64 Operand; + UINTN Result; =20 // // UINTN is same as UINT64 in x64, so this is just a cast // - Status =3D SafeUint64ToUintn(Operand, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0xababababefefefef, Result); + Result =3D 0; + Operand =3D 0xababababefefefef; + Status =3D SafeUint64ToUintn (Operand, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0xababababefefefef, Result); =20 return UNIT_TEST_PASSED; } @@ -375,28 +397,31 @@ TestSafeUintnAdd_64 ( ) { EFI_STATUS Status; - UINTN Augend =3D 0x3a3a3a3a12121212; - UINTN Addend =3D 0x3a3a3a3a12121212; - UINTN Result =3D 0; + UINTN Augend; + UINTN Addend; + UINTN Result; =20 // // If the result of addition doesn't overflow MAX_UINTN, then it's addit= ion // - Status =3D SafeUintnAdd(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7474747424242424, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a12121212; + Addend =3D 0x3a3a3a3a12121212; + Status =3D SafeUintnAdd (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7474747424242424, Result); =20 // // Otherwise should result in an error status // Augend =3D 0xababababefefefef; Addend =3D 0xbcbcbcbcdededede; - Status =3D SafeUintnAdd(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUintnAdd (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUintnAdd(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnAdd (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -409,41 +434,44 @@ TestSafeIntnAdd_64 ( ) { EFI_STATUS Status; - INTN Augend =3D 0x3a3a3a3a3a3a3a3a; - INTN Addend =3D 0x3a3a3a3a3a3a3a3a; - INTN Result =3D 0; + INTN Augend; + INTN Addend; + INTN Result; =20 // // If the result of addition doesn't overflow MAX_INTN // and doesn't underflow MIN_INTN, then it's addition // - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x7474747474747474, Result); + Result =3D 0; + Augend =3D 0x3a3a3a3a3a3a3a3a; + Addend =3D 0x3a3a3a3a3a3a3a3a; + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x7474747474747474, Result); =20 Augend =3D (-4195730024608447034); Addend =3D (-4195730024608447034); - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-8391460049216894068), Result); + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-8391460049216894068), Result); =20 // // Otherwise should result in an error status // Augend =3D 0x5a5a5a5a5a5a5a5a; Addend =3D 0x5a5a5a5a5a5a5a5a; - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 Augend =3D (-6510615555426900570); Addend =3D (-6510615555426900570); - Status =3D SafeIntnAdd(Augend, Addend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnAdd (Augend, Addend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeIntnAdd(Augend, Addend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnAdd (Augend, Addend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -456,28 +484,31 @@ TestSafeUintnSub_64 ( ) { EFI_STATUS Status; - UINTN Minuend =3D 0x5a5a5a5a5a5a5a5a; - UINTN Subtrahend =3D 0x3b3b3b3b3b3b3b3b; - UINTN Result =3D 0; + UINTN Minuend; + UINTN Subtrahend; + UINTN Result; =20 // // If Minuend >=3D Subtrahend, then it's subtraction // - Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x1f1f1f1f1f1f1f1f, Result); + Result =3D 0; + Minuend =3D 0x5a5a5a5a5a5a5a5a; + Subtrahend =3D 0x3b3b3b3b3b3b3b3b; + Status =3D SafeUintnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x1f1f1f1f1f1f1f1f, Result); =20 // // Otherwise should result in an error status // Minuend =3D 0x5a5a5a5a5a5a5a5a; Subtrahend =3D 0x6d6d6d6d6d6d6d6d; - Status =3D SafeUintnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUintnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUintnSub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnSub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -490,41 +521,44 @@ TestSafeIntnSub_64 ( ) { EFI_STATUS Status; - INTN Minuend =3D 0x5a5a5a5a5a5a5a5a; - INTN Subtrahend =3D 0x3a3a3a3a3a3a3a3a; - INTN Result =3D 0; + INTN Minuend; + INTN Subtrahend; + INTN Result; =20 // // If the result of subtractions doesn't overflow MAX_INTN or // underflow MIN_INTN, then it's subtraction // - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x2020202020202020, Result); + Minuend =3D 0x5a5a5a5a5a5a5a5a; + Subtrahend =3D 0x3a3a3a3a3a3a3a3a; + Result =3D 0; + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x2020202020202020, Result); =20 Minuend =3D 0x3a3a3a3a3a3a3a3a; Subtrahend =3D 0x5a5a5a5a5a5a5a5a; - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL((-2314885530818453536), Result); + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL ((-2314885530818453536), Result); =20 // // Otherwise should result in an error status // Minuend =3D (-8825501086245354106); Subtrahend =3D 8825501086245354106; - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 Minuend =3D (8825501086245354106); Subtrahend =3D (-8825501086245354106); - Status =3D SafeIntnSub(Minuend, Subtrahend, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnSub (Minuend, Subtrahend, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeIntnSub(Minuend, Subtrahend, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnSub (Minuend, Subtrahend, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -537,28 +571,31 @@ TestSafeUintnMult_64 ( ) { EFI_STATUS Status; - UINTN Multiplicand =3D 0x123456789a; - UINTN Multiplier =3D 0x1234567; - UINTN Result =3D 0; + UINTN Multiplicand; + UINTN Multiplier; + UINTN Result; =20 // // If the result of multiplication doesn't overflow MAX_UINTN, it will s= ucceed // - Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x14b66db9745a07f6, Result); + Result =3D 0; + Multiplicand =3D 0x123456789a; + Multiplier =3D 0x1234567; + Status =3D SafeUintnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x14b66db9745a07f6, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123456789a; Multiplier =3D 0x12345678; - Status =3D SafeUintnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(UINTN_ERROR, Result); + Status =3D SafeUintnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (UINTN_ERROR, Result); =20 - Status =3D SafeUintnMult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeUintnMult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } @@ -571,29 +608,32 @@ TestSafeIntnMult_64 ( ) { EFI_STATUS Status; - INTN Multiplicand =3D 0x123456789; - INTN Multiplier =3D 0x6789abcd; - INTN Result =3D 0; + INTN Multiplicand; + INTN Multiplier; + INTN Result; =20 // // If the result of multiplication doesn't overflow MAX_INTN and doesn't // underflow MIN_UINTN, it will succeed // - Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_NOT_EFI_ERROR(Status); - UT_ASSERT_EQUAL(0x75cd9045220d6bb5, Result); + Result =3D 0; + Multiplicand =3D 0x123456789; + Multiplier =3D 0x6789abcd; + Status =3D SafeIntnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_NOT_EFI_ERROR (Status); + UT_ASSERT_EQUAL (0x75cd9045220d6bb5, Result); =20 // // Otherwise should result in an error status // Multiplicand =3D 0x123456789; Multiplier =3D 0xa789abcd; - Status =3D SafeIntnMult(Multiplicand, Multiplier, &Result); - UT_ASSERT_EQUAL(RETURN_BUFFER_TOO_SMALL, Status); - UT_ASSERT_EQUAL(INTN_ERROR, Result); + Status =3D SafeIntnMult (Multiplicand, Multiplier, &Result); + UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status); + UT_ASSERT_EQUAL (INTN_ERROR, Result); =20 - Status =3D SafeIntnMult(Multiplicand, Multiplier, NULL); - UT_ASSERT_EQUAL(RETURN_INVALID_PARAMETER, Status); + Status =3D SafeIntnMult (Multiplicand, Multiplier, NULL); + UT_ASSERT_EQUAL (RETURN_INVALID_PARAMETER, Status); =20 return UNIT_TEST_PASSED; } --=20 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel