From a3eba6aebcb84490272fa7ba04db7461583fd0f7 Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Sat, 16 Mar 2024 13:01:47 -0700 Subject: [PATCH] Idempotent wrapper reads missing data from wrapped app AAIdrive relies on the previous behavior where ImageIdModels can remember their imageId after being loaded from a resource file. When set through Idempotent, it's remembered, but when it's loaded from XML, only the Etch app has it --- .../rhmi/RHMIApplicationWrappers.kt | 10 ++++--- .../TestRHMIApplicationIdempotent.kt | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplicationWrappers.kt b/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplicationWrappers.kt index 8944a6f..c7d191f 100644 --- a/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplicationWrappers.kt +++ b/src/main/java/io/bimmergestalt/idriveconnectkit/rhmi/RHMIApplicationWrappers.kt @@ -16,8 +16,8 @@ class RHMIApplicationIdempotent(val app: RHMIApplication): RHMIApplication(), RH override val states = app.states override val components = app.components - private val sentData = HashMap() - private val sentProperties = HashMap>().withDefault { HashMap() } + internal val sentData = HashMap() + internal val sentProperties = HashMap>().withDefault { HashMap() } override fun setModel(modelId: Int, value: Any?) { val model = models[modelId] @@ -46,7 +46,8 @@ class RHMIApplicationIdempotent(val app: RHMIApplication): RHMIApplication(), RH } } - override fun getModel(modelId: Int): Any? = sentData[modelId] + override fun getModel(modelId: Int): Any? = + sentData[modelId] ?: app.getModel(modelId) override fun setProperty(componentId: Int, propertyId: Int, value: Any?) { if (getProperty(componentId, propertyId) != value) { @@ -55,7 +56,8 @@ class RHMIApplicationIdempotent(val app: RHMIApplication): RHMIApplication(), RH } } - override fun getProperty(componentId: Int, propertyId: Int): Any? = sentProperties[componentId]?.get(propertyId) + override fun getProperty(componentId: Int, propertyId: Int): Any? = + sentProperties[componentId]?.get(propertyId) ?: app.getProperty(componentId, propertyId) override fun triggerHMIEvent(eventId: Int, args: Map) { app.triggerHMIEvent(eventId, args) diff --git a/src/test/java/io/bimmergestalt/idriveconnectkit/TestRHMIApplicationIdempotent.kt b/src/test/java/io/bimmergestalt/idriveconnectkit/TestRHMIApplicationIdempotent.kt index de7446d..0d2dcee 100644 --- a/src/test/java/io/bimmergestalt/idriveconnectkit/TestRHMIApplicationIdempotent.kt +++ b/src/test/java/io/bimmergestalt/idriveconnectkit/TestRHMIApplicationIdempotent.kt @@ -35,74 +35,96 @@ class TestRHMIApplicationIdempotent { // RaDataModel subject.models[1]?.asRaDataModel()?.value = "2" assertEquals("2", backing.modelData[1]) + assertEquals("2", subject.models[1]?.asRaDataModel()?.value) backing.modelData.remove(1) // repeated setting should not send to the backing connection subject.models[1]?.asRaDataModel()?.value = "2" assertEquals(null, backing.modelData[1]) + assertEquals("2", subject.models[1]?.asRaDataModel()?.value) // but changing the value should write to the backing connection subject.models[1]?.asRaDataModel()?.value = "3" assertEquals("3", backing.modelData[1]) + assertEquals("3", subject.models[1]?.asRaDataModel()?.value) + + // idempotent should read through to backing + subject.sentData.remove(1) + assertEquals("3", subject.models[1]?.asRaDataModel()?.value) // read from backing if cleared from Idempotent // RaIntModel subject.models[2]?.asRaIntModel()?.value = 2 assertEquals(2, backing.modelData[2]) + assertEquals(2, subject.models[2]?.asRaIntModel()?.value) backing.modelData.remove(2) // repeated setting should not send to the backing connection subject.models[2]?.asRaIntModel()?.value = 2 assertEquals(null, backing.modelData[2]) + assertEquals(2, subject.models[2]?.asRaIntModel()?.value) // but changing the value should write to the backing connection subject.models[2]?.asRaIntModel()?.value = 3 assertEquals(3, backing.modelData[2]) + assertEquals(3, subject.models[2]?.asRaIntModel()?.value) // RaGaugeModel subject.models[3]?.asRaGaugeModel()?.value = 2 + assertEquals(2, subject.models[3]?.asRaGaugeModel()?.value) assertEquals(2, backing.modelData[3]) backing.modelData.remove(3) // repeated setting should not send to the backing connection subject.models[3]?.asRaGaugeModel()?.value = 2 assertEquals(null, backing.modelData[3]) + assertEquals(2, subject.models[3]?.asRaGaugeModel()?.value) // but changing the value should write to the backing connection subject.models[3]?.asRaGaugeModel()?.value = 3 assertEquals(3, backing.modelData[3]) + assertEquals(3, subject.models[3]?.asRaGaugeModel()?.value) // RaBoolModel subject.models[4]?.asRaBoolModel()?.value = true assertEquals(true, backing.modelData[4]) + assertEquals(true, subject.models[4]?.asRaBoolModel()?.value) backing.modelData.remove(4) // repeated setting should not send to the backing connection subject.models[4]?.asRaBoolModel()?.value = true assertEquals(null, backing.modelData[4]) + assertEquals(true, subject.models[4]?.asRaBoolModel()?.value) // but changing the value should write to the backing connection subject.models[4]?.asRaBoolModel()?.value = false assertEquals(false, backing.modelData[4]) + assertEquals(false, subject.models[4]?.asRaBoolModel()?.value) // TextIdModel subject.models[5]?.asTextIdModel()?.textId = 1 assertEquals(1, (backing.modelData[5] as BMWRemoting.RHMIResourceIdentifier).id) + assertEquals(1, subject.models[5]?.asTextIdModel()?.textId) backing.modelData.remove(5) // repeated setting should not send to the backing connection subject.models[5]?.asTextIdModel()?.textId = 1 assertEquals(null, backing.modelData[5]) + assertEquals(1, subject.models[5]?.asTextIdModel()?.textId) // but changing the value should write to the backing connection subject.models[5]?.asTextIdModel()?.textId = 5 assertEquals(5, (backing.modelData[5] as BMWRemoting.RHMIResourceIdentifier).id) + assertEquals(5, subject.models[5]?.asTextIdModel()?.textId) // ImageIdModel subject.models[6]?.asImageIdModel()?.imageId = 3 assertEquals(3, (backing.modelData[6] as BMWRemoting.RHMIResourceIdentifier).id) + assertEquals(3, subject.models[6]?.asImageIdModel()?.imageId) backing.modelData.remove(6) // repeated setting should not send to the backing connection subject.models[6]?.asImageIdModel()?.imageId = 3 assertEquals(null, backing.modelData[6]) + assertEquals(3, subject.models[6]?.asImageIdModel()?.imageId) // but changing the value should write to the backing connection subject.models[6]?.asImageIdModel()?.imageId = 6 assertEquals(6, (backing.modelData[6] as BMWRemoting.RHMIResourceIdentifier).id) + assertEquals(6, subject.models[6]?.asImageIdModel()?.imageId) } @Test @@ -130,14 +152,21 @@ class TestRHMIApplicationIdempotent { fun setProperty() { subject.components[10]?.asLabel()?.setVisible(true) assertEquals(true, backing.propertyData[10]!![RHMIProperty.PropertyId.VISIBLE.id]) + assertEquals(true, subject.components[10]?.asLabel()?.properties?.get(RHMIProperty.PropertyId.VISIBLE.id)?.value) backing.propertyData.remove(10) // repeated setting should not send to the backing connection subject.components[10]?.asLabel()?.setVisible(true) assertEquals(null, backing.propertyData[10]) + assertEquals(true, subject.components[10]?.asLabel()?.properties?.get(RHMIProperty.PropertyId.VISIBLE.id)?.value) // but changing the value should write to the backing connection subject.components[10]?.asLabel()?.setVisible(false) assertEquals(false, backing.propertyData[10]!![RHMIProperty.PropertyId.VISIBLE.id]) + assertEquals(false, subject.components[10]?.asLabel()?.properties?.get(RHMIProperty.PropertyId.VISIBLE.id)?.value) + + // idempotent should read through backing + subject.sentProperties.remove(10) + assertEquals(false, subject.components[10]?.asLabel()?.properties?.get(RHMIProperty.PropertyId.VISIBLE.id)?.value) } @Test