正在显示
4 个修改的文件
包含
133 行增加
和
4 行删除
| @@ -11,7 +11,7 @@ buildscript { | @@ -11,7 +11,7 @@ buildscript { | ||
| 11 | 11 | ||
| 12 | } | 12 | } |
| 13 | dependencies { | 13 | dependencies { |
| 14 | - classpath 'com.android.tools.build:gradle:7.0.1' | 14 | + classpath 'com.android.tools.build:gradle:7.0.2' |
| 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 16 | classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" | 16 | classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" |
| 17 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" | 17 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" |
| @@ -31,9 +31,13 @@ android { | @@ -31,9 +31,13 @@ android { | ||
| 31 | 31 | ||
| 32 | sourceSets { | 32 | sourceSets { |
| 33 | main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite" | 33 | main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite" |
| 34 | - main.proto.srcDirs += "${generated.protoSrc}" | ||
| 35 | } | 34 | } |
| 36 | 35 | ||
| 36 | + testOptions { | ||
| 37 | + unitTests { | ||
| 38 | + includeAndroidResources = true | ||
| 39 | + } | ||
| 40 | + } | ||
| 37 | compileOptions { | 41 | compileOptions { |
| 38 | sourceCompatibility java_version | 42 | sourceCompatibility java_version |
| 39 | targetCompatibility java_version | 43 | targetCompatibility java_version |
| @@ -90,6 +94,7 @@ dokkaHtml { | @@ -90,6 +94,7 @@ dokkaHtml { | ||
| 90 | } | 94 | } |
| 91 | 95 | ||
| 92 | dependencies { | 96 | dependencies { |
| 97 | + protobuf files(generated.protoSrc) | ||
| 93 | implementation fileTree(dir: 'libs', include: ['*.jar']) | 98 | implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 94 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | 99 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" |
| 95 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3' | 100 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3' |
| @@ -106,10 +111,13 @@ dependencies { | @@ -106,10 +111,13 @@ dependencies { | ||
| 106 | implementation 'com.vdurmont:semver4j:3.1.0' | 111 | implementation 'com.vdurmont:semver4j:3.1.0' |
| 107 | 112 | ||
| 108 | testImplementation 'junit:junit:4.13.2' | 113 | testImplementation 'junit:junit:4.13.2' |
| 114 | + testImplementation 'org.robolectric:robolectric:4.6' | ||
| 109 | testImplementation 'org.mockito:mockito-core:3.8.0' | 115 | testImplementation 'org.mockito:mockito-core:3.8.0' |
| 110 | testImplementation "org.mockito.kotlin:mockito-kotlin:3.1.0" | 116 | testImplementation "org.mockito.kotlin:mockito-kotlin:3.1.0" |
| 111 | - androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
| 112 | - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | 117 | + testImplementation 'androidx.test:core:1.4.0' |
| 118 | + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.3" | ||
| 119 | + androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
| 120 | + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
| 113 | } | 121 | } |
| 114 | 122 | ||
| 115 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') | 123 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') |
| 1 | +package io.livekit.android.room | ||
| 2 | + | ||
| 3 | +import android.content.Context | ||
| 4 | +import androidx.test.core.app.ApplicationProvider | ||
| 5 | +import io.livekit.android.room.mock.MockEglBase | ||
| 6 | +import io.livekit.android.room.participant.LocalParticipant | ||
| 7 | +import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| 8 | +import kotlinx.coroutines.launch | ||
| 9 | +import kotlinx.coroutines.runBlocking | ||
| 10 | +import kotlinx.coroutines.test.TestCoroutineScope | ||
| 11 | +import kotlinx.coroutines.withTimeoutOrNull | ||
| 12 | +import livekit.LivekitModels | ||
| 13 | +import org.junit.Assert | ||
| 14 | +import org.junit.Before | ||
| 15 | +import org.junit.Rule | ||
| 16 | +import org.junit.Test | ||
| 17 | +import org.junit.runner.RunWith | ||
| 18 | +import org.mockito.Mock | ||
| 19 | +import org.mockito.junit.MockitoJUnit | ||
| 20 | +import org.robolectric.RobolectricTestRunner | ||
| 21 | +import org.webrtc.EglBase | ||
| 22 | +import org.webrtc.PeerConnectionFactory | ||
| 23 | + | ||
| 24 | +@ExperimentalCoroutinesApi | ||
| 25 | +@RunWith(RobolectricTestRunner::class) | ||
| 26 | +class RoomTest { | ||
| 27 | + | ||
| 28 | + @get:Rule | ||
| 29 | + var mockitoRule = MockitoJUnit.rule() | ||
| 30 | + | ||
| 31 | + lateinit var context: Context | ||
| 32 | + | ||
| 33 | + @Mock | ||
| 34 | + lateinit var rtcEngine: RTCEngine | ||
| 35 | + | ||
| 36 | + @Mock | ||
| 37 | + lateinit var peerConnectionFactory: PeerConnectionFactory | ||
| 38 | + var eglBase: EglBase = MockEglBase() | ||
| 39 | + | ||
| 40 | + val localParticantFactory = object : LocalParticipant.Factory { | ||
| 41 | + override fun create(info: LivekitModels.ParticipantInfo): LocalParticipant { | ||
| 42 | + return LocalParticipant( | ||
| 43 | + info, | ||
| 44 | + rtcEngine, | ||
| 45 | + peerConnectionFactory, | ||
| 46 | + context, | ||
| 47 | + eglBase, | ||
| 48 | + ) | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + lateinit var room: Room | ||
| 53 | + | ||
| 54 | + @Before | ||
| 55 | + fun setup() { | ||
| 56 | + context = ApplicationProvider.getApplicationContext() | ||
| 57 | + room = Room( | ||
| 58 | + context, | ||
| 59 | + rtcEngine, | ||
| 60 | + eglBase, | ||
| 61 | + localParticantFactory | ||
| 62 | + ) | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Test | ||
| 66 | + fun connectTest() { | ||
| 67 | + val job = TestCoroutineScope().launch { | ||
| 68 | + room.connect( | ||
| 69 | + url = "http://www.example.com", | ||
| 70 | + token = "", | ||
| 71 | + options = null | ||
| 72 | + ) | ||
| 73 | + } | ||
| 74 | + room.onIceConnected() | ||
| 75 | + runBlocking { | ||
| 76 | + Assert.assertNotNull( | ||
| 77 | + withTimeoutOrNull(1000) { | ||
| 78 | + job.join() | ||
| 79 | + } | ||
| 80 | + ) | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | +} |
| 1 | +package io.livekit.android.room.mock | ||
| 2 | + | ||
| 3 | +import android.graphics.SurfaceTexture | ||
| 4 | +import android.view.Surface | ||
| 5 | +import org.webrtc.EglBase | ||
| 6 | + | ||
| 7 | +class MockEglBase( | ||
| 8 | + private val eglContext: EglBase.Context = EglBase.Context { 0 } | ||
| 9 | +) : EglBase { | ||
| 10 | + | ||
| 11 | + override fun createSurface(p0: Surface?) {} | ||
| 12 | + | ||
| 13 | + override fun createSurface(p0: SurfaceTexture?) {} | ||
| 14 | + | ||
| 15 | + override fun createDummyPbufferSurface() {} | ||
| 16 | + | ||
| 17 | + override fun createPbufferSurface(p0: Int, p1: Int) {} | ||
| 18 | + | ||
| 19 | + override fun getEglBaseContext(): EglBase.Context = eglContext | ||
| 20 | + | ||
| 21 | + override fun hasSurface(): Boolean = false | ||
| 22 | + | ||
| 23 | + override fun surfaceWidth(): Int = 0 | ||
| 24 | + | ||
| 25 | + override fun surfaceHeight(): Int = 0 | ||
| 26 | + | ||
| 27 | + override fun releaseSurface() {} | ||
| 28 | + | ||
| 29 | + override fun release() {} | ||
| 30 | + | ||
| 31 | + override fun makeCurrent() {} | ||
| 32 | + | ||
| 33 | + override fun detachCurrent() {} | ||
| 34 | + | ||
| 35 | + override fun swapBuffers() {} | ||
| 36 | + | ||
| 37 | + override fun swapBuffers(p0: Long) {} | ||
| 38 | +} |
-
请 注册 或 登录 后发表评论