summaryrefslogtreecommitdiff
path: root/adb-proxy/testSrc/com/google/services/firebase/directaccess/client/device/remote/service/adb/forwardingdaemon/ResponseWriterTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'adb-proxy/testSrc/com/google/services/firebase/directaccess/client/device/remote/service/adb/forwardingdaemon/ResponseWriterTest.kt')
-rw-r--r--adb-proxy/testSrc/com/google/services/firebase/directaccess/client/device/remote/service/adb/forwardingdaemon/ResponseWriterTest.kt80
1 files changed, 80 insertions, 0 deletions
diff --git a/adb-proxy/testSrc/com/google/services/firebase/directaccess/client/device/remote/service/adb/forwardingdaemon/ResponseWriterTest.kt b/adb-proxy/testSrc/com/google/services/firebase/directaccess/client/device/remote/service/adb/forwardingdaemon/ResponseWriterTest.kt
new file mode 100644
index 0000000000..65cf63e6cd
--- /dev/null
+++ b/adb-proxy/testSrc/com/google/services/firebase/directaccess/client/device/remote/service/adb/forwardingdaemon/ResponseWriterTest.kt
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.services.firebase.directaccess.client.device.remote.service.adb.forwardingdaemon
+
+import com.android.adblib.AdbChannel
+import com.android.adblib.AdbServerSocket
+import com.android.adblib.testing.FakeAdbSession
+import com.android.adblib.testingutils.CoroutineTestUtils.runBlockingWithTimeout
+import org.junit.After
+import org.junit.Before
+import org.junit.Test
+
+class ResponseWriterTest {
+
+ private val fakeAdbSession = FakeAdbSession()
+ private lateinit var testSocket: AdbServerSocket
+ private lateinit var adbChannel: AdbChannel
+ private lateinit var responseWriter: ResponseWriter
+
+ @Before
+ fun setUp() = runBlockingWithTimeout {
+ testSocket =
+ fakeAdbSession.channelFactory.createServerSocket().also { serverSocket ->
+ serverSocket.bind()
+ }
+ adbChannel = fakeAdbSession.channelFactory.connectSocket(testSocket.localAddress()!!)
+ responseWriter = ResponseWriter(adbChannel)
+ }
+
+ @After
+ fun tearDown() = runBlockingWithTimeout {
+ adbChannel.close()
+ testSocket.close()
+ }
+
+ @Test
+ fun testWriteOkayResponseWithoutPayload() = runBlockingWithTimeout {
+ responseWriter.writeOkayResponse(0)
+ testSocket.accept().use { channel ->
+ channel.assertCommand(OKAY)
+ channel.assertCommand(WRTE, payload = "OKAY")
+ channel.assertCommand(CLSE, 0)
+ }
+ }
+
+ @Test
+ fun testWriteOkayResponseWithPayload() = runBlockingWithTimeout {
+ val okayPayload = "OKAY PAYLOAD"
+ responseWriter.writeOkayResponse(0, okayPayload)
+ testSocket.accept().use { channel ->
+ channel.assertCommand(OKAY)
+ channel.assertCommand(WRTE, payload = "OKAY${okayPayload.hexLength}$okayPayload")
+ channel.assertCommand(CLSE, 0)
+ }
+ }
+
+ @Test
+ fun testWriteFailResponseWithPayload() = runBlockingWithTimeout {
+ val failedPayload = "FAIL PAYLOAD"
+ responseWriter.writeFailResponse(0, failedPayload)
+ testSocket.accept().use { channel ->
+ channel.assertCommand(OKAY)
+ channel.assertCommand(WRTE, payload = "FAIL${failedPayload.hexLength}$failedPayload")
+ channel.assertCommand(CLSE, 0)
+ }
+ }
+}