Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.util

File ImageMakerTest.java

 

Code metrics

0
47
1
1
132
85
1
0.02
47
1
1

Classes

Class Line # Actions
ImageMakerTest 29 47 1
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

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  1 toggle @Test(groups = { "Functional" })
32    public void testParseScaleWidthHeightStrings()
33    {
34  1 Cache.setPropsAreReadOnly(true);
35  1 Cache.loadProperties("test/jalview/bin/testProps.jvprops");
36   
37  1 Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE);
38  1 Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT);
39  1 Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
40   
41  1 BitmapImageSizing bis = null;
42   
43    // No defaults set, 3 values given. Should be the 3 values.
44  1 bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
45  1 Assert.assertEquals(bis.scale(), 1.2f,
46    "scale not parsed and set to value given");
47  1 Assert.assertEquals(bis.width(), 3,
48    "width not parsed and set to value given");
49  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
54  1 Assert.assertEquals(bis.scale(), 1.2f,
55    "scale not parsed and set to value given");
56  1 Assert.assertEquals(bis.width(), 0, "width not parsed and set to 0");
57  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings(null, "1", null);
62  1 Assert.assertEquals(bis.scale(), 0f, "scale not parsed and set to 0f");
63  1 Assert.assertEquals(bis.width(), 1,
64    "width not parsed and set to value given");
65  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
70  1 Assert.assertEquals(bis.scale(), 0f,
71    "scale not parsed and set to undefined default 0f");
72  1 Assert.assertEquals(bis.width(), 0,
73    "width not parsed and set to undefined default 0");
74  1 Assert.assertEquals(bis.height(), 0,
75    "height not parsed and set to undefined default 0");
76   
77  1 Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "1");
78    // 1 default set, bis should detect this
79  1 Assert.assertEquals(bis.scale(), 0f,
80    "scale not parsed and set to undefined default 0f");
81  1 Assert.assertEquals(bis.width(), 0,
82    "width not parsed and set to undefined default 0");
83  1 Assert.assertEquals(bis.height(), 1,
84    "height not parsed and set to default 1");
85   
86  1 Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "3.4");
87  1 Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "2");
88    // Now all 3 defaults set, bis should detect this
89  1 Assert.assertEquals(bis.scale(), 3.4f,
90    "scale not parsed and set to undefined default 3.2f");
91  1 Assert.assertEquals(bis.width(), 2,
92    "width not parsed and set to undefined default 2");
93  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4");
98  1 Assert.assertEquals(bis.scale(), 1.2f,
99    "scale not parsed and set to value given");
100  1 Assert.assertEquals(bis.width(), 3,
101    "width not parsed and set to value given");
102  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null);
107  1 Assert.assertEquals(bis.scale(), 1.2f,
108    "scale not parsed and set to value given");
109  1 Assert.assertEquals(bis.width(), 0,
110    "width not parsed and set to undefined 0");
111  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings(null, null, "5");
116  1 Assert.assertEquals(bis.scale(), 0f,
117    "scale not parsed and set to undefined 0f");
118  1 Assert.assertEquals(bis.width(), 0,
119    "width not parsed and set to undefined 0");
120  1 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  1 bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null);
125  1 Assert.assertEquals(bis.scale(), 3.4f,
126    "scale not parsed and set to undefined default 3.4f");
127  1 Assert.assertEquals(bis.width(), 2,
128    "width not parsed and set to undefined default 2");
129  1 Assert.assertEquals(bis.height(), 1,
130    "height not parsed and set to default 1");
131    }
132    }