1acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot/*
2acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * Copyright (C) 2009 The Android Open Source Project
3acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot *
4acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * Licensed under the Apache License, Version 2.0 (the "License");
5acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * you may not use this file except in compliance with the License.
6acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * You may obtain a copy of the License at
7acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot *
8acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot *      http://www.apache.org/licenses/LICENSE-2.0
9acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot *
10acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * Unless required by applicable law or agreed to in writing, software
11acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * distributed under the License is distributed on an "AS IS" BASIS,
12acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * See the License for the specific language governing permissions and
14acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * limitations under the License.
15acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot */
16acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
17acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabotpackage com.android.hosttest;
18acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
19acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabotimport com.android.ddmlib.IDevice;
20acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
21acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabotimport junit.framework.Test;
22acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabotimport junit.framework.TestResult;
23acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabotimport junit.framework.TestSuite;
24acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
25acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot/**
26acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot * Helper JUnit test suite that stores reference to an Android device and test data.
27acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot */
28acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabotpublic class DeviceTestSuite extends TestSuite implements DeviceTest {
29acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
30acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    private IDevice mDevice = null;
31acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    private String mTestDataPath = null;
32acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
33acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public DeviceTestSuite(Class testClass) {
34acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        super(testClass);
35acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
36acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
37acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public DeviceTestSuite() {
38acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        super();
39acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
40acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
41acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    /**
42acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     * Adds the tests from the given class to the suite
43acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     */
44acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    @Override
45acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public void addTestSuite(Class testClass) {
46acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        addTest(new DeviceTestSuite(testClass));
47acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
48acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
49acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    /**
50acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     * Overrides parent method to pass in device and test app path to included test
51acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     */
52acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    @Override
53acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public void runTest(Test test, TestResult result) {
54acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        if (test instanceof DeviceTest) {
55acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot            DeviceTest deviceTest = (DeviceTest)test;
56acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot            deviceTest.setDevice(mDevice);
57acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot            deviceTest.setTestAppPath(mTestDataPath);
58acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        }
59acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        test.run(result);
60acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
61acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
62acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    /**
63acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     * {@inheritDoc}
64acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     */
65acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public IDevice getDevice() {
66acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        return mDevice;
67acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
68acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
69acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    /**
70acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     * {@inheritDoc}
71acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     */
72acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public String getTestAppPath() {
73acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        return mTestDataPath;
74acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
75acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
76acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    /**
77acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     * {@inheritDoc}
78acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     */
79acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public void setDevice(IDevice device) {
80acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        mDevice = device;
81acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
82acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot
83acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    /**
84acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     * {@inheritDoc}
85acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot     */
86acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    public void setTestAppPath(String path) {
87acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot        mTestDataPath = path;
88acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot    }
89acedbcb8fa5588ca7f433fed7ce36e98a827f813Brett Chabot}
90