EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.comic]

COVERAGE SUMMARY FOR SOURCE FILE [ConvertComicTaskTest.java]

nameclass, %method, %block, %line, %
ConvertComicTaskTest.java100% (1/1)100% (7/7)86%  (323/377)96%  (72.1/75)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ConvertComicTaskTest100% (1/1)100% (7/7)86%  (323/377)96%  (72.1/75)
testConvertNothingToNotYetExistentFolder (): void 100% (1/1)79%  (82/104)93%  (17.7/19)
testConvertPngToJpeg (): void 100% (1/1)86%  (131/153)96%  (27.7/29)
testConvertCbzToPdf (): void 100% (1/1)86%  (64/74)98%  (13.7/14)
ConvertComicTaskTest (): void 100% (1/1)100% (3/3)100% (1/1)
progressChanged (Task): void 100% (1/1)100% (6/6)100% (2/2)
setUp (): void 100% (1/1)100% (31/31)100% (7/7)
tearDown (): void 100% (1/1)100% (6/6)100% (3/3)

1// Jomic - a viewer for comic book archives.
2// Copyright (C) 2004-2008 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/>.
16package net.sf.jomic.comic;
17 
18import java.io.File;
19 
20import junit.framework.TestCase;
21import net.sf.jomic.tools.FileArchive;
22import net.sf.jomic.tools.FileTools;
23import net.sf.jomic.tools.ProgressChangeListener;
24import net.sf.jomic.tools.ProgressFrame;
25import net.sf.jomic.tools.Task;
26import net.sf.jomic.tools.TestTools;
27import net.sf.wraplog.Logger;
28 
29/**
30 *  TestCase for ConvertComicTask.
31 *
32 * @author    Thomas Aglassinger
33 */
34public class ConvertComicTaskTest extends TestCase implements ProgressChangeListener
35{
36    private static final String SUFFIX_TO_GET_RID_OF = ".png";
37    private FileTools fileTools;
38    private Logger logger;
39    private ProgressFrame progressFrame;
40    private TestTools testTools;
41 
42    protected void setUp()
43        throws Exception {
44        super.setUp();
45        testTools = TestTools.instance();
46        fileTools = FileTools.instance();
47        logger = Logger.getLogger(ConvertComicTaskTest.class);
48        progressFrame = new ProgressFrame();
49        progressFrame.setTitle(getClass().getName());
50    }
51 
52    public void progressChanged(Task source) {
53        progressFrame.setProgress(source.getProgress());
54    }
55 
56    public void testConvertCbzToPdf()
57        throws Exception {
58        String methodName = "testConvertCbzToPdf";
59        File sourceComicFile = testTools.getTestFile(TestTools.TEST_COMIC_CBZ);
60        File targetComicFile = testTools.getTestOutputFile(getClass().getName() + "." + methodName + ".pdf");
61        Conversion conversion = new Conversion(Conversion.COMIC_FORMAT_PDF);
62        final Task convertCbzToPdfTask = new ConvertComicTask(sourceComicFile, targetComicFile, conversion);
63 
64        convertCbzToPdfTask.addProgressChangeListener(this);
65        progressFrame.setMaximum(convertCbzToPdfTask.getMaxProgress());
66        progressFrame.setNote(methodName);
67        progressFrame.setVisible(true);
68        try {
69            convertCbzToPdfTask.start();
70        } finally {
71            convertCbzToPdfTask.removeProgressChangeListener(this);
72            progressFrame.setVisible(false);
73        }
74    }
75 
76    public void testConvertNothingToNotYetExistentFolder()
77        throws Exception {
78        String methodName = "testConvertNothing";
79        File sourceComicFile = testTools.getTestFile(TestTools.TEST_COMIC_CBZ);
80        File targetComicFolder = testTools.getTestOutputFile("newSubFolder");
81 
82        if (targetComicFolder.exists()) {
83            fileTools.attemptToDeleteAll(targetComicFolder, logger);
84            if (targetComicFolder.exists()) {
85                throw new IllegalStateException("supposedly non-existent folder must be removed: " + targetComicFolder);
86            }
87        }
88        File targetComicFile = new File(targetComicFolder, getClass().getName() + "." + methodName + ".cbz");
89        Conversion conversion = new Conversion(Conversion.COMIC_FORMAT_CBZ);
90        final Task convertNothingTask = new ConvertComicTask(sourceComicFile, targetComicFile, conversion);
91 
92        convertNothingTask.addProgressChangeListener(this);
93        progressFrame.setMaximum(convertNothingTask.getMaxProgress());
94        progressFrame.setNote(methodName);
95        progressFrame.setVisible(true);
96        try {
97            convertNothingTask.start();
98        } finally {
99            convertNothingTask.removeProgressChangeListener(this);
100            progressFrame.setVisible(false);
101        }
102    }
103 
104    public void testConvertPngToJpeg()
105        throws Exception {
106        String methodName = "testConvertPngToJpeg";
107        File sourceComicFile = testTools.getTestFile(TestTools.TEST_COMIC_CBZ);
108 
109        // Make sure the test comic contains at least one PNG image.
110        FileArchive sourceZipArchiv = new FileArchive(sourceComicFile);
111        String[] sourceImageFileNames = sourceZipArchiv.list();
112        boolean hasPng = false;
113 
114        for (int i = 0; !hasPng && (i < sourceImageFileNames.length); i += 1) {
115            String imageName = sourceImageFileNames[i];
116 
117            if (imageName.endsWith(SUFFIX_TO_GET_RID_OF)) {
118                hasPng = true;
119            }
120        }
121        if (!hasPng) {
122            throw new IllegalArgumentException(
123                    "comic must contain at least one image file ending in \""
124                    + SUFFIX_TO_GET_RID_OF + "\": " + sourceComicFile);
125        }
126 
127        File targetComicFile = testTools.getTestOutputFile(getClass().getName() + "." + methodName + ".cbz");
128        Conversion conversion = new Conversion(Conversion.COMIC_FORMAT_CBZ);
129 
130        conversion.setImageFormat(Conversion.IMAGE_FORMAT_JFIF);
131 
132        final Task convertPngToJpegTask = new ConvertComicTask(sourceComicFile, targetComicFile, conversion);
133 
134        convertPngToJpegTask.addProgressChangeListener(this);
135        progressFrame.setMaximum(convertPngToJpegTask.getMaxProgress());
136        progressFrame.setNote(methodName);
137        progressFrame.setVisible(true);
138        try {
139            convertPngToJpegTask.start();
140        } finally {
141            convertPngToJpegTask.removeProgressChangeListener(this);
142            progressFrame.setVisible(false);
143        }
144 
145        // Assert that there are no more PNG images in the created comic.
146        FileArchive zipArchiv = new FileArchive(targetComicFile);
147        String[] targetImageFileNames = zipArchiv.list();
148 
149        for (int i = 0; i < targetImageFileNames.length; i += 1) {
150            String imageName = targetImageFileNames[i];
151 
152            assertFalse("image must not have suffix \"" + SUFFIX_TO_GET_RID_OF + "\": " + imageName,
153                    imageName.endsWith(SUFFIX_TO_GET_RID_OF));
154        }
155    }
156 
157    protected void tearDown()
158        throws Exception {
159        progressFrame.dispose();
160        super.tearDown();
161    }
162}

[all classes][net.sf.jomic.comic]
EMMA 2.0.4217 (C) Vladimir Roubtsov