1 package test.prefuse.data.io; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.InputStream ; 5 6 import junit.framework.TestCase; 7 import prefuse.data.Table; 8 import prefuse.data.io.DataIOException; 9 import prefuse.data.io.DelimitedTextTableReader; 10 import prefuse.data.io.TableReader; 11 import test.prefuse.TestConfig; 12 import test.prefuse.data.TableTestData; 13 14 public class DelimitedTextTableReaderTest extends TestCase implements TableTestData { 15 16 public void testReadTableInputStream() { 17 byte[] data = TAB_DELIMITED_DATA.getBytes(); 19 InputStream is = new ByteArrayInputStream (data); 20 21 TableReader ctr = new DelimitedTextTableReader(); 23 Table t = null; 24 try { 25 t = ctr.readTable(is); 26 } catch ( DataIOException e ) { 27 e.printStackTrace(); 28 fail("Data Read Exception"); 29 } 30 31 boolean verbose = TestConfig.verbose(); 32 33 if (verbose) System.out.println("** TAB DELIMITED DATA TEST **"); 35 if (verbose) System.out.println("-- Data Types -------------"); 36 for (int c = 0, idx = -1; c < t.getColumnCount(); ++c) { 37 String name = t.getColumnType(c).getName(); 38 if ( (idx=name.lastIndexOf('.')) >= 0 ) 39 name = name.substring(idx+1); 40 assertEquals(t.getColumnType(c), TYPES[c]); 41 if (verbose) System.out.print(name + "\t"); 42 } 43 if (verbose) System.out.println(); 44 45 if (verbose) System.out.println(); 46 47 if (verbose) System.out.println("-- Table Data -------------"); 48 for (int c = 0; c < t.getColumnCount(); ++c) { 49 if (verbose) System.out.print(t.getColumnName(c) + "\t"); 50 assertEquals(t.getColumnName(c), HEADERS[c]); 51 } 52 if (verbose) System.out.println(); 53 for (int r = 0; r < t.getRowCount(); ++r) { 54 for (int c = 0; c < t.getColumnCount(); ++c) { 55 Object o = t.get(r, c); 56 if (verbose) System.out.print(o + "\t"); 57 assertEquals(TABLE[c][r], o); 58 } 59 if (verbose) System.out.println(); 60 } 61 if (verbose) System.out.println(); 62 63 } 77 78 } 79 | Popular Tags |