Changeset 6781


Ignore:
Timestamp:
08/09/10 13:07:49 (9 years ago)
Author:
melissa
Message:

Fixed tests in components/bio-formats; all tests should now pass.

Location:
trunk/components/bio-formats
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/ImageReader.java

    r6764 r6781  
    550550  /* @see IFormatReader#getCurrentFile() */ 
    551551  public String getCurrentFile() { 
     552    if (currentId == null) return null; 
    552553    return getReader().getCurrentFile(); 
    553554  } 
  • trunk/components/bio-formats/test/loci/formats/utests/LuraWaveServiceTest.java

    r6531 r6781  
    4545public class LuraWaveServiceTest { 
    4646 
     47  private ServiceFactory sf; 
    4748  private LuraWaveService service; 
    4849 
    4950  @BeforeMethod 
    5051  public void setUp() throws DependencyException { 
    51     ServiceFactory sf = new ServiceFactory(); 
    52     service = sf.getInstance(LuraWaveService.class); 
     52    sf = new ServiceFactory(); 
    5353  } 
    5454 
     
    5656  public void testInitialize() 
    5757    throws IOException, DependencyException, ServiceException { 
     58    service = sf.getInstance(LuraWaveService.class); 
    5859    service.initialize(new ByteArrayInputStream(new byte[0])); 
    5960  } 
  • trunk/components/bio-formats/test/loci/formats/utests/tiff/BaseTiffMock.java

    r6026 r6781  
    2828import loci.common.ByteArrayHandle; 
    2929import loci.common.RandomAccessInputStream; 
     30import loci.common.RandomAccessOutputStream; 
     31import loci.formats.FormatException; 
    3032import loci.formats.tiff.IFD; 
    3133import loci.formats.tiff.IFDType; 
     
    3335import loci.formats.tiff.TiffParser; 
    3436import loci.formats.tiff.TiffRational; 
     37import loci.formats.tiff.TiffSaver; 
    3538 
    3639/** 
     
    4851  private RandomAccessInputStream in; 
    4952 
     53  private RandomAccessOutputStream out; 
     54 
    5055  private TiffParser tiffParser; 
     56 
     57  private TiffSaver tiffSaver; 
    5158 
    5259  private static byte[] TIFF_HEADER = new byte[] { 
     
    5663  private static final int ENTRY_VALUE_BEGIN_OFFSET = 65535; 
    5764 
    58   public BaseTiffMock() throws IOException { 
    59     handle = new ByteArrayHandle(TIFF_HEADER); 
    60     handle.seek(TIFF_HEADER.length); 
     65  public BaseTiffMock() throws FormatException, IOException { 
     66    handle = new ByteArrayHandle(); 
    6167    handle.setOrder(ByteOrder.LITTLE_ENDIAN); 
    62     long next = ENTRY_VALUE_BEGIN_OFFSET; 
    63     // IFD entry count 
    64     handle.writeShort(getEntryCount()); 
    65     // IMAGE_WIDTH 
    66     writeIFDEntry((short) IFD.IMAGE_WIDTH, IFDType.SHORT, getImageWidth()); 
    67     // IMAGE_LENGTH 
    68     writeIFDEntry((short) IFD.IMAGE_LENGTH, IFDType.SHORT, getImageLength()); 
    69     // BITS_PER_SAMPLE 
    70     next = writeBitsPerSample(next); 
    71     // COMPRESSION 
    72     writeIFDEntry((short) IFD.COMPRESSION, IFDType.SHORT, 
    73                   getCompression()); 
    74     // PHOTOMETRIC_INTERPRETATION 
    75     writeIFDEntry((short) IFD.PHOTOMETRIC_INTERPRETATION, IFDType.SHORT, 
    76                   PhotoInterp.RGB.getCode()); 
    77     // STRIP_OFFSETS 
    78     next = writeIFDEntry((short) IFD.STRIP_OFFSETS, IFDType.LONG, 
    79                          getStripOffsets(), next); 
    80     // SAMPLES_PER_PIXEL 
    81     writeIFDEntry((short) IFD.SAMPLES_PER_PIXEL, IFDType.SHORT, 
    82                    getSamplesPerPixel()); 
    83     // ROWS_PER_STRIP 
    84     next = writeIFDEntry((short) IFD.ROWS_PER_STRIP, IFDType.LONG, 
    85                          getRowsPerStrip(), next); 
    86     // X_RESOLUTION 
    87     next = writeIFDEntry((short) IFD.X_RESOLUTION, IFDType.RATIONAL, 
    88                          getXResolution(), next); 
    89     // Y_RESOLUTION 
    90     next = writeIFDEntry((short) IFD.Y_RESOLUTION, IFDType.RATIONAL, 
    91                          getYResolution(), next); 
    92     // RESOLUTION_UNIT 
    93     writeIFDEntry((short) IFD.RESOLUTION_UNIT, IFDType.SHORT, 
    94                   getResolutionUnit()); 
    95     // Terminating IFD offset 
    96     handle.writeInt(0); 
     68    out = new RandomAccessOutputStream(handle); 
     69    tiffSaver = new TiffSaver(out); 
     70    tiffSaver.writeHeader(); 
     71 
     72    IFD ifd = new IFD(); 
     73    ifd.put(IFD.IMAGE_WIDTH, getImageWidth()); 
     74    ifd.put(IFD.IMAGE_LENGTH, getImageLength()); 
     75    ifd.put(IFD.BITS_PER_SAMPLE, getBitsPerSample()); 
     76    ifd.put(IFD.COMPRESSION, getCompression()); 
     77    ifd.put(IFD.PHOTOMETRIC_INTERPRETATION, PhotoInterp.RGB.getCode()); 
     78    ifd.put(IFD.STRIP_OFFSETS, getStripOffsets()); 
     79    ifd.put(IFD.SAMPLES_PER_PIXEL, getSamplesPerPixel()); 
     80    ifd.put(IFD.ROWS_PER_STRIP, getRowsPerStrip()); 
     81    ifd.put(IFD.X_RESOLUTION, getXResolution()); 
     82    ifd.put(IFD.Y_RESOLUTION, getYResolution()); 
     83    ifd.put(IFD.RESOLUTION_UNIT, getResolutionUnit()); 
     84 
     85    tiffSaver.writeIFD(ifd, 0); 
     86 
    9787    in = new RandomAccessInputStream(handle); 
    9888    tiffParser = new TiffParser(in); 
    9989  } 
    10090 
    101   protected void writeIFDEntry(short tag, IFDType type, int value) 
    102                                throws IOException { 
    103     handle.writeShort(tag);  // IFD entry tag 
    104     handle.writeShort(type.getCode());  // IFD entry type 
    105     handle.writeInt(1);  // IFD entry value count 
    106     handle.writeInt(value);  // The actual value 
    107   } 
    108  
    109   protected long writeIFDEntry(short tag, IFDType type, int[] values, 
    110                                long offset) throws IOException { 
    111     handle.writeShort(tag);  // IFD entry tag 
    112     handle.writeShort(type.getCode());  // IFD entry type 
    113     handle.writeInt(values.length);  // IFD entry value count 
    114     handle.writeInt((int) offset); // The offset to the value 
    115     long before = handle.getFilePointer(); 
    116     handle.seek(offset); 
    117     for (int value : values) { 
    118       handle.writeInt(value); 
    119     } 
    120     long after = handle.getFilePointer(); 
    121     handle.seek(before); 
    122     return after; 
    123   } 
    124  
    125   protected long writeIFDEntry(short tag, IFDType type, short[] values, 
    126                                long offset) throws IOException { 
    127     handle.writeShort(tag);  // IFD entry tag 
    128     handle.writeShort(type.getCode());  // IFD entry type 
    129     handle.writeInt(values.length);  // IFD entry value count 
    130     handle.writeInt((int) offset); // The offset to the value 
    131     long before = handle.getFilePointer(); 
    132     handle.seek(offset); 
    133     for (int value : values) { 
    134       handle.writeShort(value); 
    135     } 
    136     long after = handle.getFilePointer(); 
    137     handle.seek(before); 
    138     return after; 
    139   } 
    140  
    141   protected long writeIFDEntry(short tag, IFDType type, TiffRational values, 
    142                                long offset) throws IOException { 
    143     handle.writeShort(tag);  // IFD entry tag 
    144     handle.writeShort(type.getCode());  // IFD entry type 
    145     handle.writeInt(1);  // IFD entry value count 
    146     handle.writeInt((int) offset); // The offset to the value 
    147     long before = handle.getFilePointer(); 
    148     handle.seek(offset); 
    149     handle.writeInt((int) values.getNumerator()); 
    150     handle.writeInt((int) values.getDenominator()); 
    151     long after = handle.getFilePointer(); 
    152     handle.seek(before); 
    153     return after; 
    154   } 
    155  
    15691  protected int getEntryCount() { 
    15792    return 11; 
    158   } 
    159  
    160   protected long writeBitsPerSample(long offset) throws IOException { 
    161     writeIFDEntry((short) IFD.BITS_PER_SAMPLE, IFDType.SHORT, 
    162                   getBitsPerSample()[0]); 
    163     return offset; 
    16493  } 
    16594 
     
    176105  } 
    177106 
    178   public short[] getBitsPerSample() { 
    179     return new short[] { 8 }; 
     107  public int[] getBitsPerSample() { 
     108    return new int[] { 8 }; 
    180109  } 
    181110 
  • trunk/components/bio-formats/test/loci/formats/utests/tiff/BitsPerSampleSamplesPerPixelMismatchMock.java

    r6026 r6781  
    2525import java.io.IOException; 
    2626 
     27import loci.formats.FormatException; 
     28 
    2729/** 
    2830 * @author callan 
     
    3537public class BitsPerSampleSamplesPerPixelMismatchMock extends RGBTiffMock { 
    3638 
    37   public BitsPerSampleSamplesPerPixelMismatchMock() throws IOException { 
     39  public BitsPerSampleSamplesPerPixelMismatchMock() 
     40    throws FormatException, IOException 
     41  { 
    3842    super(); 
    3943  } 
    4044 
    4145  @Override 
    42   public short[] getBitsPerSample() { 
    43     return new short[] { 8, 8 }; 
     46  public int[] getBitsPerSample() { 
     47    return new int[] { 8, 8 }; 
    4448  } 
    4549 
  • trunk/components/bio-formats/test/loci/formats/utests/tiff/NonUniformRowsPerStripMock.java

    r6026 r6781  
    2525import java.io.IOException; 
    2626 
     27import loci.formats.FormatException; 
     28 
    2729/** 
    2830 * @author callan 
     
    3537public class NonUniformRowsPerStripMock extends BaseTiffMock { 
    3638 
    37   public NonUniformRowsPerStripMock() throws IOException { 
     39  public NonUniformRowsPerStripMock() throws FormatException, IOException { 
    3840    super(); 
    3941  } 
  • trunk/components/bio-formats/test/loci/formats/utests/tiff/RGBTiffMock.java

    r6026 r6781  
    2525import java.io.IOException; 
    2626 
     27import loci.formats.FormatException; 
    2728import loci.formats.tiff.IFD; 
    2829import loci.formats.tiff.IFDType; 
     
    3839public class RGBTiffMock extends BaseTiffMock { 
    3940 
    40   public RGBTiffMock() throws IOException { 
     41  public RGBTiffMock() throws FormatException, IOException { 
    4142    super(); 
    4243  } 
    4344 
    44   protected long writeBitsPerSample(long offset) throws IOException { 
    45     return writeIFDEntry((short) IFD.BITS_PER_SAMPLE, IFDType.SHORT, 
    46                          getBitsPerSample(), offset); 
    47   } 
    48  
    4945  @Override 
    50   public short[] getBitsPerSample() { 
    51     return new short[] { 8, 8, 8 }; 
     46  public int[] getBitsPerSample() { 
     47    return new int[] { 8, 8, 8 }; 
    5248  } 
    5349 
  • trunk/components/bio-formats/test/loci/formats/utests/tiff/TiffParserTest.java

    r6128 r6781  
    9999    assertNotNull(bitsPerSample); 
    100100    assertEquals(mock.getSamplesPerPixel(), bitsPerSample.length); 
    101     short[] BITS_PER_SAMPLE = mock.getBitsPerSample(); 
     101    int[] BITS_PER_SAMPLE = mock.getBitsPerSample(); 
    102102    for (int i = 0; i < BITS_PER_SAMPLE.length; i++) { 
    103103      int a = BITS_PER_SAMPLE[i]; 
    104       long b = bitsPerSample[i];  
     104      long b = bitsPerSample[i]; 
    105105      if (a != b) { 
    106106        fail(String.format( 
     
    177177  } 
    178178 
    179   @Test(expectedExceptions={ FormatException.class }) 
     179  @Test 
    180180  public void testBitsPerSampleMismatch() throws IOException, FormatException { 
    181181    mock = new BitsPerSampleSamplesPerPixelMismatchMock(); 
    182182    tiffParser = mock.getTiffParser(); 
    183183    assertTrue(tiffParser.checkHeader()); 
    184     tiffParser.getFirstIFD().getBitsPerSample(); 
     184    IFD ifd = tiffParser.getFirstIFD(); 
     185    int[] bitsPerSample = ifd.getBitsPerSample(); 
     186    int[] mockBitsPerSample = mock.getBitsPerSample(); 
     187    assertEquals(bitsPerSample.length, ifd.getSamplesPerPixel()); 
     188    for (int i=0; i<mockBitsPerSample.length; i++) { 
     189      assertEquals(bitsPerSample[i], mockBitsPerSample[i]); 
     190    } 
    185191  } 
    186192 
  • trunk/components/bio-formats/test/loci/formats/utests/tiff/TiffPixelsTest.java

    r6298 r6781  
    154154    ByteArrayHandle savedData = new ByteArrayHandle(); 
    155155    RandomAccessOutputStream out = new RandomAccessOutputStream(savedData); 
     156    RandomAccessInputStream in = new RandomAccessInputStream(savedData); 
    156157    TiffSaver saver = new TiffSaver(out); 
     158    saver.setInputStream(in); 
    157159    saver.writeImage(data, ifd, 0, FormatTools.UINT16, false); 
    158160    out.close(); 
    159     RandomAccessInputStream in = new RandomAccessInputStream(savedData); 
    160161    TiffParser parser = new TiffParser(in); 
    161162    byte[] plane = new byte[data.length]; 
Note: See TracChangeset for help on using the changeset viewer.