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.ui; |
17 | |
18 | import java.io.File; |
19 | |
20 | import javax.swing.JFrame; |
21 | |
22 | import junit.framework.TestCase; |
23 | import net.sf.jomic.comic.ComicFileFilter; |
24 | import net.sf.jomic.comic.Conversion; |
25 | import net.sf.jomic.tools.FileTools; |
26 | import net.sf.jomic.tools.TestTools; |
27 | |
28 | /** |
29 | * TestCase for ConvertWorker. |
30 | * |
31 | * @author Thomas Aglassinger |
32 | */ |
33 | public class ConvertWorkerTest extends TestCase |
34 | { |
35 | private FileTools fileTools; |
36 | private TestTools testTools; |
37 | |
38 | protected void setUp() |
39 | throws Exception { |
40 | super.setUp(); |
41 | testTools = TestTools.instance(); |
42 | fileTools = FileTools.instance(); |
43 | testTools.setupCache(); |
44 | } |
45 | |
46 | public void testConvertWorker() { |
47 | String targetFolderName = testTools.getTestFileName(ConvertWorkerTest.class, "testConvertWorker", null, null); |
48 | File targetFolder = testTools.getCleanTestOutputFolder(targetFolderName); |
49 | File[] sourceComics = new File[]{ |
50 | testTools.getTestFile(TestTools.THREE_PAGE_COMIC), |
51 | testTools.getTestFile(TestTools.TEST_MORONIC_NUMBERING_CBZ), |
52 | testTools.getTestFile(TestTools.TWO_PAGE_COMIC), |
53 | testTools.getTestFile(TestTools.SINGLE_PAGE_COMIC) |
54 | }; |
55 | Conversion conversion = new Conversion(); |
56 | ConvertWorker worker = new ConvertWorker(targetFolder, sourceComics, conversion); |
57 | |
58 | worker.start(); |
59 | |
60 | JFrame reportFrame = (JFrame) worker.get(); |
61 | |
62 | try { |
63 | File[] convertedFiles = targetFolder.listFiles(new ComicFileFilter()); |
64 | |
65 | assertEquals("number of converted comics", sourceComics.length, convertedFiles.length); |
66 | } finally { |
67 | reportFrame.dispose(); |
68 | } |
69 | } |
70 | |
71 | public void testPdfConvertWorker() { |
72 | String targetFolderName = testTools.getTestFileName( |
73 | ConvertWorkerTest.class, "testPdfConvertWorker", null, null); |
74 | File targetFolder = testTools.getCleanTestOutputFolder(targetFolderName); |
75 | File[] sourceComics = new File[]{ |
76 | testTools.getTestFile(TestTools.THREE_PAGE_COMIC), |
77 | testTools.getTestFile(TestTools.SINGLE_PAGE_COMIC) |
78 | }; |
79 | Conversion conversion = new Conversion(Conversion.COMIC_FORMAT_PDF); |
80 | ConvertWorker worker = new ConvertWorker(targetFolder, sourceComics, conversion); |
81 | |
82 | worker.start(); |
83 | worker.get(); |
84 | |
85 | File[] convertedFiles = targetFolder.listFiles(new ComicFileFilter()); |
86 | |
87 | assertEquals("number of converted comics", sourceComics.length, convertedFiles.length); |
88 | for (int i = 0; i < convertedFiles.length; i += 1) { |
89 | assertEquals("pdf", fileTools.getSuffix(convertedFiles[i])); |
90 | } |
91 | } |
92 | |
93 | protected void tearDown() |
94 | throws Exception { |
95 | fileTools = null; |
96 | testTools = null; |
97 | super.tearDown(); |
98 | } |
99 | } |