aboutsummaryrefslogtreecommitdiff
path: root/src/old/unit/xml/xml.cpp
blob: e4d779c00b8aa6b702bc9e60259c921636417e50 (plain)
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
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cpptest.h>
#include <string.h>

#include "xmlstringreader.h"
#include "xmlexception.h"

class XmlCoreTestSuite : public Test::Suite
{
public:
	XmlCoreTestSuite()
	{
		TEST_ADD( XmlCoreTestSuite::badXml01 )
		TEST_ADD( XmlCoreTestSuite::badXml02 )
		TEST_ADD( XmlCoreTestSuite::badXml03 )

		TEST_ADD( XmlCoreTestSuite::entityBuiltin01 )

		TEST_ADD( XmlCoreTestSuite::entityDoc01 )
	}
	
private:
	void badXml01()
	{
		TEST_THROWS( XmlStringReader r("<hello></bye>"), XmlException & );
	}
	
	void badXml02()
	{
		TEST_THROWS( XmlStringReader r("<hello>"), XmlException & );
	}

	void badXml03()
	{
		TEST_THROWS( XmlStringReader r("<hello param=\"stuff?"), XmlException & );
	}

	void entityBuiltin01()
	{
		XmlStringReader r("<hello>&gt;&lt;&amp;&apos;&quot;</hello>");
		TEST_ASSERT( strcmp( r.getRoot()->getContent(), "><&\'\"" ) == 0 );
	}
	
	void entityDoc01()
	{
		XmlStringReader r("<!ENTITY  name  \"bob the man\"><hello>&quot;&name;&quot;</hello>");
		TEST_ASSERT( strcmp( r.getRoot()->getContent(), "\"bob the man\"" ) == 0 );
	}
};

int main( int argc, char *argv[] )
{
	Test::TextOutput output( Test::TextOutput::Verbose );
	XmlCoreTestSuite ts;
	return ts.run( output ) ? EXIT_SUCCESS : EXIT_FAILURE;
}