Search in sources :

Example 1 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testTimerIntermediateArg.

@Test
@SmallTest
@UiThreadTest
public void testTimerIntermediateArg() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(1, new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            long end = System.currentTimeMillis();
            long time = (end - start);
            Log.d("RxTimerSupportTest", "testTimerIntermediateArg " + time);
            assertTrue(Math.abs(time) < 50 || Math.abs(time - 1 * 1000) < 50);
            start = end;
        }
    }, true);
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 2 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testIntervalLargerThan1.

@Test
@SmallTest
@UiThreadTest
public void testIntervalLargerThan1() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(3, new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            long end = System.currentTimeMillis();
            long time = (end - start);
            Log.d("RxTimerSupportTest", "3 testTimerExecution " + time);
            assertTrue(Math.abs(time - 3 * 1000) < 50);
            start = end;
        }
    });
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 3 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testRegisterAndUnregister.

@Test
@SmallTest
@UiThreadTest
public void testRegisterAndUnregister() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    OnTickListener onTickListener = new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            long end = System.currentTimeMillis();
            long time = (end - start);
            Log.d("RxTimerSupportTest", "testTimerIntermediateArg " + time);
            // assertTrue(Math.abs(time) < 50 || Math.abs(time - 1 * 1000) < 50);
            start = end;
        }
    };
    mTimerSupport.register(1, onTickListener, true);
    mTimerSupport.unregister(onTickListener);
    mTimerSupport.register(1, onTickListener, true);
    mTimerSupport.unregister(onTickListener);
    mTimerSupport.register(1, onTickListener, true);
    mTimerSupport.unregister(onTickListener);
    mTimerSupport.register(1, onTickListener, true);
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 4 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testTwoListener.

@Test
@SmallTest
@UiThreadTest
public void testTwoListener() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(1, new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            long end = System.currentTimeMillis();
            long time = (end - start);
            Log.d("RxTimerSupportTest", "1 testTimerExecution " + time);
            assertTrue(Math.abs(time - 1 * 1000) < 50);
            start = end;
        }
    });
    mTimerSupport.register(3, new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            long end = System.currentTimeMillis();
            long time = (end - start);
            Log.d("RxTimerSupportTest", "3 testTimerExecution " + time);
            assertTrue(Math.abs(time - 3 * 1000) < 50);
            start = end;
        }
    });
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 5 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testStop.

@Test
@SmallTest
@UiThreadTest
public void testStop() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(1, new OnTickListener() {

        @Override
        public void onTick() {
            // should not here
            assertTrue(false);
        }
    });
    mTimerSupport.register(3, new OnTickListener() {

        @Override
        public void onTick() {
            // should not here
            assertTrue(false);
        }
    });
    mTimerSupport.clear();
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

OnTickListener (com.tmall.wireless.tangram.support.TimerSupport.OnTickListener)9 UiThreadTest (android.support.test.annotation.UiThreadTest)8 SmallTest (android.support.test.filters.SmallTest)8 Test (org.junit.Test)8 Disposable (io.reactivex.disposables.Disposable)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1