EMMA Coverage Report (generated Sat Oct 08 11:41:37 CEST 2011)
[all classes][net.sf.jomic.tools]

COVERAGE SUMMARY FOR SOURCE FILE [ImageCacheTest.java]

nameclass, %method, %block, %line, %
ImageCacheTest.java100% (1/1)100% (6/6)93%  (201/215)99%  (48.3/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ImageCacheTest100% (1/1)100% (6/6)93%  (201/215)99%  (48.3/49)
testWithALotOfImages (): void 100% (1/1)84%  (71/85)95%  (12.3/13)
ImageCacheTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (20/20)100% (5/5)
tearDown (): void 100% (1/1)100% (9/9)100% (4/4)
testBigImageCache (): void 100% (1/1)100% (45/45)100% (12/12)
testSmallImageCache (): void 100% (1/1)100% (53/53)100% (14/14)

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/>.
16package net.sf.jomic.tools;
17 
18import java.awt.image.RenderedImage;
19import java.io.File;
20import java.io.IOException;
21 
22import org.apache.commons.logging.Log;
23import org.apache.commons.logging.LogFactory;
24 
25import junit.framework.TestCase;
26 
27/**
28 *  TestCase for ImageCache.
29 *
30 * @author    Thomas Aglassinger
31 */
32public class ImageCacheTest extends TestCase
33{
34    private FileTools fileTools;
35    private Log logger;
36    private TestTools testTools;
37 
38    protected void setUp()
39        throws Exception {
40        super.setUp();
41        testTools = TestTools.instance();
42        fileTools = FileTools.instance();
43        logger = LogFactory.getLog(ImageCacheTest.class);
44    }
45 
46    public void testBigImageCache()
47        throws IOException {
48        ImageCache cache = new ImageCache("big", Integer.MAX_VALUE);
49        File imageFile1 = testTools.getTestGeneratedInputFile("01.png");
50        File imageFile2 = testTools.getTestGeneratedInputFile("02.png");
51        RenderedImage image1 = cache.get(imageFile1);
52 
53        assertNotNull(image1);
54        assertEquals(1, cache.getEntryCount());
55 
56        RenderedImage image2 = cache.get(imageFile2);
57 
58        assertNotNull(image2);
59        assertEquals(2, cache.getEntryCount());
60        assertTrue(cache.has(imageFile1));
61        assertTrue(cache.has(imageFile2));
62    }
63 
64    public void testSmallImageCache()
65        throws IOException {
66        ImageCache cache = new ImageCache("small", 1);
67        File imageFile1 = testTools.getTestGeneratedInputFile("01.png");
68        File imageFile2 = testTools.getTestGeneratedInputFile("02.png");
69        RenderedImage image1 = cache.get(imageFile1);
70 
71        assertNotNull(image1);
72        assertEquals(1, cache.getEntryCount());
73        assertTrue(cache.has(imageFile1));
74        assertFalse(cache.has(imageFile2));
75 
76        RenderedImage image2 = cache.get(imageFile2);
77 
78        assertNotNull(image2);
79        assertEquals(1, cache.getEntryCount());
80        assertFalse(cache.has(imageFile1));
81        assertTrue(cache.has(imageFile2));
82    }
83 
84    public void testWithALotOfImages()
85        throws IOException {
86        ImageCache cache = new ImageCache("testWithALotOfImages",
87                Runtime.getRuntime().maxMemory() * 1 / 4);
88        File imageFile = testTools.getTestImageFile();
89        File tempDir = File.createTempFile(ImageCacheTest.class.getName(),
90                ".tmp");
91 
92        fileTools.delete(tempDir);
93        fileTools.mkdirs(tempDir);
94        try {
95            for (int index = 0; index < 1000; index += 1) {
96                String nextName = Integer.toString(index) + ".png";
97                File nextFile = new File(tempDir, nextName);
98 
99                fileTools.copyFile(imageFile, nextFile);
100                cache.get(nextFile);
101            }
102        } finally {
103            fileTools.attemptToDeleteAll(tempDir, logger);
104        }
105    }
106 
107    protected void tearDown()
108        throws Exception {
109        fileTools = null;
110        testTools = null;
111        super.tearDown();
112    }
113}

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