Renaming functions

Unit testing
This commit is contained in:
Oupson 2020-12-23 16:29:32 +01:00
parent 6eff6f0f45
commit 7a7bfb112f
8 changed files with 100 additions and 37 deletions

View File

@ -9,8 +9,8 @@ import oupson.apng.imageUtils.BitmapDiffCalculator
import oupson.apng.imageUtils.PngEncoder
import oupson.apng.imageUtils.PnnQuantizer
import oupson.apng.utils.Utils
import oupson.apng.utils.Utils.Companion.getBlendOp
import oupson.apng.utils.Utils.Companion.getDisposeOp
import oupson.apng.utils.Utils.Companion.encodeBlendOp
import oupson.apng.utils.Utils.Companion.encodeDisposeOp
import oupson.apng.utils.Utils.Companion.pngSignature
import java.io.File
import java.util.zip.CRC32
@ -122,8 +122,8 @@ class Apng {
fcTL.addAll(Utils.uShortToArray(1000).asList())
// Add DisposeOp and BlendOp
fcTL.add(getDisposeOp(frames[0].disposeOp))
fcTL.add(getBlendOp(frames[0].blendOp))
fcTL.add(encodeDisposeOp(frames[0].disposeOp))
fcTL.add(encodeBlendOp(frames[0].blendOp))
// Create CRC
val crc = CRC32()
@ -191,8 +191,8 @@ class Apng {
fcTL.addAll(Utils.uShortToArray(1000).asList())
// Add DisposeOp and BlendOp
fcTL.add(getDisposeOp(frames[0].disposeOp))
fcTL.add(getBlendOp(frames[0].blendOp))
fcTL.add(encodeDisposeOp(frames[0].disposeOp))
fcTL.add(encodeBlendOp(frames[0].blendOp))
// Generate CRC
val crc = CRC32()
@ -245,8 +245,8 @@ class Apng {
fcTL.addAll(Utils.uShortToArray(frames[i].delay.toInt()).asList())
fcTL.addAll(Utils.uShortToArray(1000).asList())
fcTL.add(getDisposeOp(frames[i].disposeOp))
fcTL.add(getBlendOp(frames[i].blendOp))
fcTL.add(encodeDisposeOp(frames[i].disposeOp))
fcTL.add(encodeBlendOp(frames[i].blendOp))
val crc = CRC32()
crc.update(fcTL.toByteArray(), 0, fcTL.size)

View File

@ -1,8 +1,8 @@
package oupson.apng.chunks
import oupson.apng.utils.Utils
import oupson.apng.utils.Utils.Companion.getBlendOp
import oupson.apng.utils.Utils.Companion.getDisposeOp
import oupson.apng.utils.Utils.Companion.decodeBlendOp
import oupson.apng.utils.Utils.Companion.decodeDisposeOp
@Suppress("ClassName")
class fcTL : Chunk {
@ -54,8 +54,8 @@ class fcTL : Chunk {
xOffset = Utils.uIntFromBytesBigEndian(byteArray.copyOfRange(i + 16, i + 20).map(Byte::toInt))
yOffset = Utils.uIntFromBytesBigEndian(byteArray.copyOfRange(i + 20, i + 24).map(Byte::toInt))
body = byteArray.copyOfRange(i + 4, i + bodySize + 4)
blendOp = getBlendOp(byteArray[33].toInt())
disposeOp = getDisposeOp(byteArray[32].toInt())
blendOp = decodeBlendOp(byteArray[33].toInt())
disposeOp = decodeDisposeOp(byteArray[32].toInt())
}
}
}

View File

@ -351,8 +351,8 @@ class ApngEncoder(
.plus(Utils.uShortToByteArray(1000.toShort()))
// Add DisposeOp and BlendOp
.plus(Utils.getDisposeOp(disposeOp))
.plus(Utils.getBlendOp(blendOp))
.plus(Utils.encodeDisposeOp(disposeOp))
.plus(Utils.encodeBlendOp(blendOp))
// Create CRC
crc.reset()

View File

@ -77,7 +77,7 @@ class Utils {
* @param disposeOp The DisposeOp
* @return [Int] An int equivalent to the DisposeOp
*/
fun getDisposeOp(disposeOp: DisposeOp): Byte {
fun encodeDisposeOp(disposeOp: DisposeOp): Byte {
return when (disposeOp) {
APNG_DISPOSE_OP_NONE -> 0
APNG_DISPOSE_OP_BACKGROUND -> 1
@ -90,7 +90,7 @@ class Utils {
* @param int Int of the DisposeOp
* @return [DisposeOp] A DisposeOp
*/
fun getDisposeOp(int: Int): DisposeOp {
fun decodeDisposeOp(int: Int): DisposeOp {
return when (int) {
0 -> APNG_DISPOSE_OP_NONE
1 -> APNG_DISPOSE_OP_BACKGROUND
@ -115,7 +115,7 @@ class Utils {
* @param blendOp The BlendOp
* @return [Byte] An int equivalent to the BlendOp
*/
fun getBlendOp(blendOp: BlendOp): Byte {
fun encodeBlendOp(blendOp: BlendOp): Byte {
return when (blendOp) {
APNG_BLEND_OP_SOURCE -> 0
APNG_BLEND_OP_OVER -> 1
@ -127,7 +127,7 @@ class Utils {
* @param int Int of the BlendOp
* @return [BlendOp] A BlendOp
*/
fun getBlendOp(int: Int): BlendOp {
fun decodeBlendOp(int: Int): BlendOp {
return when (int) {
0 -> APNG_BLEND_OP_SOURCE
1 -> APNG_BLEND_OP_OVER

View File

@ -1,17 +0,0 @@
package oupson.apng;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}

View File

@ -0,0 +1,80 @@
package oupson.apng
import org.junit.Assert.assertEquals
import org.junit.Test
import oupson.apng.utils.Utils
import oupson.apng.utils.Utils.Companion.uIntToByteArray
import oupson.apng.utils.Utils.Companion.uShortToByteArray
import java.nio.ByteBuffer
class UtilsUnitTest {
@Test
fun encode_disposeOp() {
assertEquals(Utils.encodeDisposeOp(Utils.Companion.DisposeOp.APNG_DISPOSE_OP_NONE), 0.toByte())
assertEquals(Utils.encodeDisposeOp(Utils.Companion.DisposeOp.APNG_DISPOSE_OP_BACKGROUND), 1.toByte())
assertEquals(Utils.encodeDisposeOp(Utils.Companion.DisposeOp.APNG_DISPOSE_OP_PREVIOUS), 2.toByte())
}
@Test
fun decode_disposeOp() {
assertEquals(Utils.decodeDisposeOp(0), Utils.Companion.DisposeOp.APNG_DISPOSE_OP_NONE)
assertEquals(Utils.decodeDisposeOp(1), Utils.Companion.DisposeOp.APNG_DISPOSE_OP_BACKGROUND)
assertEquals(Utils.decodeDisposeOp(2), Utils.Companion.DisposeOp.APNG_DISPOSE_OP_PREVIOUS)
}
@Test
fun encode_blendOp() {
assertEquals(Utils.encodeBlendOp(Utils.Companion.BlendOp.APNG_BLEND_OP_SOURCE), 0.toByte())
assertEquals(Utils.encodeBlendOp(Utils.Companion.BlendOp.APNG_BLEND_OP_OVER), 1.toByte())
}
@Test
fun decode_blendOp() {
assertEquals(Utils.decodeBlendOp(0), Utils.Companion.BlendOp.APNG_BLEND_OP_SOURCE)
assertEquals(Utils.decodeBlendOp(1), Utils.Companion.BlendOp.APNG_BLEND_OP_OVER)
}
@Test
fun decode_u32() {
for (i in 0..Int.MAX_VALUE) {
val b = ByteBuffer.allocate(4)
b.putInt(i)
val array = b.array()
assertEquals(i, Utils.uIntFromBytesBigEndian(array.map { it.toInt() }))
}
}
@Test
fun encode_u32() {
for (i in 0..Int.MAX_VALUE) {
val b = ByteBuffer.allocate(4)
b.putInt(i)
val array = b.array()
val arrayTest = uIntToByteArray(i)
for (y in 0 until 4)
assertEquals(array[y], arrayTest[y])
}
}
@Test
fun decode_u16() {
for (i in 0..Short.MAX_VALUE) {
val b = ByteBuffer.allocate(2)
b.putShort(i.toShort())
val array = b.array()
assertEquals(i, Utils.uShortFromBytesBigEndian(array.map { it.toInt() }))
}
}
@Test
fun encode_u16() {
for (i in 0..Short.MAX_VALUE) {
val b = ByteBuffer.allocate(2)
b.putShort(i.toShort())
val array = b.array()
val arrayTest = uShortToByteArray(i)
for (y in 0 until 2)
assertEquals(array[y], arrayTest[y])
}
}
}

View File

@ -40,7 +40,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0-alpha04'
implementation 'com.google.android.material:material:1.3.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0'

View File

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.20'
ext.kotlin_version = '1.4.21'
ext.anko_version = '0.10.8'
ext.dokka_version = '1.4.0'
repositories {