summaryrefslogtreecommitdiff
path: root/javatests/com/android/loganalysis/item
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/com/android/loganalysis/item')
-rw-r--r--javatests/com/android/loganalysis/item/BatteryDischargeItemTest.java56
-rw-r--r--javatests/com/android/loganalysis/item/BatteryUsageItemTest.java53
-rw-r--r--javatests/com/android/loganalysis/item/DumpsysPackageStatsItemTest.java52
-rw-r--r--javatests/com/android/loganalysis/item/DvmLockSampleItemTest.java57
-rw-r--r--javatests/com/android/loganalysis/item/GenericItemTest.java266
-rw-r--r--javatests/com/android/loganalysis/item/InterruptItemTest.java53
-rw-r--r--javatests/com/android/loganalysis/item/LocationDumpsItemTest.java81
-rw-r--r--javatests/com/android/loganalysis/item/MemInfoItemTest.java52
-rw-r--r--javatests/com/android/loganalysis/item/MonkeyLogItemTest.java67
-rw-r--r--javatests/com/android/loganalysis/item/ProcrankItemTest.java60
-rw-r--r--javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java52
-rw-r--r--javatests/com/android/loganalysis/item/SystemPropsItemTest.java52
-rw-r--r--javatests/com/android/loganalysis/item/TopItemTest.java41
-rw-r--r--javatests/com/android/loganalysis/item/WakelockItemTest.java63
14 files changed, 1005 insertions, 0 deletions
diff --git a/javatests/com/android/loganalysis/item/BatteryDischargeItemTest.java b/javatests/com/android/loganalysis/item/BatteryDischargeItemTest.java
new file mode 100644
index 0000000..5e27eb2
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/BatteryDischargeItemTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import com.android.loganalysis.item.BatteryDischargeItem.BatteryDischargeInfoItem;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Calendar;
+
+/**
+ * Unit test for {@link BatteryDischargeItem}.
+ */
+public class BatteryDischargeItemTest extends TestCase {
+
+ /**
+ * Test that {@link BatteryDischargeItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ BatteryDischargeItem item = new BatteryDischargeItem();
+ item.addBatteryDischargeInfo(Calendar.getInstance(),25, 95);
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(BatteryDischargeItem.BATTERY_DISCHARGE));
+ assertTrue(output.get(BatteryDischargeItem.BATTERY_DISCHARGE) instanceof JSONArray);
+
+ JSONArray dischargeInfo = output.getJSONArray(BatteryDischargeItem.BATTERY_DISCHARGE);
+
+ assertEquals(1, dischargeInfo.length());
+ assertTrue(dischargeInfo.getJSONObject(0).has(BatteryDischargeInfoItem.BATTERY_LEVEL));
+ assertTrue(dischargeInfo.getJSONObject(0).has(
+ BatteryDischargeInfoItem.DISCHARGE_ELAPSED_TIME));
+ assertTrue(dischargeInfo.getJSONObject(0).has(
+ BatteryDischargeInfoItem.CLOCK_TIME_OF_DISCHARGE));
+
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/BatteryUsageItemTest.java b/javatests/com/android/loganalysis/item/BatteryUsageItemTest.java
new file mode 100644
index 0000000..b44a432
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/BatteryUsageItemTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import com.android.loganalysis.item.BatteryUsageItem.BatteryUsageInfoItem;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link BatteryUsageItem}.
+ */
+public class BatteryUsageItemTest extends TestCase {
+
+ /**
+ * Test that {@link BatteryUsageItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ BatteryUsageItem item = new BatteryUsageItem();
+ item.addBatteryUsage("Cell standby", 2925);
+ item.addBatteryUsage("Uid u0a71", 68.1);
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(BatteryUsageItem.BATTERY_CAPACITY));
+ assertTrue(output.get(BatteryUsageItem.BATTERY_USAGE) instanceof JSONArray);
+
+ JSONArray usage = output.getJSONArray(BatteryUsageItem.BATTERY_USAGE);
+
+ assertEquals(2, usage.length());
+ assertTrue(usage.getJSONObject(0).has(BatteryUsageInfoItem.NAME));
+ assertTrue(usage.getJSONObject(0).has(BatteryUsageInfoItem.USAGE));
+
+ assertTrue(usage.getJSONObject(1).has(BatteryUsageInfoItem.NAME));
+ assertTrue(usage.getJSONObject(1).has(BatteryUsageInfoItem.USAGE));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/DumpsysPackageStatsItemTest.java b/javatests/com/android/loganalysis/item/DumpsysPackageStatsItemTest.java
new file mode 100644
index 0000000..dd60500
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/DumpsysPackageStatsItemTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/** Unit test for {@link DumpsysPackageStatsItem}. */
+public class DumpsysPackageStatsItemTest extends TestCase {
+
+ /** Test that {@link DumpsysPackageStatsItem#toJson()} returns correctly. */
+ public void testToJson() throws JSONException {
+ DumpsysPackageStatsItem item = new DumpsysPackageStatsItem();
+
+ item.put("com.google.android.calculator", new AppVersionItem(73000302, "7.3 (3821978)"));
+ item.put(
+ "com.google.android.googlequicksearchbox",
+ new AppVersionItem(300734793, "6.16.35.26.arm64"));
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(DumpsysPackageStatsItem.APP_VERSIONS));
+
+ JSONObject appVersionsJson = output.getJSONObject(DumpsysPackageStatsItem.APP_VERSIONS);
+
+ assertEquals(2, appVersionsJson.length());
+ final JSONObject calcAppVersionJson =
+ appVersionsJson.getJSONObject("com.google.android.calculator");
+ assertEquals(73000302, calcAppVersionJson.getInt(AppVersionItem.VERSION_CODE));
+ assertEquals("7.3 (3821978)", calcAppVersionJson.getString(AppVersionItem.VERSION_NAME));
+ final JSONObject gsaAppVersionJson =
+ appVersionsJson.getJSONObject("com.google.android.googlequicksearchbox");
+ assertEquals(300734793, gsaAppVersionJson.getInt(AppVersionItem.VERSION_CODE));
+ assertEquals("6.16.35.26.arm64", gsaAppVersionJson.getString(AppVersionItem.VERSION_NAME));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/DvmLockSampleItemTest.java b/javatests/com/android/loganalysis/item/DvmLockSampleItemTest.java
new file mode 100644
index 0000000..5d6054e
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/DvmLockSampleItemTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link DvmLockSampleItem}.
+ */
+public class DvmLockSampleItemTest extends TestCase {
+ /**
+ * Test that {@link DvmLockSampleItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ DvmLockSampleItem item = new DvmLockSampleItem();
+
+ item.setAttribute(DvmLockSampleItem.PROCESS_NAME, "android.support.test.aupt");
+ item.setAttribute(DvmLockSampleItem.SENSITIVITY_FLAG, false);
+ item.setAttribute(DvmLockSampleItem.WAITING_THREAD_NAME, "Instr: android.support.test.aupt");
+ item.setAttribute(DvmLockSampleItem.WAIT_TIME, 75);
+ item.setAttribute(DvmLockSampleItem.WAITING_SOURCE_FILE, "AccessibilityCache.java");
+ item.setAttribute(DvmLockSampleItem.WAITING_SOURCE_LINE, 256);
+ item.setAttribute(DvmLockSampleItem.OWNER_FILE_NAME, "-");
+ item.setAttribute(DvmLockSampleItem.OWNER_ACQUIRE_SOURCE_LINE, 96);
+ item.setAttribute(DvmLockSampleItem.SAMPLE_PERCENTAGE, 15);
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ // Assert that each field is the expected value
+ assertEquals("android.support.test.aupt", output.get(DvmLockSampleItem.PROCESS_NAME));
+ assertEquals(false, output.get(DvmLockSampleItem.SENSITIVITY_FLAG));
+ assertEquals("Instr: android.support.test.aupt", output.get(DvmLockSampleItem.WAITING_THREAD_NAME));
+ assertEquals(75, output.get(DvmLockSampleItem.WAIT_TIME));
+ assertEquals("AccessibilityCache.java", output.get(DvmLockSampleItem.WAITING_SOURCE_FILE));
+ assertEquals(256, output.get(DvmLockSampleItem.WAITING_SOURCE_LINE));
+ assertEquals("-", output.get(DvmLockSampleItem.OWNER_FILE_NAME));
+ assertEquals(96, output.get(DvmLockSampleItem.OWNER_ACQUIRE_SOURCE_LINE));
+ assertEquals(15, output.get(DvmLockSampleItem.SAMPLE_PERCENTAGE));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/GenericItemTest.java b/javatests/com/android/loganalysis/item/GenericItemTest.java
new file mode 100644
index 0000000..e9ea31f
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/GenericItemTest.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Unit test for {@link GenericItem}.
+ */
+public class GenericItemTest extends TestCase {
+ private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
+ "integer", "string"));
+
+ private String mStringAttribute = "String";
+ private Integer mIntegerAttribute = 1;
+
+ /** Empty item with no attributes set */
+ private GenericItem mEmptyItem1;
+ /** Empty item with no attributes set */
+ private GenericItem mEmptyItem2;
+ /** Item with only the string attribute set */
+ private GenericItem mStringItem;
+ /** Item with only the integer attribute set */
+ private GenericItem mIntegerItem;
+ /** Item with both attributes set, product of mStringItem and mIntegerItem */
+ private GenericItem mFullItem1;
+ /** Item with both attributes set, product of mStringItem and mIntegerItem */
+ private GenericItem mFullItem2;
+ /** Item that is inconsistent with the others */
+ private GenericItem mInconsistentItem;
+
+ @Override
+ public void setUp() {
+ mEmptyItem1 = new GenericItem(ATTRIBUTES);
+ mEmptyItem2 = new GenericItem(ATTRIBUTES);
+ mStringItem = new GenericItem(ATTRIBUTES);
+ mStringItem.setAttribute("string", mStringAttribute);
+ mIntegerItem = new GenericItem(ATTRIBUTES);
+ mIntegerItem.setAttribute("integer", mIntegerAttribute);
+ mFullItem1 = new GenericItem(ATTRIBUTES);
+ mFullItem1.setAttribute("string", mStringAttribute);
+ mFullItem1.setAttribute("integer", mIntegerAttribute);
+ mFullItem2 = new GenericItem(ATTRIBUTES);
+ mFullItem2.setAttribute("string", mStringAttribute);
+ mFullItem2.setAttribute("integer", mIntegerAttribute);
+ mInconsistentItem = new GenericItem(ATTRIBUTES);
+ mInconsistentItem.setAttribute("string", "gnirts");
+ mInconsistentItem.setAttribute("integer", 2);
+ }
+
+ /**
+ * Test for {@link GenericItem#mergeAttributes(IItem, Set)}.
+ */
+ public void testMergeAttributes() throws ConflictingItemException {
+ Map<String, Object> attributes;
+
+ attributes = mEmptyItem1.mergeAttributes(mEmptyItem1, ATTRIBUTES);
+ assertNull(attributes.get("string"));
+ assertNull(attributes.get("integer"));
+
+ attributes = mEmptyItem1.mergeAttributes(mEmptyItem2, ATTRIBUTES);
+ assertNull(attributes.get("string"));
+ assertNull(attributes.get("integer"));
+
+ attributes = mEmptyItem2.mergeAttributes(mEmptyItem1, ATTRIBUTES);
+ assertNull(attributes.get("string"));
+ assertNull(attributes.get("integer"));
+
+ attributes = mEmptyItem1.mergeAttributes(mStringItem, ATTRIBUTES);
+ assertEquals(mStringAttribute, attributes.get("string"));
+ assertNull(attributes.get("integer"));
+
+ attributes = mStringItem.mergeAttributes(mEmptyItem1, ATTRIBUTES);
+ assertEquals(mStringAttribute, attributes.get("string"));
+ assertNull(attributes.get("integer"));
+
+ attributes = mIntegerItem.mergeAttributes(mStringItem, ATTRIBUTES);
+ assertEquals(mStringAttribute, attributes.get("string"));
+ assertEquals(mIntegerAttribute, attributes.get("integer"));
+
+ attributes = mEmptyItem1.mergeAttributes(mFullItem1, ATTRIBUTES);
+ assertEquals(mStringAttribute, attributes.get("string"));
+ assertEquals(mIntegerAttribute, attributes.get("integer"));
+
+ attributes = mFullItem1.mergeAttributes(mEmptyItem1, ATTRIBUTES);
+ assertEquals(mStringAttribute, attributes.get("string"));
+ assertEquals(mIntegerAttribute, attributes.get("integer"));
+
+ attributes = mFullItem1.mergeAttributes(mFullItem2, ATTRIBUTES);
+ assertEquals(mStringAttribute, attributes.get("string"));
+ assertEquals(mIntegerAttribute, attributes.get("integer"));
+
+ try {
+ mFullItem1.mergeAttributes(mInconsistentItem, ATTRIBUTES);
+ fail("Expecting a ConflictingItemException");
+ } catch (ConflictingItemException e) {
+ // Expected
+ }
+ }
+
+ /**
+ * Test for {@link GenericItem#isConsistent(IItem)}.
+ */
+ public void testIsConsistent() {
+ assertTrue(mEmptyItem1.isConsistent(mEmptyItem1));
+ assertFalse(mEmptyItem1.isConsistent(null));
+ assertTrue(mEmptyItem1.isConsistent(mEmptyItem2));
+ assertTrue(mEmptyItem2.isConsistent(mEmptyItem1));
+ assertTrue(mEmptyItem1.isConsistent(mStringItem));
+ assertTrue(mStringItem.isConsistent(mEmptyItem1));
+ assertTrue(mIntegerItem.isConsistent(mStringItem));
+ assertTrue(mEmptyItem1.isConsistent(mFullItem1));
+ assertTrue(mFullItem1.isConsistent(mEmptyItem1));
+ assertTrue(mFullItem1.isConsistent(mFullItem2));
+ assertFalse(mFullItem1.isConsistent(mInconsistentItem));
+ }
+
+ /** Test {@link GenericItem#equals(Object)}. */
+ @SuppressWarnings("SelfEquals")
+ public void testEquals() {
+ assertTrue(mEmptyItem1.equals(mEmptyItem1));
+ assertFalse(mEmptyItem1.equals(null));
+ assertTrue(mEmptyItem1.equals(mEmptyItem2));
+ assertTrue(mEmptyItem2.equals(mEmptyItem1));
+ assertFalse(mEmptyItem1.equals(mStringItem));
+ assertFalse(mStringItem.equals(mEmptyItem1));
+ assertFalse(mIntegerItem.equals(mStringItem));
+ assertFalse(mEmptyItem1.equals(mFullItem1));
+ assertFalse(mFullItem1.equals(mEmptyItem1));
+ assertTrue(mFullItem1.equals(mFullItem2));
+ assertFalse(mFullItem1.equals(mInconsistentItem));
+ }
+
+ /**
+ * Test for {@link GenericItem#setAttribute(String, Object)} and
+ * {@link GenericItem#getAttribute(String)}.
+ */
+ public void testAttributes() {
+ GenericItem item = new GenericItem(ATTRIBUTES);
+
+ assertNull(item.getAttribute("string"));
+ assertNull(item.getAttribute("integer"));
+
+ item.setAttribute("string", mStringAttribute);
+ item.setAttribute("integer", mIntegerAttribute);
+
+ assertEquals(mStringAttribute, item.getAttribute("string"));
+ assertEquals(mIntegerAttribute, item.getAttribute("integer"));
+
+ item.setAttribute("string", null);
+ item.setAttribute("integer", null);
+
+ assertNull(item.getAttribute("string"));
+ assertNull(item.getAttribute("integer"));
+
+ try {
+ item.setAttribute("object", new Object());
+ fail("Failed to throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // Expected because "object" is not "string" or "integer".
+ }
+ }
+
+ /**
+ * Test for {@link GenericItem#areEqual(Object, Object)}
+ */
+ public void testAreEqual() {
+ assertTrue(GenericItem.areEqual(null, null));
+ assertTrue(GenericItem.areEqual("test", "test"));
+ assertFalse(GenericItem.areEqual(null, "test"));
+ assertFalse(GenericItem.areEqual("test", null));
+ assertFalse(GenericItem.areEqual("test", ""));
+ }
+
+ /**
+ * Test for {@link GenericItem#areConsistent(Object, Object)}
+ */
+ public void testAreConsistent() {
+ assertTrue(GenericItem.areConsistent(null, null));
+ assertTrue(GenericItem.areConsistent("test", "test"));
+ assertTrue(GenericItem.areConsistent(null, "test"));
+ assertTrue(GenericItem.areConsistent("test", null));
+ assertFalse(GenericItem.areConsistent("test", ""));
+ }
+
+ /**
+ * Test for {@link GenericItem#mergeObjects(Object, Object)}
+ */
+ public void testMergeObjects() throws ConflictingItemException {
+ assertNull(GenericItem.mergeObjects(null, null));
+ assertEquals("test", GenericItem.mergeObjects("test", "test"));
+ assertEquals("test", GenericItem.mergeObjects(null, "test"));
+ assertEquals("test", GenericItem.mergeObjects("test", null));
+
+ try {
+ assertEquals("test", GenericItem.mergeObjects("test", ""));
+ fail("Expected ConflictingItemException to be thrown");
+ } catch (ConflictingItemException e) {
+ // Expected because "test" conflicts with "".
+ }
+ }
+
+ /**
+ * Test that {@link GenericItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ GenericItem item = new GenericItem(new HashSet<String>(Arrays.asList(
+ "string", "date", "object", "integer", "long", "float", "double", "item", "null")));
+ Date date = new Date();
+ Object object = new Object();
+ NativeCrashItem subItem = new NativeCrashItem();
+
+ item.setAttribute("string", "foo");
+ item.setAttribute("date", date);
+ item.setAttribute("object", object);
+ item.setAttribute("integer", 0);
+ item.setAttribute("long", 1L);
+ item.setAttribute("float", 2.5f);
+ item.setAttribute("double", 3.5);
+ item.setAttribute("item", subItem);
+ item.setAttribute("null", null);
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has("string"));
+ assertEquals("foo", output.get("string"));
+ assertTrue(output.has("date"));
+ assertEquals(date.toString(), output.get("date"));
+ assertTrue(output.has("object"));
+ assertEquals(object.toString(), output.get("object"));
+ assertTrue(output.has("integer"));
+ assertEquals(0, output.get("integer"));
+ assertTrue(output.has("long"));
+ assertEquals(1, output.get("long"));
+ assertTrue(output.has("float"));
+ assertEquals(2.5, output.get("float"));
+ assertTrue(output.has("double"));
+ assertEquals(3.5, output.get("double"));
+ assertTrue(output.has("item"));
+ assertTrue(output.get("item") instanceof JSONObject);
+ assertFalse(output.has("null"));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/InterruptItemTest.java b/javatests/com/android/loganalysis/item/InterruptItemTest.java
new file mode 100644
index 0000000..9e9df61
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/InterruptItemTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+
+import com.android.loganalysis.item.InterruptItem.InterruptInfoItem;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link InterruptItem}.
+ */
+public class InterruptItemTest extends TestCase {
+
+ /**
+ * Test that {@link InterruptItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ InterruptItem item = new InterruptItem();
+ item.addInterrupt("smd-modem",25, InterruptItem.InterruptCategory.ALARM_INTERRUPT);
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(InterruptItem.INTERRUPTS));
+ assertTrue(output.get(InterruptItem.INTERRUPTS) instanceof JSONArray);
+
+ JSONArray interruptsInfo = output.getJSONArray(InterruptItem.INTERRUPTS);
+
+ assertEquals(1, interruptsInfo.length());
+ assertTrue(interruptsInfo.getJSONObject(0).has(InterruptInfoItem.NAME));
+ assertTrue(interruptsInfo.getJSONObject(0).has(InterruptInfoItem.CATEGORY));
+ assertTrue(interruptsInfo.getJSONObject(0).has(InterruptInfoItem.INTERRUPT_COUNT));
+
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/LocationDumpsItemTest.java b/javatests/com/android/loganalysis/item/LocationDumpsItemTest.java
new file mode 100644
index 0000000..a96bc0d
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/LocationDumpsItemTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import com.android.loganalysis.item.LocationDumpsItem.LocationInfoItem;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link LocationDumpsItem}.
+ */
+public class LocationDumpsItemTest extends TestCase {
+
+ /**
+ * Test that {@link LocationDumpsItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ LocationDumpsItem item = new LocationDumpsItem();
+ item.addLocationClient("com.google.android.gms", 500, 60, 1000, "PRIORITY_ACCURACY", 45);
+ item.addLocationClient("com.google.android.maps", 0, 0, 0, "PRIORITY_ACCURACY", 55);
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(LocationDumpsItem.LOCATION_CLIENTS));
+ assertTrue(output.get(LocationDumpsItem.LOCATION_CLIENTS) instanceof JSONArray);
+
+ JSONArray locationClients = output.getJSONArray(LocationDumpsItem.LOCATION_CLIENTS);
+
+ assertEquals(2, locationClients.length());
+ assertTrue(locationClients.getJSONObject(0).has(LocationInfoItem.PACKAGE));
+ assertTrue(locationClients.getJSONObject(0).has(LocationInfoItem.EFFECTIVE_INTERVAL));
+ assertTrue(locationClients.getJSONObject(0).has(LocationInfoItem.MIN_INTERVAL));
+ assertTrue(locationClients.getJSONObject(0).has(LocationInfoItem.MAX_INTERVAL));
+ assertTrue(locationClients.getJSONObject(0).has(LocationInfoItem.REQUEST_PRIORITY));
+ assertTrue(locationClients.getJSONObject(0).has(LocationInfoItem.LOCATION_DURATION));
+
+ assertTrue(locationClients.getJSONObject(1).has(LocationInfoItem.PACKAGE));
+ assertTrue(locationClients.getJSONObject(1).has(LocationInfoItem.EFFECTIVE_INTERVAL));
+ assertTrue(locationClients.getJSONObject(1).has(LocationInfoItem.MIN_INTERVAL));
+ assertTrue(locationClients.getJSONObject(1).has(LocationInfoItem.MAX_INTERVAL));
+ assertTrue(locationClients.getJSONObject(1).has(LocationInfoItem.REQUEST_PRIORITY));
+ assertTrue(locationClients.getJSONObject(1).has(LocationInfoItem.LOCATION_DURATION));
+ }
+
+ /**
+ * Test that {@link LocationDumpsItem#getLocationClients()} returns correctly.
+ */
+ public void testGetLocationDumps() {
+ LocationDumpsItem item = new LocationDumpsItem();
+ item.addLocationClient("com.google.android.gms", 500, 60, 1000, "PRIORITY_ACCURACY", 45);
+
+ assertEquals(item.getLocationClients().size(), 1);
+ LocationInfoItem client = item.getLocationClients().iterator().next();
+ assertNotNull(client);
+ assertEquals(client.getPackage(), "com.google.android.gms");
+ assertEquals(client.getEffectiveInterval(), 500);
+ assertEquals(client.getMinInterval(), 60);
+ assertEquals(client.getMaxInterval(), 1000);
+ assertEquals(client.getPriority(), "PRIORITY_ACCURACY");
+ assertEquals(client.getDuration(), 45);
+ }
+
+}
diff --git a/javatests/com/android/loganalysis/item/MemInfoItemTest.java b/javatests/com/android/loganalysis/item/MemInfoItemTest.java
new file mode 100644
index 0000000..3a8f307
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/MemInfoItemTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link MemInfoItem}.
+ */
+public class MemInfoItemTest extends TestCase {
+
+ /**
+ * Test that {@link MemInfoItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ MemInfoItem item = new MemInfoItem();
+ item.put("foo", 123L);
+ item.put("bar", 456L);
+ item.setText("foo: 123 kB\nbar: 456 kB");
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(MemInfoItem.LINES));
+ assertTrue(output.get(MemInfoItem.LINES) instanceof JSONObject);
+ assertTrue(output.has(MemInfoItem.TEXT));
+ assertEquals("foo: 123 kB\nbar: 456 kB", output.get(MemInfoItem.TEXT));
+
+ JSONObject lines = output.getJSONObject(MemInfoItem.LINES);
+
+ assertEquals(2, lines.length());
+
+ assertEquals(123, lines.get("foo"));
+ assertEquals(456, lines.get("bar"));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/MonkeyLogItemTest.java b/javatests/com/android/loganalysis/item/MonkeyLogItemTest.java
new file mode 100644
index 0000000..cc2867c
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/MonkeyLogItemTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link MonkeyLogItem}.
+ */
+public class MonkeyLogItemTest extends TestCase {
+ /**
+ * Test that {@link MonkeyLogItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ MonkeyLogItem item = new MonkeyLogItem();
+ item.addCategory("category1");
+ item.addCategory("category2");
+ item.addPackage("package1");
+ item.addPackage("package2");
+ item.addPackage("package3");
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(MonkeyLogItem.CATEGORIES));
+ assertTrue(output.get(MonkeyLogItem.CATEGORIES) instanceof JSONArray);
+
+ JSONArray categories = output.getJSONArray(MonkeyLogItem.CATEGORIES);
+
+ assertEquals(2, categories.length());
+ assertTrue(in("category1", categories));
+ assertTrue(in("category2", categories));
+
+ JSONArray packages = output.getJSONArray(MonkeyLogItem.PACKAGES);
+
+ assertEquals(3, packages.length());
+ assertTrue(in("package1", packages));
+ assertTrue(in("package2", packages));
+ assertTrue(in("package3", packages));
+ }
+
+ private boolean in(String value, JSONArray array) throws JSONException {
+ for (int i = 0; i < array.length(); i++) {
+ if (value.equals(array.get(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/ProcrankItemTest.java b/javatests/com/android/loganalysis/item/ProcrankItemTest.java
new file mode 100644
index 0000000..7f5d309
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/ProcrankItemTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link ProcrankItem}.
+ */
+public class ProcrankItemTest extends TestCase {
+
+ /**
+ * Test that {@link ProcrankItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ ProcrankItem item = new ProcrankItem();
+ item.addProcrankLine(0, "process0", 1, 2, 3, 4);
+ item.addProcrankLine(5, "process1", 6, 7, 8, 9);
+ item.setText("foo\nbar");
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(ProcrankItem.LINES));
+ assertTrue(output.get(ProcrankItem.LINES) instanceof JSONArray);
+ assertTrue(output.has(ProcrankItem.TEXT));
+ assertEquals("foo\nbar", output.get(ProcrankItem.TEXT));
+
+ JSONArray lines = output.getJSONArray(ProcrankItem.LINES);
+
+ assertEquals(2, lines.length());
+ assertTrue(lines.get(0) instanceof JSONObject);
+
+ JSONObject line = lines.getJSONObject(0);
+
+ assertEquals(0, line.get(ProcrankItem.PID));
+ assertEquals("process0", line.get(ProcrankItem.PROCESS_NAME));
+ assertEquals(1, line.get(ProcrankItem.VSS));
+ assertEquals(2, line.get(ProcrankItem.RSS));
+ assertEquals(3, line.get(ProcrankItem.PSS));
+ assertEquals(4, line.get(ProcrankItem.USS));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java b/javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java
new file mode 100644
index 0000000..4dd5597
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Date;
+
+/**
+ * Unit test for {@link SmartMonkeyLogItem}.
+ */
+public class SmartMonkeyLogItemTest extends TestCase {
+ /**
+ * Test that {@link SmartMonkeyLogItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ SmartMonkeyLogItem item = new SmartMonkeyLogItem();
+ item.addApplication("application1");
+ item.addPackage("package1");
+ item.addAnrTime(new Date());
+ item.addCrashTime(new Date());
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(SmartMonkeyLogItem.APPLICATIONS));
+ assertTrue(output.get(SmartMonkeyLogItem.APPLICATIONS) instanceof JSONArray);
+ assertTrue(output.has(SmartMonkeyLogItem.PACKAGES));
+ assertTrue(output.get(SmartMonkeyLogItem.PACKAGES) instanceof JSONArray);
+ assertTrue(output.has(SmartMonkeyLogItem.ANR_TIMES));
+ assertTrue(output.get(SmartMonkeyLogItem.ANR_TIMES) instanceof JSONArray);
+ assertTrue(output.has(SmartMonkeyLogItem.CRASH_TIMES));
+ assertTrue(output.get(SmartMonkeyLogItem.CRASH_TIMES) instanceof JSONArray);
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/SystemPropsItemTest.java b/javatests/com/android/loganalysis/item/SystemPropsItemTest.java
new file mode 100644
index 0000000..b9b6675
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/SystemPropsItemTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link SystemPropsItem}.
+ */
+public class SystemPropsItemTest extends TestCase {
+
+ /**
+ * Test that {@link SystemPropsItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ SystemPropsItem item = new SystemPropsItem();
+ item.put("foo", "123");
+ item.put("bar", "456");
+ item.setText("[foo]: [123]\n[bar]: [456]");
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(SystemPropsItem.LINES));
+ assertTrue(output.get(SystemPropsItem.LINES) instanceof JSONObject);
+ assertTrue(output.has(SystemPropsItem.TEXT));
+ assertEquals("[foo]: [123]\n[bar]: [456]", output.get(SystemPropsItem.TEXT));
+
+ JSONObject lines = output.getJSONObject(SystemPropsItem.LINES);
+
+ assertEquals(2, lines.length());
+
+ assertEquals("123", lines.get("foo"));
+ assertEquals("456", lines.get("bar"));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/TopItemTest.java b/javatests/com/android/loganalysis/item/TopItemTest.java
new file mode 100644
index 0000000..2df01d0
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/TopItemTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import junit.framework.TestCase;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link TopItem}.
+ */
+public class TopItemTest extends TestCase {
+
+ /**
+ * Test that {@link TopItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ TopItem item = new TopItem();
+ item.setText("User 20%, System 20%, IOW 5%, IRQ 3%");
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(TopItem.TEXT));
+ assertEquals("User 20%, System 20%, IOW 5%, IRQ 3%", output.get(TopItem.TEXT));
+ }
+}
diff --git a/javatests/com/android/loganalysis/item/WakelockItemTest.java b/javatests/com/android/loganalysis/item/WakelockItemTest.java
new file mode 100644
index 0000000..f570a7b
--- /dev/null
+++ b/javatests/com/android/loganalysis/item/WakelockItemTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.item;
+
+import com.android.loganalysis.item.WakelockItem.WakelockInfoItem;
+
+import junit.framework.TestCase;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Unit test for {@link WakelockItem}.
+ */
+public class WakelockItemTest extends TestCase {
+
+ /**
+ * Test that {@link WakelockItem#toJson()} returns correctly.
+ */
+ public void testToJson() throws JSONException {
+ WakelockItem item = new WakelockItem();
+ item.addWakeLock("screen","u100", 150000, 25,
+ WakelockItem.WakeLockCategory.PARTIAL_WAKELOCK);
+ item.addWakeLock("wlan_rx", 150000, 25,
+ WakelockItem.WakeLockCategory.KERNEL_WAKELOCK);
+
+ // Convert to JSON string and back again
+ JSONObject output = new JSONObject(item.toJson().toString());
+
+ assertTrue(output.has(WakelockItem.WAKELOCKS));
+ assertTrue(output.get(WakelockItem.WAKELOCKS) instanceof JSONArray);
+
+ JSONArray wakelockInfo = output.getJSONArray(WakelockItem.WAKELOCKS);
+
+ assertEquals(2, wakelockInfo.length());
+ assertTrue(wakelockInfo.getJSONObject(0).has(WakelockInfoItem.NAME));
+ assertTrue(wakelockInfo.getJSONObject(0).has(WakelockInfoItem.PROCESS_UID));
+ assertTrue(wakelockInfo.getJSONObject(0).has(WakelockInfoItem.HELD_TIME));
+ assertTrue(wakelockInfo.getJSONObject(0).has(WakelockInfoItem.LOCKED_COUNT));
+ assertTrue(wakelockInfo.getJSONObject(0).has(WakelockInfoItem.CATEGORY));
+
+ assertTrue(wakelockInfo.getJSONObject(1).has(WakelockInfoItem.NAME));
+ assertFalse(wakelockInfo.getJSONObject(1).has(WakelockInfoItem.PROCESS_UID));
+ assertTrue(wakelockInfo.getJSONObject(1).has(WakelockInfoItem.HELD_TIME));
+ assertTrue(wakelockInfo.getJSONObject(1).has(WakelockInfoItem.LOCKED_COUNT));
+ assertTrue(wakelockInfo.getJSONObject(1).has(WakelockInfoItem.CATEGORY));
+
+ }
+}