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
|
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
|
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "TestsAppDelegate.h"
#import "ObjFW.h"
#import "ObjFWTest.h"
static OFString *const module = @"OFXMLElementBuilder";
static OFXMLNode *nodes[2];
static size_t i = 0;
@implementation TestsAppDelegate (OFXMLElementBuilderTests)
@interface OFXMLElementBuilderTests: OTTestCase <OFXMLElementBuilderDelegate>
{
OFXMLNode *_nodes[2];
size_t _i;
}
@end
@implementation OFXMLElementBuilderTests
- (void)dealloc
{
[_nodes[0] release];
[_nodes[1] release];
[super dealloc];
}
- (void)elementBuilder: (OFXMLElementBuilder *)builder
didBuildElement: (OFXMLElement *)element
{
OFEnsure(i == 0);
nodes[i++] = [element retain];
OTAssertEqual(_i, 0);
_nodes[_i++] = [element retain];
}
- (void)elementBuilder: (OFXMLElementBuilder *)builder
didBuildOrphanNode: (OFXMLNode *)node
{
OFEnsure(i == 1);
nodes[i++] = [node retain];
OTAssertEqual(_i, 1);
_nodes[_i++] = [node retain];
}
- (void)XMLElementBuilderTests
- (void)testElementBuilder
{
void *pool = objc_autoreleasePoolPush();
OFXMLParser *parser = [OFXMLParser parser];
OFXMLElementBuilder *builder = [OFXMLElementBuilder builder];
OFString *string = @"<foo>bar<![CDATA[f<oo]]>baz<qux/>"
" <qux xmlns:qux='urn:qux'><?asd?><qux:bar/><x qux:y='z'/></qux>"
"</foo>";
parser.delegate = builder;
builder.delegate = self;
TEST(@"Building elements from parsed XML",
R([parser parseString: string]) &&
nodes[0] != nil && [nodes[0].XMLString isEqual: string] &&
R([parser parseString: @"<!--foo-->"]) &&
nodes[1] != nil && [nodes[1].XMLString isEqual: @"<!--foo-->"] &&
[parser parseString: string];
OTAssertEqualObjects(_nodes[0].XMLString, string);
[parser parseString: @"<!--foo-->"];
OTAssertEqualObjects(_nodes[1].XMLString, @"<!--foo-->");
i == 2)
[nodes[0] release];
OTAssertEqual(_i, 2);
[nodes[1] release];
objc_autoreleasePoolPop(pool);
}
@end
|