root/trunk/xmltest.d

Revision 97, 5.3 kB (checked in by pragma, 4 years ago)

- Updated to support Mango 1.3 and Build 2.07

Line 
1 /+
2     Copyright (c) 2005, Eric Anderton
3
4     Permission is hereby granted, free of charge, to any person
5     obtaining a copy of this software and associated documentation
6     files (the "Software"), to deal in the Software without
7     restriction, including without limitation the rights to use,
8     copy, modify, merge, publish, distribute, sublicense, and/or
9     sell copies of the Software, and to permit persons to whom the
10     Software is furnished to do so, subject to the following
11     conditions:
12
13     The above copyright notice and this permission notice shall be
14     included in all copies or substantial portions of the Software.
15
16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23     OTHER DEALINGS IN THE SOFTWARE.
24 +/
25
26 private import xml.utf8all;
27
28 import std.stdio;
29 import std.file;
30 import std.utf;
31 import std.string;
32 import std.system;
33
34 class DebugConsumer : IXMLConsumer{
35
36     CharT[] getEntityValue(CharT[] entity,bit parsed){
37         if(parsed){
38             return "%" ~ entity ~ ";";
39         }
40         else{
41             return "&" ~ entity ~ ";";
42         }
43     }   
44     bit xmlIsParsedProcessingInstruction(CharT[] name){
45         return name == "xml";
46     }
47    
48     void xmlStartDTD(CharT[] name,XMLAttributes externalID){
49         writef("<!DOCTYPE %s %s [",name,externalID.toCharTString());
50     }
51     void xmlEndDTD(CharT[] name,XMLAttributes externalID){
52         writef("]>");
53     }
54    
55     void xmlStartDTDElement(CharT[] name){
56         writef("<!ELEMENT %s ",name);
57     }
58     void xmlSetDTDElementChild(CharT[] name,CharT[] childName){
59         writef("%s",childName);
60     }
61     void xmlSetDTDElementOperation(CharT[] name,DTDOperation type){
62         writef("%s",charTConvert(cast(CharT)type));
63     }
64     void xmlEndDTDElement(CharT[] name){
65         writef(">");
66     }
67
68     void xmlStartDTDAttlist(CharT[] name){
69         writef("<!ATTLIST %s ",name);
70     }
71     void xmlSetDTDAttlistDef(CharT[] name,CharT[] type,CharT[] defaultDecl,CharT[] defaultValue){
72         writef("%s %s %s",type,defaultDecl,defaultValue);
73     }
74     void xmlEndDTDAttlist(CharT[] name){
75         writef(">");
76     }
77    
78     void xmlSetDTDEntity(CharT[] name,CharT[] value,CharT[] ndata,bit parsed){
79         if(parsed){
80             if(ndata){
81                 writef("<!ENTITY %%%s '%s'><!--ndata: %s -->",name,value,ndata);
82             }
83             else{
84                 writef("<!ENTITY %%%s '%s'>",name,value);
85             }
86         }
87         else{
88             writef("<!ENTITY %s '%s'>",name,value);
89         }
90     }
91        
92     void xmlSetDTDNotation(CharT[] name, CharT[] publicId, CharT[] systemLiteral){}
93        
94     void xmlParsedProcessingInstruction(CharT[] name,XMLAttributes attribs){
95         writef("<?%s %s?>",name,attribs.toCharTString());
96     }
97     void xmlProcessingInstruction(CharT[] name,CharT[] data){
98         writef("<?%s %s?>",name,data);
99     }
100    
101     void xmlComment(CharT[] text){
102         writef("<!--%s-->",text);
103     }
104    
105     void xmlStartElement(CharT[] name,XMLAttributes attribs,bit isEmpty){
106         if(isEmpty){
107             writef("<%s %s/>",name,attribs.toCharTString());
108         }
109         else{
110             writef("<%s %s>",name,attribs.toCharTString());
111         }
112     }
113     void xmlEndElement(CharT[] name,XMLAttributes attribs,bit isEmpty){
114         if(!isEmpty){
115             writef("</%s>",name);
116         }
117     }
118     void xmlText(CharT[] text,TextType type){
119         writef("%s",text);
120     }
121 }
122
123 char[][] testFiles = [
124     r"xmlconf\ibm\valid\P01\ibm01v01.xml",
125     r"xmlconf\ibm\valid\P02\ibm02v01.xml",
126     r"xmlconf\ibm\valid\P03\ibm03v01.xml",
127    
128
129    r"xmlconf\ibm\valid\P09\ibm09v01.xml",
130     r"xmlconf\ibm\valid\P09\ibm09v02.xml",
131     r"xmlconf\ibm\valid\P09\ibm09v03.xml",  // fails: dtd is in fact *invalid* (missing Doctype)
132     r"xmlconf\ibm\valid\P09\ibm09v04.xml",
133 //  r"xmlconf\ibm\valid\P09\ibm09v05.xml",  // fails: needs local dtd loading support
134
135     r"xmlconf\ibm\valid\P10\ibm10v01.xml",
136     r"xmlconf\ibm\valid\P10\ibm10v02.xml",
137     r"xmlconf\ibm\valid\P10\ibm10v03.xml", 
138     r"xmlconf\ibm\valid\P10\ibm10v04.xml",
139     r"xmlconf\ibm\valid\P10\ibm10v05.xml", 
140     r"xmlconf\ibm\valid\P10\ibm10v06.xml",
141     r"xmlconf\ibm\valid\P10\ibm10v07.xml",
142     r"xmlconf\ibm\valid\P10\ibm10v08.xml",
143    
144     r"xmlconf\ibm\valid\P11\ibm11v01.xml",
145     r"xmlconf\ibm\valid\P11\ibm11v02.xml",
146     r"xmlconf\ibm\valid\P11\ibm11v03.xml",
147     r"xmlconf\ibm\valid\P11\ibm11v04.xml",
148    
149     r"xmlconf\ibm\valid\P12\ibm12v01.xml",
150     r"xmlconf\ibm\valid\P12\ibm12v02.xml",
151     r"xmlconf\ibm\valid\P12\ibm12v03.xml",
152     r"xmlconf\ibm\valid\P12\ibm12v04.xml",
153    
154 ];
155
156 char[] getPath(char[] filename){
157     return filename[0..rfind(filename,"\\")+1];
158 }
159
160 void main(char[][] args){
161     XMLParser parser = new XMLParser;
162     OfflineProvider provider = new OfflineProvider();
163     IXMLConsumer emptyConsumer = /*new DebugConsumer();*/ new IXMLConsumerAdapter();
164        
165     char[] pwd = getPath(args[0]);
166        
167     foreach(char[] testfile; testFiles){
168         CharT[] data = charTConvert(cast(char[])std.file.read(testfile));
169         try{
170             // run through with a bogus consumer
171             provider.setCurrentPath(pwd ~ getPath(testfile));
172             parser.parse(emptyConsumer, provider, data);
173            
174             // log success
175             writefln("%s -- Pass",testfile);
176         }
177         catch(Exception e){
178             writefln("%s -- FAILED: %s\n",testfile,e.toString());
179             parser.parse(new DebugConsumer(), provider, data);
180             break;
181         }
182     }
183 }
Note: See TracBrowser for help on using the browser.