1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.comic; |
17 | |
18 | import java.awt.Dimension; |
19 | import java.io.File; |
20 | import java.io.IOException; |
21 | |
22 | import net.sf.jomic.tools.ImageInfo; |
23 | import net.sf.jomic.tools.ImageTools; |
24 | import net.sf.jomic.tools.TestTools; |
25 | import junit.framework.TestCase; |
26 | |
27 | /** |
28 | * TestCase for conversion. |
29 | * |
30 | * @author Thomas Aglassinger |
31 | */ |
32 | public class ConversionTest extends TestCase |
33 | { |
34 | private ImageTools imageTools; |
35 | private TestTools testTools; |
36 | |
37 | protected void setUp() |
38 | throws Exception { |
39 | super.setUp(); |
40 | testTools = TestTools.instance(); |
41 | imageTools = ImageTools.instance(); |
42 | } |
43 | |
44 | public void testCanExcludeThumbPages() { |
45 | Conversion conversion = new Conversion(); |
46 | File imageFile = testTools.getTestImageFile(); |
47 | ImageInfo imageInfo = new ImageInfo(imageFile); |
48 | int imageWidth = imageInfo.getWidth(); |
49 | int imageHeight = imageInfo.getHeight(); |
50 | |
51 | |
52 | conversion.setMaxThumbWidth(imageWidth); |
53 | conversion.setMaxThumbHeight(imageHeight); |
54 | conversion.setExcludeThumbPages(false); |
55 | assertTrue(conversion.isAddable(imageInfo)); |
56 | |
57 | conversion.setExcludeThumbPages(true); |
58 | assertFalse(conversion.isAddable(imageInfo)); |
59 | |
60 | conversion.setMaxThumbWidth(imageWidth - 1); |
61 | conversion.setMaxThumbHeight(imageHeight - 1); |
62 | assertTrue(conversion.isAddable(imageInfo)); |
63 | } |
64 | |
65 | public void testCanLimitSizeWithLandscape() |
66 | throws IOException { |
67 | testCanLimitImageSize(TestTools.TEST_IMAGE_LANDSCAPE_NAME); |
68 | } |
69 | |
70 | public void testCanLimitSizeWithPortrait() |
71 | throws IOException { |
72 | testCanLimitImageSize(TestTools.TEST_IMAGE_PORTRAIT_NAME); |
73 | } |
74 | |
75 | private void testCanLimitImageSize(String imageName) |
76 | throws IOException { |
77 | File imageFile = testTools.getTestFile(imageName); |
78 | Conversion conversion = new Conversion(); |
79 | Dimension imageSize = imageTools.getImageDimension(imageFile); |
80 | int imageWidth = imageSize.width; |
81 | int imageHeight = imageSize.height; |
82 | |
83 | if (imageTools.isLandscape(imageSize)) { |
84 | imageWidth = imageWidth / 2; |
85 | } |
86 | |
87 | conversion.setMaxImageWidth(imageWidth); |
88 | conversion.setMaxImageHeight(imageHeight); |
89 | assertFalse(conversion.isLimitImageSize()); |
90 | assertFalse(conversion.needsTrim(imageSize)); |
91 | |
92 | conversion.setLimitImageSize(true); |
93 | assertFalse(conversion.needsTrim(imageSize)); |
94 | |
95 | conversion.setMaxImageWidth(imageWidth - 1); |
96 | assertTrue(conversion.needsTrim(imageSize)); |
97 | |
98 | conversion.setMaxImageWidth(imageWidth); |
99 | conversion.setMaxImageHeight(imageHeight - 1); |
100 | assertTrue(conversion.needsTrim(imageSize)); |
101 | } |
102 | } |