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

COVERAGE SUMMARY FOR SOURCE FILE [ComicViewTest.java]

nameclass, %method, %block, %line, %
ComicViewTest.java100% (1/1)100% (11/11)88%  (392/446)96%  (100.4/105)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComicViewTest100% (1/1)100% (11/11)88%  (392/446)96%  (100.4/105)
testCreate (): void 100% (1/1)71%  (25/35)91%  (8.2/9)
testCopyToClipboard (): void 100% (1/1)73%  (69/94)89%  (17.8/20)
setUp (): void 100% (1/1)75%  (15/20)95%  (4.8/5)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
testPageMode (boolean): void 100% (1/1)92%  (54/59)96%  (14.4/15)
testGetPageText (): void 100% (1/1)96%  (151/157)98%  (32.4/33)
ComicViewTest (): void 100% (1/1)100% (3/3)100% (1/1)
tearDown (): void 100% (1/1)100% (9/9)100% (4/4)
testGetPageText (ComicView, boolean, boolean, boolean): void 100% (1/1)100% (46/46)100% (14/14)
testSinglePageMode (): void 100% (1/1)100% (4/4)100% (2/2)
testTwoPageMode (): void 100% (1/1)100% (4/4)100% (2/2)

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.comic;
17 
18import java.awt.Dimension;
19import java.awt.Image;
20import java.awt.Toolkit;
21import java.awt.datatransfer.Clipboard;
22import java.awt.datatransfer.DataFlavor;
23import java.awt.datatransfer.Transferable;
24import java.awt.datatransfer.UnsupportedFlavorException;
25import java.awt.image.RenderedImage;
26import java.io.IOException;
27 
28import javax.swing.JScrollPane;
29import javax.swing.TransferHandler;
30 
31import junit.extensions.abbot.ComponentTestFixture;
32import net.sf.jomic.jaiunit.Tools;
33import net.sf.jomic.tools.TestTools;
34import org.apache.commons.logging.Log;
35import org.apache.commons.logging.LogFactory;
36 
37/**
38 *  TestCase for ComicView.
39 *
40 * @author    Thomas Aglassinger
41 */
42public class ComicViewTest extends ComponentTestFixture
43{
44    private Log logger;
45    private TestTools testTools;
46 
47    protected void setUp()
48        throws Exception {
49        super.setUp();
50        testTools = TestTools.instance();
51        testTools.setupCache();
52        logger = LogFactory.getLog(ComicViewTest.class);
53    }
54 
55    public void testCopyToClipboard()
56        throws IOException, InterruptedException, UnsupportedFlavorException {
57        ComicModel model = new ComicModel(testTools.getTestFile(TestTools.SINGLE_PAGE_COMIC));
58 
59        try {
60            ComicView view = new ComicView();
61 
62            try {
63                view.setModel(model, null);
64                showFrame(view);
65 
66                ComicViewTransferHandler handler = new ComicViewTransferHandler();
67                Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
68 
69                handler.exportToClipboard(view, systemClipboard, TransferHandler.COPY);
70 
71                Transferable transferable = systemClipboard.getContents(null);
72 
73                if (logger.isDebugEnabled()) {
74                    logger.debug("transferable = " + transferable);
75                }
76                Image image = (Image) transferable.getTransferData(DataFlavor.imageFlavor);
77 
78                assertNotNull("image", image);
79                assert image instanceof RenderedImage;
80                Tools jaiTools = Tools.instance();
81 
82                jaiTools.imagesAreEqual(view.getRenderedImage(), (RenderedImage) image);
83            } finally {
84                view.dispose();
85            }
86        } finally {
87            model.dispose();
88        }
89    }
90 
91    public void testCreate()
92        throws Exception {
93        ComicModel model = new ComicModel(testTools.getTestComicFile());
94 
95        try {
96            ComicView view = new ComicView();
97 
98            try {
99                view.setTwoPageMode(false);
100                view.setModel(model, null);
101            } finally {
102                view.dispose();
103            }
104        } finally {
105            model.dispose();
106        }
107    }
108 
109    public void testGetPageText()
110        throws IOException, InterruptedException {
111        ComicModel model = new ComicModel(testTools.getTestComicFile());
112 
113        try {
114            boolean doublePageTested = false;
115            boolean twoImagesTested = false;
116            boolean singlePageAndImageTested = false;
117            ComicView view = new ComicView();
118 
119            view.setTwoPageMode(false);
120            view.setModel(model, null);
121            logger.info("start");
122            while (!(view.isLast() && doublePageTested && singlePageAndImageTested && twoImagesTested)) {
123                int currentSheetIndex = view.getCurrentSheetIndex();
124                ComicSheet sheet = view.getSheet(currentSheetIndex);
125                boolean isLandscapeImage = view.getComicImage(sheet.getLeftImageIndex()).isDoublePage();
126                boolean hasTwoImages = sheet.hasRightImage();
127 
128                logger.info("sheet=" + currentSheetIndex + ", isLandscape=" + isLandscapeImage
129                        + ", hasTwoImages=" + hasTwoImages);
130                if (isLandscapeImage) {
131                    if (!doublePageTested) {
132                        testGetPageText(view, false, false, true);
133                        doublePageTested = true;
134                    }
135                } else if (hasTwoImages) {
136                    if (!twoImagesTested) {
137                        testGetPageText(view, true, false, false);
138                        twoImagesTested = true;
139                    }
140                } else {
141                    if (!singlePageAndImageTested) {
142                        testGetPageText(view, true, true, true);
143                        singlePageAndImageTested = true;
144                    }
145                }
146                view.setTwoPageMode(true);
147                view.goNext();
148                logger.info("isLast=" + view.isLast() + ", dpT=" + doublePageTested
149                        + ", spT=" + singlePageAndImageTested + ", tiT=" + twoImagesTested);
150            }
151 
152            assertTrue(doublePageTested && singlePageAndImageTested && twoImagesTested);
153        } finally {
154            model.dispose();
155        }
156    }
157 
158    public void testSinglePageMode()
159        throws Exception {
160        testPageMode(false);
161    }
162 
163    public void testTwoPageMode()
164        throws Exception {
165        testPageMode(true);
166    }
167 
168    protected void tearDown()
169        throws Exception {
170        testTools = null;
171        logger = null;
172        super.tearDown();
173    }
174 
175    private void testGetPageText(ComicView view,
176            boolean noTwoPageEqualsIndependantOfRightFromLeft,
177            boolean twoPageEqualsIndependantOfRightFromLeft,
178            boolean twoPageEqualsSinglePage) {
179        view.setTwoPageMode(false);
180        view.setSwapLeftAndRightImage(false);
181 
182        String singleModeText = view.getPageText();
183 
184        view.setSwapLeftAndRightImage(true);
185 
186        String singleModeFromRightToLeftText = view.getPageText();
187 
188        assertEquals(noTwoPageEqualsIndependantOfRightFromLeft,
189                singleModeText.equals(singleModeFromRightToLeftText));
190        view.setTwoPageMode(true);
191        view.setSwapLeftAndRightImage(false);
192 
193        String doubleModeText = view.getPageText();
194 
195        assertEquals(twoPageEqualsSinglePage, singleModeText.equals(doubleModeText));
196        view.setSwapLeftAndRightImage(true);
197 
198        String doubleModeFromRightToLeftText = view.getPageText();
199 
200        assertEquals(twoPageEqualsIndependantOfRightFromLeft,
201                doubleModeText.equals(doubleModeFromRightToLeftText));
202    }
203 
204    private void testPageMode(boolean mode)
205        throws Exception {
206        ComicModel model = new ComicModel(testTools.getTestComicFile());
207        ComicView view = new ComicView();
208 
209        try {
210            JScrollPane scrollPane = new JScrollPane(view);
211 
212            showFrame(scrollPane, new Dimension(TestTools.FRAME_WIDTH, TestTools.FRAME_HEIGHT));
213            view.setTwoPageMode(mode);
214            view.setModel(model, null);
215            while (!view.isLast()) {
216                view.goNext();
217                testTools.waitSomeTime();
218            }
219            while (!view.isFirst()) {
220                view.goPrevious();
221                testTools.waitSomeTime();
222            }
223        } finally {
224            model.dispose();
225        }
226    }
227}

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