Files
MoGoEagleEye/app/src/androidTest/java/com/mogo/functions/test/DownloaderTest.kt

50 lines
1.7 KiB
Kotlin

package com.mogo.functions.test
import android.util.*
import androidx.test.core.app.*
import androidx.test.ext.junit.runners.*
import androidx.test.filters.*
import androidx.test.platform.app.*
import com.mogo.core.download.*
import com.mogo.eagle.core.function.main.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.junit.*
import org.junit.runner.*
import java.io.*
@RunWith(AndroidJUnit4::class)
@LargeTest
class DownloaderTest {
lateinit var launch: ActivityScenario<MainLauncherActivity>
@Before
fun before() {
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
}
companion object {
const val TAG = "DownloaderTest"
}
@Test
fun testDownload() = runBlocking {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Downloader.init(appContext)
Downloader.download(
"https://scm-1255510688.cos.ap-beijing.myqcloud.com/test/com.mogo.launcher.f/2.9.0.1002/IntelligentPilot_v2.9.0.1002_20220725_[fPadLenovoOchBus-launcher-qa]_debug.apk",
File(appContext.getExternalFilesDir(null), "/apks/2.apk").absolutePath)
.flowOn(Dispatchers.IO)
.collect {
when(it) {
is DownloadStart -> Log.d(TAG, "下载开始: ${it.downloadUrl}")
is DownloadFailed -> Log.d(TAG, "---error: ${it.msg}: ${it.downloadUrl}")
is DownloadSuccess -> Log.d(TAG, "下载成功: ${it.path}, 文件存在?:${File(it.path).exists()}")
is Downloading -> Log.d(TAG, "下载进度: ${it.downloaded}/${it.total}")
}
}
}
}