Skip to content

Commit

Permalink
no connectionMethod if both peripheral and central are set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
vkanellopoulos committed Jan 19, 2024
1 parent 1d1968a commit a7a5673
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ import java.util.UUID
internal val DeviceRetrievalMethod.connectionMethod: List<ConnectionMethod>
get() = when (this) {
is BleRetrievalMethod -> {
mutableListOf<ConnectionMethod>().apply {
val randomUUID = UUID.randomUUID()
add(
ConnectionMethodBle(
peripheralServerMode,
centralClientMode,
if (peripheralServerMode) randomUUID else null,
if (centralClientMode) randomUUID else null
if (!peripheralServerMode && !centralClientMode) emptyList()
else {
mutableListOf<ConnectionMethod>().apply {
val randomUUID = UUID.randomUUID()
add(
ConnectionMethodBle(
peripheralServerMode,
centralClientMode,
if (peripheralServerMode) randomUUID else null,
if (centralClientMode) randomUUID else null
)
)
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.europa.ec.eudi.iso18013.transfer.internal

import com.android.identity.util.CborUtil
import eu.europa.ec.eudi.iso18013.transfer.retrieval.BleRetrievalMethod
import org.junit.Assert
import org.junit.Test
Expand All @@ -12,21 +13,22 @@ class DeviceRetrievalMethodExtTest(
private val peripheralServerMode: Boolean,
private val centralClientMode: Boolean,
private val clearBleCache: Boolean,
private val expectedMethodCount: Int,
) {

companion object {
@Parameters(name = "{index}: peripheralServerMode={0}, centralClientMode={1}, clearBleCache={2}")
@JvmStatic
fun data(): List<Array<Any>> {
return listOf(
arrayOf(false, true, false),
arrayOf(false, false, false),
arrayOf(true, false, false),
arrayOf(true, true, false),
arrayOf(false, true, true),
arrayOf(false, false, true),
arrayOf(true, false, true),
arrayOf(true, true, true),
arrayOf(false, true, false, 1),
arrayOf(false, false, false, 0),
arrayOf(true, false, false, 1),
arrayOf(true, true, false, 1),
arrayOf(false, true, true, 1),
arrayOf(false, false, true, 0),
arrayOf(true, false, true, 1),
arrayOf(true, true, true, 1),
)
}
}
Expand All @@ -35,10 +37,15 @@ class DeviceRetrievalMethodExtTest(
fun testDeviceRetrievalMethodConnectionMethodsAndTransportOptions() {
val bleRetrievalMethod =
BleRetrievalMethod(peripheralServerMode, centralClientMode, clearBleCache)
val connectionMethod = bleRetrievalMethod.connectionMethod
Assert.assertEquals(1, connectionMethod.size)
val connectionMethods = bleRetrievalMethod.connectionMethod
Assert.assertEquals(expectedMethodCount, connectionMethods.size)

val transportOptions = listOf(bleRetrievalMethod).transportOptions
Assert.assertEquals(clearBleCache, transportOptions.bleClearCache)

val connectionMethod = connectionMethods.firstOrNull()
CborUtil.toDiagnostics(connectionMethod?.toDeviceEngagement() ?: byteArrayOf())
.also { println("DeviceEngagement: $it") }
}

}

0 comments on commit a7a5673

Please sign in to comment.