]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c
MdePkg/Test/BaseLib: Add SAFE_STRING_CONSTRAINT_CHECK unit test
[mirror_edk2.git] / MdePkg / Test / UnitTest / Library / BaseLib / Base64UnitTest.c
CommitLineData
e50c2bb3
MK
1/** @file\r
2 Unit tests of Base64 conversion APIs in BaseLib.\r
3\r
4 Copyright (C) Microsoft Corporation.\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <Uefi.h>\r
10#include <Library/BaseLib.h>\r
11#include <Library/BaseMemoryLib.h>\r
12#include <Library/DebugLib.h>\r
13#include <Library/MemoryAllocationLib.h>\r
14#include <Library/UnitTestLib.h>\r
15\r
16#define UNIT_TEST_APP_NAME "BaseLib Unit Test Application"\r
17#define UNIT_TEST_APP_VERSION "1.0"\r
18\r
19/**\r
20 RFC 4648 https://tools.ietf.org/html/rfc4648 test vectors\r
21\r
22 BASE64("") = ""\r
23 BASE64("f") = "Zg=="\r
24 BASE64("fo") = "Zm8="\r
25 BASE64("foo") = "Zm9v"\r
26 BASE64("foob") = "Zm9vYg=="\r
27 BASE64("fooba") = "Zm9vYmE="\r
28 BASE64("foobar") = "Zm9vYmFy"\r
29\r
30 The test vectors are using ascii strings for the binary data\r
31 */\r
32\r
33typedef struct {\r
34 CHAR8 *TestInput;\r
35 CHAR8 *TestOutput;\r
36 EFI_STATUS ExpectedStatus;\r
37 VOID *BufferToFree;\r
38 UINTN ExpectedSize;\r
39} BASIC_TEST_CONTEXT;\r
40\r
41#define B64_TEST_1 ""\r
42#define BIN_TEST_1 ""\r
43\r
44#define B64_TEST_2 "Zg=="\r
45#define BIN_TEST_2 "f"\r
46\r
47#define B64_TEST_3 "Zm8="\r
48#define BIN_TEST_3 "fo"\r
49\r
50#define B64_TEST_4 "Zm9v"\r
51#define BIN_TEST_4 "foo"\r
52\r
53#define B64_TEST_5 "Zm9vYg=="\r
54#define BIN_TEST_5 "foob"\r
55\r
56#define B64_TEST_6 "Zm9vYmE="\r
57#define BIN_TEST_6 "fooba"\r
58\r
59#define B64_TEST_7 "Zm9vYmFy"\r
60#define BIN_TEST_7 "foobar"\r
61\r
62// Adds all white space - also ends the last quantum with only spaces afterwards\r
63#define B64_TEST_8_IN " \t\v Zm9\r\nvYmFy \f "\r
64#define BIN_TEST_8 "foobar"\r
65\r
66// Not a quantum multiple of 4\r
67#define B64_ERROR_1 "Zm9vymFy="\r
68\r
69// Invalid characters in the string\r
70#define B64_ERROR_2 "Zm$vymFy"\r
71\r
72// Too many '=' characters\r
73#define B64_ERROR_3 "Z==="\r
74\r
75// Poorly placed '='\r
76#define B64_ERROR_4 "Zm=vYmFy"\r
77\r
78#define MAX_TEST_STRING_SIZE (200)\r
79\r
80// ------------------------------------------------ Input----------Output-----------Result-------Free--Expected Output Size\r
81static BASIC_TEST_CONTEXT mBasicEncodeTest1 = {BIN_TEST_1, B64_TEST_1, EFI_SUCCESS, NULL, sizeof(B64_TEST_1)};\r
82static BASIC_TEST_CONTEXT mBasicEncodeTest2 = {BIN_TEST_2, B64_TEST_2, EFI_SUCCESS, NULL, sizeof(B64_TEST_2)};\r
83static BASIC_TEST_CONTEXT mBasicEncodeTest3 = {BIN_TEST_3, B64_TEST_3, EFI_SUCCESS, NULL, sizeof(B64_TEST_3)};\r
84static BASIC_TEST_CONTEXT mBasicEncodeTest4 = {BIN_TEST_4, B64_TEST_4, EFI_SUCCESS, NULL, sizeof(B64_TEST_4)};\r
85static BASIC_TEST_CONTEXT mBasicEncodeTest5 = {BIN_TEST_5, B64_TEST_5, EFI_SUCCESS, NULL, sizeof(B64_TEST_5)};\r
86static BASIC_TEST_CONTEXT mBasicEncodeTest6 = {BIN_TEST_6, B64_TEST_6, EFI_SUCCESS, NULL, sizeof(B64_TEST_6)};\r
87static BASIC_TEST_CONTEXT mBasicEncodeTest7 = {BIN_TEST_7, B64_TEST_7, EFI_SUCCESS, NULL, sizeof(B64_TEST_7)};\r
88static BASIC_TEST_CONTEXT mBasicEncodeError1 = {BIN_TEST_7, B64_TEST_1, EFI_BUFFER_TOO_SMALL, NULL, sizeof(B64_TEST_7)};\r
89\r
90static BASIC_TEST_CONTEXT mBasicDecodeTest1 = {B64_TEST_1, BIN_TEST_1, EFI_SUCCESS, NULL, sizeof(BIN_TEST_1)-1};\r
91static BASIC_TEST_CONTEXT mBasicDecodeTest2 = {B64_TEST_2, BIN_TEST_2, EFI_SUCCESS, NULL, sizeof(BIN_TEST_2)-1};\r
92static BASIC_TEST_CONTEXT mBasicDecodeTest3 = {B64_TEST_3, BIN_TEST_3, EFI_SUCCESS, NULL, sizeof(BIN_TEST_3)-1};\r
93static BASIC_TEST_CONTEXT mBasicDecodeTest4 = {B64_TEST_4, BIN_TEST_4, EFI_SUCCESS, NULL, sizeof(BIN_TEST_4)-1};\r
94static BASIC_TEST_CONTEXT mBasicDecodeTest5 = {B64_TEST_5, BIN_TEST_5, EFI_SUCCESS, NULL, sizeof(BIN_TEST_5)-1};\r
95static BASIC_TEST_CONTEXT mBasicDecodeTest6 = {B64_TEST_6, BIN_TEST_6, EFI_SUCCESS, NULL, sizeof(BIN_TEST_6)-1};\r
96static BASIC_TEST_CONTEXT mBasicDecodeTest7 = {B64_TEST_7, BIN_TEST_7, EFI_SUCCESS, NULL, sizeof(BIN_TEST_7)-1};\r
97static BASIC_TEST_CONTEXT mBasicDecodeTest8 = {B64_TEST_8_IN, BIN_TEST_8, EFI_SUCCESS, NULL, sizeof(BIN_TEST_8)-1};\r
98\r
99static BASIC_TEST_CONTEXT mBasicDecodeError1 = {B64_ERROR_1, B64_ERROR_1, EFI_INVALID_PARAMETER, NULL, 0};\r
100static BASIC_TEST_CONTEXT mBasicDecodeError2 = {B64_ERROR_2, B64_ERROR_2, EFI_INVALID_PARAMETER, NULL, 0};\r
101static BASIC_TEST_CONTEXT mBasicDecodeError3 = {B64_ERROR_3, B64_ERROR_3, EFI_INVALID_PARAMETER, NULL, 0};\r
102static BASIC_TEST_CONTEXT mBasicDecodeError4 = {B64_ERROR_4, B64_ERROR_4, EFI_INVALID_PARAMETER, NULL, 0};\r
103static BASIC_TEST_CONTEXT mBasicDecodeError5 = {B64_TEST_7, BIN_TEST_1, EFI_BUFFER_TOO_SMALL, NULL, sizeof(BIN_TEST_7)-1};\r
104\r
105/**\r
106 Simple clean up method to make sure tests clean up even if interrupted and fail\r
107 in the middle.\r
108**/\r
109STATIC\r
110VOID\r
111EFIAPI\r
112CleanUpB64TestContext (\r
113 IN UNIT_TEST_CONTEXT Context\r
114 )\r
115{\r
116 BASIC_TEST_CONTEXT *Btc;\r
117\r
118 Btc = (BASIC_TEST_CONTEXT *)Context;\r
119 if (Btc != NULL) {\r
120 //free string if set\r
121 if (Btc->BufferToFree != NULL) {\r
122 FreePool (Btc->BufferToFree);\r
123 Btc->BufferToFree = NULL;\r
124 }\r
125 }\r
126}\r
127\r
128/**\r
129 Unit test for Base64 encode APIs of BaseLib.\r
130\r
131 @param[in] Context [Optional] An optional parameter that enables:\r
132 1) test-case reuse with varied parameters and\r
133 2) test-case re-entry for Target tests that need a\r
134 reboot. This parameter is a VOID* and it is the\r
135 responsibility of the test author to ensure that the\r
136 contents are well understood by all test cases that may\r
137 consume it.\r
138\r
139 @retval UNIT_TEST_PASSED The Unit test has completed and the test\r
140 case was successful.\r
141 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.\r
142**/\r
143STATIC\r
144UNIT_TEST_STATUS\r
145EFIAPI\r
146RfcEncodeTest (\r
147 IN UNIT_TEST_CONTEXT Context\r
148 )\r
149{\r
150 BASIC_TEST_CONTEXT *Btc;\r
151 CHAR8 *b64String;\r
152 CHAR8 *binString;\r
153 UINTN b64StringSize;\r
154 EFI_STATUS Status;\r
155 UINT8 *BinData;\r
156 UINTN BinSize;\r
157 CHAR8 *b64WorkString;\r
158 UINTN ReturnSize;\r
159 INTN CompareStatus;\r
160 UINTN indx;\r
161\r
162 Btc = (BASIC_TEST_CONTEXT *) Context;\r
163 binString = Btc->TestInput;\r
164 b64String = Btc->TestOutput;\r
165\r
166 //\r
167 // Only testing the the translate functionality, so preallocate the proper\r
168 // string buffer.\r
169 //\r
170\r
171 b64StringSize = AsciiStrnSizeS(b64String, MAX_TEST_STRING_SIZE);\r
172 BinSize = AsciiStrnLenS(binString, MAX_TEST_STRING_SIZE);\r
173 BinData = (UINT8 *) binString;\r
174\r
175 b64WorkString = (CHAR8 *) AllocatePool(b64StringSize);\r
176 UT_ASSERT_NOT_NULL(b64WorkString);\r
177\r
178 Btc->BufferToFree = b64WorkString;\r
179 ReturnSize = b64StringSize;\r
180\r
181 Status = Base64Encode(BinData, BinSize, b64WorkString, &ReturnSize);\r
182\r
183 UT_ASSERT_STATUS_EQUAL(Status, Btc->ExpectedStatus);\r
184\r
185 UT_ASSERT_EQUAL(ReturnSize, Btc->ExpectedSize);\r
186\r
187 if (!EFI_ERROR (Btc->ExpectedStatus)) {\r
188 if (ReturnSize != 0) {\r
189 CompareStatus = AsciiStrnCmp (b64String, b64WorkString, ReturnSize);\r
190 if (CompareStatus != 0) {\r
191 UT_LOG_ERROR ("b64 string compare error - size=%d\n", ReturnSize);\r
192 for (indx = 0; indx < ReturnSize; indx++) {\r
193 UT_LOG_ERROR (" %2.2x", 0xff & b64String[indx]);\r
194 }\r
195 UT_LOG_ERROR ("\n b64 work string:\n");\r
196 for (indx = 0; indx < ReturnSize; indx++) {\r
197 UT_LOG_ERROR (" %2.2x", 0xff & b64WorkString[indx]);\r
198 }\r
199 UT_LOG_ERROR ("\n");\r
200 }\r
201 UT_ASSERT_EQUAL (CompareStatus, 0);\r
202 }\r
203 }\r
204\r
205 Btc->BufferToFree = NULL;\r
206 FreePool (b64WorkString);\r
207 return UNIT_TEST_PASSED;\r
208}\r
209\r
210/**\r
211 Unit test for Base64 decode APIs of BaseLib.\r
212\r
213 @param[in] Context [Optional] An optional parameter that enables:\r
214 1) test-case reuse with varied parameters and\r
215 2) test-case re-entry for Target tests that need a\r
216 reboot. This parameter is a VOID* and it is the\r
217 responsibility of the test author to ensure that the\r
218 contents are well understood by all test cases that may\r
219 consume it.\r
220\r
221 @retval UNIT_TEST_PASSED The Unit test has completed and the test\r
222 case was successful.\r
223 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.\r
224**/\r
225STATIC\r
226UNIT_TEST_STATUS\r
227EFIAPI\r
228RfcDecodeTest(\r
229 IN UNIT_TEST_CONTEXT Context\r
230 )\r
231{\r
232 BASIC_TEST_CONTEXT *Btc;\r
233 CHAR8 *b64String;\r
234 CHAR8 *binString;\r
235 EFI_STATUS Status;\r
236 UINTN b64StringLen;\r
237 UINTN ReturnSize;\r
238 UINT8 *BinData;\r
239 UINTN BinSize;\r
240 INTN CompareStatus;\r
241 UINTN indx;\r
242\r
243 Btc = (BASIC_TEST_CONTEXT *)Context;\r
244 b64String = Btc->TestInput;\r
245 binString = Btc->TestOutput;\r
246\r
247 //\r
248 // Only testing the the translate functionality\r
249 //\r
250\r
251 b64StringLen = AsciiStrnLenS (b64String, MAX_TEST_STRING_SIZE);\r
252 BinSize = AsciiStrnLenS (binString, MAX_TEST_STRING_SIZE);\r
253\r
254 BinData = AllocatePool (BinSize);\r
090e267b 255 UT_ASSERT_NOT_NULL(BinData);\r
e50c2bb3 256\r
090e267b 257 Btc->BufferToFree = BinData;\r
e50c2bb3 258 ReturnSize = BinSize;\r
090e267b 259\r
e50c2bb3
MK
260 Status = Base64Decode (b64String, b64StringLen, BinData, &ReturnSize);\r
261\r
262 UT_ASSERT_STATUS_EQUAL (Status, Btc->ExpectedStatus);\r
263\r
264 // If an error is not expected, check the results\r
265 if (EFI_ERROR (Btc->ExpectedStatus)) {\r
266 if (Btc->ExpectedStatus == EFI_BUFFER_TOO_SMALL) {\r
267 UT_ASSERT_EQUAL (ReturnSize, Btc->ExpectedSize);\r
268 }\r
269 } else {\r
270 UT_ASSERT_EQUAL (ReturnSize, Btc->ExpectedSize);\r
271 if (ReturnSize != 0) {\r
272 CompareStatus = CompareMem (binString, BinData, ReturnSize);\r
273 if (CompareStatus != 0) {\r
274 UT_LOG_ERROR ("bin string compare error - size=%d\n", ReturnSize);\r
275 for (indx = 0; indx < ReturnSize; indx++) {\r
276 UT_LOG_ERROR (" %2.2x", 0xff & binString[indx]);\r
277 }\r
278 UT_LOG_ERROR ("\nBinData:\n");\r
279 for (indx = 0; indx < ReturnSize; indx++) {\r
280 UT_LOG_ERROR (" %2.2x", 0xff & BinData[indx]);\r
281 }\r
282 UT_LOG_ERROR ("\n");\r
283 }\r
284 UT_ASSERT_EQUAL (CompareStatus, 0);\r
285 }\r
286 }\r
287\r
288 Btc->BufferToFree = NULL;\r
289 FreePool (BinData);\r
290 return UNIT_TEST_PASSED;\r
291}\r
292\r
1c877c71
MK
293#define SOURCE_STRING L"Hello"\r
294\r
295STATIC\r
296UNIT_TEST_STATUS\r
297EFIAPI\r
298SafeStringContraintCheckTest (\r
299 IN UNIT_TEST_CONTEXT Context\r
300 )\r
301{\r
302 RETURN_STATUS Status;\r
303 CHAR16 Destination[20];\r
304 CHAR16 AllZero[20];\r
305\r
306 //\r
307 // Zero buffer used to verify Destination is not modified\r
308 //\r
309 ZeroMem (AllZero, sizeof (AllZero));\r
310\r
311 //\r
312 // Positive test case copy source unicode string to destination\r
313 //\r
314 ZeroMem (Destination, sizeof (Destination));\r
315 Status = StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR16), SOURCE_STRING);\r
316 UT_ASSERT_NOT_EFI_ERROR (Status);\r
317 UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, sizeof (SOURCE_STRING));\r
318\r
319 //\r
320 // Positive test case with DestMax the same as Source size\r
321 //\r
322 ZeroMem (Destination, sizeof (Destination));\r
323 Status = StrCpyS (Destination, sizeof (SOURCE_STRING) / sizeof (CHAR16), SOURCE_STRING);\r
324 UT_ASSERT_NOT_EFI_ERROR (Status);\r
325 UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, sizeof (SOURCE_STRING));\r
326\r
327 //\r
328 // Negative test case with Destination NULL\r
329 //\r
330 ZeroMem (Destination, sizeof (Destination));\r
331 Status = StrCpyS (NULL, sizeof (Destination) / sizeof (CHAR16), SOURCE_STRING);\r
332 UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
333 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
334\r
335 //\r
336 // Negative test case with Source NULL\r
337 //\r
338 ZeroMem (Destination, sizeof (Destination));\r
339 Status = StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR16), NULL);\r
340 UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
341 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
342\r
343 //\r
344 // Negative test case with DestMax too big\r
345 //\r
346 ZeroMem (Destination, sizeof (Destination));\r
347 Status = StrCpyS (Destination, MAX_UINTN, SOURCE_STRING);\r
348 UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
349 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
350\r
351 //\r
352 // Negative test case with DestMax 0\r
353 //\r
354 ZeroMem (Destination, sizeof (Destination));\r
355 Status = StrCpyS (Destination, 0, SOURCE_STRING);\r
356 UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER);\r
357 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
358\r
359 //\r
360 // Negative test case with DestMax smaller than Source size\r
361 //\r
362 ZeroMem (Destination, sizeof (Destination));\r
363 Status = StrCpyS (Destination, 1, SOURCE_STRING);\r
364 UT_ASSERT_STATUS_EQUAL (Status, RETURN_BUFFER_TOO_SMALL);\r
365 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
366\r
367 //\r
368 // Negative test case with DestMax smaller than Source size by one character\r
369 //\r
370 ZeroMem (Destination, sizeof (Destination));\r
371 Status = StrCpyS (Destination, sizeof (SOURCE_STRING) / sizeof (CHAR16) - 1, SOURCE_STRING);\r
372 UT_ASSERT_STATUS_EQUAL (Status, RETURN_BUFFER_TOO_SMALL);\r
373 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
374\r
375 //\r
376 // Negative test case with overlapping Destination and Source\r
377 //\r
378 ZeroMem (Destination, sizeof (Destination));\r
379 Status = StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR16), Destination);\r
380 UT_ASSERT_STATUS_EQUAL (Status, RETURN_ACCESS_DENIED);\r
381 UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero));\r
382\r
383 return UNIT_TEST_PASSED;\r
384}\r
385\r
e50c2bb3
MK
386/**\r
387 Initialze the unit test framework, suite, and unit tests for the\r
388 Base64 conversion APIs of BaseLib and run the unit tests.\r
389\r
390 @retval EFI_SUCCESS All test cases were dispatched.\r
391 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r
392 initialize the unit tests.\r
393**/\r
394STATIC\r
395EFI_STATUS\r
396EFIAPI\r
397UnitTestingEntry (\r
398 VOID\r
399 )\r
400{\r
401 EFI_STATUS Status;\r
402 UNIT_TEST_FRAMEWORK_HANDLE Fw;\r
403 UNIT_TEST_SUITE_HANDLE b64EncodeTests;\r
404 UNIT_TEST_SUITE_HANDLE b64DecodeTests;\r
1c877c71 405 UNIT_TEST_SUITE_HANDLE SafeStringTests;\r
e50c2bb3
MK
406\r
407 Fw = NULL;\r
408\r
409 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));\r
410\r
411 //\r
412 // Start setting up the test framework for running the tests.\r
413 //\r
414 Status = InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);\r
415 if (EFI_ERROR (Status)) {\r
416 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));\r
417 goto EXIT;\r
418 }\r
419\r
420 //\r
421 // Populate the B64 Encode Unit Test Suite.\r
422 //\r
423 Status = CreateUnitTestSuite (&b64EncodeTests, Fw, "b64 Encode binary to Ascii string", "BaseLib.b64Encode", NULL, NULL);\r
424 if (EFI_ERROR (Status)) {\r
425 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for b64EncodeTests\n"));\r
426 Status = EFI_OUT_OF_RESOURCES;\r
427 goto EXIT;\r
428 }\r
429\r
430 // --------------Suite-----------Description--------------Class Name----------Function--------Pre---Post-------------------Context-----------\r
431 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - Empty", "Test1", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest1);\r
432 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - f", "Test2", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest2);\r
433 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - fo", "Test3", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest3);\r
434 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - foo", "Test4", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest4);\r
435 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - foob", "Test5", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest5);\r
436 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - fooba", "Test6", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest6);\r
437 AddTestCase (b64EncodeTests, "RFC 4686 Test Vector - foobar", "Test7", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeTest7);\r
438 AddTestCase (b64EncodeTests, "Too small of output buffer", "Error1", RfcEncodeTest, NULL, CleanUpB64TestContext, &mBasicEncodeError1);\r
439 //\r
440 // Populate the B64 Decode Unit Test Suite.\r
441 //\r
442 Status = CreateUnitTestSuite (&b64DecodeTests, Fw, "b64 Decode Ascii string to binary", "BaseLib.b64Decode", NULL, NULL);\r
443 if (EFI_ERROR (Status)) {\r
444 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for b64Decode Tests\n"));\r
445 Status = EFI_OUT_OF_RESOURCES;\r
446 goto EXIT;\r
447 }\r
448\r
449 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - Empty", "Test1", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest1);\r
450 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - f", "Test2", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest2);\r
451 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - fo", "Test3", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest3);\r
452 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - foo", "Test4", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest4);\r
453 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - foob", "Test5", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest5);\r
454 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - fooba", "Test6", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest6);\r
455 AddTestCase (b64DecodeTests, "RFC 4686 Test Vector - foobar", "Test7", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest7);\r
456 AddTestCase (b64DecodeTests, "Ignore Whitespace test", "Test8", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeTest8);\r
457\r
458 AddTestCase (b64DecodeTests, "Not a quantum multiple of 4", "Error1", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeError1);\r
459 AddTestCase (b64DecodeTests, "Invalid characters in the string", "Error2", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeError2);\r
460 AddTestCase (b64DecodeTests, "Too many padding characters", "Error3", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeError3);\r
461 AddTestCase (b64DecodeTests, "Incorrectly placed padding character", "Error4", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeError4);\r
462 AddTestCase (b64DecodeTests, "Too small of output buffer", "Error5", RfcDecodeTest, NULL, CleanUpB64TestContext, &mBasicDecodeError5);\r
463\r
1c877c71
MK
464 //\r
465 // Populate the safe string Unit Test Suite.\r
466 //\r
467 Status = CreateUnitTestSuite (&SafeStringTests, Fw, "Safe String", "BaseLib.SafeString", NULL, NULL);\r
468 if (EFI_ERROR (Status)) {\r
469 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for SafeStringTests\n"));\r
470 Status = EFI_OUT_OF_RESOURCES;\r
471 goto EXIT;\r
472 }\r
473\r
474 // --------------Suite-----------Description--------------Class Name----------Function--------Pre---Post-------------------Context-----------\r
475 AddTestCase (SafeStringTests, "SAFE_STRING_CONSTRAINT_CHECK", "SafeStringContraintCheckTest", SafeStringContraintCheckTest, NULL, NULL, NULL);\r
476\r
e50c2bb3
MK
477 //\r
478 // Execute the tests.\r
479 //\r
480 Status = RunAllTestSuites (Fw);\r
481\r
482EXIT:\r
483 if (Fw) {\r
484 FreeUnitTestFramework (Fw);\r
485 }\r
486\r
487 return Status;\r
488}\r
489\r
490/**\r
491 Standard UEFI entry point for target based unit test execution from UEFI Shell.\r
492**/\r
493EFI_STATUS\r
494EFIAPI\r
495BaseLibUnitTestAppEntry (\r
496 IN EFI_HANDLE ImageHandle,\r
497 IN EFI_SYSTEM_TABLE *SystemTable\r
498 )\r
499{\r
500 return UnitTestingEntry ();\r
501}\r
502\r
503/**\r
504 Standard POSIX C entry point for host based unit test execution.\r
505**/\r
506int\r
507main (\r
508 int argc,\r
509 char *argv[]\r
510 )\r
511{\r
512 return UnitTestingEntry ();\r
513}\r