Change code style.

This commit is contained in:
youtaol
2012-12-24 19:19:18 +08:00
parent 9176879ebe
commit 2cae2557de
4 changed files with 26 additions and 38 deletions
@@ -27,7 +27,7 @@ import android.util.Log;
* @author Youtao Liu * @author Youtao Liu
*/ */
public class EndToEndTestRunner extends InstrumentationTestRunner { public class EndToEndTestRunner extends InstrumentationTestRunner {
/** /**
* Gets the parameter port which is used to fix GPS signal to emulators. * Gets the parameter port which is used to fix GPS signal to emulators.
*/ */
@@ -43,26 +43,9 @@ public class EndToEndTestRunner extends InstrumentationTestRunner {
} }
} }
String isStressTest = arguments.getString("stress"); BigTestUtils.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress"));
if (isStressTest != null && isStressTest.equalsIgnoreCase("true")) { BigTestUtils.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor"));
BigTestUtils.runStressTest = true; BigTestUtils.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource"));
} else {
BigTestUtils.runStressTest = false;
}
String isSensorTest = arguments.getString("sensor");
if (isSensorTest != null && isSensorTest.equalsIgnoreCase("true")) {
BigTestUtils.runSensorTest = true;
} else {
BigTestUtils.runSensorTest = false;
}
String isResourceUsageTest = arguments.getString("resource");
if (isResourceUsageTest != null && isResourceUsageTest.equalsIgnoreCase("true")) {
BigTestUtils.runResourceUsageTest = true;
} else {
BigTestUtils.runResourceUsageTest = false;
}
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:"
+ EndToEndTestUtils.emulatorPort); + EndToEndTestUtils.emulatorPort);
@@ -548,7 +548,6 @@ public class EndToEndTestUtils {
findMenuItem(activityMytracks.getString(R.string.menu_save), true); findMenuItem(activityMytracks.getString(R.string.menu_save), true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
SOLO.clickOnText(trackKind.toUpperCase()); SOLO.clickOnText(trackKind.toUpperCase());
// rotateAllActivities();
SOLO.waitForText(activityMytracks.getString(R.string.generic_success_title)); SOLO.waitForText(activityMytracks.getString(R.string.generic_success_title));
} }
@@ -37,12 +37,17 @@ public class BigTestUtils {
public static boolean runStressTest = true; public static boolean runStressTest = true;
public static boolean runSensorTest = true; public static boolean runSensorTest = true;
public static boolean runResourceUsageTest = true; public static boolean runResourceUsageTest = true;
protected static final String DISABLE_MESSAGE = "This test is disabled"; public static final String DISABLE_MESSAGE = "This test is disabled";
protected final static String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks"; public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks";
protected final static String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt"; public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt";
/** /**
* Gets the memory usage of MyTracks process. * Gets the memory usage of MyTracks process. This method would get the Pss
* memory. Pss is the amount of memory shared with other processes, accounted
* in a way that the amount is divided evenly between the processes that share
* it. This is memory that would not be released if the process was
* terminated, but is indicative of the amount that this process is
* "contributing" to the overall memory load.
* *
* @param context * @param context
*/ */
@@ -77,7 +82,7 @@ public class BigTestUtils {
new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int rawlevel = batteryIntent.getIntExtra("level", -1); int rawlevel = batteryIntent.getIntExtra("level", -1);
double scale = batteryIntent.getIntExtra("scale", -1); double scale = batteryIntent.getIntExtra("scale", -1);
return "Device has " + rawlevel + " of " + scale + " battery left"; return String.format("Device has %s of %s battery left", rawlevel, scale);
} }
/** /**
@@ -116,13 +121,14 @@ public class BigTestUtils {
* @param testTime the total test milliseconds * @param testTime the total test milliseconds
*/ */
public static void moniterTest(Context context, int interval, int testTime) { public static void moniterTest(Context context, int interval, int testTime) {
long startTime = (new Date()).getTime(); long startTime = System.currentTimeMillis();
while (((new Date()).getTime() - startTime) < testTime) { while ((System.currentTimeMillis() - startTime) < testTime) {
String memoryUsageString = getMyTracksPssMemoryInfo(context); String memoryUsageString = getMyTracksPssMemoryInfo(context);
String batteryUsageString = getBatteryUsageInfo(context); String batteryUsageString = getBatteryUsageInfo(context);
String oneInfo = (new java.util.Date()).toString() + ":" + memoryUsageString + ", " String oneInfo = String.format("{%s: memory use %s, battery left %s. \r\n",
+ batteryUsageString + ".\r\n"; String.format("{%1$tm/%1$td/%1$tY %1$tH:%1$tM:%1$tS", new Date()), memoryUsageString,
batteryUsageString);
writeToFile(oneInfo, true); writeToFile(oneInfo, true);
Log.i(EndToEndTestUtils.LOG_TAG, oneInfo); Log.i(EndToEndTestUtils.LOG_TAG, oneInfo);
EndToEndTestUtils.sleep(interval); EndToEndTestUtils.sleep(interval);
@@ -53,8 +53,8 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2<TrackLis
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
runTest = BigTestUtils.runResourceUsageTest;
super.setUp(); super.setUp();
runTest = BigTestUtils.runResourceUsageTest;
if (!runTest) { if (!runTest) {
return; return;
} }
@@ -81,10 +81,10 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2<TrackLis
new AlertDialog.Builder(EndToEndTestUtils.SOLO.getCurrentActivity()) new AlertDialog.Builder(EndToEndTestUtils.SOLO.getCurrentActivity())
.setTitle("Confirm long time test.") .setTitle("Confirm long time test.")
.setMessage( .setMessage(
"Please disconnect the power cord of your device and click 'Start' button. Each case need run " String
+ TEST_DURATION_IN_MILLISECONDS / 1000 / 60 .format(
+ " minutes, and the battery/memory usage will be recorded in every " "Please disconnect the power cord of your device and click 'Start' button. Each case need run %d minutes, and the battery/memory usage will be recorded in every %d minutes.",
+ INTERVALE_TO_CHECK / 60 / 1000 + "minutes.") TEST_DURATION_IN_MILLISECONDS / 1000 / 60, INTERVALE_TO_CHECK / 60 / 1000))
.setPositiveButton("Start Test", new DialogInterface.OnClickListener() { .setPositiveButton("Start Test", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
isUserConfirmed = true; isUserConfirmed = true;
@@ -142,8 +142,8 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2<TrackLis
* during recording. * during recording.
* *
* @param isShowTracksList true means show tracks list * @param isShowTracksList true means show tracks list
* @param tabNameId the name string id of tab, it's useless when the first parameter is * @param tabNameId the name string id of tab, it's useless when the first
* true. * parameter is true.
*/ */
public void recordingLongTrack(boolean isShowTracksList, int tabNameId) { public void recordingLongTrack(boolean isShowTracksList, int tabNameId) {
if (!runTest) { if (!runTest) {