Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.internal.os;
     18 
     19 import android.os.Debug;
     20 
     21 import android.test.suitebuilder.annotation.SmallTest;
     22 import junit.framework.TestCase;
     23 
     24 @SmallTest
     25 public class DebugTest extends TestCase {
     26 
     27     private final static String EXPECTED_GET_CALLER =
     28             "com\\.android\\.internal\\.os\\.DebugTest\\.testGetCaller:\\d\\d";
     29     private final static String EXPECTED_GET_CALLERS =
     30             "com\\.android\\.internal\\.os\\.DebugTest.callDepth3:\\d\\d " +
     31             "com\\.android\\.internal\\.os\\.DebugTest.callDepth2:\\d\\d " +
     32             "com\\.android\\.internal\\.os\\.DebugTest.callDepth1:\\d\\d ";
     33 
     34     /**
     35      * @return String consisting of the caller to this method.
     36      */
     37     private String callDepth0() {
     38         return Debug.getCaller();
     39     }
     40 
     41     public void testGetCaller() {
     42         assertTrue(callDepth0().matches(EXPECTED_GET_CALLER));
     43     }
     44 
     45     /**
     46      * @return String consisting of the callers to this method.
     47      */
     48     private String callDepth4() {
     49         return Debug.getCallers(3);
     50     }
     51 
     52     private String callDepth3() {
     53         return callDepth4();
     54     }
     55 
     56     private String callDepth2() {
     57         return callDepth3();
     58     }
     59 
     60     private String callDepth1() {
     61         return callDepth2();
     62     }
     63 
     64     public void testGetCallers() {
     65         assertTrue(callDepth1().matches(EXPECTED_GET_CALLERS));
     66     }
     67 }
     68