Loading tests/lib/src/com/android/testutils/FileUtils.kt 0 → 100644 +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 tests/unit/src/android/net/testutils/TrackRecordTest.kt +23 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 = """ Loading Loading
tests/lib/src/com/android/testutils/FileUtils.kt 0 → 100644 +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
tests/unit/src/android/net/testutils/TrackRecordTest.kt +23 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 = """ Loading