summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
authorCraig Mautner <cmautner@google.com>2012-04-17 17:05:26 -0700
committerCraig Mautner <cmautner@google.com>2012-04-17 17:25:50 -0700
commita51a9564fd53b661446cd63eea23208656acc678 (patch)
tree08b84aa11dd9b02309c1fa6508d2fd73e16e033d /core/tests
parentc843642fbb76619520f960043adaa268e252a657 (diff)
downloadframeworks_base-a51a9564fd53b661446cd63eea23208656acc678.zip
frameworks_base-a51a9564fd53b661446cd63eea23208656acc678.tar.gz
frameworks_base-a51a9564fd53b661446cd63eea23208656acc678.tar.bz2
Add call-stack reporting methods into Debug
Added two public methods to Debug. These methods return a String indicating the caller (getCaller()) or callers (getCallers(int depth)) of the calling method. The String indicates the class, method and line number of the caller(s). Similar to using Throwable.fillInStackTrace() but much more concise. Change-Id: I53d0085aa50e4501d28e8eb3ad5b91ef700ac218
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/coretests/src/com/android/internal/os/DebugTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/core/tests/coretests/src/com/android/internal/os/DebugTest.java b/core/tests/coretests/src/com/android/internal/os/DebugTest.java
new file mode 100644
index 0000000..88c7d1b
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/os/DebugTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.os;
+
+import android.os.Debug;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.TestCase;
+
+@SmallTest
+public class DebugTest extends TestCase {
+
+ private final static String EXPECTED_GET_CALLER =
+ "com\\.android\\.internal\\.os\\.DebugTest\\.testGetCaller:\\d\\d";
+ private final static String EXPECTED_GET_CALLERS =
+ "com\\.android\\.internal\\.os\\.DebugTest.callDepth3:\\d\\d " +
+ "com\\.android\\.internal\\.os\\.DebugTest.callDepth2:\\d\\d " +
+ "com\\.android\\.internal\\.os\\.DebugTest.callDepth1:\\d\\d ";
+
+ /**
+ * @return String consisting of the caller to this method.
+ */
+ private String callDepth0() {
+ return Debug.getCaller();
+ }
+
+ public void testGetCaller() {
+ assertTrue(callDepth0().matches(EXPECTED_GET_CALLER));
+ }
+
+ /**
+ * @return String consisting of the callers to this method.
+ */
+ private String callDepth4() {
+ return Debug.getCallers(3);
+ }
+
+ private String callDepth3() {
+ return callDepth4();
+ }
+
+ private String callDepth2() {
+ return callDepth3();
+ }
+
+ private String callDepth1() {
+ return callDepth2();
+ }
+
+ public void testGetCallers() {
+ assertTrue(callDepth1().matches(EXPECTED_GET_CALLERS));
+ }
+}