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

COVERAGE SUMMARY FOR SOURCE FILE [ProgressFrameTest.java]

nameclass, %method, %block, %line, %
ProgressFrameTest.java100% (1/1)100% (5/5)92%  (147/160)93%  (29.8/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProgressFrameTest100% (1/1)100% (5/5)92%  (147/160)93%  (29.8/32)
testProgress (): void 100% (1/1)88%  (89/101)89%  (17.8/20)
setUp (): void 100% (1/1)94%  (16/17)99%  (3.9/4)
ProgressFrameTest (): void 100% (1/1)100% (3/3)100% (1/1)
computeComplicatedStuff (): void 100% (1/1)100% (4/4)100% (2/2)
delay (boolean): void 100% (1/1)100% (35/35)100% (5/5)

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.ui;
17 
18import junit.framework.TestCase;
19import net.sf.wraplog.Logger;
20import net.sf.jomic.tools.ProgressFrame;
21import net.sf.jomic.tools.TestTools;
22 
23/**
24 *  TestCase for ProgressFrame.
25 *
26 * @author    Thomas Aglassinger
27 */
28public class ProgressFrameTest extends TestCase
29{
30    private static final int MAXIMUM_DELAY = 5;
31    private static final long MAXIMUM_PROGRESS = Long.MAX_VALUE / 4;
32 
33    private Logger logger;
34    private ProgressFrame progressFrame;
35    private TestTools testTools;
36 
37    protected void setUp()
38        throws Exception {
39        super.setUp();
40        testTools = TestTools.instance();
41        logger = Logger.getLogger(ProgressFrameTest.class);
42    }
43 
44    public void testProgress() {
45        long increment = Math.max(MAXIMUM_PROGRESS / 32, 1);
46 
47        progressFrame = new ProgressFrame();
48        progressFrame.setTitle(ProgressFrameTest.class.getName());
49        progressFrame.setMaximum(MAXIMUM_PROGRESS);
50        for (int run = 0; run < 2; run += 1) {
51            progressFrame.reset();
52            progressFrame.setNote("Testing...");
53            progressFrame.setVisible(true);
54            delay(true);
55            for (long progress = 0; (!progressFrame.isCanceled())
56                    && (progress <= MAXIMUM_PROGRESS); progress += increment) {
57                progressFrame.setProgress(progress);
58                if (logger.isInfoEnabled()) {
59 
60                    logger.info("progress " + progress + "/"
61                            + MAXIMUM_PROGRESS);
62                }
63                computeComplicatedStuff();
64            }
65            if (progressFrame.isCanceled()) {
66                progressFrame.setNote("Canceling...");
67                delay(false);
68            }
69            progressFrame.dispose();
70        }
71    }
72 
73    private void computeComplicatedStuff() {
74        testTools.waitSomeTime();
75    }
76 
77    private void delay(boolean cancelable) {
78        for (int delay = 0; (!(cancelable && progressFrame.isCanceled()) && (delay <= MAXIMUM_DELAY)); delay += 1) {
79            if (logger.isInfoEnabled()) {
80                logger.info("delay " + delay + "/" + MAXIMUM_DELAY);
81            }
82            computeComplicatedStuff();
83        }
84    }
85}

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