Merge vulkan-cts-1.0 to master
[platform/upstream/VK-GL-CTS.git] / framework / qphelper / qpXmlWriter.h
1 #ifndef _QPXMLWRITER_H
2 #define _QPXMLWRITER_H
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Helper Library
5  * -------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Test log library
24  *//*--------------------------------------------------------------------*/
25
26 #include "deDefs.h"
27
28 #include <stdio.h>
29
30 DE_BEGIN_EXTERN_C
31
32 typedef struct qpXmlWriter_s    qpXmlWriter;
33
34 typedef enum qpXmlAttributeType_e
35 {
36         QP_XML_ATTRIBUTE_STRING = 0,
37         QP_XML_ATTRIBUTE_INT,
38         QP_XML_ATTRIBUTE_BOOL,
39
40         QP_XML_ATTRIBUTE_LAST
41 } qpXmlAttributeType;
42
43 typedef struct qpXmlAttribute_s
44 {
45         const char*                     name;
46         qpXmlAttributeType      type;
47         const char*                     stringValue;
48         int                                     intValue;
49         deBool                          boolValue;
50 } qpXmlAttribute;
51
52 DE_INLINE qpXmlAttribute qpSetStringAttrib (const char* name, const char* value)
53 {
54         qpXmlAttribute attrib;
55         attrib.name                     = name;
56         attrib.type                     = QP_XML_ATTRIBUTE_STRING;
57         attrib.stringValue      = value;
58         attrib.intValue         = -678;
59         attrib.boolValue        = (deBool)0xFFFFFFFFu;
60         return attrib;
61 }
62
63 DE_INLINE qpXmlAttribute qpSetIntAttrib (const char* name, int value)
64 {
65         qpXmlAttribute attrib;
66         attrib.name                     = name;
67         attrib.type                     = QP_XML_ATTRIBUTE_INT;
68         attrib.stringValue      = "<intAttrib>";
69         attrib.intValue         = value;
70         attrib.boolValue        = (deBool)0xFFFFFFFFu;
71         return attrib;
72 }
73
74 DE_INLINE qpXmlAttribute qpSetBoolAttrib (const char* name, deBool value)
75 {
76         qpXmlAttribute attrib;
77         attrib.name                     = name;
78         attrib.type                     = QP_XML_ATTRIBUTE_BOOL;
79         attrib.stringValue      = "<boolAttrib>";
80         attrib.intValue         = -679;
81         attrib.boolValue        = value;
82         return attrib;
83 }
84 /*--------------------------------------------------------------------*//*!
85  * \brief Create a file based XML Writer instance
86  * \param fileName Name of the file
87  * \param useCompression Set to DE_TRUE to use compression, if supported by implementation
88  * \return qpXmlWriter instance, or DE_NULL if cannot create file
89  *//*--------------------------------------------------------------------*/
90 qpXmlWriter*    qpXmlWriter_createFileWriter (FILE* outFile, deBool useCompression);
91
92 /*--------------------------------------------------------------------*//*!
93  * \brief XML Writer instance
94  * \param a     qpXmlWriter instance
95  *//*--------------------------------------------------------------------*/
96 void                    qpXmlWriter_destroy (qpXmlWriter* writer);
97
98 /*--------------------------------------------------------------------*//*!
99  * \brief XML Writer instance
100  * \param a     qpXmlWriter instance
101  *//*--------------------------------------------------------------------*/
102 void                    qpXmlWriter_flush (qpXmlWriter* writer);
103
104 /*--------------------------------------------------------------------*//*!
105  * \brief Start XML document
106  * \param writer qpXmlWriter instance
107  * \return true on success, false on error
108  *//*--------------------------------------------------------------------*/
109 deBool                  qpXmlWriter_startDocument (qpXmlWriter* writer);
110
111 /*--------------------------------------------------------------------*//*!
112  * \brief End XML document
113  * \param writer qpXmlWriter instance
114  * \return true on success, false on error
115  *//*--------------------------------------------------------------------*/
116 deBool                  qpXmlWriter_endDocument (qpXmlWriter* writer);
117
118 /*--------------------------------------------------------------------*//*!
119  * \brief Start XML element
120  * \param writer qpXmlWriter instance
121  * \param elementName Name of the element
122  * \return true on success, false on error
123  *//*--------------------------------------------------------------------*/
124 deBool                  qpXmlWriter_startElement (qpXmlWriter* writer, const char* elementName, int numAttribs, const qpXmlAttribute* attribs);
125
126 /*--------------------------------------------------------------------*//*!
127  * \brief End XML element
128  * \param writer qpXmlWriter instance
129  * \param elementName Name of the element
130  * \return true on success, false on error
131  *//*--------------------------------------------------------------------*/
132 deBool                  qpXmlWriter_endElement (qpXmlWriter* writer, const char* elementName);
133
134 /*--------------------------------------------------------------------*//*!
135  * \brief Write raw string into XML document
136  * \param writer qpXmlWriter instance
137  * \param content String to be written
138  * \return true on success, false on error
139  *//*--------------------------------------------------------------------*/
140 deBool                  qpXmlWriter_writeString (qpXmlWriter* writer, const char* content);
141
142 /*--------------------------------------------------------------------*//*!
143  * \brief Write base64 encoded data into XML document
144  * \param writer        qpXmlWriter instance
145  * \param data          Pointer to data to be written
146  * \param numBytes      Length of data in bytes
147  * \return true on success, false on error
148  *//*--------------------------------------------------------------------*/
149 deBool                  qpXmlWriter_writeBase64 (qpXmlWriter* writer, const deUint8* data, size_t numBytes);
150
151 /*--------------------------------------------------------------------*//*!
152  * \brief Convenience function for writing XML element
153  * \param writer qpXmlWriter instance
154  * \param elementName Name of the element
155  * \param elementContent Contents of the element
156  * \return true on success, false on error
157  *//*--------------------------------------------------------------------*/
158 deBool                  qpXmlWriter_writeStringElement (qpXmlWriter* writer, const char* elementName, const char* elementContent);
159
160 DE_END_EXTERN_C
161
162 #endif /* _QPXMLWRITER_H */