Search in sources :

Example 1 with Broadcaster

use of android.os.Broadcaster in project android_frameworks_base by ParanoidAndroid.

the class BroadcasterTest method test4.

@MediumTest
public void test4() throws Exception {
    /*
        * Two handlers request different messages, with translations, sending
        * only one.  The other one should never get sent.
        */
    HandlerTester tester = new HandlerTester() {

        Handler h1;

        Handler h2;

        public void go() {
            Broadcaster b = new Broadcaster();
            h1 = new H();
            h2 = new H();
            b.request(MESSAGE_A, h1, MESSAGE_C);
            b.request(MESSAGE_B, h2, MESSAGE_D);
            Message msg = new Message();
            msg.what = MESSAGE_A;
            b.broadcast(msg);
        }

        public void handleMessage(Message msg) {
            if (msg.what == MESSAGE_C && msg.getTarget() == h1) {
                success();
            } else {
                failure();
            }
        }
    };
    tester.doTest(1000);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Broadcaster(android.os.Broadcaster) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 2 with Broadcaster

use of android.os.Broadcaster in project android_frameworks_base by ParanoidAndroid.

the class BroadcasterTest method test6.

@MediumTest
public void test6() throws Exception {
    /*
        * Two handlers request same message. Cancel the request for the
        * 2nd handler, make sure the first still works.
        */
    HandlerTester tester = new HandlerTester() {

        Handler h1;

        Handler h2;

        public void go() {
            Broadcaster b = new Broadcaster();
            h1 = new H();
            h2 = new H();
            b.request(MESSAGE_A, h1, MESSAGE_C);
            b.request(MESSAGE_A, h2, MESSAGE_D);
            b.cancelRequest(MESSAGE_A, h2, MESSAGE_D);
            Message msg = new Message();
            msg.what = MESSAGE_A;
            b.broadcast(msg);
        }

        public void handleMessage(Message msg) {
            if (msg.what == MESSAGE_C && msg.getTarget() == h1) {
                success();
            } else {
                failure();
            }
        }
    };
    tester.doTest(1000);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Broadcaster(android.os.Broadcaster) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 3 with Broadcaster

use of android.os.Broadcaster in project android_frameworks_base by ResurrectionRemix.

the class BroadcasterTest method test4.

@MediumTest
public void test4() throws Exception {
    /*
        * Two handlers request different messages, with translations, sending
        * only one.  The other one should never get sent.
        */
    HandlerTester tester = new HandlerTester() {

        Handler h1;

        Handler h2;

        public void go() {
            Broadcaster b = new Broadcaster();
            h1 = new H();
            h2 = new H();
            b.request(MESSAGE_A, h1, MESSAGE_C);
            b.request(MESSAGE_B, h2, MESSAGE_D);
            Message msg = new Message();
            msg.what = MESSAGE_A;
            b.broadcast(msg);
        }

        public void handleMessage(Message msg) {
            if (msg.what == MESSAGE_C && msg.getTarget() == h1) {
                success();
            } else {
                failure();
            }
        }
    };
    tester.doTest(1000);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Broadcaster(android.os.Broadcaster) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 4 with Broadcaster

use of android.os.Broadcaster in project android_frameworks_base by DirtyUnicorns.

the class BroadcasterTest method test5.

@MediumTest
public void test5() throws Exception {
    /*
        * Two handlers request different messages, with translations, sending
        * only one.  The other one should never get sent.
        */
    HandlerTester tester = new HandlerTester() {

        Handler h1;

        Handler h2;

        public void go() {
            Broadcaster b = new Broadcaster();
            h1 = new H();
            h2 = new H();
            b.request(MESSAGE_A, h1, MESSAGE_C);
            b.request(MESSAGE_B, h2, MESSAGE_D);
            Message msg = new Message();
            msg.what = MESSAGE_B;
            b.broadcast(msg);
        }

        public void handleMessage(Message msg) {
            if (msg.what == MESSAGE_D && msg.getTarget() == h2) {
                success();
            } else {
                failure();
            }
        }
    };
    tester.doTest(1000);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Broadcaster(android.os.Broadcaster) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 5 with Broadcaster

use of android.os.Broadcaster in project android_frameworks_base by AOSPA.

the class BroadcasterTest method test5.

@MediumTest
public void test5() throws Exception {
    /*
        * Two handlers request different messages, with translations, sending
        * only one.  The other one should never get sent.
        */
    HandlerTester tester = new HandlerTester() {

        Handler h1;

        Handler h2;

        public void go() {
            Broadcaster b = new Broadcaster();
            h1 = new H();
            h2 = new H();
            b.request(MESSAGE_A, h1, MESSAGE_C);
            b.request(MESSAGE_B, h2, MESSAGE_D);
            Message msg = new Message();
            msg.what = MESSAGE_B;
            b.broadcast(msg);
        }

        public void handleMessage(Message msg) {
            if (msg.what == MESSAGE_D && msg.getTarget() == h2) {
                success();
            } else {
                failure();
            }
        }
    };
    tester.doTest(1000);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Broadcaster(android.os.Broadcaster) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

Broadcaster (android.os.Broadcaster)24 Handler (android.os.Handler)24 Message (android.os.Message)24 MediumTest (android.test.suitebuilder.annotation.MediumTest)24