Android Open Source - Cafe Cafe Listener






From Project

Back to project page Cafe.

License

The source code is released under:

Apache License

If you think the Android project Cafe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.baidu.cafe;
// ww w . j  a v a2 s.com
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;

import com.baidu.cafe.local.LocalLib;
import com.baidu.cafe.utils.ReflectHelper;
import com.zutubi.android.junitreport.JUnitReportListener;

/**
 * @author luxiaoyu01@baidu.com
 * @date 2012-6-25
 * @version
 * @todo
 */
public class CafeListener extends JUnitReportListener {
    private int           mPackageRcv    = 0;
    private int           mPackageSnd    = 0;
    private static String mName          = null;
    private LocalLib      mLocalLib      = null;
    private Context       mTargetContext = null;

    public CafeListener(Context context, Context targetContext, String reportFile,
            String reportDir, boolean filterTraces, boolean multiFile,
            Instrumentation instrumentation) {
        super(context, targetContext, reportFile, reportDir, filterTraces, multiFile);
        // activity == null, so we can not use those fuction in Locallib which use it.
        this.mLocalLib = new LocalLib(instrumentation, null);
        this.mTargetContext = targetContext;
    }

    @Override
    public void startTest(Test test) {
        mName = ((TestCase) test).getName();
        System.out.println("mTestCaseName:" + mName);
        LocalLib.mTestCaseName = mName;
        mPackageRcv = LocalLib.getPackageRcv(mTargetContext.getPackageName());
        mPackageSnd = LocalLib.getPackageSnd(mTargetContext.getPackageName());
        super.startTest(test);
    }

    @Override
    public void addError(Test test, Throwable error) {
        mLocalLib.screenShotNamedSuffix(mName);
        super.addError(test, error);
    }

    @Override
    public void addFailure(Test test, AssertionFailedError error) {
        mLocalLib.screenShotNamedSuffix(mName);
        super.addFailure(test, error);
    }

    @Override
    public void endTest(Test test) {
        long mTestStartTime = 0;
        try {
            mTestStartTime = (Long) ReflectHelper.getField(this,
                    "com.zutubi.android.junitreport.JUnitReportListener", "mTestStartTime");
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        String packageName = mTargetContext.getPackageName();
        String string = String.format(
                "Testcase: %s  Time: %sms  PackageRcv: %sbytes  PackageSnd: %sbytes",
                ((TestCase) test).getClass(), System.currentTimeMillis() - mTestStartTime,
                LocalLib.getPackageRcv(packageName) - mPackageRcv,
                LocalLib.getPackageSnd(packageName) - mPackageSnd);
        Log.i("NetworkStatus", string);
        super.endTest(test);
    }

}




Java Source Code List

com.baidu.cafe.CafeExceptionHandler.java
com.baidu.cafe.CafeListener.java
com.baidu.cafe.CafeServiceTestCase.java
com.baidu.cafe.CafeTestCase.java
com.baidu.cafe.CafeTestRunner.java
com.baidu.cafe.TearDownHelper.java
com.baidu.cafe.local.DESEncryption.java
com.baidu.cafe.local.FPSTracer.java
com.baidu.cafe.local.FileUtils.java
com.baidu.cafe.local.LocalLib.java
com.baidu.cafe.local.Log.java
com.baidu.cafe.local.NetworkUtils.java
com.baidu.cafe.local.SnapshotHelper.java
com.baidu.cafe.local.record.CafeWebViewClient.java
com.baidu.cafe.local.record.OutputEvent.java
com.baidu.cafe.local.record.ViewRecorderSDK.java
com.baidu.cafe.local.record.ViewRecorder.java
com.baidu.cafe.local.record.WebElementRecorder.java
com.baidu.cafe.local.traveler.APPTraveler.java
com.baidu.cafe.local.traveler.Logger.java
com.baidu.cafe.local.traveler.Operation.java
com.baidu.cafe.local.traveler.Util.java
com.baidu.cafe.local.traveler.ViewHelper.java
com.baidu.cafe.remote.ArmsBinder.java
com.baidu.cafe.remote.ArmsBootupReceiver.java
com.baidu.cafe.remote.Arms.java
com.baidu.cafe.remote.Armser.java
com.baidu.cafe.remote.BatteryState.java
com.baidu.cafe.remote.LockActivity.java
com.baidu.cafe.remote.Log.java
com.baidu.cafe.remote.MonkeyNetwork.java
com.baidu.cafe.remote.MyIntent.java
com.baidu.cafe.remote.SystemLib.java
com.baidu.cafe.remote.UILib.java
com.baidu.cafe.remote.ViewPropertyProvider.java
com.baidu.cafe.utils.CommandResult.java
com.baidu.cafe.utils.ReflectHelper.java
com.baidu.cafe.utils.ShellExecute.java
com.baidu.cafe.utils.Strings.java
com.baidu.cafe.utils.TreeNode.java