More tests
This commit is contained in:
parent
be9e5426e0
commit
ac3a448834
|
@ -18,8 +18,6 @@ import java.io.ByteArrayOutputStream
|
|||
|
||||
|
||||
class ApngEncoderInstrumentedTest {
|
||||
// TODO TEST IF OPTIMISED ANIMATIONS AND NON-OPTIMISED ANIMATIONS ARE THE SAME
|
||||
|
||||
@Test
|
||||
fun testDiffBunny() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
|
|
@ -3,7 +3,6 @@ package oupson.apng.chunks
|
|||
/**
|
||||
* An interface for the png chunks
|
||||
*/
|
||||
@Deprecated("Deprecated", level = DeprecationLevel.WARNING)
|
||||
interface Chunk {
|
||||
var body : ByteArray
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package oupson.apng.chunks
|
|||
|
||||
import oupson.apng.utils.Utils
|
||||
|
||||
@Deprecated("Deprecated", level = DeprecationLevel.WARNING)
|
||||
class IHDR : Chunk {
|
||||
override var body = byteArrayOf()
|
||||
var pngWidth = -1
|
||||
|
|
|
@ -5,7 +5,6 @@ import oupson.apng.utils.Utils.Companion.decodeBlendOp
|
|||
import oupson.apng.utils.Utils.Companion.decodeDisposeOp
|
||||
|
||||
@Suppress("ClassName")
|
||||
@Deprecated("Deprecated", level = DeprecationLevel.WARNING)
|
||||
class fcTL : Chunk {
|
||||
override var body : ByteArray = byteArrayOf()
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ class ApngEncoder(
|
|||
* @param encodeAlpha If the alpha channel must be encoded.
|
||||
* @return [ApngEncoder] for chaining.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
fun setEncodeAlpha(encodeAlpha: Boolean): ApngEncoder {
|
||||
if (optimise && !encodeAlpha)
|
||||
throw BadParameterException("If encodeAlpha is false, then optimise must be false")
|
||||
|
@ -135,12 +134,12 @@ class ApngEncoder(
|
|||
* - [FILTER_LAST]
|
||||
* @return [ApngEncoder] for chaining.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
@Throws(BadParameterException::class)
|
||||
fun setFilter(filter: Int): ApngEncoder {
|
||||
if (filter <= FILTER_LAST) {
|
||||
this.filter = filter
|
||||
} else {
|
||||
Log.e(TAG, "Invalid filter")
|
||||
throw BadParameterException("Invalid filter value")
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
@ -168,6 +167,7 @@ class ApngEncoder(
|
|||
* Get the repetition count.
|
||||
* @return An [Int], the number of repetition, zero for infinite.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
fun getRepetitionCount() : Int {
|
||||
return this.repetitionCount
|
||||
}
|
||||
|
@ -177,19 +177,25 @@ class ApngEncoder(
|
|||
* @param compressionLevel A integer between 0 and 9 (not include).
|
||||
* @return [ApngEncoder] for chaining.
|
||||
*/
|
||||
@Throws(BadParameterException::class)
|
||||
fun setCompressionLevel(compressionLevel: Int): ApngEncoder {
|
||||
if (compressionLevel in 0..9) {
|
||||
this.compressionLevel = compressionLevel
|
||||
} else {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Invalid compression level : $compressionLevel, expected a number in range 0..9"
|
||||
)
|
||||
throw BadParameterException("Invalid compression level : $compressionLevel, expected a number in range 0..9")
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Get compression level.
|
||||
* @return [Int] the compression level, an integer in between 0 and 9
|
||||
*/
|
||||
fun getCompressionLevel() : Int {
|
||||
return this.compressionLevel
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the first frame will be included in the animation.
|
||||
* @param firstFrameInAnim A boolean.
|
||||
|
@ -204,6 +210,7 @@ class ApngEncoder(
|
|||
* Get if the first frame will be included in the animation.
|
||||
* @return [Boolean] True if the first frame will be included in the animation.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
fun isFirstFrameInAnim() : Boolean {
|
||||
return this.firstFrameInAnim
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package oupson.apng
|
||||
|
||||
import junit.framework.TestCase.*
|
||||
import org.junit.Test
|
||||
import oupson.apng.encoder.ApngEncoder
|
||||
import oupson.apng.exceptions.BadParameterException
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
class ApngEncoderTest {
|
||||
@Test
|
||||
fun testOptimiseApngGetterSetter() {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
val encoder = ApngEncoder(outputStream, 500, 500, 10)
|
||||
assertTrue(encoder.isAlphaEncoded())
|
||||
assertTrue(encoder.isOptimisingApng())
|
||||
|
||||
encoder.setOptimiseApng(false)
|
||||
encoder.setEncodeAlpha(false)
|
||||
|
||||
assertFalse(encoder.isOptimisingApng())
|
||||
|
||||
try {
|
||||
encoder.setOptimiseApng(true)
|
||||
fail("setOptimiseApng(true) must throw an exception when encode alpha is false")
|
||||
} catch (e : BadParameterException) {
|
||||
// Good behavior
|
||||
}
|
||||
|
||||
encoder.setEncodeAlpha(true)
|
||||
encoder.setOptimiseApng(true)
|
||||
|
||||
assertTrue(encoder.isAlphaEncoded())
|
||||
outputStream.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEncodeAlphaGetterSetter() {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
val encoder = ApngEncoder(outputStream, 500, 500, 10)
|
||||
assertTrue(encoder.isAlphaEncoded())
|
||||
assertTrue(encoder.isOptimisingApng())
|
||||
|
||||
try {
|
||||
encoder.setEncodeAlpha(false)
|
||||
fail("setEncodeAlpha(false) must throw an exception when optimise apng is true")
|
||||
} catch (e : BadParameterException) {
|
||||
// Good behavior
|
||||
}
|
||||
|
||||
encoder.setOptimiseApng(false)
|
||||
encoder.setEncodeAlpha(false)
|
||||
assertFalse(encoder.isAlphaEncoded())
|
||||
outputStream.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFilters() {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
val encoder = ApngEncoder(outputStream, 500, 500, 10)
|
||||
|
||||
for (filters in arrayListOf(ApngEncoder.FILTER_LAST, ApngEncoder.FILTER_NONE, ApngEncoder.FILTER_SUB, ApngEncoder.FILTER_UP)) {
|
||||
encoder.setFilter(filters)
|
||||
assertEquals(filters, encoder.getFilter())
|
||||
}
|
||||
|
||||
try {
|
||||
encoder.setFilter(999)
|
||||
fail("Invalid filter must throw and exception")
|
||||
} catch (e : BadParameterException) {
|
||||
// Good behavior
|
||||
}
|
||||
outputStream.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompressionLevel() {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
val encoder = ApngEncoder(outputStream, 500, 500, 10)
|
||||
for (i in 0..9) {
|
||||
encoder.setCompressionLevel(i)
|
||||
assertEquals(encoder.getCompressionLevel(), i)
|
||||
}
|
||||
|
||||
try {
|
||||
encoder.setCompressionLevel(999)
|
||||
fail("Invalid compression level must throw and exception")
|
||||
} catch (e : BadParameterException) {
|
||||
// Good behavior
|
||||
}
|
||||
|
||||
outputStream.close()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue