-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This closes #30
- Loading branch information
Showing
10 changed files
with
446 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegInputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.imaging.formats.jpeg.decoder; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.commons.imaging.ImageReadException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for class {@link JpegInputStream}. | ||
* @see JpegInputStream | ||
**/ | ||
public class JpegInputStreamTest { | ||
|
||
@Test(expected = ImageReadException.class) | ||
public void testNextBitThrowsImageReadExceptionOne() throws IOException, ImageReadException { | ||
int[] byteArray = new int[6]; | ||
byteArray[0] = (byte) (-1); | ||
byteArray[1] = (byte) 74; | ||
JpegInputStream jpegInputStream = new JpegInputStream(byteArray); | ||
|
||
jpegInputStream.nextBit(); | ||
|
||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testNextBitThrowsImageReadExceptionTwo() throws IOException, ImageReadException { | ||
int[] byteArray = new int[0]; | ||
JpegInputStream jpegInputStream = new JpegInputStream(byteArray); | ||
|
||
jpegInputStream.nextBit(); | ||
|
||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/org/apache/commons/imaging/formats/jpeg/segments/App2SegmentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.imaging.formats.jpeg.segments; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.commons.imaging.ImageReadException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for class {@link App2Segment}. | ||
* @see App2Segment | ||
**/ | ||
public class App2SegmentTest { | ||
|
||
@Test | ||
public void testEqualsReturningTrue() throws IOException, ImageReadException { | ||
App2Segment app2Segment = new App2Segment(0, 0, null); | ||
|
||
assertTrue(app2Segment.equals(app2Segment)); | ||
} | ||
|
||
@Test | ||
public void testEqualsReturningFalse() throws IOException, ImageReadException { | ||
byte[] byteArray = new byte[3]; | ||
App2Segment app2Segment = new App2Segment(65475, byteArray); | ||
|
||
assertFalse(app2Segment.equals(byteArray)); | ||
} | ||
|
||
@Test | ||
public void testCompareTo() throws IOException, ImageReadException { | ||
App2Segment app2Segment = new App2Segment(0, 0, null); | ||
|
||
assertEquals(0, app2Segment.compareTo(app2Segment)); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/org/apache/commons/imaging/formats/pnm/PgmFileInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.imaging.formats.pnm; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.apache.commons.imaging.ImageReadException; | ||
import org.junit.Test; | ||
|
||
public class PgmFileInfoTest { | ||
|
||
@Test(expected = ImageReadException.class) | ||
public void testCreateThrowsImageReadExceptionOne() throws ImageReadException { | ||
new PgmFileInfo(16711680, 16711680, false, 16711680); | ||
} | ||
|
||
@Test(expected = ImageReadException.class) | ||
public void testCreateThrowsImageReadExceptionTwo() throws ImageReadException { | ||
new PgmFileInfo(0, 0, true, 0); | ||
} | ||
|
||
@Test | ||
public void testGetBitDepth() throws ImageReadException { | ||
PgmFileInfo pgmFileInfo = new PgmFileInfo(65535, 65535, false, 65535); | ||
|
||
assertEquals(65535, pgmFileInfo.getBitDepth()); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/org/apache/commons/imaging/formats/pnm/PpmFileInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.imaging.formats.pnm; | ||
|
||
import org.apache.commons.imaging.ImageReadException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for class {@link PpmFileInfo}. | ||
* @see PpmFileInfo | ||
* | ||
**/ | ||
public class PpmFileInfoTest { | ||
|
||
@Test(expected = ImageReadException.class) | ||
public void testCreatesPpmFileInfoOne() throws ImageReadException { | ||
new PpmFileInfo(0, 0, false, 16711680); | ||
} | ||
|
||
@Test(expected = ImageReadException.class) | ||
public void testCreatesPpmFileInfoThree() throws ImageReadException { | ||
new PpmFileInfo(0, 0, true, 0); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAsciiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.imaging.formats.tiff.fieldtypes; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
import java.nio.ByteOrder; | ||
|
||
import org.apache.commons.imaging.ImageWriteException; | ||
import org.apache.commons.imaging.formats.tiff.TiffField; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for class {@link FieldTypeAscii}. | ||
* @see FieldTypeAscii | ||
* | ||
**/ | ||
public class FieldTypeAsciiTest { | ||
|
||
@Test(expected = ImageWriteException.class) | ||
public void testCreatesFieldTypeAsciiAndCallsWriteData() throws ImageWriteException { | ||
FieldTypeAscii fieldTypeAscii = new FieldTypeAscii(0, "1"); | ||
byte[] byteArray = new byte[1]; | ||
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; | ||
TiffField tiffField = new TiffField(0, 0, fieldTypeAscii, 0L, 0, byteArray, byteOrder, 1); | ||
|
||
fieldTypeAscii.writeData(tiffField, byteOrder); | ||
|
||
} | ||
|
||
@Test | ||
public void testCreatesFieldTypeAsciiAndWriteDataUsingByteArray() throws ImageWriteException { | ||
FieldTypeAscii fieldTypeAscii = new FieldTypeAscii(0, "1"); | ||
byte[] byteArray = new byte[1]; | ||
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; | ||
byte[] byteArrayTwo = fieldTypeAscii.writeData(byteArray, byteOrder); | ||
|
||
assertArrayEquals(new byte[] {(byte)0, (byte)0}, byteArrayTwo); | ||
} | ||
|
||
@Test | ||
public void testCreatesFieldTypeAsciiAndWriteDataUsingString() throws ImageWriteException { | ||
FieldTypeAscii fieldTypeAscii = new FieldTypeAscii(0, "1"); | ||
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; | ||
byte[] byteArrayTwo = fieldTypeAscii.writeData("asdf", byteOrder); | ||
|
||
assertArrayEquals(new byte[] {(byte)97, (byte)115, (byte)100, (byte)102, (byte)0}, byteArrayTwo); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRationalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.imaging.formats.tiff.fieldtypes; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
import java.nio.ByteOrder; | ||
|
||
import org.apache.commons.imaging.ImageWriteException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for class {@link FieldTypeRational}. | ||
* @see FieldTypeRational | ||
* | ||
**/ | ||
public class FieldTypeRationalTest { | ||
|
||
@Test | ||
public void testWriteDataWithNull() throws ImageWriteException { | ||
FieldTypeRational fieldTypeRational = new FieldTypeRational(9, null); | ||
Double doubleOne = new Double(2.2); | ||
byte[] byteArray = fieldTypeRational.writeData(doubleOne, null); | ||
|
||
assertArrayEquals(new byte[] {(byte)11, (byte)0, (byte)0, (byte)0, (byte)5, (byte)0, (byte)0, (byte)0}, byteArray); | ||
} | ||
|
||
@Test(expected = ImageWriteException.class) | ||
public void testWriteDataWithNonNull() throws ImageWriteException { | ||
FieldTypeRational fieldTypeRational = new FieldTypeRational((-922), "z_AX"); | ||
ByteOrder byteOrder = ByteOrder.nativeOrder(); | ||
|
||
fieldTypeRational.writeData("z_AX", byteOrder); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.