Skip to content

Commit

Permalink
v1.5.0 included screen-size into device response data and modified Ab…
Browse files Browse the repository at this point in the history
…stractModel.generateWidgets to be able to access this response data (ActionResult) directly
  • Loading branch information
Hotzkow committed Jul 22, 2020
1 parent f185f51 commit 3afa13d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

version = "1.4.4"
version = "1.5.0"
group = "org.droidmate"

plugins {
Expand All @@ -39,7 +39,7 @@ dependencies {
// compile("org.droidmate:deviceDaemonLib") {
// in theory it should be 'api', but for some reason that does not work for transitive classpath dependencies
version {
require("[2.4.1, 2.5[")
require("[2.4.1, 2.6[")
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/main/kotlin/org/droidmate/explorationModel/ExplorationTrace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,29 @@ open class ExplorationTrace<S,W>(private val watcher: MutableList<ModelFeatureI>
return trace.getOrNull { it.lastOrNull() }
}

/**
* in contrast to [last] this method returns a list containing exactly the last action or
* in case the last entry was action queue all actions which belong to this queue
*/
suspend fun lastActionSequence(): List<Interaction<W>> {
val actions: List<Interaction<W>> = trace.getAll()
val res = mutableListOf<Interaction<W>>()
val last = actions.lastOrNull() ?: return emptyList()
if (last.actionType.isQueueEnd()){
var numQueues = 1
var idx = actions.size-2
while (idx >= 0 && numQueues > 0){
val a = actions[idx--]
when {
a.actionType.isQueueEnd() -> numQueues++
a.actionType.isQueueStart() -> numQueues --
else -> res.add(a)
}
}
} else res.add(last)
return res
}

/** this has to access a co-routine actor prefer using [size] if synchronization is not critical */
suspend fun isEmpty(): Boolean{
return trace.get { it.isEmpty() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ModelConfig private constructor(path: Path,
private val config: Configuration,
@Suppress("MemberVisibilityCanBePrivate") // used by some model features to restore/load their state
val isLoadC: Boolean = false) : Configuration by config {
/** @path path-string locationg the base directory where all model data is supposed to be dumped */
/** @path path-string locating the base directory where all model data is supposed to be dumped */

constructor(path: Path, appName: String, isLoadC: Boolean = false): this(path.toAbsolutePath(), appName, resourceConfig, isLoadC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,19 @@ abstract class AbstractModel<S,W>: CoroutineScope where S: State<W>, W: Widget {

private fun generateWidgets(action: ActionResult, @Suppress("UNUSED_PARAMETER") trace: ExplorationTrace<S,W>): Collection<W>{
val elements: Map<Int, UiElementPropertiesI> = action.guiSnapshot.widgets.associateBy { it.idHash }
return generateWidgets(action, elements)
}

open fun generateWidgets(action: ActionResult, elements: Map<Int, UiElementPropertiesI>): Collection<W>{
return generateWidgets(elements)
}

/** used on model update to compute the list of UI elements contained in the current UI screen ([State]).
* used by ModelParser to create [Widget] object from persisted data
*/
@Deprecated("this function signature will change " +
"please use generateWidgets(action: ActionResult, elements: Map<Int, UiElementPropertiesI>) instead",
replaceWith = ReplaceWith("generateWidgets(action, elements)"))
open fun generateWidgets(elements: Map<Int, UiElementPropertiesI>): Collection<W>{
val widgets = HashMap<Int,W>()
val workQueue = LinkedList<UiElementPropertiesI>().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.droidmate.deviceInterface.exploration.ExplorationAction
import org.droidmate.deviceInterface.exploration.Rectangle
import org.droidmate.deviceInterface.exploration.Swipe
import org.droidmate.explorationModel.debugOut
import org.droidmate.explorationModel.interaction.Widget.Companion.copy
import java.util.*
import kotlin.math.abs
import kotlin.math.max
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import java.util.*
import kotlin.collections.HashMap

@Suppress("unused")
open class Widget private constructor(properties: UiElementPropertiesI,
open class Widget protected constructor(properties: UiElementPropertiesI,
val parentId: ConcreteId?, overrideId: ConcreteId?): UiElementPropertiesI {

constructor(properties: UiElementPropertiesI, parentId: ConcreteId?): this(properties,parentId,null)
Expand Down Expand Up @@ -111,10 +111,30 @@ open class Widget private constructor(properties: UiElementPropertiesI,
return relevantProperties.joinToString("<;>").toUUID()
}

@JvmOverloads open fun <W: Widget> copy(boundaries: Rectangle, visibleBounds:Rectangle,
defVisible:Boolean, id:ConcreteId?,
init: (properties: UiElementPropertiesI)-> W ): W{
val properties: MutableMap<String,Any?> = HashMap()
StringCreator.annotatedProperties.forEach { p ->
properties[p.property.name] = p.property.call(this)
}
properties[this::boundaries.name] = boundaries
properties[this::visibleBounds.name] = visibleBounds
properties[this::definedAsVisible.name] = defVisible

return init(UiElementP(properties))
}

companion object {
/** used for dummy initializations, if nullable is undesirable */
internal val emptyWidget by lazy{ Widget(DummyProperties,null) }

fun <W: Widget> W.copy(boundaries: Rectangle = this.boundaries, visibleBounds:Rectangle = this.visibleBounds,
defVisible:Boolean=this.definedAsVisible, id:ConcreteId? = null,
init: (properties: UiElementPropertiesI)-> W = {
properties ->
Widget(properties, parentId, id) as W
}): W = copy(boundaries, visibleBounds, defVisible, id, init)
}

/*** overwritten functions ***/
Expand Down Expand Up @@ -170,17 +190,9 @@ open class Widget private constructor(properties: UiElementPropertiesI,
final override val definedAsVisible: Boolean = properties.definedAsVisible
final override val hasUncoveredArea: Boolean = properties.hasUncoveredArea

@JvmOverloads open fun copy(boundaries: Rectangle = this.boundaries, visibleBounds:Rectangle = this.visibleBounds,
defVisible:Boolean=this.definedAsVisible, id:ConcreteId? = null): Widget{
val properties: MutableMap<String,Any?> = HashMap()
StringCreator.annotatedProperties.forEach { p ->
properties[p.property.name] = p.property.call(this)
}
properties[this::boundaries.name] = boundaries
properties[this::visibleBounds.name] = visibleBounds
properties[this::definedAsVisible.name] = defVisible
return Widget(UiElementP(properties),parentId,id)
}

/* end override */

}


0 comments on commit 3afa13d

Please sign in to comment.