source: trunk/tests/SWT/java/SWTTestCase.java@ 12

Last change on this file since 12 was 12, checked in by lpino, 18 years ago
  • Initial commit
File size: 2.5 KB
Line 
1/*
2 * SWTTestCase.java
3 */
4
5/*
6 * Copyright (c) 2002, 2004 EclipseOS2 Team.
7 * This file is made available under the terms of the Common Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/cpl-v10.html
10 */
11
12import java.io.PrintWriter;
13import java.io.StringWriter;
14
15import org.eclipse.swt.*;
16import org.eclipse.swt.widgets.*;
17import org.eclipse.swt.events.*;
18import org.eclipse.swt.graphics.*;
19
20/**
21 * Common SWT test case class. It overrides init() and done() methods of the
22 * base class to create and destroy the display. Also the overriden exec()
23 * method calls createTopShell() to create the top shell, initComponents()
24 * to initialize shell components and then opens the top shell and starts the
25 * main execution loop.
26 *
27 * Subclasses should normally override only the main() method to call go()
28 * as described in the TestCase class, and the initComponents() method to
29 * create necessary widgets besides the top shell, register necessary
30 * listeners and do other stuff as required by the testcase.
31 *
32 * By default initComponents() simply calls the setTitle() method. setTitle()
33 * (which is not intended to be subclassed) can be used by subclasses to set
34 * the current title of the top shell widget, which is composed of the test
35 * description string returned by the getFullName() and the argument of the
36 * setTitle() method. Default initComponents() implementation calls setTitle()
37 * with null argument, which means that only the string returned by
38 * getFullName() is set as the widget title.
39 */
40
41public class SWTTestCase extends TestCase {
42
43static {
44 PART = "SWT";
45}
46
47Display display;
48Shell shell;
49
50public static void main (String [] args) {
51 go (new SWTTestCase ());
52}
53
54protected void init () {
55 display = new Display ();
56}
57
58protected void done () {
59 display.dispose ();
60}
61
62protected void exec () {
63 shell = createTopShell (display);
64 initComponents ();
65 shell.open ();
66 while (!shell.isDisposed ()) {
67 if (!display.readAndDispatch ()) display.sleep ();
68 }
69}
70
71Shell createTopShell (Display display) {
72 return new Shell (display);
73}
74
75void initComponents() {
76 String t = shell.getText();
77 if (t == null || t.length() == 0) setTitle (null);
78}
79
80void setTitle (String title) {
81 String t = getFullName();
82 if (title != null) {
83 t += " [" + title + "]";
84 sayObjective (title);
85 }
86 shell.setText (t);
87}
88
89}
90
Note: See TracBrowser for help on using the repository browser.