--- /dev/null
+package jalview.util;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import jalview.bin.Cache;
+import jalview.util.imagemaker.BitmapImageSizing;
+
+public class ImageMakerTest
+{
+ @Test(groups = { "Functional" })
+ public void testParseScaleWidthHeightStrings()
+ {
+ Cache.setPropsAreReadOnly(true);
+ Cache.loadProperties("test/jalview/bin/testProps.jvprops");
+
+ Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE);
+ Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT);
+ Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
+
+ BitmapImageSizing bis = null;
+
+ bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
+ Assert.assertEquals(bis.scale(), 1.2f,
+ "scale not parsed and set to value given");
+ Assert.assertEquals(bis.width(), 3,
+ "width not parsed and set to value given");
+ Assert.assertEquals(bis.height(), 4,
+ "height not parsed and set to value given");
+
+ bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
+ Assert.assertEquals(bis.scale(), 1.2f,
+ "scale not parsed and set to value given");
+ Assert.assertEquals(bis.width(), 0, "width not parsed and set to 0");
+ Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
+
+ bis = ImageMaker.parseScaleWidthHeightStrings(null, "1", null);
+ Assert.assertEquals(bis.scale(), 0f, "scale not parsed and set to 0f");
+ Assert.assertEquals(bis.width(), 1,
+ "width not parsed and set to value given");
+ Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
+
+ // this should set bis to the dynamic defaultBitmapImageSizing
+ bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
+ Assert.assertEquals(bis.scale(), 0f,
+ "scale not parsed and set to undefined default 0f");
+ Assert.assertEquals(bis.width(), 0,
+ "width not parsed and set to undefined default 0");
+ Assert.assertEquals(bis.height(), 0,
+ "height not parsed and set to undefined default 0");
+
+ Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "1");
+ Assert.assertEquals(bis.scale(), 0f,
+ "scale not parsed and set to undefined default 0f");
+ Assert.assertEquals(bis.width(), 0,
+ "width not parsed and set to undefined default 0");
+ Assert.assertEquals(bis.height(), 1,
+ "height not parsed and set to default 1");
+
+ Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "3.4");
+ Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "2");
+ Assert.assertEquals(bis.scale(), 3.4f,
+ "scale not parsed and set to undefined default 3.2f");
+ Assert.assertEquals(bis.width(), 2,
+ "width not parsed and set to undefined default 2");
+ Assert.assertEquals(bis.height(), 1,
+ "height not parsed and set to default 1");
+
+ // override actual default values
+ bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
+ Assert.assertEquals(bis.scale(), 1.2f,
+ "scale not parsed and set to value given");
+ Assert.assertEquals(bis.width(), 3,
+ "width not parsed and set to value given");
+ Assert.assertEquals(bis.height(), 4,
+ "height not parsed and set to value given");
+
+ bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
+ Assert.assertEquals(bis.scale(), 1.2f,
+ "scale not parsed and set to value given");
+ Assert.assertEquals(bis.width(), 0,
+ "width not parsed and set to undefined 0");
+ Assert.assertEquals(bis.height(), 0,
+ "height not parsed and set to undefined 0");
+
+ bis = ImageMaker.parseScaleWidthHeightStrings(null, null, "5");
+ Assert.assertEquals(bis.scale(), 0f,
+ "scale not parsed and set to undefined 0f");
+ Assert.assertEquals(bis.width(), 0,
+ "width not parsed and set to undefined 0");
+ Assert.assertEquals(bis.height(), 5,
+ "height not parsed and set to value given");
+
+ bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
+ Assert.assertEquals(bis.scale(), 3.4f,
+ "scale not parsed and set to undefined default 3.2f");
+ Assert.assertEquals(bis.width(), 2,
+ "width not parsed and set to undefined default 2");
+ Assert.assertEquals(bis.height(), 1,
+ "height not parsed and set to default 1");
+ }
+}