1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: TestAWTUtilities.java,v 1.4 2002/09/12 19:09:36 ludovicc Exp $
37 */
38 package test.view.awt;
39
40 import java.awt.*;
41 import junit.framework.TestCase;
42 import org.scopemvc.controller.basic.BasicController;
43 import org.scopemvc.core.*;
44
45 import org.scopemvc.view.awt.*;
46 import org.scopemvc.view.swing.SwingView;
47
48 /***
49 * <P>
50 *
51 * </P>
52 *
53 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>Steve Meyfroidt</A>
54 * @created 05 September 2002
55 * @version $Revision: 1.4 $ $Date: 2002/09/12 19:09:36 $
56 */
57 public final class TestAWTUtilities extends TestCase {
58
59 private Dimension screenDimension;
60 private Frame dummyFrame;
61
62
63 /***
64 * Constructor for the TestAWTUtilities object
65 *
66 * @param inName Name of the test
67 */
68 public TestAWTUtilities(String inName) {
69 super(inName);
70 }
71
72
73 /***
74 * A unit test for JUnit
75 *
76 * @throws Exception Any abnormal exception
77 */
78 public void testFindControlIssuer() throws Exception {
79 assertNull(AWTUtilities.findControlIssuer(null));
80
81 org.scopemvc.view.swing.SPanel v = new org.scopemvc.view.swing.SPanel();
82 assertNull(AWTUtilities.findControlIssuer(v));
83
84 Controller c = new DummyController();
85 v.setController(c);
86 assertSame(v, AWTUtilities.findControlIssuer(v));
87
88 org.scopemvc.view.swing.SPanel v2 = new org.scopemvc.view.swing.SPanel();
89 v.add(v2);
90
91 assertSame(v, AWTUtilities.findControlIssuer(v2));
92
93 v.setController(null);
94 assertNull(AWTUtilities.findControlIssuer(v));
95 }
96
97
98 /***
99 * A unit test for JUnit
100 *
101 * @throws Exception Any abnormal exception
102 */
103 public void testCentreOnScreen() throws Exception {
104 Window w = new Window(dummyFrame);
105 w.setBounds(0, 0, 100, 50);
106 AWTUtilities.centreOnScreen(w);
107
108 Rectangle r = w.getBounds();
109 assertTrue(Math.abs(screenDimension.width - (r.x + r.width) - r.x) <= 1);
110 // rounding error if odd width
111 assertTrue(Math.abs(screenDimension.height - (r.y + r.height) - r.y) <= 1);
112 // rounding error if odd height
113 }
114
115
116 /***
117 * A unit test for JUnit
118 *
119 * @throws Exception Any abnormal exception
120 */
121 public void testCentreOnWindow() throws Exception {
122 Window w1 = new Window(dummyFrame);
123 w1.setBounds(10, 10, 100, 60);
124 Window w2 = new Window(dummyFrame);
125 w2.setBounds(10, 10, 50, 30);
126
127 AWTUtilities.centreOnWindow(w1, w2);
128 Rectangle r1 = w1.getBounds();
129 Rectangle r2 = w2.getBounds();
130
131 assertTrue(r1.x == 10);
132 assertTrue(r1.y == 10);
133 assertTrue(r1.width == 100);
134 assertTrue(r1.height == 60);
135
136 assertTrue(r2.x == 25);
137 assertTrue(r2.y == 15);
138 assertTrue(r2.width == 50);
139 assertTrue(r2.height == 30);
140 }
141
142
143 /***
144 * The JUnit setup method
145 *
146 * @throws Exception Any abnormal exception
147 */
148 protected void setUp() throws Exception {
149 dummyFrame = new Frame("TestAWTUtilities");
150 dummyFrame.setVisible(true);
151 screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
152 }
153
154
155 /***
156 * The teardown method for JUnit
157 *
158 * @throws Exception Any abnormal exception
159 */
160 protected void tearDown() throws Exception {
161 dummyFrame.setVisible(false);
162 }
163
164
165 // ***** Need test for fitOnScreen()
166
167 static class DummyController extends BasicController {
168 }
169 }
170
This page was automatically generated by Maven