FileDocCategorySizeDatePackage
TestNativeEventPool.javaAPI DocphoneME MR2 API (J2ME)4501Wed May 02 18:00:16 BST 2007com.sun.midp.events

TestNativeEventPool

public class TestNativeEventPool extends TestCase
Unit tests for the NativeEventPool class.

Fields Summary
Constructors Summary
Methods Summary
public voidrunTests()
Runs all tests.

        declare("testCreate");
        testCreate();
        declare("testGetPutGet");
        testGetPutGet();
        declare("testClear");
        testClear();
        declare("testFillPool");
        testFillPool();
        declare("testMultiPut");
        testMultiPut();
    
voidtestClear()
Tests that the event is cleared when it is returned to the pool. This is at least as much a test of NativeEvent.clear() as it is of the NativeEventPool's clearing function.

        NativeEventPool pool = new NativeEventPool();
        NativeEvent evt = new NativeEvent(83);

        evt.intParam1 = 1;
        evt.intParam2 = 2;
        evt.intParam3 = 3;
        evt.intParam4 = 4;

        evt.stringParam1 = "one";
        evt.stringParam2 = "two";
        evt.stringParam3 = "three";
        evt.stringParam4 = "four";
        evt.stringParam5 = "five";
        evt.stringParam6 = "six";

        pool.putBack(evt);

        assertEquals(0, evt.type);
        assertEquals(0, evt.intParam1);
        assertEquals(0, evt.intParam2);
        assertEquals(0, evt.intParam3);
        assertEquals(0, evt.intParam4);
        assertEquals(null, evt.stringParam1);
        assertEquals(null, evt.stringParam2);
        assertEquals(null, evt.stringParam3);
        assertEquals(null, evt.stringParam4);
        assertEquals(null, evt.stringParam5);
        assertEquals(null, evt.stringParam6);
    
voidtestCreate()
Tests basic creation of a native event pool.

        NativeEventPool pool = new NativeEventPool();
        assertEquals(0, pool.eventsInPool);
        assertNotNull(pool.eventStack);
    
voidtestFillPool()
Tests filling up the event pool.

        NativeEventPool pool = new NativeEventPool();

        for (int i = 0; i < NativeEventPool.DEFAULT_SIZE; i++) {
            pool.putBack(new NativeEvent());
        }

        assertEquals(NativeEventPool.DEFAULT_SIZE, pool.eventsInPool);
        pool.putBack(new NativeEvent());
        assertEquals(NativeEventPool.DEFAULT_SIZE, pool.eventsInPool);
    
voidtestGetPutGet()
Tests a simple get-put-get sequence.

        NativeEventPool pool = new NativeEventPool();
        NativeEvent evt = pool.get();
        assertEquals(0, pool.eventsInPool);

        pool.putBack(evt);
        assertEquals(1, pool.eventsInPool);
        assertSame(evt, pool.eventStack[0]);

        NativeEvent evt2 = pool.get();
        assertSame(evt, evt2);
        assertEquals(0, pool.eventsInPool);
    
voidtestMultiPut()
Tests putting multiple events into the pool.

        final int NUM_EVENTS = 3;
        assertTrue(NUM_EVENTS < NativeEventPool.DEFAULT_SIZE);

        NativeEventPool pool = new NativeEventPool();
        NativeEvent evts[] = new NativeEvent[NUM_EVENTS];
        for (int i = 0; i < NUM_EVENTS; i++) {
            evts[i] = new NativeEvent();
            pool.putBack(evts[i]);
        }

        assertEquals(NUM_EVENTS, pool.eventsInPool);
        for (int i = 0; i < NUM_EVENTS; i++) {
            assertSame(evts[i], pool.eventStack[i]);
        }