summaryrefslogtreecommitdiff
path: root/tests/test_dom_modify.cpp
blob: b775d2dcd9ad6f4b49065bdf2b097df207c74eaf (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
60
61
62
63
#include "common.hpp"

TEST_XML(dom_attr_assign, "<node attr1='' attr2='' attr3='' attr4='' attr5=''/>")
{
	xml_node node = doc.child("node");

	node.attribute("attr1") = "v1";
	xml_attribute() = "v1";

	node.attribute("attr2") = -2147483647 - 1;
	xml_attribute() = -2147483647 - 1;

	node.attribute("attr3") = 2147483647u;
	xml_attribute() = 2147483647;

	node.attribute("attr4") = 0.5;
	xml_attribute() = 0.5;

	node.attribute("attr5") = true;
	xml_attribute() = true;

	CHECK_NODE(node, "<node attr1=\"v1\" attr2=\"-2147483648\" attr3=\"2147483647\" attr4=\"0.5\" attr5=\"true\" />");
}

TEST_XML(dom_attr_set_value, "<node attr1='' attr2='' attr3='' attr4='' attr5=''/>")
{
	xml_node node = doc.child("node");

	CHECK(node.attribute("attr1").set_value("v1"));
	CHECK(!xml_attribute().set_value("v1"));

	CHECK(node.attribute("attr2").set_value(-2147483647 - 1));
	CHECK(!xml_attribute().set_value(-2147483647 - 1));

	CHECK(node.attribute("attr3").set_value(2147483647u));
	CHECK(!xml_attribute().set_value(2147483647));

	CHECK(node.attribute("attr4").set_value(0.5));
	CHECK(!xml_attribute().set_value(0.5));

	CHECK(node.attribute("attr5").set_value(true));
	CHECK(!xml_attribute().set_value(true));

	CHECK_NODE(node, "<node attr1=\"v1\" attr2=\"-2147483648\" attr3=\"2147483647\" attr4=\"0.5\" attr5=\"true\" />");
}

TEST_XML(dom_node_set_name, "<node>text</node>")
{
	CHECK(doc.child("node").set_name("n"));
	CHECK(!doc.child("node").first_child().set_name("n"));
	CHECK(!xml_node().set_name("n"));

	CHECK_NODE(doc, "<n>text</n>");
}

TEST_XML(dom_node_set_value, "<node>text</node>")
{
	CHECK(doc.child("node").first_child().set_value("no text"));
	CHECK(!doc.child("node").set_value("no text"));
	CHECK(!xml_node().set_value("no text"));

	CHECK_NODE(doc, "<node>no text</node>");
}