summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlxmlhttprequest/data/element.qml
blob: 78c0374f8aa56249ced47813885468cda492918b (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import Qt 4.6

QtObject {
    property bool xmlTest: false
    property bool dataOK: false

    Script {
        function checkElement(e, person, fruit)
        {
            if (e.tagName != "root")
                return;

            if (e.nodeName != "root")
                return;

            if (e.nodeValue != null)
                return;

            if (e.nodeType != 1)
                return;

            var childTagNames = [ "person", "fruit" ];

            if (e.childNodes.length != childTagNames.length)
                return;

            for (var ii = 0; ii < childTagNames.length; ++ii) {
                if (e.childNodes[ii].tagName != childTagNames[ii])
                    return;
            }

            if (e.childNodes[childTagNames.length + 1] != null)
                return;

            // Check writing fails
            e.childNodes[0] = null;
            if (e.childNodes[0] == null)
                return;

            e.childNodes[10] = 10;
            if (e.childNodes[10] != null)
                return;

            if (e.firstChild.tagName != e.childNodes[0].tagName)
                return;

            if (e.lastChild.tagName != e.childNodes[1].tagName)
                return;

            if (e.previousSibling != null)
                return;

            if (e.nextSibling != null)
                return;

            if (e.attributes == null)
                return;

            if (e.attributes.length != 2)
                return;

            var attr1 = e.attributes["attr"];
            if (attr1.nodeValue != "value")
                return;

            var attrIdx = e.attributes[0];
            if (attrIdx.nodeValue != "value")
                return;

            var attr2 = e.attributes["attr2"];
            if (attr2.nodeValue != "value2")
                return;

            var attr3 = e.attributes["attr3"];
            if (attr3 != null)
                return;

            var attrIdx2 = e.attributes[11];
            if (attrIdx2 != null)
                return;

            // Check writing fails
            e.attributes[0] = null;
            if (e.attributes[0] == null)
                return;

            e.attributes["attr"] = null;
            if (e.attributes["attr"] == null)
                return;

            e.attributes["attr3"] = 10;
            if (e.attributes["attr3"] != null)
                return;

            // Check person and fruit sub elements
            if (person.parentNode.nodeName != "root")
                return;

            if (person.previousSibling != null)
                return;

            if (person.nextSibling.nodeName != "fruit")
                return;

            if (fruit.parentNode.nodeName != "root")
                return;

            if (fruit.previousSibling.nodeName != "person")
                return;

            if (fruit.nextSibling != null)
                return;

            xmlTest = true;
        }

        function checkXML(document)
        {
            checkElement(document.documentElement, 
                         document.documentElement.childNodes[0], 
                         document.documentElement.childNodes[1]);
        }
    }

    Component.onCompleted: {
        var x = new XMLHttpRequest;

        x.open("GET", "element.xml");

        // Test to the end
        x.onreadystatechange = function() {
            if (x.readyState == XMLHttpRequest.DONE) {

                dataOK = true;

                if (x.responseXML != null)
                    checkXML(x.responseXML);

            }
        }

        x.send()
    }
}