package tv.anypoint.dsl import tv.anypoint.dsl.handler.HttpHandler import tv.anypoint.dsl.model.adb.ExtraKey import tv.anypoint.dsl.model.adb.IntentAction import tv.anypoint.dsl.model.Tc import tv.anypoint.dsl.service.TestCase import java.time.Duration import java.time.LocalDateTime import java.time.Period import java.time.temporal.ChronoUnit import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException inline fun tc( block: Tc.() -> Unit ) = Tc().also { block(it) } inline fun http( block: HttpHandler.() -> Unit ) = HttpHandler().also { block(it) } data class Adb( val a: IntentAction, val es: Map ) inline fun adb( a: IntentAction, es: Map ) { val adb = Adb(a, es) val aStr = "-a $a" val esStr: String = es.entries.joinToString(" ") { "--es ${it.key.string} ${it.value}" } println("[ADB] adb shell am broadcast $aStr $esStr") } fun TestCase.expected( expectedLog: String, timeout: Long = 10_000L ) { val startedAt = LocalDateTime.now() while (true) { val now = LocalDateTime.now() if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) { throw TimeoutException("failed to find log. expectedLog: $expectedLog, absoluteFilePath: ${this.tc.logInfo.absoluteFilePath}") } // TODO: tc 로그에서 expectedLog 찾기 tc.logInfo.cursor ~ 마지막 라인까지의 로그 중에 찾으면 됨 } }