1/*
2 * Copyright (C) 2010, 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
17package com.android.frameworks.telephonytests;
18
19import android.os.Bundle;
20
21import android.test.InstrumentationTestRunner;
22import android.test.InstrumentationTestSuite;
23import android.util.Log;
24
25import java.io.IOException;
26
27import com.android.internal.telephony.RilChannel;
28import com.android.internal.telephony.mockril.MockRilTest;
29
30import junit.framework.TestSuite;
31
32public class TelephonyMockRilTestRunner extends InstrumentationTestRunner {
33
34    public RilChannel mMockRilChannel;
35
36    @Override
37    public TestSuite getAllTests() {
38        log("getAllTests E");
39        TestSuite suite = new InstrumentationTestSuite(this);
40        suite.addTestSuite(MockRilTest.class);
41        log("getAllTests X");
42        return suite;
43    }
44
45    @Override
46    public ClassLoader getLoader() {
47        log("getLoader EX");
48        return TelephonyMockRilTestRunner.class.getClassLoader();
49    }
50
51    @Override
52    public void onCreate(Bundle icicle) {
53        log("onCreate E");
54        try {
55            mMockRilChannel = RilChannel.makeRilChannel();
56        } catch (IOException e) {
57            // TODO Auto-generated catch block
58            e.printStackTrace();
59        }
60        log("onCreate X");
61
62        super.onCreate(icicle);
63    }
64
65    @Override
66    public void onDestroy() {
67        // I've not seen this called
68        log("onDestroy EX");
69        super.onDestroy();
70    }
71
72    @Override
73    public void onStart() {
74        // Called when the instrumentation thread is started.
75        // At the moment we don't need the thread so return
76        // which will shut down this unused thread.
77        log("onStart EX");
78        super.onStart();
79    }
80
81    @Override
82    public void finish(int resultCode, Bundle results) {
83        // Called when complete so I ask the mMockRilChannel to quit.
84        log("finish E");
85        mMockRilChannel.close();
86        log("finish X");
87        super.finish(resultCode, results);
88    }
89
90    private void log(String s) {
91        Log.e("TelephonyMockRilTestRunner", s);
92    }
93}
94