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

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