73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include "ZUnitTest.hpp"
|
|
|
|
#include <ZUtil/ZXMLWriter.hpp>
|
|
|
|
static const char* test_WriteSuccess();
|
|
static const char* test_WriteFailure();
|
|
|
|
ZUnitTest ZXMLWriterUnitTests[] =
|
|
{
|
|
{ "ZXMLWriter: WriteSuccess", test_WriteSuccess },
|
|
{ "ZXMLWriter: WriteFailure", test_WriteFailure }
|
|
};
|
|
|
|
//Now declare the ZUnitTestBlock associated with this.
|
|
DECLARE_ZTESTBLOCK(ZXMLWriter);
|
|
|
|
/*************************************************************************/
|
|
|
|
namespace ZXMLWriterTestData
|
|
{
|
|
const char* test1Output = "<node1>" LINE_TERMINATOR
|
|
"<node2>" LINE_TERMINATOR
|
|
"<node3 attr1=\"value1\" attr2=\"value2\"/>" LINE_TERMINATOR
|
|
"</node2>" LINE_TERMINATOR
|
|
"Node1Body" LINE_TERMINATOR
|
|
"</node1>" LINE_TERMINATOR;
|
|
|
|
const char* test2Output = "<node1><node2><node3 attr1=\"value1\" attr2=\"value2\"/></node2>Node1Body</node1>";
|
|
|
|
const char* test3Output = "" LINE_TERMINATOR
|
|
LINE_TERMINATOR;
|
|
|
|
}
|
|
|
|
using namespace ZXMLWriterTestData;
|
|
|
|
/*************************************************************************/
|
|
|
|
static const char* test_WriteSuccess()
|
|
{
|
|
ZString output;
|
|
ZKVTree tree;
|
|
|
|
tree.Put("node1", "Node1Body");
|
|
|
|
tree.Put("node1.node2", "");
|
|
|
|
tree.Put("node1.node2.node3", "");
|
|
tree.Put("node1.node2.node3.attr1", "value1");
|
|
tree.Put("node1.node2.node3.attr2", "value2");
|
|
|
|
ZXMLWriter writer1;
|
|
ZXMLWriter writer2;
|
|
|
|
TASSERT(writer1.Write(tree, output, true), "ZXMLWriter failed to write valid data set #1!");
|
|
TASSERT(output == test1Output, "ZXMLWriter wrote incorrect value for data set #1!");
|
|
|
|
output.Clear();
|
|
|
|
TASSERT(writer2.Write(tree, output, false), "ZXMLWriter failed to write valid data set #1 with no newlines!");
|
|
TASSERT(output == test2Output, "ZXMLWriter wrote incorrect value for data set #1 with no newlines!");
|
|
|
|
//TODO - one more output case, preferably something a bit more complicated?
|
|
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/*************************************************************************/
|
|
|
|
static const char* test_WriteFailure()
|
|
{
|
|
return "TODO";
|
|
} |