Skip to content

Commit

Permalink
Add State for RunTestAndroidCorellium
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral committed May 5, 2021
1 parent 72c2dcf commit 937ea43
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package flank.corellium.adapter

import com.linkedin.dex.parser.DexParser
import com.linkedin.dex.parser.TestMethod
import flank.corellium.api.Apk
import net.dongliu.apk.parser.ApkFile
import org.xml.sax.InputSource
import java.io.StringReader
import javax.xml.parsers.DocumentBuilderFactory

object ParseApkTestCases : Apk.ParseTestCases, (String) -> List<String> by { path ->
DexParser.findTestMethods(path).map(TestMethod::testName)
}

object ParseApkPackageName : Apk.ParsePackageName, (String) -> String by { path ->
ApkFile(path).apkMeta.packageName
}

object ParseApkInfo : Apk.ParseInfo, (String) -> Apk.Info by { path ->
Apk.Info(
packageName = ApkFile(path).apkMeta.packageName,
testRunner = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(InputSource(StringReader(ApkFile(path).manifestXml)))
.getElementsByTagName("instrumentation").item(0).attributes
.getNamedItem("android:name").nodeValue
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package flank.corellium.adapter

import flank.corellium.api.Apk
import org.junit.Assert.assertEquals
import org.junit.Test

private const val TEST_APK_PATH = "../../test_artifacts/master/apk/app-single-success-debug-androidTest.apk"

class ParseApkTest {

@Test
fun parseTestCases() {
assertEquals(
listOf(
"com.example.test_app.InstrumentedTest#ignoredTestWithIgnore",
"com.example.test_app.InstrumentedTest#ignoredTestWithSuppress",
"com.example.test_app.InstrumentedTest#test",
),
ParseApkTestCases(TEST_APK_PATH)
)
}

@Test
fun parsePackageName() {
assertEquals(
"com.example.test_app.test",
ParseApkPackageName(TEST_APK_PATH)
)
}

@Test
fun parseInfo() {
assertEquals(
Apk.Info(
packageName = "com.example.test_app.test",
testRunner = "androidx.test.runner.AndroidJUnitRunner"
),
ParseApkInfo(TEST_APK_PATH)
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package flank.corellium.api

/**
* Structured representation of the parsed test apk file.
* @property packageName Parsed apk package name.
*/
data class TestApk(
val packageName: String,
val testCases: List<String>
) {

object Apk {

interface Parse : (LocalPath) -> TestApk
data class Info(
val packageName: String,
val testRunner: String,
)

/**
* @return The full list of test methods from parsed apk.
Expand All @@ -22,6 +19,11 @@ data class TestApk(
* @return The package name for given apk.
*/
interface ParsePackageName: (LocalPath) -> PackageName

/**
* @return The package name for given apk.
*/
interface ParseInfo: (LocalPath) -> Info
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CorelliumApi(
val invokeAndroidDevices: AndroidInstance.Invoke,
val installAndroidApps: AndroidApps.Install,
val executeTest: AndroidTestPlan.Execute,
val parseTestCases: TestApk.ParseTestCases,
val parsePackageName: TestApk.ParsePackageName,
val parseTestCases: Apk.ParseTestCases,
val parsePackageName: Apk.ParsePackageName,
val parseTestApkInfo: Apk.ParseInfo,
)
Loading

0 comments on commit 937ea43

Please # to comment.