FileDocCategorySizeDatePackage
IdleHandlerTest.javaAPI DocAndroid 1.5 API6045Wed May 06 22:42:02 BST 2009com.android.unit_tests.os

IdleHandlerTest

public class IdleHandlerTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestOneShotFirst()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 100);
                addIdleHandler();
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    if (mCount == 1) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return false;
            }
        };

        tester.doTest(1000);
    
public voidtestOneShotLater()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessage(mHandler.obtainMessage(0));
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    addIdleHandler();
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(2), 100);
                } else if (msg.what == 2) {
                    if (mCount == 1) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return false;
            }
        };

        tester.doTest(1000);
    
public voidtestRepeatedFirst()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 100);
                addIdleHandler();
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    if (mCount == 2) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return true;
            }
        };

        tester.doTest(1000);
    
public voidtestRepeatedLater()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessage(mHandler.obtainMessage(0));
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    addIdleHandler();
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(2), 100);
                } else if (msg.what == 2) {
                    if (mCount == 2) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return true;
            }
        };

        tester.doTest(1000);