Skip to content

Commit

Permalink
Merge pull request #64 from usefulness/more_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Apr 17, 2022
2 parents c1e3e53 + 4ed603a commit cf4c4e6
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 119 deletions.
2 changes: 1 addition & 1 deletion diffuse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {

testImplementation libs.junit.api
testRuntimeOnly libs.junit.engine
testImplementation libs.truth
testImplementation libs.assertJ
}

def fatJarProvider = tasks.register('fatJar', Jar) { task ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jakewharton.diffuse

import com.google.common.truth.Truth.assertThat
import com.jakewharton.diffuse.format.Field
import com.jakewharton.diffuse.format.TypeDescriptor
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class DexFieldTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.jakewharton.diffuse

import com.google.common.truth.Truth.assertThat
import com.jakewharton.diffuse.format.Field
import com.jakewharton.diffuse.format.Method
import com.jakewharton.diffuse.format.TypeDescriptor
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class DexMembersTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jakewharton.diffuse

import com.google.common.truth.Truth.assertThat
import com.jakewharton.diffuse.format.Method
import com.jakewharton.diffuse.format.TypeDescriptor
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class DexMethodTest {
Expand Down
98 changes: 63 additions & 35 deletions diffuse/src/test/kotlin/com/jakewharton/diffuse/FunctionalTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jakewharton.diffuse

import com.google.common.truth.Truth.assertThat
import java.io.File
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir

Expand All @@ -11,19 +11,12 @@ class FunctionalTest {
lateinit var anotherTempDir: File

@Test
internal fun `diffuse diff on stripe`() {
val output = anotherTempDir.resolve("diffuse-out")
val apkA = loadResource("stripe/paymentsheet-example-release-master.apk")
val apkB = loadResource("stripe/paymentsheet-example-release-pr.apk")

main(
"diff",
"--apk", apkA, apkB,
"--text", output.path,
)

assertThat(output.readLines()).contains(" - com.stripe.android.model.PaymentMethod component17\$payments_core_release() → PaymentMethod\$USBankAccount")
}
internal fun `diffuse diff on stripe`() = runTest(
mode = "apk",
root = "stripe",
artifactA = "paymentsheet-example-release-master.apk",
artifactB = "paymentsheet-example-release-pr.apk",
)

@Test
internal fun `diffuse diff on obfuscated artifact`() {
Expand All @@ -47,32 +40,67 @@ class FunctionalTest {
}

@Test
internal fun `diffuse diff on aar`() {
val output = anotherTempDir.resolve("diffuse-out")
val aarA = loadResource("lazythreeten/lazythreetenbp-release.aar")

main(
"diff",
"--aar", aarA, aarA,
"--text", output.path,
)

assertThat(output.readLines()).contains(" total │ 160.7 KiB │ 160.7 KiB │ 0 B ")
}
internal fun `diffuse diff on aar`() = runTest(
mode = "aar",
root = "lazythreeten",
artifactA = "lazythreetenbp-release.aar",
)

@Test
internal fun `diffuse diff on signed artifact`() {
val output = anotherTempDir.resolve("diffuse-out")
val apkA = loadResource("otwarty-wykop-mobilny/app-release.apk")
val mappingA = loadResource("otwarty-wykop-mobilny/mapping.txt")
internal fun `diffuse diff on signed artifact`() = runTest(
mode = "apk",
root = "otwarty-wykop-mobilny",
artifactA = "app-release.apk",
mappingA = "mapping.txt",
)

@Test
internal fun `diffuse info returns proper size`() = runTest(
mode = "jar",
root = "diffuse",
artifactA = "diffuse-unspecified-r8.jar",
)

private fun runTest(
mode: String,
root: String,
artifactA: String,
artifactB: String = artifactA,
mappingA: String? = null,
mappingB: String? = mappingA,
) {
val diffOutput = anotherTempDir.resolve("diffuse-diff")
val infoOutput = anotherTempDir.resolve("diffuse-info")
val artifactAResource = loadResource("$root/$artifactA")
val artifactBResource = loadResource("$root/$artifactB")
val mappingAResource = mappingA?.let { loadResource("$root/$it") }
val mappingBResource = mappingB?.let { loadResource("$root/$it") }
val expectedDiff = loadResource("$root/diff.txt").let(::File)
val expectedInfo = loadResource("$root/info.txt").let(::File)

if (mappingAResource == null || mappingBResource == null) {
main(
"diff",
"--$mode", artifactAResource, artifactBResource,
"--text", diffOutput.path,
)
} else {
main(
"diff",
"--$mode", artifactAResource, artifactBResource,
"--old-mapping", mappingAResource,
"--new-mapping", mappingBResource,
"--text", diffOutput.path,
)
}
main(
"diff",
"--apk", apkA, apkA,
"--old-mapping", mappingA,
"--new-mapping", mappingA,
"--text", output.path,
"info",
"--$mode", artifactBResource,
"--text", infoOutput.path,
)

assertThat(diffOutput).hasSameTextualContentAs(expectedDiff)
assertThat(infoOutput).hasSameTextualContentAs(expectedInfo)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.jakewharton.diffuse

import com.google.common.truth.Truth.assertThat
import com.jakewharton.diffuse.format.Field
import com.jakewharton.diffuse.format.Method
import com.jakewharton.diffuse.format.TypeDescriptor
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class MemberTest {
Expand Down
17 changes: 17 additions & 0 deletions diffuse/src/test/resources/diffuse/diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OLD: diffuse-unspecified-r8.jar
NEW: diffuse-unspecified-r8.jar

│ compressed │ uncompressed
├─────────┬─────────┬──────┼──────────┬──────────┬──────
JAR │ old │ new │ diff │ old │ new │ diff
───────┼─────────┼─────────┼──────┼──────────┼──────────┼──────
class │ 1.6 MiB │ 1.6 MiB │ 0 B │ 2.8 MiB │ 2.8 MiB │ 0 B
other │ 8 KiB │ 8 KiB │ 0 B │ 76.4 KiB │ 76.4 KiB │ 0 B
───────┼─────────┼─────────┼──────┼──────────┼──────────┼──────
total │ 1.6 MiB │ 1.6 MiB │ 0 B │ 2.9 MiB │ 2.9 MiB │ 0 B

CLASSES │ old │ new │ diff
─────────┼──────┼──────┼───────────
classes │ 1315 │ 1315 │ 0 (+0 -0)
methods │ 7031 │ 7031 │ 0 (+0 -0)
fields │ 3018 │ 3018 │ 0 (+0 -0)
Binary file not shown.
14 changes: 14 additions & 0 deletions diffuse/src/test/resources/diffuse/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diffuse-unspecified-r8.jar

JAR │ compressed │ uncompressed
───────┼────────────┼──────────────
class │ 1.6 MiB │ 2.8 MiB
other │ 8 KiB │ 76.4 KiB
───────┼────────────┼──────────────
total │ 1.6 MiB │ 2.9 MiB

CLASSES │ count
─────────┼───────
classes │ 1315
methods │ 7031
fields │ 3018
16 changes: 16 additions & 0 deletions diffuse/src/test/resources/lazythreeten/diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
OLD: lazythreetenbp-release.aar
NEW: lazythreetenbp-release.aar

AAR │ old │ new │ diff
──────────┼───────────┼───────────┼──────
jar │ 19.9 KiB │ 19.9 KiB │ 0 B
manifest │ 249 B │ 249 B │ 0 B
other │ 96 B │ 96 B │ 0 B
──────────┼───────────┼───────────┼──────
total │ 160.7 KiB │ 160.7 KiB │ 0 B

JAR │ old │ new │ diff
─────────┼─────┼─────┼───────────
classes │ 6 │ 6 │ 0 (+0 -0)
methods │ 65 │ 65 │ 0 (+0 -0)
fields │ 10 │ 10 │ 0 (+0 -0)
15 changes: 15 additions & 0 deletions diffuse/src/test/resources/lazythreeten/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
lazythreetenbp-release.aar

AAR │ compressed │ uncompressed
──────────┼────────────┼──────────────
jar │ 18.5 KiB │ 19.9 KiB
manifest │ 279 B │ 249 B
other │ 2.5 KiB │ 96 B
──────────┼────────────┼──────────────
total │ 209.1 KiB │ 160.7 KiB

JAR │ count
─────────┼───────
classes │ 6
methods │ 65
fields │ 10
31 changes: 31 additions & 0 deletions diffuse/src/test/resources/otwarty-wykop-mobilny/diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
OLD: app-release.apk (signature: V1, V2)
NEW: app-release.apk (signature: V1, V2)

│ compressed │ uncompressed
├───────────┬───────────┬──────┼───────────┬───────────┬──────
APK │ old │ new │ diff │ old │ new │ diff
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
dex │ 4.3 MiB │ 4.3 MiB │ 0 B │ 10.5 MiB │ 10.5 MiB │ 0 B
arsc │ 1.3 MiB │ 1.3 MiB │ 0 B │ 1.3 MiB │ 1.3 MiB │ 0 B
manifest │ 6.3 KiB │ 6.3 KiB │ 0 B │ 33.5 KiB │ 33.5 KiB │ 0 B
res │ 1,024 KiB │ 1,024 KiB │ 0 B │ 1.4 MiB │ 1.4 MiB │ 0 B
asset │ 43.4 KiB │ 43.4 KiB │ 0 B │ 108.2 KiB │ 108.2 KiB │ 0 B
other │ 192.5 KiB │ 192.5 KiB │ 0 B │ 363.1 KiB │ 363.1 KiB │ 0 B
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
total │ 6.8 MiB │ 6.8 MiB │ 0 B │ 13.7 MiB │ 13.7 MiB │ 0 B

│ raw │ unique
├───────┬───────┬──────┼───────┬───────┬───────────
DEX │ old │ new │ diff │ old │ new │ diff
─────────┼───────┼───────┼──────┼───────┼───────┼───────────
files │ 3 │ 3 │ 0 │ │ │
strings │ 58937 │ 58937 │ 0 │ 53837 │ 53837 │ 0 (+0 -0)
types │ 17789 │ 17789 │ 0 │ 15888 │ 15888 │ 0 (+0 -0)
classes │ 14135 │ 14135 │ 0 │ 14135 │ 14135 │ 0 (+0 -0)
methods │ 92288 │ 92288 │ 0 │ 88766 │ 88766 │ 0 (+0 -0)
fields │ 40111 │ 40111 │ 0 │ 39533 │ 39533 │ 0 (+0 -0)

ARSC │ old │ new │ diff
─────────┼──────┼──────┼──────
configs │ 327 │ 327 │ 0
entries │ 6210 │ 6210 │ 0
26 changes: 26 additions & 0 deletions diffuse/src/test/resources/otwarty-wykop-mobilny/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
app-release.apk (signature: V1, V2)

APK │ compressed │ uncompressed
──────────┼────────────┼──────────────
dex │ 4.3 MiB │ 10.5 MiB
arsc │ 1.3 MiB │ 1.3 MiB
manifest │ 6.3 KiB │ 33.5 KiB
res │ 1,024 KiB │ 1.4 MiB
asset │ 43.4 KiB │ 108.2 KiB
other │ 192.5 KiB │ 363.1 KiB
──────────┼────────────┼──────────────
total │ 6.8 MiB │ 13.7 MiB

DEX │ raw │ unique
─────────┼───────┼────────
files │ 3 │
strings │ 58937 │ 53837
types │ 17789 │ 15888
classes │ 14135 │ 14135
methods │ 92288 │ 88785
fields │ 40111 │ 39533

ARSC │ count
─────────┼───────
configs │ 327
entries │ 6210
Binary file added diffuse/src/test/resources/stripe/diff.txt
Binary file not shown.
26 changes: 26 additions & 0 deletions diffuse/src/test/resources/stripe/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
paymentsheet-example-release-pr.apk (signature: none)

APK │ compressed │ uncompressed
──────────┼────────────┼──────────────
dex │ 12.6 MiB │ 42.5 MiB
arsc │ 1.6 MiB │ 1.6 MiB
manifest │ 2.8 KiB │ 12.1 KiB
res │ 759.9 KiB │ 1.2 MiB
asset │ 78.4 KiB │ 107.8 KiB
other │ 79.3 KiB │ 154.6 KiB
──────────┼────────────┼──────────────
total │ 15.1 MiB │ 45.5 MiB

DEX │ raw │ unique
─────────┼────────┼────────
files │ 3 │
strings │ 204811 │ 181406
types │ 35115 │ 32736
classes │ 30225 │ 30225
methods │ 176455 │ 171028
fields │ 118589 │ 117840

ARSC │ count
─────────┼───────
configs │ 293
entries │ 5576
2 changes: 1 addition & 1 deletion formats/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ dependencies {

testImplementation libs.junit.api
testRuntimeOnly libs.junit.engine
testImplementation libs.truth
testImplementation libs.assertJ
}
Loading

0 comments on commit cf4c4e6

Please sign in to comment.