-
Notifications
You must be signed in to change notification settings - Fork 89
/
XmlTreeLibUnitTests.c
571 lines (472 loc) · 20.3 KB
/
XmlTreeLibUnitTests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/**
@file
Code for unit testing the XmlTreeLib.
Copyright (C) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/PrintLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UnitTestLib.h>
#include <XmlTypes.h>
#include <Library/XmlTreeLib.h>
#include "TestData.h"
#define UNIT_TEST_APP_NAME "XML Lib Unit Test Application"
#define UNIT_TEST_APP_VERSION "0.3"
/**
Simple clean up method to make sure string parsing tests clean up even if interrupted and fail in the middle.
**/
VOID
EFIAPI
CleanUpXmlStringParseContext (
IN UNIT_TEST_CONTEXT Context
)
{
XmlStringParseContext *XmlContext = (XmlStringParseContext *)Context;
if (XmlContext != NULL) {
// free string if set
if (XmlContext->String != NULL) {
FreePool (XmlContext->String);
XmlContext->String = NULL;
}
}
}
/**
Simple clean up method to make sure tests clean up even if interrupted and fail in the middle.
**/
VOID
EFIAPI
CleanUpXmlTestContext (
IN UNIT_TEST_CONTEXT Context
)
{
XmlTestContext *XmlContext = (XmlTestContext *)Context;
if (XmlContext != NULL) {
// free string if set
if (XmlContext->ToFreeXmlString != NULL) {
FreePool (XmlContext->ToFreeXmlString);
XmlContext->ToFreeXmlString = NULL;
}
// free xml node tree
if (XmlContext->Node != NULL) {
FreeXmlTree (&(XmlContext->Node));
}
}
}
/**
Simple Test method that can be used to validate lots of different XML strings.
**/
UNIT_TEST_STATUS
EFIAPI
ParseValidXml (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
XmlTestContext *XmlContext = (XmlTestContext *)Context;
EFI_STATUS Status;
UINTN ResultTotalElements, ResultTotalAttributes, ResultMaxDepth, ResultMaxAttributes, StringSize;
ResultTotalElements = 0;
ResultTotalAttributes = 0;
ResultMaxDepth = 0;
ResultMaxAttributes = 0;
if (XmlContext == NULL) {
DEBUG ((DEBUG_ERROR, "%a Context is NULL. Test is not valid\n", __FUNCTION__));
return UNIT_TEST_ERROR_TEST_FAILED;
}
if (XmlContext->InputXmlString == NULL) {
DEBUG ((DEBUG_ERROR, "%a InputXmlString in the context struct is NULL. Test is not valid!\n", __FUNCTION__));
return UNIT_TEST_ERROR_TEST_FAILED;
}
Status = CreateXmlTree (XmlContext->InputXmlString, AsciiStrLen (XmlContext->InputXmlString), &ResultData);
XmlContext->Node = ResultData; // set dynamic memory pointer in struct so memory gets cleanup in cleanup function
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a Failed to create xml tree node\n", __FUNCTION__));
}
UT_ASSERT_NOT_NULL (ResultData);
// Check all the things we can check to make sure it was parsed correctly
Status = XmlTreeNumberOfNodes (ResultData, &ResultTotalElements);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->TotalElements, ResultTotalElements);
Status = XmlTreeNumberOfAttributes (ResultData, &ResultTotalAttributes);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->TotalAttributes, ResultTotalAttributes);
Status = XmlTreeMaxDepth (ResultData, &ResultMaxDepth);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->MaxDepth, ResultMaxDepth);
Status = XmlTreeMaxAttributes (ResultData, &ResultMaxAttributes);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->MaxAttributes, ResultMaxAttributes);
// write to string
Status = XmlTreeToString (ResultData, TRUE, &StringSize, &XmlContext->ToFreeXmlString);
UT_ASSERT_NOT_EFI_ERROR (Status);
DebugPrintXmlTree (ResultData, 0);
// free the old xml tree
FreeXmlTree (&ResultData);
XmlContext->Node = NULL;
// read from the new string
Status = CreateXmlTree (XmlContext->ToFreeXmlString, AsciiStrLen (XmlContext->ToFreeXmlString), &ResultData);
XmlContext->Node = ResultData;
UT_ASSERT_NOT_EFI_ERROR (Status);
ResultTotalElements = 0;
ResultTotalAttributes = 0;
ResultMaxDepth = 0;
ResultMaxAttributes = 0;
// Check all the things we can check to make sure it was parsed correctly
Status = XmlTreeNumberOfNodes (ResultData, &ResultTotalElements);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->TotalElements, ResultTotalElements);
Status = XmlTreeNumberOfAttributes (ResultData, &ResultTotalAttributes);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->TotalAttributes, ResultTotalAttributes);
Status = XmlTreeMaxDepth (ResultData, &ResultMaxDepth);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->MaxDepth, ResultMaxDepth);
Status = XmlTreeMaxAttributes (ResultData, &ResultMaxAttributes);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (XmlContext->MaxAttributes, ResultMaxAttributes);
DebugPrintXmlTree (ResultData, 0);
return UNIT_TEST_PASSED;
}
/**
Parse strings
**/
UNIT_TEST_STATUS
EFIAPI
TestStringParsing (
IN UNIT_TEST_CONTEXT Context
)
{
UINTN Length = 0;
XmlStringParseContext *XmlContext = (XmlStringParseContext *)Context;
EFI_STATUS Status;
// Test the data input - these are test errors not failures
if (XmlContext->StringEscaped == NULL) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (StringEscaped == NULL)\n"));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
Length = AsciiStrLen (XmlContext->StringEscaped);
if (Length != XmlContext->EscapedLength) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (EscapedLength Incorrect %d Test Data EscapedLength %d)\n", Length, XmlContext->EscapedLength));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
if (XmlContext->StringNotEscaped == NULL) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (StringNotEscaped == NULL)\n"));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
Length = AsciiStrLen (XmlContext->StringNotEscaped);
if (Length != XmlContext->NotEscapedLength) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (NotEscapedLength Incorrect %d Test Data NotEscapedLength %d)\n", Length, XmlContext->NotEscapedLength));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
if (XmlContext->String != NULL) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (String Not NULL Before Test)\n"));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
// Now start actual tests
// Test Escape Function
Status = XmlEscape (XmlContext->StringNotEscaped, XmlContext->NotEscapedLength + 1, &(XmlContext->String));
UT_ASSERT_NOT_EFI_ERROR (Status);
Length = AsciiStrLen (XmlContext->String);
UT_ASSERT_EQUAL (Length, XmlContext->EscapedLength);
UT_ASSERT_MEM_EQUAL (XmlContext->String, XmlContext->StringEscaped, Length+1);
FreePool (XmlContext->String);
XmlContext->String = NULL;
// Test UnEscape Function
Status = XmlUnEscape (XmlContext->StringEscaped, XmlContext->EscapedLength + 1, &(XmlContext->String));
UT_ASSERT_NOT_EFI_ERROR (Status);
Length = AsciiStrLen (XmlContext->String);
UT_ASSERT_EQUAL (Length, XmlContext->NotEscapedLength);
UT_ASSERT_MEM_EQUAL (XmlContext->String, XmlContext->StringNotEscaped, Length + 1);
FreePool (XmlContext->String);
XmlContext->String = NULL;
return UNIT_TEST_PASSED;
}
/**
Verify UnEscape works on strings with no escape codes
**/
UNIT_TEST_STATUS
EFIAPI
TestStringUnescapeErrorTest (
IN UNIT_TEST_CONTEXT Context
)
{
UINTN Length = 0;
XmlStringParseContext *XmlContext = (XmlStringParseContext *)Context;
EFI_STATUS Status;
// Test the data input - these are test errors not failures
if (XmlContext->StringEscaped == NULL) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (StringEscaped == NULL)\n"));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
Length = AsciiStrLen (XmlContext->StringEscaped);
if (Length != XmlContext->EscapedLength) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (EscapedLength Incorrect %d Test Data EscapedLength %d)\n", Length, XmlContext->EscapedLength));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
if (XmlContext->String != NULL) {
DEBUG ((DEBUG_ERROR, "Test Data Error - Context invalid (String Not NULL Before Test)\n"));
return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
}
// Test UnEscape Function
Status = XmlUnEscape (XmlContext->StringEscaped, XmlContext->EscapedLength + 1, &(XmlContext->String));
UT_ASSERT_NOT_EFI_ERROR (Status);
Length = AsciiStrLen (XmlContext->String);
UT_ASSERT_EQUAL (Length, XmlContext->NotEscapedLength);
UT_ASSERT_MEM_EQUAL (XmlContext->String, XmlContext->StringNotEscaped, Length + 1);
FreePool (XmlContext->String);
XmlContext->String = NULL;
return UNIT_TEST_PASSED;
}
/**
Test that invalid Xml is not parsed and error is reported correctly
**/
UNIT_TEST_STATUS
EFIAPI
ParseInValidXml1 (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
EFI_STATUS Status;
CHAR8 BadString[] = "This is not valid xml"; // Not even close
Status = CreateXmlTree (BadString, AsciiStrLen (BadString), &ResultData);
if (ResultData != NULL) {
FreePool (ResultData);
UT_ASSERT_TRUE (ResultData == NULL); // cause it to fail here after memory clean up
}
UT_ASSERT_TRUE (EFI_ERROR (Status));
return UNIT_TEST_PASSED;
}
/**
Test that invalid Xml is not parsed and error is reported correctly
**/
UNIT_TEST_STATUS
EFIAPI
ParseInValidXml2 (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
EFI_STATUS Status;
CHAR8 BadString[] = "<Node1><Node2></Node1>"; // malformed XML
Status = CreateXmlTree (BadString, AsciiStrLen (BadString), &ResultData);
if (ResultData != NULL) {
FreePool (ResultData);
UT_ASSERT_TRUE (ResultData == NULL); // cause it to fail here after memory clean up
}
UT_ASSERT_TRUE (EFI_ERROR (Status));
return UNIT_TEST_PASSED;
}
/**
Test that invalid Xml is not parsed and error is reported correctly
**/
UNIT_TEST_STATUS
EFIAPI
ParseInValidXml3 (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
EFI_STATUS Status;
CHAR8 BadString[] = "<Node1><Node2><Node3 /></Node1>"; // malformed xml - Missing Node 2 closure
Status = CreateXmlTree (BadString, AsciiStrLen (BadString), &ResultData);
if (ResultData != NULL) {
FreePool (ResultData);
UT_ASSERT_TRUE (ResultData == NULL); // cause it to fail here after memory clean up
}
UT_ASSERT_TRUE (EFI_ERROR (Status));
return UNIT_TEST_PASSED;
}
/**
Test Node count function on known count
**/
UNIT_TEST_STATUS
EFIAPI
TestNodeCount (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
UINTN TotalElements = 0;
EFI_STATUS Status;
CHAR8 MyString[] = "<Node1><Node2><Node3 /><Node4 /></Node2> </Node1>"; // 4 nodes with depth of 3
Status = CreateXmlTree (MyString, AsciiStrLen (MyString), &ResultData);
UT_ASSERT_NOT_NULL (ResultData);
Status = XmlTreeNumberOfNodes (ResultData, &TotalElements);
// free our memory
FreeXmlTree (&ResultData);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (4, TotalElements);
return UNIT_TEST_PASSED;
}
/**
Test Node max depth function on known value
**/
UNIT_TEST_STATUS
EFIAPI
TestNodeMaxDepth (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
UINTN MaxDepth = 0;
EFI_STATUS Status;
CHAR8 MyString[] = "<Node1><Node2><Node3 /><Node4 /></Node2><Node5><Node6><Node7 /></Node6></Node5></Node1>"; // 4 nodes with depth of 4
Status = CreateXmlTree (MyString, AsciiStrLen (MyString), &ResultData);
UT_ASSERT_NOT_NULL (ResultData);
Status = XmlTreeMaxDepth (ResultData, &MaxDepth);
// free our memory
FreeXmlTree (&ResultData);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (4, MaxDepth);
return UNIT_TEST_PASSED;
}
/**
Test attribute count function with known value
**/
UNIT_TEST_STATUS
EFIAPI
TestAttributeCount (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
UINTN Count = 0;
EFI_STATUS Status;
CHAR8 MyString[] = "<Node1 att1='test1'><Node2 att2='test2'><Node3 att3='test3' att4='test4' /></Node2></Node1>"; // 4 attributes total
Status = CreateXmlTree (MyString, AsciiStrLen (MyString), &ResultData);
UT_ASSERT_NOT_NULL (ResultData);
Status = XmlTreeNumberOfAttributes (ResultData, &Count);
// free our memory
FreeXmlTree (&ResultData);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (4, Count);
return UNIT_TEST_PASSED;
}
/**
Test max attribute function on known value
**/
UNIT_TEST_STATUS
EFIAPI
TestAttributeMax (
IN UNIT_TEST_CONTEXT Context
)
{
XmlNode *ResultData = NULL;
UINTN Count = 0;
EFI_STATUS Status;
CHAR8 MyString[] = "<Node1 att1='test1'><Node2 att2='test2'><Node3 att3='test3' att4='test4' /></Node2></Node1>"; // 4 attributes total
Status = CreateXmlTree (MyString, AsciiStrLen (MyString), &ResultData);
UT_ASSERT_NOT_NULL (ResultData);
Status = XmlTreeMaxAttributes (ResultData, &Count);
// free our memory
FreeXmlTree (&ResultData);
UT_ASSERT_NOT_EFI_ERROR (Status);
UT_ASSERT_EQUAL (2, Count);
return UNIT_TEST_PASSED;
}
/**
Main fuction sets up the unit test environment
**/
EFI_STATUS
EFIAPI
UnitTestingEntry (
)
{
EFI_STATUS Status;
UNIT_TEST_FRAMEWORK_HANDLE Fw = NULL;
UNIT_TEST_SUITE_HANDLE InputTestSuite;
UNIT_TEST_SUITE_HANDLE ProcessEscapedInputTestSuite;
UNIT_TEST_SUITE_HANDLE BasicMetricsTestSuite;
DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
//
// Start setting up the test framework for running the tests.
//
Status = InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
goto EXIT;
}
///
// Test the Escape / Unescape functions for special characters in the XML strings
//
Status = CreateUnitTestSuite (&ProcessEscapedInputTestSuite, Fw, "XML Escape Strings Test Suite ", "Common.Xml.ParseEscape", NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for XML Escape Input String Parsing Test Suite\n"));
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with no escape characters", "ParseEscapeNone", TestStringParsing, NULL, CleanUpXmlStringParseContext, &Context1);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with three Less Than escape characters", "ParseEscapeLessThan", TestStringParsing, NULL, CleanUpXmlStringParseContext, &ContextLT);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with three Greater Than escape characters", "ParseEscapeGreaterThan", TestStringParsing, NULL, CleanUpXmlStringParseContext, &ContextGT);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with three Quote escape characters", "ParseEscapeQuote", TestStringParsing, NULL, CleanUpXmlStringParseContext, &ContextQuote);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with three Apostrophe escape characters", "ParseEscapeApostrophe", TestStringParsing, NULL, CleanUpXmlStringParseContext, &ContextApostrophe);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with three Ampersand escape characters", "ParseEscapeAmpersand", TestStringParsing, NULL, CleanUpXmlStringParseContext, &ContextAmp);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with all escape characters and other inputs", "ParseEscapeMany", TestStringParsing, NULL, CleanUpXmlStringParseContext, &Context7Esc);
AddTestCase (ProcessEscapedInputTestSuite, "Parse string with Ampersand but no escape", "ParseAmpersand", TestStringUnescapeErrorTest, NULL, CleanUpXmlStringParseContext, &ContextAmpNoEsc);
//
// The the metric functions - Max depth, node count, max attributes, attribute count
//
Status = CreateUnitTestSuite (&BasicMetricsTestSuite, Fw, "XML Node Tree Metrics", "Common.Xml.TreeMetrics", NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for XML Node Tree Metrics Test Suite\n"));
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (BasicMetricsTestSuite, "Test Node Count Function", "NodeCount", TestNodeCount, NULL, NULL, NULL);
AddTestCase (BasicMetricsTestSuite, "Test Max Node Depth Function", "MaxDepth", TestNodeMaxDepth, NULL, NULL, NULL);
AddTestCase (BasicMetricsTestSuite, "Test Attribute Count Function", "AttributeCount", TestAttributeCount, NULL, NULL, NULL);
AddTestCase (BasicMetricsTestSuite, "Test Max Node Depth Function", "AttributeMax", TestAttributeMax, NULL, NULL, NULL);
//
// Test the conversion of string to tree and back to string
//
Status = CreateUnitTestSuite (&InputTestSuite, Fw, "XML Input Parsing Test Suite ", "Common.Xml.Parse", NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for XML Input Parsing Test Suite\n"));
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (InputTestSuite, "Parse Valid XML with a very simple root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly1Context);
AddTestCase (InputTestSuite, "Parse Valid XML with a very simple empty tag root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly2Context);
AddTestCase (InputTestSuite, "Parse Valid XML with a very simple root, tailing with uninitialized memory", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly3Context);
AddTestCase (InputTestSuite, "Parse Valid XML with a very simple empty tag root, tailing with uninitialized memory", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly4Context);
AddTestCase (InputTestSuite, "Parse Valid XML with two very simple roots, report only first root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly5Context);
AddTestCase (InputTestSuite, "Parse Valid XML with two very simple empty tag roots, report only first root", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &VerySimpleElementsOnly6Context);
AddTestCase (InputTestSuite, "Parse Valid XML with simple elements 3 layers", "ValidElements", ParseValidXml, NULL, CleanUpXmlTestContext, &SimpleElementsOnlyContext);
AddTestCase (InputTestSuite, "Parse Valid XML with 2 elements and 2 attributes", "ValidElementsAndAttributes", ParseValidXml, NULL, CleanUpXmlTestContext, &SimpleElementsAttributesContext);
AddTestCase (InputTestSuite, "Parse Invalid XML string containing an attribute with invalid xml chars", "NonXmlEncodedAttribute", ParseValidXml, NULL, CleanUpXmlTestContext, &NonEncodedXmlAttribute1Context);
AddTestCase (InputTestSuite, "Parse valid encoded XML string containing an attribute with encoded xml chars", "XmlEncodedAttribute", ParseValidXml, NULL, CleanUpXmlTestContext, &EncodedXmlAttribute1Context);
AddTestCase (InputTestSuite, "Fail parsing string with no XML Tags", "InvalidString", ParseInValidXml1, NULL, NULL, NULL);
AddTestCase (InputTestSuite, "Fail parsing string missing closing element", "InvalidString", ParseInValidXml2, NULL, NULL, NULL);
AddTestCase (InputTestSuite, "Fail parsing string missing nested closing element", "InvalidString", ParseInValidXml3, NULL, NULL, NULL);
AddTestCase (InputTestSuite, "Parse Valid XML with a long data element", "LongElement", ParseValidXml, NULL, CleanUpXmlTestContext, &LongElementContext);
//
// Execute the tests.
//
Status = RunAllTestSuites (Fw);
EXIT:
if (Fw) {
FreeUnitTestFramework (Fw);
}
return Status;
}
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return UnitTestingEntry ();
}
int
main (
int argc,
char *argv[]
)
{
return UnitTestingEntry ();
}