|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| package nu.xom.tests; |
|
22 |
| |
|
23 |
| import java.io.BufferedReader; |
|
24 |
| import java.io.IOException; |
|
25 |
| import java.io.PipedReader; |
|
26 |
| import java.io.PipedWriter; |
|
27 |
| import java.io.Reader; |
|
28 |
| import java.io.Writer; |
|
29 |
| |
|
30 |
| import nu.xom.Attribute; |
|
31 |
| import nu.xom.Builder; |
|
32 |
| import nu.xom.Element; |
|
33 |
| import nu.xom.NodeFactory; |
|
34 |
| import nu.xom.Nodes; |
|
35 |
| import nu.xom.ParsingException; |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public class MegaTest extends XOMTestCase { |
|
48 |
| |
|
49 |
| private Reader in; |
|
50 |
| private Writer out; |
|
51 |
| private Builder builder; |
|
52 |
| private final static int expectedResult = 200000000; |
|
53 |
| private int actualResult = 0; |
|
54 |
| private Thread generator; |
|
55 |
| |
|
56 |
0
| public MegaTest(String name) {
|
|
57 |
0
| super(name);
|
|
58 |
| } |
|
59 |
| |
|
60 |
| |
|
61 |
0
| public static void main(String[] args) throws Exception {
|
|
62 |
0
| MegaTest test = new MegaTest("MegaTest");
|
|
63 |
0
| test.setUp();
|
|
64 |
0
| test.testMegaFile();
|
|
65 |
| } |
|
66 |
| |
|
67 |
| |
|
68 |
0
| protected void setUp() throws IOException {
|
|
69 |
0
| PipedReader pin = new PipedReader();
|
|
70 |
0
| out = new PipedWriter(pin);
|
|
71 |
0
| in = new BufferedReader(pin);
|
|
72 |
0
| actualResult = 0;
|
|
73 |
0
| builder = new Builder(new MinimizingFactory());
|
|
74 |
0
| generator = new Generator();
|
|
75 |
0
| generator.start();
|
|
76 |
| } |
|
77 |
| |
|
78 |
| |
|
79 |
| class Generator extends Thread { |
|
80 |
| |
|
81 |
0
| public void run() {
|
|
82 |
0
| try {
|
|
83 |
0
| out.write("<?xml version='1.0'?>\n");
|
|
84 |
0
| out.write("<root>\n");
|
|
85 |
0
| for (int i = 0; i < expectedResult; i++) {
|
|
86 |
0
| out.write(" <data>1</data>\n");
|
|
87 |
| |
|
88 |
0
| if (i % 10000 == 0) {
|
|
89 |
0
| System.out.println(i / 10000);
|
|
90 |
| } |
|
91 |
| } |
|
92 |
0
| out.write("</root>\n");
|
|
93 |
0
| out.close();
|
|
94 |
| } |
|
95 |
| catch (IOException ex) { |
|
96 |
0
| fail("threw IOException " + ex);
|
|
97 |
| } |
|
98 |
| |
|
99 |
| } |
|
100 |
| |
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
0
| public void testMegaFile()
|
|
105 |
| throws IOException, ParsingException { |
|
106 |
| |
|
107 |
0
| builder.build(in);
|
|
108 |
0
| assertEquals(expectedResult, actualResult);
|
|
109 |
| |
|
110 |
| } |
|
111 |
| |
|
112 |
| |
|
113 |
| private class MinimizingFactory extends NodeFactory { |
|
114 |
| |
|
115 |
| private Nodes empty = new Nodes(); |
|
116 |
| |
|
117 |
0
| public Nodes makeComment(String data) {
|
|
118 |
0
| return empty;
|
|
119 |
| } |
|
120 |
| |
|
121 |
0
| public Nodes finishMakingElement(Element element) {
|
|
122 |
0
| if (element.getQualifiedName().equals("data")) {
|
|
123 |
0
| actualResult += Integer.parseInt(element.getValue());
|
|
124 |
0
| return empty;
|
|
125 |
| } |
|
126 |
0
| return new Nodes(element);
|
|
127 |
| } |
|
128 |
| |
|
129 |
0
| public Nodes makeAttribute(String name, String URI,
|
|
130 |
| String value, Attribute.Type type) { |
|
131 |
0
| return empty;
|
|
132 |
| } |
|
133 |
| |
|
134 |
0
| public Nodes makeDocType(String rootElementName,
|
|
135 |
| String publicID, String systemID) { |
|
136 |
0
| return empty;
|
|
137 |
| } |
|
138 |
| |
|
139 |
0
| public Nodes makeText(String data) {
|
|
140 |
0
| data = data.trim();
|
|
141 |
0
| if ("".equals(data)) return empty;
|
|
142 |
0
| return super.makeText(data);
|
|
143 |
| } |
|
144 |
| |
|
145 |
0
| public Nodes makeProcessingInstruction(
|
|
146 |
| String target, String data) { |
|
147 |
0
| return empty;
|
|
148 |
| } |
|
149 |
| |
|
150 |
| } |
|
151 |
| |
|
152 |
| } |