aboutsummaryrefslogtreecommitdiffstats
path: root/chimpchat/test
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2011-06-13 09:17:03 -0700
committerMichael Wright <michaelwr@google.com>2011-06-20 14:24:05 -0700
commit8c09f35fe02c38c18f8f7b9e0a531d6ac158476e (patch)
tree3528a0073582805b438e88b8d0014e844d914c41 /chimpchat/test
parent7af6646391705a276b814bf8b45f8874554831fb (diff)
downloadsdk-8c09f35fe02c38c18f8f7b9e0a531d6ac158476e.zip
sdk-8c09f35fe02c38c18f8f7b9e0a531d6ac158476e.tar.gz
sdk-8c09f35fe02c38c18f8f7b9e0a531d6ac158476e.tar.bz2
Refactored MonkeyRunner to use ChimpChat
Change-Id: Icbe5bcb066021d578faae43aa49b58ab1595870b
Diffstat (limited to 'chimpchat/test')
-rw-r--r--chimpchat/test/Android.mk25
-rw-r--r--chimpchat/test/com/android/chimpchat/AllTests.java49
-rw-r--r--chimpchat/test/com/android/chimpchat/ImageUtilsTest.java96
-rw-r--r--chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java59
-rw-r--r--chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java138
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt10
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt15
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image1.pngbin0 -> 184289 bytes
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image1.rawbin0 -> 307545 bytes
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image2.pngbin0 -> 82036 bytes
-rw-r--r--chimpchat/test/resources/com/android/monkeyrunner/image2.rawbin0 -> 1536345 bytes
11 files changed, 392 insertions, 0 deletions
diff --git a/chimpchat/test/Android.mk b/chimpchat/test/Android.mk
new file mode 100644
index 0000000..7b6698d
--- /dev/null
+++ b/chimpchat/test/Android.mk
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_MODULE := chimpchattest
+LOCAL_JAVA_LIBRARIES := junit chimpchat ddmlib guavalib
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/chimpchat/test/com/android/chimpchat/AllTests.java b/chimpchat/test/com/android/chimpchat/AllTests.java
new file mode 100644
index 0000000..9f647e3
--- /dev/null
+++ b/chimpchat/test/com/android/chimpchat/AllTests.java
@@ -0,0 +1,49 @@
+/*
+ * 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.chimpchat;
+
+import com.android.chimpchat.adb.AdbChimpDeviceTest;
+import com.android.chimpchat.adb.LinearInterpolatorTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Test suite to run all the tests for MonkeyRunner.
+ */
+public class AllTests {
+ public static Test suite(Class<? extends TestCase>... classes) {
+ TestSuite suite = new TestSuite();
+ for (Class<? extends TestCase> clz : classes) {
+ suite.addTestSuite(clz);
+ }
+ return suite;
+ }
+
+ public static void main(String args[]) {
+ TestRunner tr = new TestRunner();
+ TestResult result = tr.doRun(AllTests.suite(ImageUtilsTest.class,
+ LinearInterpolatorTest.class, AdbChimpDeviceTest.class));
+ if (result.wasSuccessful()) {
+ System.exit(0);
+ } else {
+ System.exit(1);
+ }
+ }
+}
diff --git a/chimpchat/test/com/android/chimpchat/ImageUtilsTest.java b/chimpchat/test/com/android/chimpchat/ImageUtilsTest.java
new file mode 100644
index 0000000..19dc4ed
--- /dev/null
+++ b/chimpchat/test/com/android/chimpchat/ImageUtilsTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.chimpchat;
+
+import com.android.ddmlib.RawImage;
+import com.android.chimpchat.adb.image.CaptureRawAndConvertedImage;
+import com.android.chimpchat.adb.image.ImageUtils;
+import com.android.chimpchat.adb.image.CaptureRawAndConvertedImage.ChimpRawImage;
+
+import junit.framework.TestCase;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+
+import javax.imageio.ImageIO;
+
+public class ImageUtilsTest extends TestCase {
+ private static BufferedImage createBufferedImage(String name) throws IOException {
+ InputStream is = ImageUtilsTest.class.getResourceAsStream(name);
+ BufferedImage img = ImageIO.read(is);
+ is.close();
+ return img;
+ }
+
+ private static RawImage createRawImage(String name) throws IOException, ClassNotFoundException {
+ ObjectInputStream is =
+ new ObjectInputStream(ImageUtilsTest.class.getResourceAsStream(name));
+ CaptureRawAndConvertedImage.ChimpRawImage wrapper = (ChimpRawImage) is.readObject();
+ is.close();
+ return wrapper.toRawImage();
+ }
+
+ /**
+ * Check that the two images will draw the same (ie. have the same pixels). This is different
+ * that BufferedImage.equals(), which also wants to check that they have the same ColorModel
+ * and other parameters.
+ *
+ * @param i1 the first image
+ * @param i2 the second image
+ * @return true if both images will draw the same (ie. have same pixels).
+ */
+ private static boolean checkImagesHaveSamePixels(BufferedImage i1, BufferedImage i2) {
+ if (i1.getWidth() != i2.getWidth()) {
+ return false;
+ }
+ if (i1.getHeight() != i2.getHeight()) {
+ return false;
+ }
+
+ for (int y = 0; y < i1.getHeight(); y++) {
+ for (int x = 0; x < i1.getWidth(); x++) {
+ int p1 = i1.getRGB(x, y);
+ int p2 = i2.getRGB(x, y);
+ if (p1 != p2) {
+ WritableRaster r1 = i1.getRaster();
+ WritableRaster r2 = i2.getRaster();
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public void testImageConversionOld() throws IOException, ClassNotFoundException {
+ RawImage rawImage = createRawImage("image1.raw");
+ BufferedImage convertedImage = ImageUtils.convertImage(rawImage);
+ BufferedImage correctConvertedImage = createBufferedImage("image1.png");
+
+ assertTrue(checkImagesHaveSamePixels(convertedImage, correctConvertedImage));
+ }
+
+ public void testImageConversionNew() throws IOException, ClassNotFoundException {
+ RawImage rawImage = createRawImage("image2.raw");
+ BufferedImage convertedImage = ImageUtils.convertImage(rawImage);
+ BufferedImage correctConvertedImage = createBufferedImage("image2.png");
+
+ assertTrue(checkImagesHaveSamePixels(convertedImage, correctConvertedImage));
+ }
+}
diff --git a/chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java b/chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java
new file mode 100644
index 0000000..482941a
--- /dev/null
+++ b/chimpchat/test/com/android/chimpchat/adb/AdbChimpDeviceTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.chimpchat.adb;
+
+import com.google.common.base.Joiner;
+import com.google.common.io.Resources;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Unit Tests for AdbChimpDevice.
+ */
+public class AdbChimpDeviceTest extends TestCase {
+ private static String MULTILINE_RESULT = "\r\n" +
+ "Test results for InstrumentationTestRunner=.\r\n" +
+ "Time: 2.242\r\n" +
+ "\r\n" +
+ "OK (1 test)";
+
+ private static String getResource(String resName) throws IOException {
+ URL resource = Resources.getResource(AdbChimpDeviceTest.class, resName);
+ List<String> lines = Resources.readLines(resource, Charset.defaultCharset());
+ return Joiner.on("\r\n").join(lines);
+ }
+
+ public void testSimpleResultParse() throws IOException {
+ String result = getResource("instrument_result.txt");
+ Map<String, Object> convertedResult = AdbChimpDevice.convertInstrumentResult(result);
+
+ assertEquals("one", convertedResult.get("result1"));
+ assertEquals("two", convertedResult.get("result2"));
+ }
+
+ public void testMultilineResultParse() throws IOException {
+ String result = getResource("multiline_instrument_result.txt");
+ Map<String, Object> convertedResult = AdbChimpDevice.convertInstrumentResult(result);
+
+ assertEquals(MULTILINE_RESULT, convertedResult.get("stream"));
+ }
+}
diff --git a/chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java b/chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java
new file mode 100644
index 0000000..f9bc72f
--- /dev/null
+++ b/chimpchat/test/com/android/chimpchat/adb/LinearInterpolatorTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.chimpchat.adb;
+
+import com.google.common.collect.Lists;
+
+import com.android.chimpchat.adb.LinearInterpolator.Point;
+
+import junit.framework.TestCase;
+
+import java.util.List;
+
+/**
+ * Unit tests for the LinerInterpolator class.S
+ */
+public class LinearInterpolatorTest extends TestCase {
+ private static class Collector implements LinearInterpolator.Callback {
+ private final List<LinearInterpolator.Point> points = Lists.newArrayList();
+
+ public List<LinearInterpolator.Point> getPoints() {
+ return points;
+ }
+
+ public void end(Point input) {
+ points.add(input);
+ }
+
+ public void start(Point input) {
+ points.add(input);
+ }
+
+ public void step(Point input) {
+ points.add(input);
+ }
+ }
+
+ List<Integer> STEP_POINTS = Lists.newArrayList(0, 100, 200, 300, 400, 500, 600, 700, 800, 900,
+ 1000);
+ List<Integer> REVERSE_STEP_POINTS = Lists.newArrayList(1000, 900, 800, 700, 600, 500, 400, 300,
+ 200, 100, 0);
+
+ public void testLerpRight() {
+ LinearInterpolator lerp = new LinearInterpolator(10);
+ Collector collector = new Collector();
+ lerp.interpolate(new LinearInterpolator.Point(0, 100),
+ new LinearInterpolator.Point(1000, 100),
+ collector);
+
+ List<LinearInterpolator.Point> points = collector.getPoints();
+ assertEquals(11, points.size());
+ for (int x = 0; x < points.size(); x++) {
+ assertEquals(new Point(STEP_POINTS.get(x), 100), points.get(x));
+ }
+ }
+
+ public void testLerpLeft() {
+ LinearInterpolator lerp = new LinearInterpolator(10);
+ Collector collector = new Collector();
+ lerp.interpolate(new LinearInterpolator.Point(1000, 100),
+ new LinearInterpolator.Point(0, 100),
+ collector);
+
+ List<LinearInterpolator.Point> points = collector.getPoints();
+ assertEquals(11, points.size());
+ for (int x = 0; x < points.size(); x++) {
+ assertEquals(new Point(REVERSE_STEP_POINTS.get(x), 100), points.get(x));
+ }
+ }
+
+ public void testLerpUp() {
+ LinearInterpolator lerp = new LinearInterpolator(10);
+ Collector collector = new Collector();
+ lerp.interpolate(new LinearInterpolator.Point(100, 1000),
+ new LinearInterpolator.Point(100, 0),
+ collector);
+
+ List<LinearInterpolator.Point> points = collector.getPoints();
+ assertEquals(11, points.size());
+ for (int x = 0; x < points.size(); x++) {
+ assertEquals(new Point(100, REVERSE_STEP_POINTS.get(x)), points.get(x));
+ }
+ }
+
+ public void testLerpDown() {
+ LinearInterpolator lerp = new LinearInterpolator(10);
+ Collector collector = new Collector();
+ lerp.interpolate(new LinearInterpolator.Point(100, 0),
+ new LinearInterpolator.Point(100, 1000),
+ collector);
+
+ List<LinearInterpolator.Point> points = collector.getPoints();
+ assertEquals(11, points.size());
+ for (int x = 0; x < points.size(); x++) {
+ assertEquals(new Point(100, STEP_POINTS.get(x)), points.get(x));
+ }
+ }
+
+ public void testLerpNW() {
+ LinearInterpolator lerp = new LinearInterpolator(10);
+ Collector collector = new Collector();
+ lerp.interpolate(new LinearInterpolator.Point(0, 0),
+ new LinearInterpolator.Point(1000, 1000),
+ collector);
+
+ List<LinearInterpolator.Point> points = collector.getPoints();
+ assertEquals(11, points.size());
+ for (int x = 0; x < points.size(); x++) {
+ assertEquals(new Point(STEP_POINTS.get(x), STEP_POINTS.get(x)), points.get(x));
+ }
+ }
+
+ public void testLerpNE() {
+ LinearInterpolator lerp = new LinearInterpolator(10);
+ Collector collector = new Collector();
+ lerp.interpolate(new LinearInterpolator.Point(1000, 1000),
+ new LinearInterpolator.Point(0, 0),
+ collector);
+
+ List<LinearInterpolator.Point> points = collector.getPoints();
+ assertEquals(11, points.size());
+ for (int x = 0; x < points.size(); x++) {
+ assertEquals(new Point(REVERSE_STEP_POINTS.get(x), REVERSE_STEP_POINTS.get(x)), points.get(x));
+ }
+ }
+}
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt b/chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt
new file mode 100644
index 0000000..c127c0f
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/adb/instrument_result.txt
@@ -0,0 +1,10 @@
+INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
+INSTRUMENTATION_STATUS: current=1
+INSTRUMENTATION_STATUS: class=com.example.android.notepad.NotePadTest
+INSTRUMENTATION_STATUS: stream=.
+INSTRUMENTATION_STATUS: numtests=1
+INSTRUMENTATION_STATUS: test=testActivityTestCaseSetUpProperly
+INSTRUMENTATION_STATUS_CODE: 0
+INSTRUMENTATION_RESULT: result1=one
+INSTRUMENTATION_RESULT: result2=two
+INSTRUMENTATION_CODE: -1
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt b/chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt
new file mode 100644
index 0000000..32fd901
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/adb/multiline_instrument_result.txt
@@ -0,0 +1,15 @@
+INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
+INSTRUMENTATION_STATUS: current=1
+INSTRUMENTATION_STATUS: class=com.example.android.notepad.NotePadTest
+INSTRUMENTATION_STATUS: stream=.
+INSTRUMENTATION_STATUS: numtests=1
+INSTRUMENTATION_STATUS: test=testActivityTestCaseSetUpProperly
+INSTRUMENTATION_STATUS_CODE: 0
+INSTRUMENTATION_RESULT: stream=
+Test results for InstrumentationTestRunner=.
+Time: 2.242
+
+OK (1 test)
+
+
+INSTRUMENTATION_CODE: -1
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image1.png b/chimpchat/test/resources/com/android/monkeyrunner/image1.png
new file mode 100644
index 0000000..9ef1800
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image1.png
Binary files differ
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image1.raw b/chimpchat/test/resources/com/android/monkeyrunner/image1.raw
new file mode 100644
index 0000000..99ec013
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image1.raw
Binary files differ
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image2.png b/chimpchat/test/resources/com/android/monkeyrunner/image2.png
new file mode 100644
index 0000000..03ff0c1
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image2.png
Binary files differ
diff --git a/chimpchat/test/resources/com/android/monkeyrunner/image2.raw b/chimpchat/test/resources/com/android/monkeyrunner/image2.raw
new file mode 100644
index 0000000..06e5b47
--- /dev/null
+++ b/chimpchat/test/resources/com/android/monkeyrunner/image2.raw
Binary files differ