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