bzr branch
http://darksoft.org/webbzr/xmlbench/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
#include <stdio.h> |
2 |
#include <stdarg.h> |
|
3 |
#include <sys/time.h> |
|
4 |
||
5 |
#include <libxml/xmlmemory.h> |
|
6 |
#include <libxml/parser.h> |
|
7 |
#include <libxml/xmlschemas.h> |
|
8 |
||
9 |
#include "tools.h" |
|
10 |
||
11 |
xmlDocPtr doc=0; |
|
12 |
#ifdef LIBXML_SCHEMAS_ENABLED
|
|
13 |
xmlSchemaParserCtxtPtr xsdctx; |
|
14 |
xmlSchemaPtr xsdschema; |
|
15 |
xmlSchemaValidCtxtPtr xsd; |
|
16 |
#endif /* LIBXML_SCHEMAS_ENABLED */ |
|
17 |
||
18 |
void err(void *ctx, const char *msg, ...) { |
|
19 |
va_list prm; |
|
20 |
va_start(prm,msg); |
|
21 |
vprintf(msg,prm); |
|
22 |
va_end(prm); |
|
23 |
}
|
|
24 |
||
25 |
void warn(void *ctx, const char *msg, ...) { |
|
26 |
va_list prm; |
|
27 |
va_start(prm,msg); |
|
28 |
vprintf(msg,prm); |
|
29 |
va_end(prm); |
|
30 |
}
|
|
31 |
||
32 |
void initXML(struct TestData *td) { |
|
33 |
xmlInitParser(); |
|
34 |
}
|
|
35 |
||
36 |
void releaseXML(struct TestData *td) { |
|
37 |
#ifdef LIBXML_SCHEMAS_ENABLED
|
|
38 |
xmlSchemaFreeValidCtxt(xsd); |
|
39 |
xmlSchemaFree(xsdschema); |
|
40 |
xmlSchemaFreeParserCtxt(xsdctx); |
|
41 |
#endif /* LIBXML_SCHEMAS_ENABLED */ |
|
2
by Suren A. Chilingaryan
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts |
42 |
if (doc) { |
43 |
xmlFreeDoc(doc); |
|
44 |
doc = NULL; |
|
45 |
}
|
|
1
by Suren A. Chilingaryan
Initial import |
46 |
xmlCleanupParser(); |
47 |
}
|
|
48 |
||
49 |
void initXML_Validation(struct TestData *td) { |
|
50 |
#ifdef LIBXML_SCHEMAS_ENABLED
|
|
51 |
xsdctx=xmlSchemaNewMemParserCtxt(td->xsd,td->xsdlen); |
|
52 |
if (!xsdctx) { |
|
53 |
printf("Error parsing document schema (xmlSchemaNewMemParserCtxt)!\n"); |
|
54 |
exit(0); |
|
55 |
}
|
|
56 |
xsdschema=xmlSchemaParse(xsdctx); |
|
57 |
if (!xsdschema) { |
|
58 |
printf("Error parsing document schema (xmlSchemaParse)!\n"); |
|
59 |
exit(0); |
|
60 |
}
|
|
61 |
xsd=xmlSchemaNewValidCtxt(xsdschema); |
|
62 |
if (!xsd) { |
|
63 |
printf("Error parsing document schema (xmlSchemaNewValidCtxt)!\n"); |
|
64 |
exit(0); |
|
65 |
}
|
|
66 |
xmlSchemaSetValidErrors(xsd,err,warn,NULL); |
|
67 |
#endif /* LIBXML_SCHEMAS_ENABLED */ |
|
68 |
}
|
|
69 |
||
70 |
||
71 |
void parseXML(struct TestData *td, unsigned long iter) { |
|
72 |
if (doc) { |
|
73 |
xmlFreeDoc(doc); |
|
74 |
}
|
|
75 |
doc=xmlParseMemory(td->xml,td->xmllen); |
|
76 |
if (!doc) { |
|
77 |
printf("Error parsing document!\n"); |
|
78 |
exit(0); |
|
79 |
}
|
|
80 |
}
|
|
81 |
||
82 |
void validateXML(struct TestData *td, unsigned long iter) { |
|
83 |
#ifdef LIBXML_SCHEMAS_ENABLED
|
|
84 |
if (xmlSchemaValidateDoc(xsd,doc)) { |
|
85 |
puts("Error in XML file!"); |
|
86 |
exit(0); |
|
87 |
}
|
|
88 |
#endif /* LIBXML_SCHEMAS_ENABLED */ |
|
89 |
}
|
|
90 |
||
91 |
int main(int argc, char *argv[]) { |
|
92 |
return Test(argc,argv); |
|
93 |
}
|