2 * (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.test;
\r
15 import java.awt.Button;
\r
16 import java.awt.Frame;
\r
17 import java.awt.GridLayout;
\r
18 import java.awt.datatransfer.Clipboard;
\r
19 import java.awt.event.ActionEvent;
\r
20 import java.awt.event.ActionListener;
\r
21 import java.awt.event.WindowEvent;
\r
22 import java.awt.event.WindowAdapter;
\r
24 import java.util.Date;
\r
25 import java.text.DateFormat;
\r
27 import com.ibm.richtext.textpanel.MTextPanel;
\r
28 import com.ibm.richtext.awtui.TextFrame;
\r
30 public class ITestTextPanel extends Frame implements ActionListener {
\r
35 private static final long serialVersionUID = 4776220202735727574L;
\r
37 //static final String COPYRIGHT =
\r
38 // "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
39 private static long fgOpCount = 0;
\r
41 private TestTextPanel fTest;
\r
43 private MTextPanel fTextPanel;
\r
44 private Frame fTextFrame;
\r
45 private Clipboard fClipboard;
\r
46 private Button fExersize, fStressTest;
\r
48 public static void main(String[] args) {
\r
50 Date startDate = new Date();
\r
53 Clipboard clipboard = new Clipboard("ITextTestPanel");
\r
54 TextFrame frame = new TextFrame(null, "Interactive Test", clipboard);
\r
55 MTextPanel panel = frame.getTextPanel();
\r
57 new ITestTextPanel(panel, frame, clipboard).show();
\r
60 DateFormat df = DateFormat.getDateTimeInstance();
\r
61 System.out.println("Start time: " + df.format(startDate));
\r
62 System.out.println("End Time: " + df.format(new Date()));
\r
63 System.out.println("Op count: " + fgOpCount);
\r
67 public ITestTextPanel(MTextPanel panel,
\r
69 Clipboard clipboard) {
\r
72 fTest = new TestTextPanel(fTextPanel);
\r
73 fClipboard = clipboard;
\r
75 setLayout(new GridLayout(0, 1));
\r
78 fTextFrame.setSize(350, 500);
\r
82 fExersize = new Button("Exercise");
\r
83 fExersize.addActionListener(this);
\r
86 fStressTest = new Button("Stress Test");
\r
87 fStressTest.addActionListener(this);
\r
92 addWindowListener(new WindowAdapter() {
\r
93 public void windowActivated(WindowEvent e) {
\r
94 //activateTextFrame();
\r
96 public void windowClosing(WindowEvent e) {
\r
104 private void activateTextFrame() {
\r
106 fTextFrame.toFront();
\r
109 public void actionPerformed(ActionEvent event) {
\r
111 Object source = event.getSource();
\r
112 activateTextFrame();
\r
113 Date startDate = new Date();
\r
114 boolean exitedNormally = false;
\r
117 if (source == fExersize) {
\r
118 fTest.incRandSeed();
\r
119 for (int i=0; i < 100; i++) {
\r
120 selectOperation(fTextFrame, fClipboard);
\r
123 else if (source == fStressTest) {
\r
124 fTest.incRandSeed();
\r
126 selectOperation(fTextFrame, fClipboard);
\r
129 exitedNormally = true;
\r
132 if (!exitedNormally) {
\r
133 DateFormat df = DateFormat.getDateTimeInstance();
\r
134 System.out.println("Start time: " + df.format(startDate));
\r
135 System.out.println("End Time: " + df.format(new Date()));
\r
136 System.out.println("Rand seed: " + fTest.getRandSeed());
\r
137 System.out.println("Op count: " + fgOpCount);
\r
143 * Perform a random operation on the MTextPanel. Frame can
\r
146 private static final int OP_COUNT = 15;
\r
148 public void selectOperation(Frame frame,
\r
149 Clipboard clipboard) {
\r
151 int op = fTest.randInt(OP_COUNT);
\r
156 fTest._testSetSelection();
\r
160 fTest._testModifications(TestTextPanel.MOD_TEXT,
\r
165 fTest._testEditMenuOperations(clipboard);
\r
169 fTest._testModFlag(fTextPanel.getCommandLogSize());
\r
173 fTest.applyCharacterStyle();
\r
177 fTest.applyParagraphStyle();
\r
188 fTest.selectText();
\r
196 //if (frame != null) {
\r
197 // fTest.resizeFrame(frame);
\r
202 fTest.applyKeyRemap();
\r
206 fTest._testCommandLogControl();
\r
210 throw new Error("OP_COUNT is incorrect");
\r