Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit da6b7db

Browse files
committed
Merge branch 'master' into release
# Conflicts: # app/build.gradle
2 parents 6712071 + 0633ce2 commit da6b7db

File tree

23 files changed

+521
-500
lines changed

23 files changed

+521
-500
lines changed

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ apply plugin: 'kotlinx-serialization'
99
apply plugin: "com.github.johnrengelman.shadow"
1010

1111

12-
def CORE_VERSION = "2.7.0"
13-
def CONSOLE_VERSION = "2.7.0"
12+
def CORE_VERSION = "2.7.1-dev-1"
13+
def CONSOLE_VERSION = "2.7.1-dev-1"
1414
def LUAMIRAI_VERSION = "2.0.8"
1515

1616

@@ -24,8 +24,8 @@ android {
2424
applicationId "io.github.mzdluo123.mirai.android"
2525
minSdkVersion 26
2626
targetSdkVersion 30
27-
versionCode 58
28-
versionName "3.3.1"
27+
versionCode 59
28+
versionName "3.3.2"
2929
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3030
buildConfigField("String", "COREVERSION", "\"$CORE_VERSION\"")
3131
buildConfigField("String", "CONSOLEVERSION", "\"$CONSOLE_VERSION\"")

app/src/androidTest/assets/test.jar

54.2 KB
Binary file not shown.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package io.github.mzdluo123.mirai.android
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import androidx.test.espresso.IdlingRegistry
6+
import androidx.test.ext.junit.runners.AndroidJUnit4
7+
import androidx.test.rule.ServiceTestRule
8+
import io.github.mzdluo123.mirai.android.service.BotService
9+
import io.github.mzdluo123.mirai.android.service.ServiceConnector
10+
import kotlinx.coroutines.*
11+
import org.junit.Assert
12+
import org.junit.Before
13+
import org.junit.Rule
14+
import org.junit.Test
15+
import org.junit.runner.RunWith
16+
import kotlin.concurrent.thread
17+
18+
@RunWith(AndroidJUnit4::class)
19+
class BotServiceTest {
20+
@get:Rule
21+
val rule = ServiceTestRule()
22+
23+
@Before
24+
fun init() {
25+
IdlingRegistry.getInstance().register(IdleResources.botServiceLoading)
26+
}
27+
28+
@Test
29+
fun startBotTest() {
30+
BotApplication.context.startBotService()
31+
val conn = ServiceConnector(BotApplication.context)
32+
rule.bindService(
33+
Intent(BotApplication.context, BotService::class.java),
34+
conn,
35+
Context.BIND_AUTO_CREATE
36+
)
37+
Assert.assertTrue(conn.botService.botInfo.isNotEmpty())
38+
}
39+
40+
@Test
41+
fun helpTest() {
42+
runBlocking {
43+
BotApplication.context.startBotService()
44+
val feature = CompletableDeferred<Boolean>()
45+
val conn = ServiceConnector(BotApplication.context)
46+
rule.bindService(
47+
Intent(BotApplication.context, BotService::class.java),
48+
conn,
49+
Context.BIND_AUTO_CREATE
50+
)
51+
val console = object : IConsole.Stub() {
52+
override fun newLog(log: String?) {
53+
if (log != null && "/help" in log) {
54+
feature.complete(true)
55+
}
56+
}
57+
}
58+
conn.botService.registerConsole(console)
59+
launch {
60+
repeat(10) {
61+
conn.botService.runCmd("/help")
62+
delay(100)
63+
}
64+
}
65+
withTimeout(5000) {
66+
Assert.assertTrue(feature.await())
67+
}
68+
}
69+
}
70+
71+
@Test
72+
fun fastRestartTest() {
73+
runBlocking {
74+
BotApplication.context.startBotService()
75+
val feature = CompletableDeferred<Boolean>()
76+
val conn = ServiceConnector(BotApplication.context)
77+
val console = object : IConsole.Stub() {
78+
var count = 0
79+
override fun newLog(log: String?) {
80+
if (log != null && "mirai-console started successfully." in log) {
81+
count++
82+
if (count == 1) {
83+
thread {
84+
BotApplication.context.stopBotService()
85+
Thread.sleep(1000)
86+
BotApplication.context.startBotService()
87+
rule.bindService(
88+
Intent(BotApplication.context, BotService::class.java),
89+
conn,
90+
Context.BIND_AUTO_CREATE
91+
)
92+
}.start()
93+
}
94+
if (count == 2) {
95+
feature.complete(true)
96+
97+
}
98+
}
99+
}
100+
}
101+
conn.registerConsole(console)
102+
rule.bindService(
103+
Intent(BotApplication.context, BotService::class.java),
104+
conn,
105+
Context.BIND_AUTO_CREATE
106+
)
107+
withTimeout(8000) {
108+
Assert.assertTrue(feature.await())
109+
}
110+
111+
}
112+
}
113+
//
114+
// @Test
115+
// fun broadcastReceiverTest() {
116+
// runBlocking {
117+
// AppSettings.allowPushMsg = true
118+
// BotApplication.context.startBotService()
119+
// val feature = CompletableDeferred<Boolean>()
120+
// val conn = ServiceConnector(BotApplication.context)
121+
// val console = object : IConsole.Stub() {
122+
// override fun newLog(log: String?) {
123+
// if (log != null && "成功处理一个群消息推送请求" in log) {
124+
// feature.complete(true)
125+
// }
126+
// }
127+
// }
128+
// conn.registerConsole(console)
129+
// rule.bindService(
130+
// Intent(BotApplication.context, BotService::class.java),
131+
// conn,
132+
// Context.BIND_AUTO_CREATE
133+
// )
134+
//
135+
// launch {
136+
// repeat(30) {
137+
// LocalBroadcastManager.getInstance(BotApplication.context)
138+
// .sendBroadcast(Intent("io.github.mzdluo123.mirai.android.PushMsg").apply {
139+
// data =
140+
// Uri.parse("ma://sendGroupMsg?msg=HelloWorld&id=4234234&at=43434343")
141+
// })
142+
// delay(300)
143+
// }
144+
// }
145+
// withTimeout(6000) {
146+
// Assert.assertTrue(feature.await())
147+
// }
148+
// }
149+
// }
150+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.github.mzdluo123.mirai.android
2+
3+
import androidx.fragment.app.testing.launchFragmentInContainer
4+
import androidx.test.espresso.Espresso.onView
5+
import androidx.test.espresso.assertion.ViewAssertions
6+
import androidx.test.espresso.matcher.ViewMatchers.*
7+
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import io.github.mzdluo123.mirai.android.ui.about.AboutFragment
9+
import io.github.mzdluo123.mirai.android.ui.console.ConsoleFragment
10+
import io.github.mzdluo123.mirai.android.ui.plugin.PluginFragment
11+
import io.github.mzdluo123.mirai.android.ui.script.ScriptFragment
12+
import io.github.mzdluo123.mirai.android.ui.tools.ToolsFragment
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@RunWith(AndroidJUnit4::class)
17+
class PageLoadTest {
18+
//
19+
// @get:Rule
20+
// val activityRule = ActivityTestRule(MainActivity::class.java)
21+
22+
23+
@Test
24+
fun consoleTest() {
25+
with(launchFragmentInContainer<ConsoleFragment>()) {
26+
onView(withId(R.id.commandSend_btn)).check(ViewAssertions.matches(isDisplayed()))
27+
}
28+
}
29+
30+
@Test
31+
fun pluginsTest() {
32+
with(launchFragmentInContainer<PluginFragment>()) {
33+
onView(withId(R.id.plugin_recycler)).check(ViewAssertions.matches(isDisplayed()))
34+
}
35+
}
36+
37+
@Test
38+
fun scriptTest() {
39+
with(launchFragmentInContainer<ScriptFragment>()) {
40+
onView(withId(R.id.script_embed_text)).check(ViewAssertions.matches(isDisplayed()))
41+
}
42+
}
43+
44+
@Test
45+
fun aboutTest() {
46+
with(launchFragmentInContainer<AboutFragment>()) {
47+
onView(withText("关于Mirai")).check(ViewAssertions.matches(isDisplayed()))
48+
}
49+
}
50+
51+
@Test
52+
fun toolsTest() {
53+
with(launchFragmentInContainer<ToolsFragment>(themeResId = R.style.AppTheme)) {
54+
onView(withId(R.id.btn_export_device)).check(ViewAssertions.matches(isDisplayed()))
55+
}
56+
}
57+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package io.github.mzdluo123.mirai.android
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
7+
import io.github.mzdluo123.mirai.android.service.BotService
8+
import io.github.mzdluo123.mirai.android.service.ServiceConnector
9+
import io.github.mzdluo123.mirai.android.ui.plugin.PluginViewModel
10+
import kotlinx.coroutines.*
11+
import org.junit.Assert
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
import java.io.File
15+
16+
@RunWith(AndroidJUnit4::class)
17+
class PluginCompileTest {
18+
19+
val testContext = getInstrumentation().context
20+
21+
@Test
22+
fun compileTest() {
23+
val origin = testContext.assets.open("test.jar")
24+
val out = File(BotApplication.context.externalCacheDir, "tmp.jar")
25+
val outStream = out.outputStream()
26+
origin.use {
27+
it.copyTo(outStream)
28+
outStream.close()
29+
}
30+
31+
// val dexCompile = DexCompiler(BotApplication.context.filesDir,BotApplication.context.cacheDir)
32+
// val outFile = dexCompile.compile(out,true)
33+
// dexCompile.copyResourcesAndMove(outFile, File(BotApplication.context.cacheDir,"test-android.jar"))
34+
35+
runBlocking {
36+
PluginViewModel().compilePlugin(out, true)
37+
BotApplication.context.startBotService()
38+
val feature = CompletableDeferred<Boolean>()
39+
val conn = ServiceConnector(BotApplication.context)
40+
BotApplication.context.bindService(
41+
Intent(BotApplication.context, BotService::class.java),
42+
conn,
43+
Context.BIND_AUTO_CREATE
44+
)
45+
val console = object : IConsole.Stub() {
46+
override fun newLog(log: String?) {
47+
if (log != null && "/ga-switch" in log) {
48+
feature.complete(true)
49+
}
50+
}
51+
}
52+
conn.registerConsole(console)
53+
launch {
54+
repeat(60) {
55+
conn.botService.runCmd("/help")
56+
delay(100)
57+
}
58+
}
59+
File(BotApplication.context.filesDir, "/plugins/test-android.jar").deleteOnExit()
60+
withTimeout(6000) {
61+
Assert.assertTrue(feature.await())
62+
}
63+
}
64+
65+
}
66+
}

0 commit comments

Comments
 (0)