use of com.android.internal.util.StateMachine.LogRec in project platform_frameworks_base by android.
the class StateMachineTest method testStateMachine1.
@MediumTest
public void testStateMachine1() throws Exception {
StateMachine1 sm1 = new StateMachine1("sm1");
sm1.start();
if (sm1.isDbg())
tlog("testStateMachine1 E");
synchronized (sm1) {
// Send two messages
sm1.sendMessage(TEST_CMD_1);
sm1.sendMessage(TEST_CMD_2);
try {
// wait for the messages to be handled
sm1.wait();
} catch (InterruptedException e) {
tloge("testStateMachine1: exception while waiting " + e.getMessage());
}
}
assertEquals(2, sm1.mEnterCount);
assertEquals(2, sm1.mExitCount);
assertEquals(2, sm1.getLogRecSize());
LogRec lr;
lr = sm1.getLogRec(0);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(sm1.mS1, lr.getState());
assertEquals(sm1.mS1, lr.getOriginalState());
lr = sm1.getLogRec(1);
assertEquals(TEST_CMD_2, lr.getWhat());
assertEquals(sm1.mS1, lr.getState());
assertEquals(sm1.mS1, lr.getOriginalState());
assertEquals(2, sm1.mEnterCount);
assertEquals(2, sm1.mExitCount);
if (sm1.isDbg())
tlog("testStateMachine1 X");
}
use of com.android.internal.util.StateMachine.LogRec in project platform_frameworks_base by android.
the class StateMachineTest method testStateMachine3.
@MediumTest
public void testStateMachine3() throws Exception {
StateMachine3 sm3 = new StateMachine3("sm3");
sm3.start();
if (sm3.isDbg())
tlog("testStateMachine3 E");
synchronized (sm3) {
// Send two messages
sm3.sendMessage(TEST_CMD_1);
sm3.sendMessage(TEST_CMD_2);
try {
// wait for the messages to be handled
sm3.wait();
} catch (InterruptedException e) {
tloge("testStateMachine3: exception while waiting " + e.getMessage());
}
}
assertEquals(2, sm3.getLogRecSize());
LogRec lr;
lr = sm3.getLogRec(0);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(sm3.mParentState, lr.getState());
assertEquals(sm3.mChildState, lr.getOriginalState());
lr = sm3.getLogRec(1);
assertEquals(TEST_CMD_2, lr.getWhat());
assertEquals(sm3.mParentState, lr.getState());
assertEquals(sm3.mChildState, lr.getOriginalState());
if (sm3.isDbg())
tlog("testStateMachine3 X");
}
use of com.android.internal.util.StateMachine.LogRec in project platform_frameworks_base by android.
the class StateMachineTest method testStateMachineSharedThread.
@MediumTest
public void testStateMachineSharedThread() throws Exception {
if (DBG)
tlog("testStateMachineSharedThread E");
// Create and start the handler thread
HandlerThread smThread = new HandlerThread("testStateMachineSharedThread");
smThread.start();
// Create the state machines
StateMachineSharedThread[] sms = new StateMachineSharedThread[10];
for (int i = 0; i < sms.length; i++) {
sms[i] = new StateMachineSharedThread("smSharedThread", smThread.getLooper(), sms.length);
sms[i].start();
}
synchronized (waitObject) {
// Send messages to each of the state machines
for (StateMachineSharedThread sm : sms) {
for (int i = 1; i <= 4; i++) {
sm.sendMessage(i);
}
}
// Wait for the last state machine to notify its done
try {
waitObject.wait();
} catch (InterruptedException e) {
tloge("testStateMachineSharedThread: exception while waiting " + e.getMessage());
}
}
for (StateMachineSharedThread sm : sms) {
assertEquals(4, sm.getLogRecCount());
for (int i = 0; i < sm.getLogRecSize(); i++) {
LogRec lr = sm.getLogRec(i);
assertEquals(i + 1, lr.getWhat());
assertEquals(sm.mS1, lr.getState());
assertEquals(sm.mS1, lr.getOriginalState());
}
}
if (DBG)
tlog("testStateMachineSharedThread X");
}
use of com.android.internal.util.StateMachine.LogRec in project platform_frameworks_base by android.
the class StateMachineTest method testStateMachineQuitNow.
@SmallTest
public void testStateMachineQuitNow() throws Exception {
if (WAIT_FOR_DEBUGGER)
Debug.waitForDebugger();
StateMachineQuitNowTest smQuitNowTest = new StateMachineQuitNowTest("smQuitNowTest");
smQuitNowTest.start();
if (smQuitNowTest.isDbg())
tlog("testStateMachineQuitNow E");
synchronized (smQuitNowTest) {
// we send 6 only one will be processed.
for (int i = 1; i <= 6; i++) {
smQuitNowTest.sendMessage(smQuitNowTest.obtainMessage(i));
}
try {
// wait for the messages to be handled
smQuitNowTest.wait();
} catch (InterruptedException e) {
tloge("testStateMachineQuitNow: exception while waiting " + e.getMessage());
}
}
tlog("testStateMachineQuiteNow: logRecs=" + smQuitNowTest.mLogRecs);
assertEquals(3, smQuitNowTest.mLogRecs.size());
Iterator<LogRec> itr = smQuitNowTest.mLogRecs.iterator();
LogRec lr = itr.next();
assertEquals(1, lr.getWhat());
assertEquals(smQuitNowTest.mS1, lr.getState());
assertEquals(smQuitNowTest.mS1, lr.getOriginalState());
lr = itr.next();
assertEquals(EXIT, lr.getInfo());
assertEquals(smQuitNowTest.mS1, lr.getState());
lr = itr.next();
assertEquals(ON_QUITTING, lr.getInfo());
if (smQuitNowTest.isDbg())
tlog("testStateMachineQuitNow X");
}
use of com.android.internal.util.StateMachine.LogRec in project platform_frameworks_base by android.
the class StateMachineTest method testStateMachineEnterExitTransitionToTest.
@SmallTest
public void testStateMachineEnterExitTransitionToTest() throws Exception {
//if (WAIT_FOR_DEBUGGER) Debug.waitForDebugger();
StateMachineEnterExitTransitionToTest smEnterExitTranstionToTest = new StateMachineEnterExitTransitionToTest("smEnterExitTranstionToTest");
smEnterExitTranstionToTest.start();
if (smEnterExitTranstionToTest.isDbg()) {
tlog("testStateMachineEnterExitTransitionToTest E");
}
synchronized (smEnterExitTranstionToTest) {
smEnterExitTranstionToTest.sendMessage(TEST_CMD_1);
try {
// wait for the messages to be handled
smEnterExitTranstionToTest.wait();
} catch (InterruptedException e) {
tloge("testStateMachineEnterExitTransitionToTest: exception while waiting " + e.getMessage());
}
}
dumpLogRecs(smEnterExitTranstionToTest);
assertEquals(9, smEnterExitTranstionToTest.getLogRecCount());
LogRec lr;
lr = smEnterExitTranstionToTest.getLogRec(0);
assertEquals(ENTER, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS1, lr.getState());
lr = smEnterExitTranstionToTest.getLogRec(1);
assertEquals(EXIT, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS1, lr.getState());
lr = smEnterExitTranstionToTest.getLogRec(2);
assertEquals(ENTER, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS2, lr.getState());
lr = smEnterExitTranstionToTest.getLogRec(3);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(smEnterExitTranstionToTest.mS2, lr.getState());
assertEquals(smEnterExitTranstionToTest.mS2, lr.getOriginalState());
assertEquals(smEnterExitTranstionToTest.mS3, lr.getDestState());
lr = smEnterExitTranstionToTest.getLogRec(4);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(smEnterExitTranstionToTest.mS2, lr.getState());
assertEquals(smEnterExitTranstionToTest.mS2, lr.getOriginalState());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getDestState());
assertEquals(EXIT, lr.getInfo());
lr = smEnterExitTranstionToTest.getLogRec(5);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(ENTER, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS3, lr.getState());
assertEquals(smEnterExitTranstionToTest.mS3, lr.getOriginalState());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getDestState());
lr = smEnterExitTranstionToTest.getLogRec(6);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(EXIT, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS3, lr.getState());
assertEquals(smEnterExitTranstionToTest.mS3, lr.getOriginalState());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getDestState());
lr = smEnterExitTranstionToTest.getLogRec(7);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(ENTER, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getState());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getOriginalState());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getDestState());
lr = smEnterExitTranstionToTest.getLogRec(8);
assertEquals(TEST_CMD_1, lr.getWhat());
assertEquals(EXIT, lr.getInfo());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getState());
assertEquals(smEnterExitTranstionToTest.mS4, lr.getOriginalState());
if (smEnterExitTranstionToTest.isDbg()) {
tlog("testStateMachineEnterExitTransitionToTest X");
}
}
Aggregations