Commit ef718468 authored by Yoland Yan's avatar Yoland Yan Committed by Commit Bot

Convert Shape Detection tests to JUnit4

For more on JUnit4 migration, please check
src/testing/android/docs/junit4.md

Bug: 640116
Cq-Include-Trybots: master.tryserver.chromium.mac:mac_optional_gpu_tests_rel
Change-Id: I06ab6c5d14bdc382b294482d6a7b3cec497117e0
Reviewed-on: https://chromium-review.googlesource.com/701363Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Yoland Yan <yolandyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506760}
parent b8d32e14
......@@ -5,8 +5,12 @@
package org.chromium.shape_detection;
import android.support.test.filters.SmallTest;
import android.test.InstrumentationTestCase;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.shape_detection.mojom.BarcodeDetection;
import org.chromium.shape_detection.mojom.BarcodeDetectionResult;
......@@ -17,12 +21,11 @@ import java.util.concurrent.TimeUnit;
/**
* Test suite for BarcodeDetectionImpl.
*/
public class BarcodeDetectionImplTest extends InstrumentationTestCase {
@RunWith(BaseJUnit4ClassRunner.class)
public class BarcodeDetectionImplTest {
private static final org.chromium.skia.mojom.Bitmap QR_CODE_BITMAP =
TestUtils.mojoBitmapFromFile("qr_code.png");
public BarcodeDetectionImplTest() {}
private static BarcodeDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap) {
BarcodeDetection detector = new BarcodeDetectionImpl();
......@@ -36,12 +39,13 @@ public class BarcodeDetectionImplTest extends InstrumentationTestCase {
try {
toReturn = queue.poll(5L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail("Could not get BarcodeDetectionResult: " + e.toString());
Assert.fail("Could not get BarcodeDetectionResult: " + e.toString());
}
assertNotNull(toReturn);
Assert.assertNotNull(toReturn);
return toReturn;
}
@Test
@SmallTest
@Feature({"ShapeDetection"})
public void testDetectBase64ValidImageString() {
......@@ -49,11 +53,11 @@ public class BarcodeDetectionImplTest extends InstrumentationTestCase {
return;
}
BarcodeDetectionResult[] results = detect(QR_CODE_BITMAP);
assertEquals(1, results.length);
assertEquals("https://chromium.org", results[0].rawValue);
assertEquals(40.0, results[0].boundingBox.x, 0.0);
assertEquals(40.0, results[0].boundingBox.y, 0.0);
assertEquals(250.0, results[0].boundingBox.width, 0.0);
assertEquals(250.0, results[0].boundingBox.height, 0.0);
Assert.assertEquals(1, results.length);
Assert.assertEquals("https://chromium.org", results[0].rawValue);
Assert.assertEquals(40.0, results[0].boundingBox.x, 0.0);
Assert.assertEquals(40.0, results[0].boundingBox.y, 0.0);
Assert.assertEquals(250.0, results[0].boundingBox.width, 0.0);
Assert.assertEquals(250.0, results[0].boundingBox.height, 0.0);
}
}
......@@ -5,8 +5,12 @@
package org.chromium.shape_detection;
import android.support.test.filters.SmallTest;
import android.test.InstrumentationTestCase;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.gfx.mojom.RectF;
import org.chromium.shape_detection.mojom.TextDetection;
......@@ -18,7 +22,8 @@ import java.util.concurrent.TimeUnit;
/**
* Test suite for TextDetectionImpl.
*/
public class TextDetectionImplTest extends InstrumentationTestCase {
@RunWith(BaseJUnit4ClassRunner.class)
public class TextDetectionImplTest {
private static final String[] DETECTION_EXPECTED_TEXT = {
"The quick brown fox jumped over the lazy dog.", "Helvetica Neue 36."};
private static final float[][] TEXT_BOUNDING_BOX = {
......@@ -26,8 +31,6 @@ public class TextDetectionImplTest extends InstrumentationTestCase {
private static final org.chromium.skia.mojom.Bitmap TEXT_DETECTION_BITMAP =
TestUtils.mojoBitmapFromText(DETECTION_EXPECTED_TEXT);
public TextDetectionImplTest() {}
private static TextDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap) {
TextDetection detector = new TextDetectionImpl();
......@@ -41,12 +44,13 @@ public class TextDetectionImplTest extends InstrumentationTestCase {
try {
toReturn = queue.poll(5L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail("Could not get TextDetectionResult: " + e.toString());
Assert.fail("Could not get TextDetectionResult: " + e.toString());
}
assertNotNull(toReturn);
Assert.assertNotNull(toReturn);
return toReturn;
}
@Test
@SmallTest
@Feature({"ShapeDetection"})
public void testDetectSucceedsOnValidBitmap() {
......@@ -54,23 +58,23 @@ public class TextDetectionImplTest extends InstrumentationTestCase {
return;
}
TextDetectionResult[] results = detect(TEXT_DETECTION_BITMAP);
assertEquals(DETECTION_EXPECTED_TEXT.length, results.length);
Assert.assertEquals(DETECTION_EXPECTED_TEXT.length, results.length);
for (int i = 0; i < DETECTION_EXPECTED_TEXT.length; i++) {
assertEquals(results[i].rawValue, DETECTION_EXPECTED_TEXT[i]);
assertEquals(TEXT_BOUNDING_BOX[i][0], results[i].boundingBox.x, 0.0);
assertEquals(TEXT_BOUNDING_BOX[i][1], results[i].boundingBox.y, 0.0);
assertEquals(TEXT_BOUNDING_BOX[i][2], results[i].boundingBox.width, 0.0);
assertEquals(TEXT_BOUNDING_BOX[i][3], results[i].boundingBox.height, 0.0);
Assert.assertEquals(results[i].rawValue, DETECTION_EXPECTED_TEXT[i]);
Assert.assertEquals(TEXT_BOUNDING_BOX[i][0], results[i].boundingBox.x, 0.0);
Assert.assertEquals(TEXT_BOUNDING_BOX[i][1], results[i].boundingBox.y, 0.0);
Assert.assertEquals(TEXT_BOUNDING_BOX[i][2], results[i].boundingBox.width, 0.0);
Assert.assertEquals(TEXT_BOUNDING_BOX[i][3], results[i].boundingBox.height, 0.0);
RectF cornerRectF = new RectF();
cornerRectF.x = results[i].cornerPoints[0].x;
cornerRectF.y = results[i].cornerPoints[0].y;
cornerRectF.width = results[i].cornerPoints[1].x - cornerRectF.x;
cornerRectF.height = results[i].cornerPoints[2].y - cornerRectF.y;
assertEquals(results[i].boundingBox, cornerRectF);
assertEquals(results[i].cornerPoints[3].x, results[i].cornerPoints[1].x, 0.0);
assertEquals(results[i].cornerPoints[3].y, results[i].cornerPoints[2].y, 0.0);
Assert.assertEquals(results[i].boundingBox, cornerRectF);
Assert.assertEquals(results[i].cornerPoints[3].x, results[i].cornerPoints[1].x, 0.0);
Assert.assertEquals(results[i].cornerPoints[3].y, results[i].cornerPoints[2].y, 0.0);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment