TestNativeEventPoolpublic class TestNativeEventPool extends TestCase Unit tests for the NativeEventPool class. |
Methods Summary |
---|
public void | runTests()Runs all tests.
declare("testCreate");
testCreate();
declare("testGetPutGet");
testGetPutGet();
declare("testClear");
testClear();
declare("testFillPool");
testFillPool();
declare("testMultiPut");
testMultiPut();
| void | testClear()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);
| void | testCreate()Tests basic creation of a native event pool.
NativeEventPool pool = new NativeEventPool();
assertEquals(0, pool.eventsInPool);
assertNotNull(pool.eventStack);
| void | testFillPool()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);
| void | testGetPutGet()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);
| void | testMultiPut()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]);
}
|
|