xref: /aosp_15_r20/external/deqp/framework/qphelper/qpXmlWriter.h (revision 35238bce31c2a825756842865a792f8cf7f89930)
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     bool boolValue;
50 } qpXmlAttribute;
51 
qpSetStringAttrib(const char * name,const char * value)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   = (bool)0xFFFFFFFFu;
60     return attrib;
61 }
62 
qpSetIntAttrib(const char * name,int value)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   = (bool)0xFFFFFFFFu;
71     return attrib;
72 }
73 
qpSetBoolAttrib(const char * name,bool value)74 DE_INLINE qpXmlAttribute qpSetBoolAttrib(const char *name, bool 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 true to use compression, if supported by implementation
88  * \param flushAfterWrite Set to true to call fflush after writing each XML token
89  * \return qpXmlWriter instance, or DE_NULL if cannot create file
90  *//*--------------------------------------------------------------------*/
91 qpXmlWriter *qpXmlWriter_createFileWriter(FILE *outFile, bool useCompression, bool flushAfterWrite);
92 
93 /*--------------------------------------------------------------------*//*!
94  * \brief XML Writer instance
95  * \param a    qpXmlWriter instance
96  *//*--------------------------------------------------------------------*/
97 void qpXmlWriter_destroy(qpXmlWriter *writer);
98 
99 /*--------------------------------------------------------------------*//*!
100  * \brief XML Writer instance
101  * \param a    qpXmlWriter instance
102  *//*--------------------------------------------------------------------*/
103 void qpXmlWriter_flush(qpXmlWriter *writer);
104 
105 /*--------------------------------------------------------------------*//*!
106  * \brief Start XML document
107  * \param writer qpXmlWriter instance
108  * \param writeXmlHeader whether to write the <xml.. header
109  * \return true on success, false on error
110  *//*--------------------------------------------------------------------*/
111 bool qpXmlWriter_startDocument(qpXmlWriter *writer, bool writeXmlHeader);
112 
113 /*--------------------------------------------------------------------*//*!
114  * \brief End XML document
115  * \param writer qpXmlWriter instance
116  * \return true on success, false on error
117  *//*--------------------------------------------------------------------*/
118 bool qpXmlWriter_endDocument(qpXmlWriter *writer);
119 
120 /*--------------------------------------------------------------------*//*!
121  * \brief Start XML element
122  * \param writer qpXmlWriter instance
123  * \param elementName Name of the element
124  * \return true on success, false on error
125  *//*--------------------------------------------------------------------*/
126 bool qpXmlWriter_startElement(qpXmlWriter *writer, const char *elementName, int numAttribs,
127                               const qpXmlAttribute *attribs);
128 
129 /*--------------------------------------------------------------------*//*!
130  * \brief End XML element
131  * \param writer qpXmlWriter instance
132  * \param elementName Name of the element
133  * \return true on success, false on error
134  *//*--------------------------------------------------------------------*/
135 bool qpXmlWriter_endElement(qpXmlWriter *writer, const char *elementName);
136 
137 /*--------------------------------------------------------------------*//*!
138  * \brief Write raw string into XML document
139  * \param writer qpXmlWriter instance
140  * \param content String to be written
141  * \return true on success, false on error
142  *//*--------------------------------------------------------------------*/
143 bool qpXmlWriter_writeString(qpXmlWriter *writer, const char *content);
144 
145 /*--------------------------------------------------------------------*//*!
146  * \brief Write base64 encoded data into XML document
147  * \param writer    qpXmlWriter instance
148  * \param data        Pointer to data to be written
149  * \param numBytes    Length of data in bytes
150  * \return true on success, false on error
151  *//*--------------------------------------------------------------------*/
152 bool qpXmlWriter_writeBase64(qpXmlWriter *writer, const uint8_t *data, size_t numBytes);
153 
154 /*--------------------------------------------------------------------*//*!
155  * \brief Convenience function for writing XML element
156  * \param writer qpXmlWriter instance
157  * \param elementName Name of the element
158  * \param elementContent Contents of the element
159  * \return true on success, false on error
160  *//*--------------------------------------------------------------------*/
161 bool qpXmlWriter_writeStringElement(qpXmlWriter *writer, const char *elementName, const char *elementContent);
162 
163 DE_END_EXTERN_C
164 
165 #endif /* _QPXMLWRITER_H */
166