Merge changes I5c16c650,I3151fb6b
* changes: StateMachine: make toString() terser utiltests: add script to run tests
This commit is contained in:
@@ -2070,8 +2070,6 @@ public class StateMachine {
|
||||
* @param args
|
||||
*/
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
// Cannot just invoke pw.println(this.toString()) because if the
|
||||
// resulting string is to long it won't be displayed.
|
||||
pw.println(getName() + ":");
|
||||
pw.println(" total records=" + getLogRecCount());
|
||||
for (int i = 0; i < getLogRecSize(); i++) {
|
||||
@@ -2083,12 +2081,15 @@ public class StateMachine {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringWriter sr = new StringWriter();
|
||||
PrintWriter pr = new PrintWriter(sr);
|
||||
dump(null, pr, null);
|
||||
pr.flush();
|
||||
pr.close();
|
||||
return sr.toString();
|
||||
String name = "(null)";
|
||||
String state = "(null)";
|
||||
try {
|
||||
name = mName.toString();
|
||||
state = mSmHandler.getCurrentState().getName().toString();
|
||||
} catch (NullPointerException npe) {
|
||||
// Will use default(s) initialized above.
|
||||
}
|
||||
return "name=" + name + " state=" + state;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
24
core/tests/utiltests/runtests.sh
Executable file
24
core/tests/utiltests/runtests.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z $ANDROID_BUILD_TOP ]; then
|
||||
echo "You need to source and lunch before you can use this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Running tests"
|
||||
|
||||
set -e # fail early
|
||||
|
||||
echo "+ mmma -j32 $ANDROID_BUILD_TOP/frameworks/base/core/tests/utiltests"
|
||||
# NOTE Don't actually run the command above since this shell doesn't inherit functions from the
|
||||
# caller.
|
||||
make -j32 -C $ANDROID_BUILD_TOP -f build/core/main.mk MODULES-IN-frameworks-base-core-tests-utiltests
|
||||
|
||||
set -x # print commands
|
||||
|
||||
adb root
|
||||
adb wait-for-device
|
||||
|
||||
adb install -r -g "$OUT/data/app/FrameworksUtilTests/FrameworksUtilTests.apk"
|
||||
|
||||
adb shell am instrument -w "$@" 'com.android.frameworks.utiltests/android.support.test.runner.AndroidJUnitRunner'
|
||||
@@ -79,6 +79,66 @@ public class StateMachineTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StateMachine#toString()}.
|
||||
*/
|
||||
class StateMachineToStringTest extends StateMachine {
|
||||
StateMachineToStringTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleState extends State {
|
||||
String mName;
|
||||
|
||||
ExampleState(String name) {
|
||||
mName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testToStringSucceedsEvenIfMachineHasNoStates() throws Exception {
|
||||
StateMachine stateMachine = new StateMachineToStringTest("TestStateMachine");
|
||||
assertTrue(stateMachine.toString().contains("TestStateMachine"));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testToStringSucceedsEvenIfStateHasNoName() throws Exception {
|
||||
StateMachine stateMachine = new StateMachineToStringTest("TestStateMachine");
|
||||
State exampleState = new ExampleState(null);
|
||||
stateMachine.addState(exampleState);
|
||||
stateMachine.setInitialState(exampleState);
|
||||
stateMachine.start();
|
||||
assertTrue(stateMachine.toString().contains("TestStateMachine"));
|
||||
assertTrue(stateMachine.toString().contains("(null)"));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testToStringIncludesMachineAndStateNames() throws Exception {
|
||||
StateMachine stateMachine = new StateMachineToStringTest("TestStateMachine");
|
||||
State exampleState = new ExampleState("exampleState");
|
||||
stateMachine.addState(exampleState);
|
||||
stateMachine.setInitialState(exampleState);
|
||||
stateMachine.start();
|
||||
assertTrue(stateMachine.toString().contains("TestStateMachine"));
|
||||
assertTrue(stateMachine.toString().contains("exampleState"));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testToStringDoesNotContainMultipleLines() throws Exception {
|
||||
StateMachine stateMachine = new StateMachineToStringTest("TestStateMachine");
|
||||
State exampleState = new ExampleState("exampleState");
|
||||
stateMachine.addState(exampleState);
|
||||
stateMachine.setInitialState(exampleState);
|
||||
stateMachine.start();
|
||||
assertFalse(stateMachine.toString().contains("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StateMachine#quit()}.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user