1
// Copyright (C) 2009-2011 Christian Stehno
2
// No rights reserved: this software is in the public domain.
9
bool simple_xml( irr::io::IFileSystem * fs )
11
io::IXMLReaderUTF8* reader = fs->createXMLReaderUTF8("media/test.xml");
14
logTestString("Could not create XML reader.\n");
18
const core::stringc expected[] = {
26
if (reader->getNodeType() == io::EXN_ELEMENT)
28
if (expected[i++] != reader->getNodeName())
30
logTestString("Did not find expected string in XML element name.\n");
41
// CDATA should return everything between "![CDATA[" and "]]>" as it's in the file
42
bool cdata( irr::io::IFileSystem * fs )
44
io::IXMLReaderUTF8* reader = fs->createXMLReaderUTF8("media/cdata.xml");
47
logTestString("Could not create XML reader.\n");
51
const core::stringc textNode("text");
52
core::array< core::stringc > compareStrings;
53
compareStrings.push_back("simple");
54
compareStrings.push_back("");
55
compareStrings.push_back("] ]> ");
56
compareStrings.push_back("]\n]> ");
57
compareStrings.push_back("\nNewlines\n\tand tabs\n\t\tgogogo");
58
compareStrings.push_back("&&#@#$%*()@#$%*()#$%*(");
59
compareStrings.push_back("& & && &&& &a &ü &ä &ö &&#");
65
if (reader->getNodeType() == io::EXN_ELEMENT)
67
if ( core::stringc(reader->getNodeName()) == textNode )
71
if (reader->getNodeType() == io::EXN_CDATA)
73
core::stringc data = reader->getNodeData();
74
core::stringc name = reader->getNodeName();
75
if ( count == compareStrings.size() )
77
logTestString("too many cdata elements for reading in %s:%d\n", __FILE__, __LINE__);
79
else if ( count < compareStrings.size() )
81
core::stringc cmpString(compareStrings[count]);
83
// some (unused) variables to ease debugging
84
// const c8* dataRaw = data.c_str();
85
// const c8* cmpRaw = cmpString.c_str();
86
if ( cmpString != data )
89
logTestString("cdata read failed for string %d in %s:%d\n", count, __FILE__, __LINE__);
94
if ( reader->getNodeType() == io::EXN_ELEMENT_END )
107
bool attributeValues(irr::io::IFileSystem * fs)
109
io::IXMLReaderUTF8* reader = fs->createXMLReaderUTF8("media/attributes.xml");
112
logTestString("Could not create XML reader.\n");
117
bool hasNode = false;
118
while (reader->read())
120
if (io::EXN_ELEMENT == reader->getNodeType() )
122
if ( core::stringc(reader->getNodeName()) == core::stringc("element_position") )
125
int id1 = reader->getAttributeValueAsInt("id1");
126
if ( id1 != 152722522 )
128
logTestString("id1 is %d in %s:%d\n", id1, __FILE__, __LINE__);
131
int id2 = reader->getAttributeValueAsInt("id2");
133
int x = reader->getAttributeValueAsInt("x");
135
int y = reader->getAttributeValueAsInt("y");
143
logTestString("missing node in xml in %s:%d\n", __FILE__, __LINE__);
151
/** Tests for XML handling */
154
IrrlichtDevice *device = createDevice(video::EDT_NULL, dimension2du(400, 200));
158
logTestString("Test simple XML reader features.\n");
159
result &= simple_xml(device->getFileSystem());
160
logTestString("Test XML reader CDATA support.\n");
161
result &= cdata(device->getFileSystem());
162
logTestString("Test XML reader attribute support.\n");
163
result &= attributeValues(device->getFileSystem());
165
device->closeDevice();