1/*
2 * Copyright (C) 2007 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 android.test;
18
19import java.io.PrintStream;
20
21import android.os.Bundle;
22
23import junit.framework.AssertionFailedError;
24import junit.framework.Test;
25import junit.framework.TestCase;
26import junit.runner.BaseTestRunner;
27import junit.textui.ResultPrinter;
28
29
30/**
31 * Subclass of ResultPrinter that adds test case results to a bundle.
32 *
33 * {@hide} - This class is deprecated, and will be going away.  Please don't use it.
34 */
35public class BundlePrinter extends ResultPrinter {
36
37    private Bundle mResults;
38    private boolean mFailure;
39    private boolean mError;
40
41    public BundlePrinter(PrintStream writer, Bundle result) {
42        super(writer);
43        mResults = result;
44    }
45
46    @Override
47    public void addError(Test test, Throwable t) {
48        mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
49        mFailure = true;
50        super.addError(test, t);
51    }
52
53    @Override
54    public void addFailure(Test test, AssertionFailedError t) {
55        mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
56        mError = true;
57        super.addFailure(test, t);
58    }
59
60    @Override
61    public void endTest(Test test) {
62        if (!mFailure && !mError) {
63            mResults.putString(getComboName(test), "passed");
64        }
65        super.endTest(test);
66    }
67
68    @Override
69    public void startTest(Test test) {
70        mFailure = false;
71        mError = false;
72        super.startTest(test);
73    }
74
75    private String getComboName(Test test) {
76        return test.getClass().getName() + ":" + ((TestCase) test).getName();
77    }
78
79}
80