Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / test / jalview / util / ImageMakerTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.util;
22
23 import org.testng.Assert;
24 import org.testng.annotations.Test;
25
26 import jalview.bin.Cache;
27 import jalview.util.imagemaker.BitmapImageSizing;
28
29 public class ImageMakerTest
30 {
31   @Test(groups = { "Functional" })
32   public void testParseScaleWidthHeightStrings()
33   {
34     Cache.setPropsAreReadOnly(true);
35     Cache.loadProperties("test/jalview/bin/testProps.jvprops");
36
37     Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE);
38     Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT);
39     Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
40
41     BitmapImageSizing bis = null;
42
43     // No defaults set, 3 values given. Should be the 3 values.
44     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
45     Assert.assertEquals(bis.scale(), 1.2f,
46             "scale not parsed and set to value given");
47     Assert.assertEquals(bis.width(), 3,
48             "width not parsed and set to value given");
49     Assert.assertEquals(bis.height(), 4,
50             "height not parsed and set to value given");
51
52     // No defaults set, 1 value given. Should be the 1 value and 2 0s.
53     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
54     Assert.assertEquals(bis.scale(), 1.2f,
55             "scale not parsed and set to value given");
56     Assert.assertEquals(bis.width(), 0, "width not parsed and set to 0");
57     Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
58
59     // No defaults set, 1 value given. Should be the 1 value and 2 0s. (checking
60     // the other value)
61     bis = ImageMaker.parseScaleWidthHeightStrings(null, "1", null);
62     Assert.assertEquals(bis.scale(), 0f, "scale not parsed and set to 0f");
63     Assert.assertEquals(bis.width(), 1,
64             "width not parsed and set to value given");
65     Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0");
66
67     // No defaults set, no values given, these should first look at defaults and
68     // then set all to 0
69     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
70     Assert.assertEquals(bis.scale(), 0f,
71             "scale not parsed and set to undefined default 0f");
72     Assert.assertEquals(bis.width(), 0,
73             "width not parsed and set to undefined default 0");
74     Assert.assertEquals(bis.height(), 0,
75             "height not parsed and set to undefined default 0");
76
77     Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "1");
78     // 1 default set, bis should detect this
79     Assert.assertEquals(bis.scale(), 0f,
80             "scale not parsed and set to undefined default 0f");
81     Assert.assertEquals(bis.width(), 0,
82             "width not parsed and set to undefined default 0");
83     Assert.assertEquals(bis.height(), 1,
84             "height not parsed and set to default 1");
85
86     Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "3.4");
87     Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "2");
88     // Now all 3 defaults set, bis should detect this
89     Assert.assertEquals(bis.scale(), 3.4f,
90             "scale not parsed and set to undefined default 3.2f");
91     Assert.assertEquals(bis.width(), 2,
92             "width not parsed and set to undefined default 2");
93     Assert.assertEquals(bis.height(), 1,
94             "height not parsed and set to default 1");
95
96     // 3 defaults set, and 3 values given, should use the 3 values
97     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
98     Assert.assertEquals(bis.scale(), 1.2f,
99             "scale not parsed and set to value given");
100     Assert.assertEquals(bis.width(), 3,
101             "width not parsed and set to value given");
102     Assert.assertEquals(bis.height(), 4,
103             "height not parsed and set to value given");
104
105     // 3 defaults set, and 1 value given, should use the 1 value and 2 0s
106     bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
107     Assert.assertEquals(bis.scale(), 1.2f,
108             "scale not parsed and set to value given");
109     Assert.assertEquals(bis.width(), 0,
110             "width not parsed and set to undefined 0");
111     Assert.assertEquals(bis.height(), 0,
112             "height not parsed and set to undefined 0");
113
114     // 3 defaults set, and 1 value given, should use the 1 value and 2 0s
115     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, "5");
116     Assert.assertEquals(bis.scale(), 0f,
117             "scale not parsed and set to undefined 0f");
118     Assert.assertEquals(bis.width(), 0,
119             "width not parsed and set to undefined 0");
120     Assert.assertEquals(bis.height(), 5,
121             "height not parsed and set to value given");
122
123     // 3 defaults set, and no values given, should use the 3 default values
124     bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
125     Assert.assertEquals(bis.scale(), 3.4f,
126             "scale not parsed and set to undefined default 3.4f");
127     Assert.assertEquals(bis.width(), 2,
128             "width not parsed and set to undefined default 2");
129     Assert.assertEquals(bis.height(), 1,
130             "height not parsed and set to default 1");
131   }
132 }