1 36 package org.columba.ristretto.message.io; 37 38 import java.io.File ; 39 import java.io.IOException ; 40 import java.util.regex.Matcher ; 41 import java.util.regex.Pattern ; 42 43 import org.columba.ristretto.io.FileSource; 44 import org.columba.ristretto.io.Source; 45 46 import junit.framework.TestCase; 47 48 public class FileSourceTest extends TestCase { 49 50 private static final String TEST_FILENAME_STR = "src/test/org/columba/ristretto/message/io/FileSourceTest.eml"; 51 52 57 public FileSourceTest(String arg0) { 58 super(arg0); 59 } 60 61 public void testLength() throws IOException { 62 File file = new File (TEST_FILENAME_STR); 63 FileSource source = new FileSource(file); 64 assertEquals( file.length(), source.length() ); 65 } 66 67 public void testFromActualPosition1() throws IOException { 68 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 69 source.seek(10); 70 Source subsource = source.fromActualPosition(); 71 assertTrue(subsource.next() == 't'); 72 assertTrue(subsource.next() == 'e'); 73 assertTrue(subsource.next() == 's'); 74 assertTrue(subsource.next() == 't'); 75 } 76 77 public void testFromActualPosition2() throws IOException { 78 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 79 source.seek(50); 80 Source subsource = source.fromActualPosition(); 81 assertEquals("is a test", subsource.toString()); 82 } 83 84 public void testFromActualPosition3() throws IOException { 85 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 86 source.seek(50); 87 Source subsource = source.fromActualPosition(); 88 subsource.seek(5); 89 Source subsubsource = subsource.fromActualPosition(); 90 assertTrue(subsubsource.toString().equals("test")); 91 } 92 93 public void testNext() throws IOException { 94 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 95 assertTrue(source.next() == 'T'); 96 assertTrue(source.next() == 'h'); 97 assertTrue(source.next() == 'i'); 98 assertTrue(source.next() == 's'); 99 } 100 101 public void testRegexp() throws IOException { 102 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 103 Pattern pattern = Pattern.compile("test"); 104 Matcher matcher = pattern.matcher(source); 105 assertTrue(matcher.find()); 106 } 107 108 public void testSeek() throws IOException { 109 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 110 source.seek(10); 111 assertTrue(source.next() == 't'); 112 assertTrue(source.next() == 'e'); 113 assertTrue(source.next() == 's'); 114 assertTrue(source.next() == 't'); 115 } 116 117 public void testSubSequence1() throws IOException { 118 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 119 Source subsource = source.subSource(10, 13); 120 assertTrue(subsource.next() == 't'); 121 assertTrue(subsource.next() == 'e'); 122 assertTrue(subsource.next() == 's'); 123 assertTrue(subsource.next() == 't'); 124 } 125 126 public void testSubSequence2() throws IOException { 127 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 128 Source subsource = source.subSource(5, 9); 129 assertTrue(subsource.toString().equals("is a")); 130 } 131 132 public void testSubSequence3() throws IOException { 133 FileSource source = new FileSource(new File (TEST_FILENAME_STR)); 134 Source subsource = source.subSource(5, 9); 135 Source subsubsource = subsource.subSource(0, 2); 136 assertTrue(subsubsource.toString().equals("is")); 137 } 138 139 } 140 | Popular Tags |