From: Ben Soares Date: Wed, 13 Sep 2023 19:26:38 +0000 (+0100) Subject: JAL-4274 Tests for BIS defaults and overrides X-Git-Tag: Release_2_11_3_0~8^2~5^2~22 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1f1d99b50321fbf7d3f1bb5cce55d31bf7c86859;p=jalview.git JAL-4274 Tests for BIS defaults and overrides --- diff --git a/test/jalview/util/ImageMakerTest.java b/test/jalview/util/ImageMakerTest.java new file mode 100644 index 0000000..acb4160 --- /dev/null +++ b/test/jalview/util/ImageMakerTest.java @@ -0,0 +1,102 @@ +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"); + } +}