acb41608c0ef68452101945ec2c0c0ecfc4c6cd3
[jalview.git] / test / jalview / util / ImageMakerTest.java
1 package jalview.util;
2
3 import org.testng.Assert;
4 import org.testng.annotations.Test;
5
6 import jalview.bin.Cache;
7 import jalview.util.imagemaker.BitmapImageSizing;
8
9 public class ImageMakerTest
10 {
11   @Test(groups = { "Functional" })
12   public void testParseScaleWidthHeightStrings()
13   {
14     Cache.setPropsAreReadOnly(true);
15     Cache.loadProperties("test/jalview/bin/testProps.jvprops");
16
17     Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE);
18     Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT);
19     Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
20
21     BitmapImageSizing bis = null;
22
23     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
24     Assert.assertEquals(bis.scale(), 1.2f,
25             "scale not parsed and set to value given");
26     Assert.assertEquals(bis.width(), 3,
27             "width not parsed and set to value given");
28     Assert.assertEquals(bis.height(), 4,
29             "height not parsed and set to value given");
30
31     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
32     Assert.assertEquals(bis.scale(), 1.2f,
33             "scale not parsed and set to value given");
34     Assert.assertEquals(bis.width(), 0, "width not parsed and set to 0");
35     Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
36
37     bis = ImageMaker.parseScaleWidthHeightStrings(null, "1", null);
38     Assert.assertEquals(bis.scale(), 0f, "scale not parsed and set to 0f");
39     Assert.assertEquals(bis.width(), 1,
40             "width not parsed and set to value given");
41     Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
42
43     // this should set bis to the dynamic defaultBitmapImageSizing
44     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
45     Assert.assertEquals(bis.scale(), 0f,
46             "scale not parsed and set to undefined default 0f");
47     Assert.assertEquals(bis.width(), 0,
48             "width not parsed and set to undefined default 0");
49     Assert.assertEquals(bis.height(), 0,
50             "height not parsed and set to undefined default 0");
51
52     Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "1");
53     Assert.assertEquals(bis.scale(), 0f,
54             "scale not parsed and set to undefined default 0f");
55     Assert.assertEquals(bis.width(), 0,
56             "width not parsed and set to undefined default 0");
57     Assert.assertEquals(bis.height(), 1,
58             "height not parsed and set to default 1");
59
60     Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "3.4");
61     Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "2");
62     Assert.assertEquals(bis.scale(), 3.4f,
63             "scale not parsed and set to undefined default 3.2f");
64     Assert.assertEquals(bis.width(), 2,
65             "width not parsed and set to undefined default 2");
66     Assert.assertEquals(bis.height(), 1,
67             "height not parsed and set to default 1");
68
69     // override actual default values
70     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
71     Assert.assertEquals(bis.scale(), 1.2f,
72             "scale not parsed and set to value given");
73     Assert.assertEquals(bis.width(), 3,
74             "width not parsed and set to value given");
75     Assert.assertEquals(bis.height(), 4,
76             "height not parsed and set to value given");
77
78     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
79     Assert.assertEquals(bis.scale(), 1.2f,
80             "scale not parsed and set to value given");
81     Assert.assertEquals(bis.width(), 0,
82             "width not parsed and set to undefined 0");
83     Assert.assertEquals(bis.height(), 0,
84             "height not parsed and set to undefined 0");
85
86     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, "5");
87     Assert.assertEquals(bis.scale(), 0f,
88             "scale not parsed and set to undefined 0f");
89     Assert.assertEquals(bis.width(), 0,
90             "width not parsed and set to undefined 0");
91     Assert.assertEquals(bis.height(), 5,
92             "height not parsed and set to value given");
93
94     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
95     Assert.assertEquals(bis.scale(), 3.4f,
96             "scale not parsed and set to undefined default 3.2f");
97     Assert.assertEquals(bis.width(), 2,
98             "width not parsed and set to undefined default 2");
99     Assert.assertEquals(bis.height(), 1,
100             "height not parsed and set to default 1");
101   }
102 }