diff options
author | Wink Saville <wink@google.com> | 2012-05-29 12:40:46 -0700 |
---|---|---|
committer | Wink Saville <wink@google.com> | 2012-05-29 12:40:46 -0700 |
commit | bbf30dfd767f823f5f40d14b498e2a593454c5c9 (patch) | |
tree | 8a73a775e4f6ac59eade4b465e7e2a3672078358 /core/tests/coretests | |
parent | fe002daf4aa6a7ba6cfc2379f11c517f419c77d1 (diff) | |
download | frameworks_base-bbf30dfd767f823f5f40d14b498e2a593454c5c9.zip frameworks_base-bbf30dfd767f823f5f40d14b498e2a593454c5c9.tar.gz frameworks_base-bbf30dfd767f823f5f40d14b498e2a593454c5c9.tar.bz2 |
Enhance StateMachine Quitting and logging support.
Make StateMachine#quit non-conditional and remove the need to
process the SM_QUIT_CMD it is now private.
Rename halting to onHalting.
Add onQuitting
Change the message specific logging to be more generic and change
the xxxProcessedMessagesYyy methods to xxxLogRecXyy names. Also add
addLogRec(String) and addLogRec(String, State) as the generic logging
methods.
bug: 5678189
Change-Id: I22f66d11828bfd70498db625fe1be728b90478b7
Diffstat (limited to 'core/tests/coretests')
-rw-r--r-- | core/tests/coretests/src/com/android/internal/util/StateMachineTest.java | 602 |
1 files changed, 366 insertions, 236 deletions
diff --git a/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java b/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java index ab6b2b6..418bbd6 100644 --- a/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java +++ b/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java @@ -24,7 +24,7 @@ import android.os.SystemClock; import com.android.internal.util.State; import com.android.internal.util.StateMachine; -import com.android.internal.util.StateMachine.ProcessedMessageInfo; +import com.android.internal.util.StateMachine.LogRec; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; @@ -36,6 +36,10 @@ import junit.framework.TestCase; * Test for StateMachine. */ public class StateMachineTest extends TestCase { + private static final String ENTER = "enter"; + private static final String EXIT = "exit"; + private static final String ON_QUITTING = "ON_QUITTING"; + private static final int TEST_CMD_1 = 1; private static final int TEST_CMD_2 = 2; private static final int TEST_CMD_3 = 3; @@ -47,11 +51,18 @@ public class StateMachineTest extends TestCase { private static final boolean WAIT_FOR_DEBUGGER = false; private static final String TAG = "StateMachineTest"; + private void sleep(int millis) { + try { + Thread.sleep(millis); + } catch(InterruptedException e) { + } + } + /** - * Tests that we can quit the state machine. + * Tests {@link StateMachine#quit()}. */ class StateMachineQuitTest extends StateMachine { - private int mQuitCount = 0; + Object mWaitUntilTestDone = new Object(); StateMachineQuitTest(String name) { super(name); @@ -65,29 +76,45 @@ public class StateMachineTest extends TestCase { setInitialState(mS1); } + @Override + public void onQuitting() { + Log.d(TAG, "onQuitting"); + addLogRec(ON_QUITTING); + synchronized (mThisSm) { + mThisSm.notifyAll(); + } + + // Don't leave onQuitting before the test is done as everything is cleared + // including the log records. + synchronized (mWaitUntilTestDone) { + try { + mWaitUntilTestDone.wait(); + } catch(InterruptedException e) { + } + } + } + class S1 extends State { + public void exit() { + Log.d(TAG, "S1.exit"); + addLogRec(EXIT, mS1); + } @Override public boolean processMessage(Message message) { - if (isQuit(message)) { - mQuitCount += 1; - if (mQuitCount > 2) { - // Returning NOT_HANDLED to actually quit - return NOT_HANDLED; - } else { - // Do NOT quit - return HANDLED; + switch(message.what) { + // Sleep and assume the other messages will be queued up. + case TEST_CMD_1: { + Log.d(TAG, "TEST_CMD_1"); + sleep(500); + quit(); + break; + } + default: { + Log.d(TAG, "default what=" + message.what); + break; } - } else { - // All other message are handled - return HANDLED; } - } - } - - @Override - protected void quitting() { - synchronized (mThisSm) { - mThisSm.notifyAll(); + return HANDLED; } } @@ -96,62 +123,167 @@ public class StateMachineTest extends TestCase { } @SmallTest - public void testStateMachineQuitTest() throws Exception { + public void testStateMachineQuit() throws Exception { if (WAIT_FOR_DEBUGGER) Debug.waitForDebugger(); StateMachineQuitTest smQuitTest = new StateMachineQuitTest("smQuitTest"); smQuitTest.start(); - if (smQuitTest.isDbg()) Log.d(TAG, "testStateMachineQuitTest E"); + if (smQuitTest.isDbg()) Log.d(TAG, "testStateMachineQuit E"); synchronized (smQuitTest) { - // Send 6 messages + + // Send 6 message we'll quit on the first but all 6 should be processed before quitting. for (int i = 1; i <= 6; i++) { - smQuitTest.sendMessage(i); + smQuitTest.sendMessage(smQuitTest.obtainMessage(i)); + } + + try { + // wait for the messages to be handled + smQuitTest.wait(); + } catch (InterruptedException e) { + Log.e(TAG, "testStateMachineQuit: exception while waiting " + e.getMessage()); + } + } + + assertEquals(8, smQuitTest.getLogRecCount()); + + LogRec lr; + + for (int i = 0; i < 6; i++) { + lr = smQuitTest.getLogRec(i); + assertEquals(i+1, lr.getWhat()); + assertEquals(smQuitTest.mS1, lr.getState()); + assertEquals(smQuitTest.mS1, lr.getOriginalState()); + } + lr = smQuitTest.getLogRec(6); + assertEquals(EXIT, lr.getInfo()); + assertEquals(smQuitTest.mS1, lr.getState()); + + lr = smQuitTest.getLogRec(7); + assertEquals(ON_QUITTING, lr.getInfo()); + + synchronized (smQuitTest.mWaitUntilTestDone) { + smQuitTest.mWaitUntilTestDone.notifyAll(); + } + if (smQuitTest.isDbg()) Log.d(TAG, "testStateMachineQuit X"); + } + + /** + * Tests {@link StateMachine#quitNow()} + */ + class StateMachineQuitNowTest extends StateMachine { + Object mWaitUntilTestDone = new Object(); + + StateMachineQuitNowTest(String name) { + super(name); + mThisSm = this; + setDbg(DBG); + + // Setup state machine with 1 state + addState(mS1); + + // Set the initial state + setInitialState(mS1); + } + + @Override + public void onQuitting() { + Log.d(TAG, "onQuitting"); + addLogRec(ON_QUITTING); + synchronized (mThisSm) { + mThisSm.notifyAll(); + } + + // Don't leave onQuitting before the test is done as everything is cleared + // including the log records. + synchronized (mWaitUntilTestDone) { + try { + mWaitUntilTestDone.wait(); + } catch(InterruptedException e) { + } + } + } + + class S1 extends State { + public void exit() { + Log.d(TAG, "S1.exit"); + addLogRec(EXIT, mS1); } + @Override + public boolean processMessage(Message message) { + switch(message.what) { + // Sleep and assume the other messages will be queued up. + case TEST_CMD_1: { + Log.d(TAG, "TEST_CMD_1"); + sleep(500); + quitNow(); + break; + } + default: { + Log.d(TAG, "default what=" + message.what); + break; + } + } + return HANDLED; + } + } + + private StateMachineQuitNowTest mThisSm; + private S1 mS1 = new S1(); + } - // First two are ignored - smQuitTest.quit(); - smQuitTest.quit(); + @SmallTest + public void testStateMachineQuitNow() throws Exception { + if (WAIT_FOR_DEBUGGER) Debug.waitForDebugger(); - // Now we will quit - smQuitTest.quit(); + StateMachineQuitNowTest smQuitNowTest = new StateMachineQuitNowTest("smQuitNowTest"); + smQuitNowTest.start(); + if (smQuitNowTest.isDbg()) Log.d(TAG, "testStateMachineQuitNow E"); + + synchronized (smQuitNowTest) { + + // Send 6 messages but we'll QuitNow on the first so even though + // 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 - smQuitTest.wait(); + smQuitNowTest.wait(); } catch (InterruptedException e) { - Log.e(TAG, "testStateMachineQuitTest: exception while waiting " + e.getMessage()); + Log.e(TAG, "testStateMachineQuitNow: exception while waiting " + e.getMessage()); } } - assertTrue(smQuitTest.getProcessedMessagesCount() == 9); + // Only three records because we executed quitNow. + assertEquals(3, smQuitNowTest.getLogRecCount()); - ProcessedMessageInfo pmi; + LogRec lr; - // The first two message didn't quit and were handled by mS1 - pmi = smQuitTest.getProcessedMessageInfo(6); - assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat()); - assertEquals(smQuitTest.mS1, pmi.getState()); - assertEquals(smQuitTest.mS1, pmi.getOriginalState()); + lr = smQuitNowTest.getLogRec(0); + assertEquals(1, lr.getWhat()); + assertEquals(smQuitNowTest.mS1, lr.getState()); + assertEquals(smQuitNowTest.mS1, lr.getOriginalState()); - pmi = smQuitTest.getProcessedMessageInfo(7); - assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat()); - assertEquals(smQuitTest.mS1, pmi.getState()); - assertEquals(smQuitTest.mS1, pmi.getOriginalState()); + lr = smQuitNowTest.getLogRec(1); + assertEquals(EXIT, lr.getInfo()); + assertEquals(smQuitNowTest.mS1, lr.getState()); - // The last message was never handled so the states are null - pmi = smQuitTest.getProcessedMessageInfo(8); - assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat()); - assertEquals(null, pmi.getState()); - assertEquals(null, pmi.getOriginalState()); + lr = smQuitNowTest.getLogRec(2); + assertEquals(ON_QUITTING, lr.getInfo()); - if (smQuitTest.isDbg()) Log.d(TAG, "testStateMachineQuitTest X"); + synchronized (smQuitNowTest.mWaitUntilTestDone) { + smQuitNowTest.mWaitUntilTestDone.notifyAll(); + } + if (smQuitNowTest.isDbg()) Log.d(TAG, "testStateMachineQuitNow X"); } /** * Test enter/exit can use transitionTo */ class StateMachineEnterExitTransitionToTest extends StateMachine { + StateMachineEnterExitTransitionToTest(String name) { super(name); mThisSm = this; @@ -170,20 +302,15 @@ public class StateMachineTest extends TestCase { class S1 extends State { @Override public void enter() { - // Test that message is HSM_INIT_CMD - assertEquals(SM_INIT_CMD, getCurrentMessage().what); - - // Test that a transition in enter and the initial state works - mS1EnterCount += 1; + // Test transitions in enter on the initial state work + addLogRec(ENTER, mS1); transitionTo(mS2); Log.d(TAG, "S1.enter"); } @Override public void exit() { // Test that message is HSM_INIT_CMD - assertEquals(SM_INIT_CMD, getCurrentMessage().what); - - mS1ExitCount += 1; + addLogRec(EXIT, mS1); Log.d(TAG, "S1.exit"); } } @@ -191,19 +318,15 @@ public class StateMachineTest extends TestCase { class S2 extends State { @Override public void enter() { - // Test that message is HSM_INIT_CMD - assertEquals(SM_INIT_CMD, getCurrentMessage().what); - - mS2EnterCount += 1; + addLogRec(ENTER, mS2); Log.d(TAG, "S2.enter"); } @Override public void exit() { - // Test that message is TEST_CMD_1 + addLogRec(EXIT, mS2); assertEquals(TEST_CMD_1, getCurrentMessage().what); // Test transition in exit work - mS2ExitCount += 1; transitionTo(mS4); Log.d(TAG, "S2.exit"); } @@ -220,36 +343,33 @@ public class StateMachineTest extends TestCase { class S3 extends State { @Override public void enter() { - // Test that we can do halting in an enter/exit - transitionToHaltingState(); - mS3EnterCount += 1; + addLogRec(ENTER, mS3); Log.d(TAG, "S3.enter"); } @Override public void exit() { - mS3ExitCount += 1; + addLogRec(EXIT, mS3); Log.d(TAG, "S3.exit"); } } - class S4 extends State { @Override public void enter() { + addLogRec(ENTER, mS4); // Test that we can do halting in an enter/exit transitionToHaltingState(); - mS4EnterCount += 1; Log.d(TAG, "S4.enter"); } @Override public void exit() { - mS4ExitCount += 1; + addLogRec(EXIT, mS4); Log.d(TAG, "S4.exit"); } } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -260,14 +380,6 @@ public class StateMachineTest extends TestCase { private S2 mS2 = new S2(); private S3 mS3 = new S3(); private S4 mS4 = new S4(); - private int mS1EnterCount = 0; - private int mS1ExitCount = 0; - private int mS2EnterCount = 0; - private int mS2ExitCount = 0; - private int mS3EnterCount = 0; - private int mS3ExitCount = 0; - private int mS4EnterCount = 0; - private int mS4ExitCount = 0; } @SmallTest @@ -293,24 +405,46 @@ public class StateMachineTest extends TestCase { } } - assertTrue(smEnterExitTranstionToTest.getProcessedMessagesCount() == 1); + assertEquals(smEnterExitTranstionToTest.getLogRecCount(), 9); + + 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()); + + lr = smEnterExitTranstionToTest.getLogRec(4); + assertEquals(EXIT, lr.getInfo()); + assertEquals(smEnterExitTranstionToTest.mS2, lr.getState()); + + lr = smEnterExitTranstionToTest.getLogRec(5); + assertEquals(ENTER, lr.getInfo()); + assertEquals(smEnterExitTranstionToTest.mS3, lr.getState()); - ProcessedMessageInfo pmi; + lr = smEnterExitTranstionToTest.getLogRec(6); + assertEquals(EXIT, lr.getInfo()); + assertEquals(smEnterExitTranstionToTest.mS3, lr.getState()); - // Message should be handled by mS2. - pmi = smEnterExitTranstionToTest.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(smEnterExitTranstionToTest.mS2, pmi.getState()); - assertEquals(smEnterExitTranstionToTest.mS2, pmi.getOriginalState()); + lr = smEnterExitTranstionToTest.getLogRec(7); + assertEquals(ENTER, lr.getInfo()); + assertEquals(smEnterExitTranstionToTest.mS4, lr.getState()); - assertEquals(smEnterExitTranstionToTest.mS1EnterCount, 1); - assertEquals(smEnterExitTranstionToTest.mS1ExitCount, 1); - assertEquals(smEnterExitTranstionToTest.mS2EnterCount, 1); - assertEquals(smEnterExitTranstionToTest.mS2ExitCount, 1); - assertEquals(smEnterExitTranstionToTest.mS3EnterCount, 1); - assertEquals(smEnterExitTranstionToTest.mS3ExitCount, 1); - assertEquals(smEnterExitTranstionToTest.mS3EnterCount, 1); - assertEquals(smEnterExitTranstionToTest.mS3ExitCount, 1); + lr = smEnterExitTranstionToTest.getLogRec(8); + assertEquals(EXIT, lr.getInfo()); + assertEquals(smEnterExitTranstionToTest.mS4, lr.getState()); if (smEnterExitTranstionToTest.isDbg()) { Log.d(TAG, "testStateMachineEnterExitTransitionToTest X"); @@ -325,7 +459,7 @@ public class StateMachineTest extends TestCase { super(name); mThisSm = this; setDbg(DBG); - setProcessedMessagesSize(3); + setLogRecSize(3); // Setup state machine with 1 state addState(mS1); @@ -345,7 +479,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -377,24 +511,24 @@ public class StateMachineTest extends TestCase { } } - assertTrue(sm0.getProcessedMessagesCount() == 6); - assertTrue(sm0.getProcessedMessagesSize() == 3); + assertEquals(6, sm0.getLogRecCount()); + assertEquals(3, sm0.getLogRecSize()); - ProcessedMessageInfo pmi; - pmi = sm0.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_4, pmi.getWhat()); - assertEquals(sm0.mS1, pmi.getState()); - assertEquals(sm0.mS1, pmi.getOriginalState()); + LogRec lr; + lr = sm0.getLogRec(0); + assertEquals(TEST_CMD_4, lr.getWhat()); + assertEquals(sm0.mS1, lr.getState()); + assertEquals(sm0.mS1, lr.getOriginalState()); - pmi = sm0.getProcessedMessageInfo(1); - assertEquals(TEST_CMD_5, pmi.getWhat()); - assertEquals(sm0.mS1, pmi.getState()); - assertEquals(sm0.mS1, pmi.getOriginalState()); + lr = sm0.getLogRec(1); + assertEquals(TEST_CMD_5, lr.getWhat()); + assertEquals(sm0.mS1, lr.getState()); + assertEquals(sm0.mS1, lr.getOriginalState()); - pmi = sm0.getProcessedMessageInfo(2); - assertEquals(TEST_CMD_6, pmi.getWhat()); - assertEquals(sm0.mS1, pmi.getState()); - assertEquals(sm0.mS1, pmi.getOriginalState()); + lr = sm0.getLogRec(2); + assertEquals(TEST_CMD_6, lr.getWhat()); + assertEquals(sm0.mS1, lr.getState()); + assertEquals(sm0.mS1, lr.getOriginalState()); if (sm0.isDbg()) Log.d(TAG, "testStateMachine0 X"); } @@ -444,7 +578,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -479,18 +613,18 @@ public class StateMachineTest extends TestCase { assertEquals(2, sm1.mEnterCount); assertEquals(2, sm1.mExitCount); - assertTrue(sm1.getProcessedMessagesSize() == 2); + assertEquals(2, sm1.getLogRecSize()); - ProcessedMessageInfo pmi; - pmi = sm1.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(sm1.mS1, pmi.getState()); - assertEquals(sm1.mS1, pmi.getOriginalState()); + LogRec lr; + lr = sm1.getLogRec(0); + assertEquals(TEST_CMD_1, lr.getWhat()); + assertEquals(sm1.mS1, lr.getState()); + assertEquals(sm1.mS1, lr.getOriginalState()); - pmi = sm1.getProcessedMessageInfo(1); - assertEquals(TEST_CMD_2, pmi.getWhat()); - assertEquals(sm1.mS1, pmi.getState()); - assertEquals(sm1.mS1, pmi.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); @@ -550,7 +684,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -583,24 +717,24 @@ public class StateMachineTest extends TestCase { } } - assertTrue(sm2.getProcessedMessagesSize() == 4); + assertEquals(4, sm2.getLogRecSize()); - ProcessedMessageInfo pmi; - pmi = sm2.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(sm2.mS1, pmi.getState()); + LogRec lr; + lr = sm2.getLogRec(0); + assertEquals(TEST_CMD_1, lr.getWhat()); + assertEquals(sm2.mS1, lr.getState()); - pmi = sm2.getProcessedMessageInfo(1); - assertEquals(TEST_CMD_2, pmi.getWhat()); - assertEquals(sm2.mS1, pmi.getState()); + lr = sm2.getLogRec(1); + assertEquals(TEST_CMD_2, lr.getWhat()); + assertEquals(sm2.mS1, lr.getState()); - pmi = sm2.getProcessedMessageInfo(2); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(sm2.mS2, pmi.getState()); + lr = sm2.getLogRec(2); + assertEquals(TEST_CMD_1, lr.getWhat()); + assertEquals(sm2.mS2, lr.getState()); - pmi = sm2.getProcessedMessageInfo(3); - assertEquals(TEST_CMD_2, pmi.getWhat()); - assertEquals(sm2.mS2, pmi.getState()); + lr = sm2.getLogRec(3); + assertEquals(TEST_CMD_2, lr.getWhat()); + assertEquals(sm2.mS2, lr.getState()); assertTrue(sm2.mDidEnter); assertTrue(sm2.mDidExit); @@ -647,7 +781,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -677,18 +811,18 @@ public class StateMachineTest extends TestCase { } } - assertTrue(sm3.getProcessedMessagesSize() == 2); + assertEquals(2, sm3.getLogRecSize()); - ProcessedMessageInfo pmi; - pmi = sm3.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(sm3.mParentState, pmi.getState()); - assertEquals(sm3.mChildState, pmi.getOriginalState()); + LogRec lr; + lr = sm3.getLogRec(0); + assertEquals(TEST_CMD_1, lr.getWhat()); + assertEquals(sm3.mParentState, lr.getState()); + assertEquals(sm3.mChildState, lr.getOriginalState()); - pmi = sm3.getProcessedMessageInfo(1); - assertEquals(TEST_CMD_2, pmi.getWhat()); - assertEquals(sm3.mParentState, pmi.getState()); - assertEquals(sm3.mChildState, pmi.getOriginalState()); + lr = sm3.getLogRec(1); + assertEquals(TEST_CMD_2, lr.getWhat()); + assertEquals(sm3.mParentState, lr.getState()); + assertEquals(sm3.mChildState, lr.getOriginalState()); if (sm3.isDbg()) Log.d(TAG, "testStateMachine3 X"); } @@ -742,7 +876,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -774,18 +908,18 @@ public class StateMachineTest extends TestCase { } - assertTrue(sm4.getProcessedMessagesSize() == 2); + assertEquals(2, sm4.getLogRecSize()); - ProcessedMessageInfo pmi; - pmi = sm4.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(sm4.mChildState1, pmi.getState()); - assertEquals(sm4.mChildState1, pmi.getOriginalState()); + LogRec lr; + lr = sm4.getLogRec(0); + assertEquals(TEST_CMD_1, lr.getWhat()); + assertEquals(sm4.mChildState1, lr.getState()); + assertEquals(sm4.mChildState1, lr.getOriginalState()); - pmi = sm4.getProcessedMessageInfo(1); - assertEquals(TEST_CMD_2, pmi.getWhat()); - assertEquals(sm4.mParentState, pmi.getState()); - assertEquals(sm4.mChildState2, pmi.getOriginalState()); + lr = sm4.getLogRec(1); + assertEquals(TEST_CMD_2, lr.getWhat()); + assertEquals(sm4.mParentState, lr.getState()); + assertEquals(sm4.mChildState2, lr.getOriginalState()); if (sm4.isDbg()) Log.d(TAG, "testStateMachine4 X"); } @@ -1018,7 +1152,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -1073,7 +1207,7 @@ public class StateMachineTest extends TestCase { } - assertTrue(sm5.getProcessedMessagesSize() == 6); + assertEquals(6, sm5.getLogRecSize()); assertEquals(1, sm5.mParentState1EnterCount); assertEquals(1, sm5.mParentState1ExitCount); @@ -1090,36 +1224,36 @@ public class StateMachineTest extends TestCase { assertEquals(1, sm5.mChildState5EnterCount); assertEquals(1, sm5.mChildState5ExitCount); - ProcessedMessageInfo pmi; - pmi = sm5.getProcessedMessageInfo(0); - assertEquals(TEST_CMD_1, pmi.getWhat()); - assertEquals(sm5.mChildState1, pmi.getState()); - assertEquals(sm5.mChildState1, pmi.getOriginalState()); - - pmi = sm5.getProcessedMessageInfo(1); - assertEquals(TEST_CMD_2, pmi.getWhat()); - assertEquals(sm5.mChildState2, pmi.getState()); - assertEquals(sm5.mChildState2, pmi.getOriginalState()); - - pmi = sm5.getProcessedMessageInfo(2); - assertEquals(TEST_CMD_3, pmi.getWhat()); - assertEquals(sm5.mChildState5, pmi.getState()); - assertEquals(sm5.mChildState5, pmi.getOriginalState()); - - pmi = sm5.getProcessedMessageInfo(3); - assertEquals(TEST_CMD_4, pmi.getWhat()); - assertEquals(sm5.mChildState3, pmi.getState()); - assertEquals(sm5.mChildState3, pmi.getOriginalState()); - - pmi = sm5.getProcessedMessageInfo(4); - assertEquals(TEST_CMD_5, pmi.getWhat()); - assertEquals(sm5.mChildState4, pmi.getState()); - assertEquals(sm5.mChildState4, pmi.getOriginalState()); - - pmi = sm5.getProcessedMessageInfo(5); - assertEquals(TEST_CMD_6, pmi.getWhat()); - assertEquals(sm5.mParentState2, pmi.getState()); - assertEquals(sm5.mParentState2, pmi.getOriginalState()); + LogRec lr; + lr = sm5.getLogRec(0); + assertEquals(TEST_CMD_1, lr.getWhat()); + assertEquals(sm5.mChildState1, lr.getState()); + assertEquals(sm5.mChildState1, lr.getOriginalState()); + + lr = sm5.getLogRec(1); + assertEquals(TEST_CMD_2, lr.getWhat()); + assertEquals(sm5.mChildState2, lr.getState()); + assertEquals(sm5.mChildState2, lr.getOriginalState()); + + lr = sm5.getLogRec(2); + assertEquals(TEST_CMD_3, lr.getWhat()); + assertEquals(sm5.mChildState5, lr.getState()); + assertEquals(sm5.mChildState5, lr.getOriginalState()); + + lr = sm5.getLogRec(3); + assertEquals(TEST_CMD_4, lr.getWhat()); + assertEquals(sm5.mChildState3, lr.getState()); + assertEquals(sm5.mChildState3, lr.getOriginalState()); + + lr = sm5.getLogRec(4); + assertEquals(TEST_CMD_5, lr.getWhat()); + assertEquals(sm5.mChildState4, lr.getState()); + assertEquals(sm5.mChildState4, lr.getOriginalState()); + + lr = sm5.getLogRec(5); + assertEquals(TEST_CMD_6, lr.getWhat()); + assertEquals(sm5.mParentState2, lr.getState()); + assertEquals(sm5.mParentState2, lr.getOriginalState()); if (sm5.isDbg()) Log.d(TAG, "testStateMachine5 X"); } @@ -1161,7 +1295,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -1176,7 +1310,6 @@ public class StateMachineTest extends TestCase { @MediumTest public void testStateMachine6() throws Exception { - long sentTimeMsg2; final int DELAY_TIME = 250; final int DELAY_FUDGE = 20; @@ -1186,7 +1319,6 @@ public class StateMachineTest extends TestCase { synchronized (sm6) { // Send a message - sentTimeMsg2 = SystemClock.elapsedRealtime(); sm6.sendMessageDelayed(TEST_CMD_2, DELAY_TIME); try { @@ -1268,7 +1400,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -1285,7 +1417,6 @@ public class StateMachineTest extends TestCase { @MediumTest public void testStateMachine7() throws Exception { - long sentTimeMsg2; final int SM7_DELAY_FUDGE = 20; StateMachine7 sm7 = new StateMachine7("sm7"); @@ -1294,7 +1425,6 @@ public class StateMachineTest extends TestCase { synchronized (sm7) { // Send a message - sentTimeMsg2 = SystemClock.elapsedRealtime(); sm7.sendMessage(TEST_CMD_1); try { @@ -1350,7 +1480,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { synchronized (mThisSm) { mThisSm.notifyAll(); } @@ -1383,7 +1513,7 @@ public class StateMachineTest extends TestCase { } } - assertTrue(sm.getProcessedMessagesCount() == 2); + assertEquals(sm.getLogRecCount(), 2); assertEquals(2, sm.mUnhandledMessageCount); if (sm.isDbg()) Log.d(TAG, "testStateMachineUnhandledMessage X"); @@ -1420,7 +1550,7 @@ public class StateMachineTest extends TestCase { } @Override - protected void halting() { + protected void onHalting() { // Update the shared counter, which is OK since all state // machines are using the same thread. sharedCounter += 1; @@ -1470,12 +1600,12 @@ public class StateMachineTest extends TestCase { } for (StateMachineSharedThread sm : sms) { - assertTrue(sm.getProcessedMessagesCount() == 4); - for (int i = 0; i < sm.getProcessedMessagesCount(); i++) { - ProcessedMessageInfo pmi = sm.getProcessedMessageInfo(i); - assertEquals(i+1, pmi.getWhat()); - assertEquals(sm.mS1, pmi.getState()); - assertEquals(sm.mS1, pmi.getOriginalState()); + assertEquals(sm.getLogRecCount(), 4); + for (int i = 0; i < sm.getLogRecCount(); i++) { + LogRec lr = sm.getLogRec(i); + assertEquals(i+1, lr.getWhat()); + assertEquals(sm.mS1, lr.getState()); + assertEquals(sm.mS1, lr.getOriginalState()); } } @@ -1501,41 +1631,41 @@ public class StateMachineTest extends TestCase { } } - assertEquals(7, sm.getProcessedMessagesCount()); - ProcessedMessageInfo pmi = sm.getProcessedMessageInfo(0); - assertEquals(Hsm1.CMD_1, pmi.getWhat()); - assertEquals(sm.mS1, pmi.getState()); - assertEquals(sm.mS1, pmi.getOriginalState()); + assertEquals(7, sm.getLogRecCount()); + LogRec lr = sm.getLogRec(0); + assertEquals(Hsm1.CMD_1, lr.getWhat()); + assertEquals(sm.mS1, lr.getState()); + assertEquals(sm.mS1, lr.getOriginalState()); - pmi = sm.getProcessedMessageInfo(1); - assertEquals(Hsm1.CMD_2, pmi.getWhat()); - assertEquals(sm.mP1, pmi.getState()); - assertEquals(sm.mS1, pmi.getOriginalState()); + lr = sm.getLogRec(1); + assertEquals(Hsm1.CMD_2, lr.getWhat()); + assertEquals(sm.mP1, lr.getState()); + assertEquals(sm.mS1, lr.getOriginalState()); - pmi = sm.getProcessedMessageInfo(2); - assertEquals(Hsm1.CMD_2, pmi.getWhat()); - assertEquals(sm.mS2, pmi.getState()); - assertEquals(sm.mS2, pmi.getOriginalState()); + lr = sm.getLogRec(2); + assertEquals(Hsm1.CMD_2, lr.getWhat()); + assertEquals(sm.mS2, lr.getState()); + assertEquals(sm.mS2, lr.getOriginalState()); - pmi = sm.getProcessedMessageInfo(3); - assertEquals(Hsm1.CMD_3, pmi.getWhat()); - assertEquals(sm.mS2, pmi.getState()); - assertEquals(sm.mS2, pmi.getOriginalState()); + lr = sm.getLogRec(3); + assertEquals(Hsm1.CMD_3, lr.getWhat()); + assertEquals(sm.mS2, lr.getState()); + assertEquals(sm.mS2, lr.getOriginalState()); - pmi = sm.getProcessedMessageInfo(4); - assertEquals(Hsm1.CMD_3, pmi.getWhat()); - assertEquals(sm.mP2, pmi.getState()); - assertEquals(sm.mP2, pmi.getOriginalState()); + lr = sm.getLogRec(4); + assertEquals(Hsm1.CMD_3, lr.getWhat()); + assertEquals(sm.mP2, lr.getState()); + assertEquals(sm.mP2, lr.getOriginalState()); - pmi = sm.getProcessedMessageInfo(5); - assertEquals(Hsm1.CMD_4, pmi.getWhat()); - assertEquals(sm.mP2, pmi.getState()); - assertEquals(sm.mP2, pmi.getOriginalState()); + lr = sm.getLogRec(5); + assertEquals(Hsm1.CMD_4, lr.getWhat()); + assertEquals(sm.mP2, lr.getState()); + assertEquals(sm.mP2, lr.getOriginalState()); - pmi = sm.getProcessedMessageInfo(6); - assertEquals(Hsm1.CMD_5, pmi.getWhat()); - assertEquals(sm.mP2, pmi.getState()); - assertEquals(sm.mP2, pmi.getOriginalState()); + lr = sm.getLogRec(6); + assertEquals(Hsm1.CMD_5, lr.getWhat()); + assertEquals(sm.mP2, lr.getState()); + assertEquals(sm.mP2, lr.getOriginalState()); if (DBG) Log.d(TAG, "testStateMachineSharedThread X"); } @@ -1684,7 +1814,7 @@ class Hsm1 extends StateMachine { } @Override - protected void halting() { + protected void onHalting() { Log.d(TAG, "halting"); synchronized (this) { this.notifyAll(); |