summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/lib/src/com/android/testutils/FileUtils.kt11
-rw-r--r--tests/unit/src/android/net/testutils/TrackRecordTest.kt23
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/lib/src/com/android/testutils/FileUtils.kt b/tests/lib/src/com/android/testutils/FileUtils.kt
new file mode 100644
index 0000000..edd8d83
--- /dev/null
+++ b/tests/lib/src/com/android/testutils/FileUtils.kt
@@ -0,0 +1,11 @@
+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
diff --git a/tests/unit/src/android/net/testutils/TrackRecordTest.kt b/tests/unit/src/android/net/testutils/TrackRecordTest.kt
index c240e65..54a3c91 100644
--- a/tests/unit/src/android/net/testutils/TrackRecordTest.kt
+++ b/tests/unit/src/android/net/testutils/TrackRecordTest.kt
@@ -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 = """