16#define UNIT_TEST_APP_NAME "BaseLib Unit Test Application"
17#define UNIT_TEST_APP_VERSION "1.0"
44#define B64_TEST_2 "Zg=="
47#define B64_TEST_3 "Zm8="
48#define BIN_TEST_3 "fo"
50#define B64_TEST_4 "Zm9v"
51#define BIN_TEST_4 "foo"
53#define B64_TEST_5 "Zm9vYg=="
54#define BIN_TEST_5 "foob"
56#define B64_TEST_6 "Zm9vYmE="
57#define BIN_TEST_6 "fooba"
59#define B64_TEST_7 "Zm9vYmFy"
60#define BIN_TEST_7 "foobar"
63#define B64_TEST_8_IN " \t\v Zm9\r\nvYmFy \f "
64#define BIN_TEST_8 "foobar"
67#define B64_ERROR_1 "Zm9vymFy="
70#define B64_ERROR_2 "Zm$vymFy"
73#define B64_ERROR_3 "Z==="
76#define B64_ERROR_4 "Zm=vYmFy"
78#define MAX_TEST_STRING_SIZE (200)
88static BASIC_TEST_CONTEXT mBasicEncodeError1 = { BIN_TEST_7, B64_TEST_1, EFI_BUFFER_TOO_SMALL,
NULL,
sizeof (B64_TEST_7) };
99static BASIC_TEST_CONTEXT mBasicDecodeError1 = { B64_ERROR_1, B64_ERROR_1, EFI_INVALID_PARAMETER,
NULL, 0 };
100static BASIC_TEST_CONTEXT mBasicDecodeError2 = { B64_ERROR_2, B64_ERROR_2, EFI_INVALID_PARAMETER,
NULL, 0 };
101static BASIC_TEST_CONTEXT mBasicDecodeError3 = { B64_ERROR_3, B64_ERROR_3, EFI_INVALID_PARAMETER,
NULL, 0 };
102static BASIC_TEST_CONTEXT mBasicDecodeError4 = { B64_ERROR_4, B64_ERROR_4, EFI_INVALID_PARAMETER,
NULL, 0 };
103static BASIC_TEST_CONTEXT mBasicDecodeError5 = { B64_TEST_7, BIN_TEST_1, EFI_BUFFER_TOO_SMALL,
NULL,
sizeof (BIN_TEST_7)-1 };
121 if (Btc->BufferToFree !=
NULL) {
123 Btc->BufferToFree =
NULL;
157 CHAR8 *b64WorkString;
163 binString = Btc->TestInput;
164 b64String = Btc->TestOutput;
173 BinData = (UINT8 *)binString;
178 Btc->BufferToFree = b64WorkString;
179 ReturnSize = b64StringSize;
181 Status =
Base64Encode (BinData, BinSize, b64WorkString, &ReturnSize);
187 if (!EFI_ERROR (Btc->ExpectedStatus)) {
188 if (ReturnSize != 0) {
189 CompareStatus =
AsciiStrnCmp (b64String, b64WorkString, ReturnSize);
190 if (CompareStatus != 0) {
191 UT_LOG_ERROR (
"b64 string compare error - size=%d\n", ReturnSize);
192 for (indx = 0; indx < ReturnSize; indx++) {
197 for (indx = 0; indx < ReturnSize; indx++) {
208 Btc->BufferToFree =
NULL;
210 return UNIT_TEST_PASSED;
247 b64String = Btc->TestInput;
248 binString = Btc->TestOutput;
254 b64StringLen =
AsciiStrnLenS (b64String, MAX_TEST_STRING_SIZE);
260 Btc->BufferToFree = BinData;
261 ReturnSize = BinSize;
263 Status =
Base64Decode (b64String, b64StringLen, BinData, &ReturnSize);
268 if (EFI_ERROR (Btc->ExpectedStatus)) {
269 if (Btc->ExpectedStatus == EFI_BUFFER_TOO_SMALL) {
274 if (ReturnSize != 0) {
275 CompareStatus =
CompareMem (binString, BinData, ReturnSize);
276 if (CompareStatus != 0) {
277 UT_LOG_ERROR (
"bin string compare error - size=%d\n", ReturnSize);
278 for (indx = 0; indx < ReturnSize; indx++) {
283 for (indx = 0; indx < ReturnSize; indx++) {
294 Btc->BufferToFree =
NULL;
296 return UNIT_TEST_PASSED;
299#define SOURCE_STRING L"Hello"
304SafeStringContraintCheckTest (
308 RETURN_STATUS Status;
309 CHAR16 Destination[20];
315 ZeroMem (AllZero,
sizeof (AllZero));
320 ZeroMem (Destination,
sizeof (Destination));
321 Status =
StrCpyS (Destination,
sizeof (Destination) /
sizeof (CHAR16), SOURCE_STRING);
328 ZeroMem (Destination,
sizeof (Destination));
329 Status =
StrCpyS (Destination,
sizeof (SOURCE_STRING) /
sizeof (CHAR16), SOURCE_STRING);
336 ZeroMem (Destination,
sizeof (Destination));
337 Status =
StrCpyS (
NULL,
sizeof (Destination) /
sizeof (CHAR16), SOURCE_STRING);
344 ZeroMem (Destination,
sizeof (Destination));
345 Status =
StrCpyS (Destination,
sizeof (Destination) /
sizeof (CHAR16),
NULL);
352 ZeroMem (Destination,
sizeof (Destination));
353 Status =
StrCpyS (Destination, MAX_UINTN, SOURCE_STRING);
360 ZeroMem (Destination,
sizeof (Destination));
361 Status =
StrCpyS (Destination, 0, SOURCE_STRING);
368 ZeroMem (Destination,
sizeof (Destination));
369 Status =
StrCpyS (Destination, 1, SOURCE_STRING);
376 ZeroMem (Destination,
sizeof (Destination));
377 Status =
StrCpyS (Destination,
sizeof (SOURCE_STRING) /
sizeof (CHAR16) - 1, SOURCE_STRING);
384 ZeroMem (Destination,
sizeof (Destination));
385 Status =
StrCpyS (Destination,
sizeof (Destination) /
sizeof (CHAR16), Destination);
389 return UNIT_TEST_PASSED;
408 UNIT_TEST_FRAMEWORK_HANDLE Fw;
409 UNIT_TEST_SUITE_HANDLE b64EncodeTests;
410 UNIT_TEST_SUITE_HANDLE b64DecodeTests;
411 UNIT_TEST_SUITE_HANDLE SafeStringTests;
415 DEBUG ((DEBUG_INFO,
"%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
421 if (EFI_ERROR (Status)) {
422 DEBUG ((DEBUG_ERROR,
"Failed in InitUnitTestFramework. Status = %r\n", Status));
430 if (EFI_ERROR (Status)) {
431 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for b64EncodeTests\n"));
432 Status = EFI_OUT_OF_RESOURCES;
449 if (EFI_ERROR (Status)) {
450 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for b64Decode Tests\n"));
451 Status = EFI_OUT_OF_RESOURCES;
474 if (EFI_ERROR (Status)) {
475 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for SafeStringTests\n"));
476 Status = EFI_OUT_OF_RESOURCES;
481 AddTestCase (SafeStringTests,
"SAFE_STRING_CONSTRAINT_CHECK",
"SafeStringContraintCheckTest", SafeStringContraintCheckTest,
NULL,
NULL,
NULL);
STATIC UNIT_TEST_STATUS EFIAPI RfcDecodeTest(IN UNIT_TEST_CONTEXT Context)
STATIC UNIT_TEST_STATUS EFIAPI RfcEncodeTest(IN UNIT_TEST_CONTEXT Context)
EFI_STATUS EFIAPI BaseLibUnitTestAppEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC VOID EFIAPI CleanUpB64TestContext(IN UNIT_TEST_CONTEXT Context)
STATIC EFI_STATUS EFIAPI UnitTestingEntry(VOID)
UINTN EFIAPI AsciiStrnLenS(IN CONST CHAR8 *String, IN UINTN MaxSize)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
RETURN_STATUS EFIAPI Base64Decode(IN CONST CHAR8 *Source OPTIONAL, IN UINTN SourceSize, OUT UINT8 *Destination OPTIONAL, IN OUT UINTN *DestinationSize)
UINTN EFIAPI AsciiStrnSizeS(IN CONST CHAR8 *String, IN UINTN MaxSize)
RETURN_STATUS EFIAPI Base64Encode(IN CONST UINT8 *Source, IN UINTN SourceLength, OUT CHAR8 *Destination OPTIONAL, IN OUT UINTN *DestinationSize)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
int main()
=== TEST ENGINE ================================================================================
VOID EFIAPI FreePool(IN VOID *Buffer)
#define RETURN_BUFFER_TOO_SMALL
#define RETURN_ACCESS_DENIED
#define RETURN_INVALID_PARAMETER
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
#define UT_ASSERT_NOT_NULL(Pointer)
#define UT_LOG_ERROR(Format,...)
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
#define UT_ASSERT_EQUAL(ValueA, ValueB)
#define UT_ASSERT_STATUS_EQUAL(Status, Expected)
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
#define UT_ASSERT_NOT_EFI_ERROR(Status)