Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 247dd412 authored by Chalard Jean's avatar Chalard Jean Committed by android-build-merger
Browse files

Add a test for the interpreter am: 708e800c

am: f2d5d4c1

Change-Id: Id78a235d9bd7f2478b6fd1c79235f86b6ca734c7
parents 48c47010 f2d5d4c1
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
package com.android.testutils

// This function is private because the 2 is hardcoded here, and is not correct if not called
// directly from __LINE__ or __FILE__.
private fun callerStackTrace(): StackTraceElement = try {
    throw RuntimeException()
} catch (e: RuntimeException) {
    e.stackTrace[2] // 0 is here, 1 is get() in __FILE__ or __LINE__
}
val __FILE__: String get() = callerStackTrace().fileName
val __LINE__: Int get() = callerStackTrace().lineNumber
+23 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.net.testutils
import android.os.SystemClock
import com.android.testutils.ArrayTrackRecord
import com.android.testutils.TrackRecord
import com.android.testutils.__FILE__
import com.android.testutils.__LINE__
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -207,6 +209,27 @@ class TrackRecordTest {
        assertTrue(delay > SHORT_TIMEOUT)
    }

    // Just make sure the interpreter actually throws an exception when the spec
    // does not conform to the behavior. The interpreter is just a tool to test a
    // tool used for a tool for test, let's not have hundreds of tests for it ;
    // if it's broken one of the tests using it will break.
    @Test
    fun testInterpreter() {
        val interpretLine = __LINE__ + 2
        try {
            interpretTestSpec(useReadHeads = true, spec = """
                add(4) | poll(1, 0) = 5
            """)
            fail("This spec should have thrown")
        } catch (e: InterpretException) {
            assertTrue(e.cause is AssertionError)
            assertEquals(interpretLine + 1, e.stackTrace[0].lineNumber)
            assertTrue(e.stackTrace[0].fileName.contains(__FILE__))
            assertTrue(e.stackTrace[0].methodName.contains("testInterpreter"))
            assertTrue(e.stackTrace[0].methodName.contains("thread1"))
        }
    }

    @Test
    fun testMultiplePoll() {
        interpretTestSpec(useReadHeads = false, spec = """