Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
207   521   59   6,27
34   345   0,29   33
33     1,79  
1    
 
  TextInputTest       Line # 30 207 59 86,1% 0.8613139
 
  (17)
 
1    /* $Id: TextInputTest.java,v 1.1 2008/07/26 07:56:13 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.base.io;
19   
20    import java.io.File;
21   
22    import org.qedeq.base.test.QedeqTestCase;
23   
24    /**
25    * Test {@link org.qedeq.kernel.utility.TextInput}.
26    *
27    * @version $Revision: 1.1 $
28    * @author Michael Meyling
29    */
 
30    public class TextInputTest extends QedeqTestCase {
31   
32    private TextInput qedeqInput;
33   
34    private TextInput emptyInput;
35   
36    private final String XML_DATA =
37    /* 1 */ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
38    /* 2 */ + "<QEDEQ \n"
39    /* 3 */ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
40    /* 4 */ + " xsi:noNamespaceSchemaLocation=\"http://www.qedeq.org/0_01_06/xml/qedeq.xsd\">\n"
41    /* 5 */ + " <HEADER email=\"mime@qedeq.org\">\n"
42    /* 6 */ + " <SPEC name=\"qedeq_sample1\" ruleVersion=\"1.00.00\">\n"
43    /* 7 */ + " <LOCATIONS>\n"
44    /* 8 */ + " \t\r <LOCATION value=\"http://qedeq.org/0.01.06/sample1\"/>\n"
45    /* 9 */ + " </LOCATIONS>\n"
46    /* 10 */ + " </SPEC>\n"
47    /* 11 */ + " <TITLE>\n"
48    /* 12 */ + " <LATEX language=\"en\">\n"
49    /* 13 */ + " Example1\n"
50    /* 14 */ + " </LATEX>\n"
51    /* 15 */ + " </TITLE>\n"
52    /* 16 */ + " <ABSTRACT>\n"
53    /* 17 */ + " <LATEX language=\"en\">\n"
54    /* 18 */ + " 1789.01239In this very first qedeq module the XML specification is demonstrated.\n"
55    /* 19 */ + " </LATEX>\n"
56    /* 20 */ + " </ABSTRACT>\n"
57    /* 21 */ + " <AUTHORS>\n"
58    /* 22 */ + " <AUTHOR email=\"michael@meyling.com\">\n"
59    /* 23 */ + " <LATEX language=\"de\">\n"
60    /* 24 */ + " <![CDATA[Michael Meyling]]>\n"
61    /* 25 */ + " </LATEX>\n"
62    /* 26 */ + " </AUTHOR>\n"
63    /* 27 */ + " </AUTHORS>\n"
64    /* 28 */ + " </HEADER>\n"
65    /* 29 */ + "</QEDEQ>";
66   
67   
68    /*
69    * @see TestCase#setUp()
70    */
 
71  17 toggle protected void setUp() throws Exception {
72  17 qedeqInput = new TextInput(XML_DATA);
73  17 emptyInput = new TextInput("");
74  17 super.setUp();
75    }
76   
77    /*
78    * @see TestCase#tearDown()
79    */
 
80  17 toggle protected void tearDown() throws Exception {
81  17 qedeqInput = null;
82  17 super.tearDown();
83    }
84   
85    /**
86    * Test constructor {@link TextInput#TextInput(File)}.
87    * @throws Exception Test failed.
88    */
 
89  1 toggle public void testTextInputFileString() throws Exception {
90  1 final File file = new File(this.getClass().getName() + ".testTexFileInput.impl");
91  1 IoUtility.saveFile(file, XML_DATA, IoUtility.getDefaultEncoding());
92  1 TextInput ti = new TextInput(file, IoUtility.getDefaultEncoding());
93  833 while (!qedeqInput.isEmpty()) {
94  832 assertEquals(qedeqInput.read(), ti.read());
95    }
96  1 file.delete();
97    }
98   
99    /**
100    * Test constructor {@link TextInput#TextInput(String)}.
101    */
 
102  1 toggle public void testTextInputStringStringString() {
103  1 int i = 0;
104  833 while (!qedeqInput.isEmpty()) {
105  832 assertEquals(qedeqInput.read(), XML_DATA.charAt(i++));
106    }
107  1 try {
108  1 new TextInput((String) null);
109  0 fail("NullPointerException expected");
110    } catch (NullPointerException e) {
111    // expected
112    }
113    }
114   
115    /**
116    * Test constructor {@link TextInput#TextInput(StringBuffer)}.
117    */
 
118  1 toggle public void testTextInputStringBufferStringString() {
119  1 final StringBuffer buffer = new StringBuffer(XML_DATA);
120  1 final TextInput ti = new TextInput(buffer);
121  1 int i = 0;
122  833 while (!ti.isEmpty()) {
123  832 assertEquals(ti.read(), XML_DATA.charAt(i++));
124    }
125  1 try {
126  1 new TextInput((StringBuffer) null);
127  0 fail("NullPointerException expected");
128    } catch (NullPointerException e) {
129    // expected
130    }
131    }
132   
133    /**
134    * Test {@link TextInput#read()}.
135    */
 
136  1 toggle public void testRead() {
137  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
138  45 for (int i = 0; i < first.length(); i++) {
139  44 assertEquals(first.charAt(i), qedeqInput.read());
140    }
141  1 qedeqInput.setPosition(qedeqInput.getMaximumPosition());
142  11 for (int i = 0; i < 10; i++) {
143  10 assertEquals(-1, qedeqInput.read());
144    }
145  1 qedeqInput.setPosition(0);
146  45 for (int i = 0; i < first.length(); i++) {
147  44 assertEquals(first.charAt(i), qedeqInput.read());
148    }
149  11 for (int i = 0; i < 10; i++) {
150  10 assertEquals(-1, emptyInput.read());
151    }
152    }
153   
154    /**
155    * Test {@link TextInput#read()}.
156    */
 
157  1 toggle public void testReadString() {
158  1 qedeqInput.read();
159  1 qedeqInput.read();
160  1 assertEquals("xml", qedeqInput.readString(3));
161    }
162   
163    /**
164    * Test {@link TextInput#getChar()}.
165    */
 
166  1 toggle public void testGetChar() {
167  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
168  45 for (int i = 0; i < first.length(); i++) {
169  44 assertEquals(first.charAt(i), qedeqInput.getChar());
170  44 assertEquals(first.charAt(i), qedeqInput.read());
171    }
172  1 qedeqInput.setPosition(qedeqInput.getMaximumPosition());
173  11 for (int i = 0; i < 10; i++) {
174  10 assertEquals(-1, qedeqInput.getChar());
175  10 assertEquals(-1, qedeqInput.read());
176    }
177  1 qedeqInput.setPosition(0);
178  45 for (int i = 0; i < first.length(); i++) {
179  44 assertEquals(first.charAt(i), qedeqInput.getChar());
180  44 assertEquals(first.charAt(i), qedeqInput.read());
181    }
182    }
183   
184    /**
185    * Test {@link TextInput#getChar(int)}.
186    */
 
187  1 toggle public void testGetCharInt() {
188  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
189  45 for (int i = 0; i < first.length(); i++) {
190  44 assertEquals(first.charAt(i), qedeqInput.getChar(0));
191  44 assertEquals(first.charAt(i), qedeqInput.read());
192    }
193  1 qedeqInput.setPosition(qedeqInput.getMaximumPosition());
194  11 for (int i = 0; i < 10; i++) {
195  10 assertEquals(-1, qedeqInput.getChar(0));
196    }
197  11 for (int i = 0; i < 10; i++) {
198  10 assertEquals(-1, qedeqInput.getChar(i));
199    }
200  1 assertEquals('>', qedeqInput.getChar(-1));
201  1 assertEquals('Q', qedeqInput.getChar(-2));
202  1 assertEquals('E', qedeqInput.getChar(-3));
203  1 assertEquals('D', qedeqInput.getChar(-4));
204  1 assertEquals('E', qedeqInput.getChar(-5));
205  1 assertEquals('Q', qedeqInput.getChar(-6));
206  1 assertEquals('/', qedeqInput.getChar(-7));
207  1 assertEquals('<', qedeqInput.getChar(-8));
208  1 qedeqInput.setPosition(0);
209  45 for (int i = 0; i < first.length(); i++) {
210  44 assertEquals(first.charAt(i), qedeqInput.getChar(0));
211  44 assertEquals(first.charAt(i), qedeqInput.read());
212    }
213  1 qedeqInput.setPosition(0);
214  45 for (int i = 0; i < first.length(); i++) {
215  44 assertEquals(first.charAt(i), qedeqInput.getChar(i));
216    }
217    }
218   
219    /**
220    * Test {@link TextInput#skipWhiteSpace()}.
221    */
 
222  1 toggle public void testSkipWhiteSpace() {
223  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
224  1 qedeqInput.skipWhiteSpace();
225  1 assertEquals(0, qedeqInput.getPosition());
226  1 qedeqInput.setPosition(first.length());
227  1 qedeqInput.skipWhiteSpace();
228  1 assertEquals(first.length() + 1, qedeqInput.getPosition());
229  1 qedeqInput.setRow(8);
230  1 assertEquals(" \t\r <LOCATION value=\"http://qedeq.org/0.01.06/sample1\"/>", qedeqInput.getLine());
231  1 qedeqInput.skipWhiteSpace();
232  1 assertEquals(9, qedeqInput.getColumn());
233  1 assertEquals('<', qedeqInput.getChar());
234  1 qedeqInput.setRow(8);
235  1 qedeqInput.setPosition(qedeqInput.getPosition() - 1);
236  1 qedeqInput.skipWhiteSpace();
237  1 assertEquals(9, qedeqInput.getColumn());
238  1 assertEquals('<', qedeqInput.getChar());
239    }
240   
241    /**
242    * Test {@link TextInput#skipWhiteSpace()}.
243    */
 
244  1 toggle public void testSkipWhiteSpaceInverse() {
245  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
246  1 qedeqInput.skipWhiteSpaceInverse();
247  1 assertEquals(0, qedeqInput.getPosition());
248  1 qedeqInput.setPosition(first.length() + 1);
249  1 qedeqInput.skipWhiteSpaceInverse();
250  1 assertEquals('\n', qedeqInput.getChar());
251  1 assertEquals(first.length(), qedeqInput.getPosition());
252  1 qedeqInput.setRow(8);
253  1 assertEquals(" \t\r <LOCATION value=\"http://qedeq.org/0.01.06/sample1\"/>", qedeqInput.getLine());
254  1 qedeqInput.setColumn(9);
255  1 qedeqInput.skipWhiteSpaceInverse();
256  1 assertEquals(7, qedeqInput.getRow());
257  1 assertEquals('>', qedeqInput.getChar(-1));
258  1 qedeqInput.read();
259  1 assertEquals(8, qedeqInput.getRow());
260    }
261   
262    /**
263    * Tests {@link TextInput#skipBackToBeginOfXmlTag()}.
264    */
 
265  1 toggle public void testSkipBackToBeginOfXmlTag() {
266  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
267  1 qedeqInput.setPosition(first.length());
268  1 qedeqInput.skipBackToBeginOfXmlTag();
269  1 assertEquals(0, qedeqInput.getPosition());
270  1 qedeqInput.setPosition(first.length() + 1);
271  1 qedeqInput.skipWhiteSpace();
272    // now we are at "<"
273  1 final int pos = qedeqInput.getPosition();
274  1 qedeqInput.skipBackToBeginOfXmlTag();
275  1 assertEquals(pos, qedeqInput.getPosition());
276  1 qedeqInput.readInverse();
277    // now we are just before "<"
278  1 qedeqInput.skipBackToBeginOfXmlTag();
279  1 assertEquals(0, qedeqInput.getPosition());
280    }
281   
282    /**
283    * Test {@link TextInput#isEmpty()}.
284    */
 
285  1 toggle public void testIsEmpty() {
286  1 assertFalse(qedeqInput.isEmpty());
287  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
288  45 for (int i = 0; i < first.length(); i++) {
289  44 qedeqInput.read();
290  44 assertFalse(qedeqInput.isEmpty());
291    }
292  1 qedeqInput.setPosition(qedeqInput.getMaximumPosition());
293  1 assertTrue(qedeqInput.isEmpty());
294    }
295   
296    /**
297    * Test {@link TextInput#isEmpty()}.
298    */
 
299  1 toggle public void testIsEmptyInt() {
300  1 assertFalse(qedeqInput.isEmpty(0));
301  1 assertFalse(qedeqInput.isEmpty(-1));
302  1 assertFalse(qedeqInput.isEmpty(1));
303  1 final String first = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
304  1 assertFalse(qedeqInput.isEmpty(first.length()));
305  45 for (int i = 0; i < first.length(); i++) {
306  44 qedeqInput.read();
307    }
308  1 assertFalse(qedeqInput.isEmpty(0));
309  1 qedeqInput.setPosition(qedeqInput.getMaximumPosition());
310  1 assertTrue(qedeqInput.isEmpty(0));
311  1 assertFalse(qedeqInput.isEmpty(-1));
312  1 assertTrue(qedeqInput.isEmpty(1));
313    }
314   
315    /**
316    * Test {@link TextInput#readLetterDigitString()}.
317    */
 
318  1 toggle public void testReadLetterDigitString() {
319  1 qedeqInput.read();
320  1 qedeqInput.read();
321  1 assertEquals("xml", qedeqInput.readLetterDigitString());
322  1 qedeqInput.setRow(13);
323  1 assertEquals("Example1", qedeqInput.readLetterDigitString());
324  1 qedeqInput.setRow(13);
325  1 qedeqInput.setColumn(1);
326  1 qedeqInput.skipWhiteSpace();
327  1 assertEquals("Example1", qedeqInput.readLetterDigitString());
328  1 try {
329  1 qedeqInput.readLetterDigitString();
330  0 fail("IllegalArgumentException expected");
331    } catch (IllegalArgumentException e) {
332    // expected
333    }
334  1 try {
335  1 emptyInput.readLetterDigitString();
336  0 fail("IllegalArgumentException expected");
337    } catch (IllegalArgumentException e) {
338    // expected
339    }
340    }
341   
342    /**
343    * Tests {@link TextInput#readCounter()}.
344    */
 
345  1 toggle public void testReadCounter() {
346  1 qedeqInput.setRow(18);
347  1 assertEquals("1789", qedeqInput.readCounter());
348  1 try {
349  1 qedeqInput.readCounter();
350  0 fail("IllegalArgumentException expected");
351    } catch (IllegalArgumentException e) {
352    // expected
353    }
354  1 qedeqInput.read();
355  1 try {
356  1 qedeqInput.readCounter();
357  0 fail("IllegalArgumentException expected");
358    } catch (IllegalArgumentException e) {
359    // expected
360    }
361  1 qedeqInput.read();
362  1 assertEquals("1239", qedeqInput.readCounter());
363  1 try {
364  1 qedeqInput.readCounter();
365  0 fail("IllegalArgumentException expected");
366    } catch (IllegalArgumentException e) {
367    // expected
368    }
369  1 try {
370  1 emptyInput.readLetterDigitString();
371  0 fail("IllegalArgumentException expected");
372    } catch (IllegalArgumentException e) {
373    // expected
374    }
375    }
376   
377    /**
378    * Test {@link TextInput#readQuoted()}.
379    */
 
380  1 toggle public void testReadQuoted() {
381  1 final TextInput first = new TextInput("Hell=\"one\" Water=\"two\"");
382  1 first.setPosition(5);
383  1 assertEquals("one", first.readQuoted());
384  1 first.readString(7);
385  1 assertEquals("two", first.readQuoted());
386  1 final TextInput second = new TextInput("\"\"\"one\" Water=\"two\"");
387  1 assertEquals("\"one", second.readQuoted());
388  1 second.setPosition(1);
389  1 assertEquals("", second.readQuoted());
390  1 final int position = second.getPosition();
391  1 try {
392  1 second.readQuoted();
393  0 fail("IllegalArgumentException expected");
394    } catch (IllegalArgumentException e) {
395    // expected
396    }
397  1 assertTrue(position < second.getPosition());
398    }
399   
400    /**
401    * Test {@link TextInput#readInverse()}.
402    */
 
403  1 toggle public void testReadInverse() {
404  1 assertEquals(-1, qedeqInput.readInverse());
405  1 assertEquals('<', qedeqInput.read());
406  1 assertEquals('<', qedeqInput.readInverse());
407    }
408   
409    /**
410    * Test {@link TextInput#readNextAttributeValue()}.
411    */
 
412  0 toggle public void pestReadNextAttributeValue() {
413    // qedeqInput.readNextAttributeValue();
414  0 fail("not implemented");
415    }
416   
417    /**
418    * Test {@link TextInput#readNextXmlName()}.
419    */
 
420  0 toggle public void pestReadNextXmlName() {
421  0 qedeqInput.readNextXmlName();
422  0 fail("not implemented");
423    }
424   
425    /**
426    * Test {@link TextInput#getRow()}.
427    */
 
428  0 toggle public void pestGetRow() {
429  0 fail("not implemented");
430    }
431   
432    /**
433    * Test {@link TextInput#getColumn()}.
434    */
 
435  0 toggle public void pestGetColumn() {
436  0 fail("not implemented");
437    }
438   
439    /**
440    * Test {@link TextInput#getLine()}.
441    */
 
442  0 toggle public void pestGetLine() {
443  0 fail("not implemented");
444    }
445   
446    /**
447    * Test {@link TextInput#getPosition()} and {@link TextInput#setPosition(int)}.
448    */
 
449  0 toggle public void pestGetSetPosition() {
450  0 fail("not implemented");
451    }
452   
453    /**
454    * Test {@link TextInput#getMaximumPosition()}.
455    */
 
456  0 toggle public void pestGetMaximumPosition() {
457  0 fail("not implemented");
458    }
459   
460    /**
461    * Test {@link TextInput#setRow(int)}.
462    */
 
463  0 toggle public void pestSetRow() {
464  0 fail("not implemented");
465    }
466   
467    /**
468    * Test {@link TextInput#setColumn(int)}.
469    */
 
470  0 toggle public void pestSetColumn() {
471  0 fail("not implemented");
472    }
473   
474    /**
475    * Test {@link TextInput#getAddress()}.
476    */
 
477  0 toggle public void pestGetAddress() {
478  0 fail("not implemented");
479    }
480   
481    /**
482    * Test {@link TextInput#getLocalAddress()}.
483    */
 
484  0 toggle public void pestGetLocalAddress() {
485  0 fail("not implemented");
486    }
487   
488    /**
489    * Test {@link TextInput#showLinePosition()}.
490    */
 
491  0 toggle public void pestShowLinePosition() {
492  0 fail("not implemented");
493    }
494   
495    /**
496    * Test {@link TextInput#hashCode()}.
497    */
 
498  0 toggle public void pestHashCode() {
499  0 fail("not implemented");
500    }
501   
502    /**
503    * Test {@link TextInput#equals(Object)}.
504    */
 
505  1 toggle public void testEquals() {
506  1 assertTrue(qedeqInput.equals(qedeqInput));
507  1 assertFalse(emptyInput.equals(qedeqInput));
508  1 assertFalse(emptyInput.equals(null));
509  1 assertFalse(qedeqInput.equals(null));
510  1 assertFalse(qedeqInput.equals(emptyInput));
511  1 assertTrue(emptyInput.equals(emptyInput));
512    }
513   
514    /**
515    * Test {@link TextInput#toString()}.
516    */
 
517  0 toggle public void pestToString() {
518  0 fail("not implemented");
519    }
520   
521    }