From 2cae2557de3f7b81f0ddcfa12251c0a3c8d8b5b3 Mon Sep 17 00:00:00 2001 From: youtaol Date: Mon, 24 Dec 2012 19:19:18 +0800 Subject: [PATCH] Change code style. --- .../endtoendtest/EndToEndTestRunner.java | 25 +++---------------- .../endtoendtest/EndToEndTestUtils.java | 1 - .../endtoendtest/others/BigTestUtils.java | 24 +++++++++++------- .../others/ResourceUsageTest.java | 14 +++++------ 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java index b8269a792..cc1831208 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java @@ -27,7 +27,7 @@ import android.util.Log; * @author Youtao Liu */ public class EndToEndTestRunner extends InstrumentationTestRunner { - + /** * 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"); - if (isStressTest != null && isStressTest.equalsIgnoreCase("true")) { - BigTestUtils.runStressTest = true; - } 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; - } + BigTestUtils.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); + BigTestUtils.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); + BigTestUtils.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource")); Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" + EndToEndTestUtils.emulatorPort); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java index ea1e128a8..383f5fae5 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java @@ -548,7 +548,6 @@ public class EndToEndTestUtils { findMenuItem(activityMytracks.getString(R.string.menu_save), true); instrumentation.waitForIdleSync(); SOLO.clickOnText(trackKind.toUpperCase()); - // rotateAllActivities(); SOLO.waitForText(activityMytracks.getString(R.string.generic_success_title)); } diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java index b5fe7bbc8..15a57c970 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java @@ -37,12 +37,17 @@ public class BigTestUtils { public static boolean runStressTest = true; public static boolean runSensorTest = true; public static boolean runResourceUsageTest = true; - protected static final String DISABLE_MESSAGE = "This test is disabled"; - protected final static String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks"; - protected final static String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt"; + public static final String DISABLE_MESSAGE = "This test is disabled"; + public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks"; + 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 */ @@ -77,7 +82,7 @@ public class BigTestUtils { new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int rawlevel = batteryIntent.getIntExtra("level", -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 */ 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 batteryUsageString = getBatteryUsageInfo(context); - String oneInfo = (new java.util.Date()).toString() + ":" + memoryUsageString + ", " - + batteryUsageString + ".\r\n"; + String oneInfo = String.format("{%s: memory use %s, battery left %s. \r\n", + String.format("{%1$tm/%1$td/%1$tY %1$tH:%1$tM:%1$tS", new Date()), memoryUsageString, + batteryUsageString); writeToFile(oneInfo, true); Log.i(EndToEndTestUtils.LOG_TAG, oneInfo); EndToEndTestUtils.sleep(interval); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java index 32e660d75..5506112f3 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java @@ -53,8 +53,8 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2