Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger) | - |
5 | : testLogger(logger) | - |
6 | { | - |
7 | do { if (!(testLogger)) qt_assert("testLogger","qtestxunitstreamer.cpp",56); } while (0); never executed: qt_assert("testLogger","qtestxunitstreamer.cpp",56); never evaluated: !(testLogger) | 0 |
8 | } | 0 |
9 | | - |
10 | QTestXunitStreamer::~QTestXunitStreamer() | - |
11 | {} | - |
12 | | - |
13 | void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size) | - |
14 | { | - |
15 | if (size == 0) return; never evaluated: size == 0 | 0 |
16 | | - |
17 | buf[0] = 0; | - |
18 | | - |
19 | if (!element) return; never evaluated: !element | 0 |
20 | | - |
21 | char* endbuf = buf + size; | - |
22 | element = element->parentElement(); | - |
23 | while (element && buf+2 < endbuf) { never evaluated: buf+2 < endbuf | 0 |
24 | *(buf++) = ' '; | - |
25 | *(buf++) = ' '; | - |
26 | *buf = 0; | - |
27 | element = element->parentElement(); | - |
28 | } | 0 |
29 | } | 0 |
30 | | - |
31 | void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const | - |
32 | { | - |
33 | if (!element || !formatted ) never evaluated: !element never evaluated: !formatted | 0 |
34 | return; | 0 |
35 | | - |
36 | char indent[20]; | - |
37 | indentForElement(element, indent, sizeof(indent)); | - |
38 | | - |
39 | | - |
40 | if (element->elementType() == QTest::LET_Error) { never evaluated: element->elementType() == QTest::LET_Error | 0 |
41 | if (element->parentElement()->elementType() == QTest::LET_SystemError) { never evaluated: element->parentElement()->elementType() == QTest::LET_SystemError | 0 |
42 | QTest::qt_asprintf(formatted, "<![CDATA["); | - |
43 | } else { | 0 |
44 | QTest::qt_asprintf(formatted, "%s<!--", indent); | - |
45 | } | 0 |
46 | return; | 0 |
47 | } | - |
48 | | - |
49 | QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName()); | - |
50 | } | 0 |
51 | | - |
52 | void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const | - |
53 | { | - |
54 | if (!element || !formatted ) never evaluated: !element never evaluated: !formatted | 0 |
55 | return; | 0 |
56 | | - |
57 | if (!element->childElements()) { never evaluated: !element->childElements() | 0 |
58 | formatted->data()[0] = '\0'; | - |
59 | return; | 0 |
60 | } | - |
61 | | - |
62 | char indent[20]; | - |
63 | indentForElement(element, indent, sizeof(indent)); | - |
64 | | - |
65 | QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName()); | - |
66 | } | 0 |
67 | | - |
68 | void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const | - |
69 | { | - |
70 | if (!attribute || !formatted ) never evaluated: !attribute never evaluated: !formatted | 0 |
71 | return; | 0 |
72 | | - |
73 | QTest::AttributeIndex attrindex = attribute->index(); | - |
74 | | - |
75 | | - |
76 | if (element && element->elementType() == QTest::LET_Error never evaluated: element->elementType() == QTest::LET_Error | 0 |
77 | && element->parentElement()->elementType() == QTest::LET_SystemError) { never evaluated: element->parentElement()->elementType() == QTest::LET_SystemError | 0 |
78 | | - |
79 | if (attrindex != QTest::AI_Description) return; never evaluated: attrindex != QTest::AI_Description | 0 |
80 | | - |
81 | QXmlTestLogger::xmlCdata(formatted, attribute->value()); | - |
82 | return; | 0 |
83 | } | - |
84 | | - |
85 | char const* key = 0; | - |
86 | if (attrindex == QTest::AI_Description) never evaluated: attrindex == QTest::AI_Description | 0 |
87 | key = "message"; never executed: key = "message"; | 0 |
88 | else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line) never evaluated: attrindex != QTest::AI_File never evaluated: attrindex != QTest::AI_Line | 0 |
89 | key = attribute->name(); never executed: key = attribute->name(); | 0 |
90 | | - |
91 | if (key) { | 0 |
92 | QTestCharBuffer quotedValue; | - |
93 | QXmlTestLogger::xmlQuote("edValue, attribute->value()); | - |
94 | QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData()); | - |
95 | } else { | 0 |
96 | formatted->data()[0] = '\0'; | - |
97 | } | 0 |
98 | } | - |
99 | | - |
100 | void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const | - |
101 | { | - |
102 | if (!element || !formatted ) never evaluated: !element never evaluated: !formatted | 0 |
103 | return; | 0 |
104 | | - |
105 | | - |
106 | if (element->elementType() == QTest::LET_Error) { never evaluated: element->elementType() == QTest::LET_Error | 0 |
107 | if (element->parentElement()->elementType() == QTest::LET_SystemError) { never evaluated: element->parentElement()->elementType() == QTest::LET_SystemError | 0 |
108 | QTest::qt_asprintf(formatted, "]]>\n"); | - |
109 | } else { | 0 |
110 | QTest::qt_asprintf(formatted, " -->\n"); | - |
111 | } | 0 |
112 | return; | 0 |
113 | } | - |
114 | | - |
115 | if (!element->childElements()) never evaluated: !element->childElements() | 0 |
116 | QTest::qt_asprintf(formatted, "/>\n"); never executed: QTest::qt_asprintf(formatted, "/>\n"); | 0 |
117 | else | - |
118 | QTest::qt_asprintf(formatted, ">\n"); never executed: QTest::qt_asprintf(formatted, ">\n"); | 0 |
119 | } | - |
120 | | - |
121 | void QTestXunitStreamer::output(QTestElement *element) const | - |
122 | { | - |
123 | do { if (!(element)) qt_assert("element","qtestxunitstreamer.cpp",172); } while (0); never executed: qt_assert("element","qtestxunitstreamer.cpp",172); never evaluated: !(element) | 0 |
124 | | - |
125 | outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | - |
126 | outputElements(element); | - |
127 | } | 0 |
128 | | - |
129 | void QTestXunitStreamer::outputElements(QTestElement *element, bool) const | - |
130 | { | - |
131 | QTestCharBuffer buf; | - |
132 | bool hasChildren; | - |
133 | | - |
134 | | - |
135 | | - |
136 | | - |
137 | while (element && element->nextElement()) { never evaluated: element->nextElement() | 0 |
138 | element = element->nextElement(); | - |
139 | } | 0 |
140 | while (element) { | 0 |
141 | hasChildren = element->childElements(); | - |
142 | | - |
143 | if (element->elementType() != QTest::LET_Benchmark) { never evaluated: element->elementType() != QTest::LET_Benchmark | 0 |
144 | formatStart(element, &buf); | - |
145 | outputString(buf.data()); | - |
146 | | - |
147 | outputElementAttributes(element, element->attributes()); | - |
148 | | - |
149 | formatAfterAttributes(element, &buf); | - |
150 | outputString(buf.data()); | - |
151 | | - |
152 | if (hasChildren) never evaluated: hasChildren | 0 |
153 | outputElements(element->childElements(), true); never executed: outputElements(element->childElements(), true); | 0 |
154 | | - |
155 | formatEnd(element, &buf); | - |
156 | outputString(buf.data()); | - |
157 | } | 0 |
158 | element = element->previousElement(); | - |
159 | } | 0 |
160 | } | 0 |
161 | | - |
162 | void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const | - |
163 | { | - |
164 | QTestCharBuffer buf; | - |
165 | while (attribute) { never evaluated: attribute | 0 |
166 | formatAttributes(element, attribute, &buf); | - |
167 | outputString(buf.data()); | - |
168 | attribute = attribute->nextElement(); | - |
169 | } | 0 |
170 | } | 0 |
171 | | - |
172 | void QTestXunitStreamer::outputString(const char *msg) const | - |
173 | { | - |
174 | testLogger->outputString(msg); | - |
175 | } | 0 |
176 | | - |
177 | | - |
178 | | - |
| | |