@Test public void testInitializeMatrixSetsRotateOnRotation() { Matrix matrix = mock(Matrix.class); TransformationUtils.initializeMatrixForRotation(ExifInterface.ORIENTATION_ROTATE_90, matrix); verify(matrix).setRotate(90); TransformationUtils.initializeMatrixForRotation(ExifInterface.ORIENTATION_ROTATE_180, matrix); verify(matrix).setRotate(180); TransformationUtils.initializeMatrixForRotation(ExifInterface.ORIENTATION_ROTATE_270, matrix); verify(matrix).setRotate(-90); }
@Test public void testRotateImage() { Bitmap toRotate = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); Bitmap zero = TransformationUtils.rotateImage(toRotate, 0); assertTrue(toRotate == zero); Bitmap ninety = TransformationUtils.rotateImage(toRotate, 90); assertTrue(Shadows.shadowOf(ninety).getDescription().contains("rotate=90.0")); assertEquals(toRotate.getWidth(), toRotate.getHeight()); }
@Test public void testInitializeMatrixSetsScaleIfFlipHorizontal() { Matrix matrix = mock(Matrix.class); TransformationUtils.initializeMatrixForRotation( ExifInterface.ORIENTATION_FLIP_HORIZONTAL, matrix); verify(matrix).setScale(-1, 1); }
@Test public void testFitCenterHandlesBitmapsWithNullConfigs() { Bitmap toFit = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565); Shadows.shadowOf(toFit).setConfig(null); Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, toFit, 50, 50); assertEquals(Bitmap.Config.ARGB_8888, transformed.getConfig()); }
@Test public void testFitCenterReturnsGivenBitmapIfGivenBitmapHeightMatchesExactly() { Bitmap toFit = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444); Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, toFit, toFit.getWidth() * 2, toFit.getHeight()); assertTrue(toFit == transformed); }
@Test public void testInitializeMatrixSetsScaleAndRotateIfTransverse() { Matrix matrix = mock(Matrix.class); TransformationUtils.initializeMatrixForRotation(ExifInterface.ORIENTATION_TRANSVERSE, matrix); verify(matrix).setRotate(-90); verify(matrix).postScale(-1, 1); }
@Test public void testInitializeMatrixSetsScaleAndRotateIfFlipVertical() { Matrix matrix = mock(Matrix.class); TransformationUtils.initializeMatrixForRotation( ExifInterface.ORIENTATION_FLIP_VERTICAL, matrix); verify(matrix).setRotate(180); verify(matrix).postScale(-1, 1); }
@Test public void testRotateImageExifReturnsGivenBitmapIfOrientationIsInvalid() { Bitmap toRotate = Bitmap.createBitmap(200, 100, Bitmap.Config.ARGB_8888); // Use assertTrue because Robolectric incorrectly implements equality for Bitmaps. We want // not just an identical Bitmap, but our original Bitmap object back. Bitmap rotated = TransformationUtils.rotateImageExif(bitmapPool, toRotate, -1); assertTrue(toRotate == rotated); }
@Test public void testRotateImageExifHandlesBitmapsWithNullConfigs() { Bitmap toRotate = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565); Shadows.shadowOf(toRotate).setConfig(null); Bitmap rotated = TransformationUtils.rotateImageExif( bitmapPool, toRotate, ExifInterface.ORIENTATION_ROTATE_180); assertEquals(Bitmap.Config.ARGB_8888, rotated.getConfig()); }
@Test public void testRotateImageExifReturnsGivenBitmapIfRotationIsNormal() { Bitmap toRotate = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444); // Use assertTrue because Robolectric incorrectly implements equality for Bitmaps. We want // not just an identical Bitmap, but our original Bitmap object back. Bitmap rotated = TransformationUtils.rotateImageExif(bitmapPool, toRotate, ExifInterface.ORIENTATION_NORMAL); assertTrue(toRotate == rotated); }
// Test for Issue #195. @Test public void testFitCenterUsesFloorInsteadOfRoundingForOutputBitmapSize() { Bitmap toTransform = Bitmap.createBitmap(1230, 1640, Bitmap.Config.RGB_565); Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, toTransform, 1075, 1366); assertEquals(1024, transformed.getWidth()); assertEquals(1366, transformed.getHeight()); }
@Test public void testFitCenterWithSquareBitmap() { final int maxSide = 500; Bitmap square = Bitmap.createBitmap(600, 600, Bitmap.Config.ARGB_8888); Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, square, maxSide, maxSide); assertHasOriginalAspectRatio(square, transformed); assertBitmapFitsExactlyWithinBounds(maxSide, transformed); }
@Test public void testCenterCropReturnsGivenBitmapIfGivenBitmapExactlyMatchesGivenDimensions() { Bitmap toCrop = Bitmap.createBitmap(200, 300, Bitmap.Config.ARGB_8888); Bitmap transformed = TransformationUtils.centerCrop(bitmapPool, toCrop, toCrop.getWidth(), toCrop.getHeight()); // Robolectric incorrectly implements equals() for Bitmaps, we want the original object not // just an equivalent. assertTrue(toCrop == transformed); }
@Test public void testFitCenterSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlpha() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); toTransform.setHasAlpha(false); Bitmap result = TransformationUtils.fitCenter( bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2); assertFalse(result.hasAlpha()); }
@Test public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); toTransform.setHasAlpha(true); Bitmap result = TransformationUtils.centerCrop( bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2); assertTrue(result.hasAlpha()); }
@Test public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888); reset(bitmapPool); when(bitmapPool.get(eq(50), eq(50), eq(Bitmap.Config.ARGB_8888))).thenReturn(toReuse); toReuse.setHasAlpha(false); toTransform.setHasAlpha(true); Bitmap result = TransformationUtils.centerCrop( bitmapPool, toTransform, toReuse.getWidth(), toReuse.getHeight()); assertEquals(toReuse, result); assertTrue(result.hasAlpha()); }
@Test public void testGetExifOrientationDegrees() { assertEquals( 0, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_NORMAL)); assertEquals( 90, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_TRANSPOSE)); assertEquals( 90, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_ROTATE_90)); assertEquals( 180, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_ROTATE_180)); assertEquals( 180, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_FLIP_VERTICAL)); assertEquals( 270, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_TRANSVERSE)); assertEquals( 270, TransformationUtils.getExifOrientationDegrees(ExifInterface.ORIENTATION_ROTATE_270)); }
public void fetchDatasetInformation() throws TechnicalException { try { String databaseMapSerialFilePathAndName = this.serialFolderPathAndName + DATABASE_MAP_SERIAL_FILE_NAME; String templateMapSerialFilePathAndName = this.serialFolderPathAndName + TEMPLATE_MAP_SERIAL_FILE_NAME; String datasetMapSerialFilePathAndName = this.serialFolderPathAndName + DATASET_MAP_SERIAL_FILE_NAME; String datasetMap2SerialFilePathAndName = this.serialFolderPathAndName + DATASET_MAP2_SERIAL_FILE_NAME; if (new File(databaseMapSerialFilePathAndName).exists() && new File(templateMapSerialFilePathAndName).exists() && new File(datasetMapSerialFilePathAndName).exists() && new File(datasetMap2SerialFilePathAndName).exists()) { databaseNameToDatasetInformationMap = (HashMap<String, HashMap<String, List<String>>>) MyUtils.readSerializedObject(databaseMapSerialFilePathAndName); System.out.println( "Using serial, quick check: " + this.databaseNameToDatasetInformationMap.size()); /*datasetNameToDatabaseNameMap = (HashMap<String, String>)MyUtils.readSerializedObject( datasetMapSerialFilePathAndName); System.out.println("Using serial, quick check: " + this.datasetNameToDatabaseNameMap.size());*/ templateNameToDatabaseNameMap = (HashMap<String, String>) MyUtils.readSerializedObject(templateMapSerialFilePathAndName); System.out.println( "Using serial, quick check: " + this.templateNameToDatabaseNameMap.size()); datasetNameToTemplateName = (HashMap<String, String>) MyUtils.readSerializedObject(datasetMapSerialFilePathAndName); System.out.println("Using serial, quick check: " + this.datasetNameToTemplateName.size()); datasetNameToDatasetType = (HashMap<String, String>) MyUtils.readSerializedObject(datasetMap2SerialFilePathAndName); System.out.println("Using serial, quick check: " + this.datasetNameToDatasetType.size()); } else { System.out.println("No serial at " + databaseMapSerialFilePathAndName + " , connecting..."); this.databaseNameToDatasetInformationMap = new HashMap<String, HashMap<String, List<String>>>(); // Check every database for the dataset or the template name for (String databaseName : this.databaseNames) { connect(databaseName); // Prepare list of tables this.preparedStatementDatabase = this.connection.prepareStatement( "select meta_conf__dataset__main.dataset, meta_conf__dataset__main.type, meta_template__template__main.template " + "from meta_conf__dataset__main, meta_template__template__main " + "where meta_conf__dataset__main.dataset_id_key = meta_template__template__main.dataset_id_key;"); ResultSet resultSet = this.preparedStatementDatabase.executeQuery(); HashMap<String, List<String>> map = new HashMap<String, List<String>>(); resultSet.beforeFirst(); while (resultSet.next()) { String datasetName = resultSet.getString(1); String datasetType = resultSet.getString(2); String templateName = resultSet.getString(3); List<String> list = map.get(templateName); if (null == list) { list = new ArrayList<String>(); } list.add(datasetName); map.put(templateName, list); MyUtils.checkStatusProgram( TransformationUtils.isGenomicSequence(datasetType) || TransformationUtils.isTableSet(datasetType)); /*MyUtils.checkStatusProgram(datasetNameToDatabaseNameMap.get(datasetName)==null); datasetNameToDatabaseNameMap.put(datasetName, databaseName);*/ MyUtils.checkStatusProgram(datasetNameToTemplateName.get(datasetName) == null); datasetNameToTemplateName.put(datasetName, templateName); MyUtils.checkStatusProgram(datasetNameToDatasetType.get(datasetName) == null); datasetNameToDatasetType.put(datasetName, datasetType); String databaseNameTmp = templateNameToDatabaseNameMap.get(templateName); if (null == databaseNameTmp) { templateNameToDatabaseNameMap.put(templateName, databaseName); } else { MyUtils.checkStatusProgram(databaseNameTmp.equals(databaseName)); } } this.preparedStatementDatabase.close(); resultSet.close(); disconnect(); MyUtils.checkStatusProgram( this.databaseNameToDatasetInformationMap.get(databaseName) == null); this.databaseNameToDatasetInformationMap.put(databaseName, map); MyUtils.writeSerializedObject( this.databaseNameToDatasetInformationMap, databaseMapSerialFilePathAndName); // MyUtils.writeSerializedObject(this.datasetNameToDatabaseNameMap, // datasetMapSerialFilePathAndName); MyUtils.writeSerializedObject( this.templateNameToDatabaseNameMap, templateMapSerialFilePathAndName); MyUtils.writeSerializedObject( this.datasetNameToTemplateName, datasetMapSerialFilePathAndName); MyUtils.writeSerializedObject( this.datasetNameToDatasetType, datasetMap2SerialFilePathAndName); } } System.out.println(databaseNameToDatasetInformationMap); } catch (SQLException e) { throw new TechnicalException(e); } }