CameraTooTestpublic class CameraTooTest extends Object
Fields Summary |
---|
private static final FilenameFilter | OUTPUT_FILE_DECIDER |
Methods Summary |
---|
private void | assertComparatorEq(T lhs, T rhs, java.util.Comparator rel)
assertEquals(String.format("%s should be equal to %s", lhs, rhs), rel.compare(lhs, rhs), 0);
assertEquals(String.format("%s should be equal to %s (reverse check)", lhs, rhs),
rel.compare(rhs, lhs), 0);
| private void | assertComparatorLt(T lhs, T rhs, java.util.Comparator rel)
assertTrue(String.format("%s should be less than %s", lhs, rhs), rel.compare(lhs, rhs) < 0);
assertTrue(String.format("%s should be less than %s (reverse check)", lhs, rhs),
rel.compare(rhs, lhs) > 0);
| private void | assertOptimalSize(android.util.Size[] options, int minWidth, int minHeight, android.util.Size expected)
Size verdict = CameraTooActivity.chooseBigEnoughSize(options, minWidth, minHeight);
assertEquals(String.format("Expected optimal size %s but got %s", expected, verdict),
verdict, expected);
| public void | capturedImageSaver()
ByteBuffer buf = ByteBuffer.allocate(25);
for(int index = 0; index < buf.capacity(); ++index)
buf.put(index, (byte) index);
Image.Plane plane = mock(Image.Plane.class);
when(plane.getBuffer()).thenReturn(buf);
when(plane.getPixelStride()).thenReturn(1);
when(plane.getRowStride()).thenReturn(5);
Image.Plane[] onlyPlaneThatMatters = { plane };
Image image = mock(Image.class);
when(image.getPlanes()).thenReturn(onlyPlaneThatMatters);
when(image.getWidth()).thenReturn(5);
when(image.getHeight()).thenReturn(5);
File picturesFolder =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
Set<File> preListing =
new HashSet<File>(Arrays.asList(picturesFolder.listFiles(OUTPUT_FILE_DECIDER)));
CameraTooActivity.CapturedImageSaver saver =
new CameraTooActivity.CapturedImageSaver(image);
saver.run();
Set<File> postListing =
new HashSet<File>(Arrays.asList(picturesFolder.listFiles(OUTPUT_FILE_DECIDER)));
Set<File> newFiles = newlyAddedElements(preListing, postListing);
assertEquals(newFiles.size(), 1);
File picture = newFiles.iterator().next();
FileInputStream istream = new FileInputStream(picture);
for(int count = 0; count < buf.capacity(); ++count) {
assertEquals(istream.read(), buf.get(count));
}
assertEquals(istream.read(), -1);
assertTrue(picture.delete());
| public void | chooseBigEnoughSize()
Size empty = new Size(0, 0), fatAndFlat = new Size(100, 0), tallAndThin = new Size(0, 100);
Size smallSquare = new Size(4, 4), horizRect = new Size(8, 2), vertRect = new Size(2, 8);
Size largeSquare = new Size(5, 5);
Size[] siz =
{ empty, fatAndFlat, tallAndThin, smallSquare, horizRect, vertRect, largeSquare };
assertOptimalSize(siz, 0, 0, empty);
assertOptimalSize(siz, 1, 0, fatAndFlat);
assertOptimalSize(siz, 0, 1, tallAndThin);
assertOptimalSize(siz, 4, 4, smallSquare);
assertOptimalSize(siz, 1, 1, smallSquare);
assertOptimalSize(siz, 2, 1, smallSquare);
assertOptimalSize(siz, 1, 2, smallSquare);
assertOptimalSize(siz, 3, 4, smallSquare);
assertOptimalSize(siz, 4, 3, smallSquare);
assertOptimalSize(siz, 8, 2, horizRect);
assertOptimalSize(siz, 5, 1, horizRect);
assertOptimalSize(siz, 5, 2, horizRect);
assertOptimalSize(siz, 2, 8, vertRect);
assertOptimalSize(siz, 1, 5, vertRect);
assertOptimalSize(siz, 2, 5, vertRect);
assertOptimalSize(siz, 5, 5, largeSquare);
assertOptimalSize(siz, 3, 5, largeSquare);
assertOptimalSize(siz, 5, 3, largeSquare);
| public void | compareSizesByArea()
Size empty = new Size(0, 0), fatAndFlat = new Size(100, 0), tallAndThin = new Size(0, 100);
Size smallSquare = new Size(4, 4), horizRect = new Size(8, 2), vertRect = new Size(2, 8);
Size largeSquare = new Size(5, 5);
Comparator<Size> rel = new CameraTooActivity.CompareSizesByArea();
assertComparatorEq(empty, fatAndFlat, rel);
assertComparatorEq(empty, tallAndThin, rel);
assertComparatorEq(fatAndFlat, empty, rel);
assertComparatorEq(fatAndFlat, tallAndThin, rel);
assertComparatorEq(tallAndThin, empty, rel);
assertComparatorEq(tallAndThin, fatAndFlat, rel);
assertComparatorEq(smallSquare, horizRect, rel);
assertComparatorEq(smallSquare, vertRect, rel);
assertComparatorEq(horizRect, smallSquare, rel);
assertComparatorEq(horizRect, vertRect, rel);
assertComparatorEq(vertRect, smallSquare, rel);
assertComparatorEq(vertRect, horizRect, rel);
assertComparatorLt(empty, smallSquare, rel);
assertComparatorLt(empty, horizRect, rel);
assertComparatorLt(empty, vertRect, rel);
assertComparatorLt(fatAndFlat, smallSquare, rel);
assertComparatorLt(fatAndFlat, horizRect, rel);
assertComparatorLt(fatAndFlat, vertRect, rel);
assertComparatorLt(tallAndThin, smallSquare, rel);
assertComparatorLt(tallAndThin, horizRect, rel);
assertComparatorLt(tallAndThin, vertRect, rel);
assertComparatorLt(empty, largeSquare, rel);
assertComparatorLt(fatAndFlat, largeSquare, rel);
assertComparatorLt(tallAndThin, largeSquare, rel);
assertComparatorLt(smallSquare, largeSquare, rel);
assertComparatorLt(horizRect, largeSquare, rel);
assertComparatorLt(vertRect, largeSquare, rel);
| private static java.util.Set | newlyAddedElements(java.util.Set before, java.util.Set after)
Set<T> result = new HashSet<T>(after);
result.removeAll(before);
return result;
|
|