001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: package com.ibm.richtext.test;
014:
015: import java.awt.Button;
016: import java.awt.Frame;
017: import java.awt.GridLayout;
018: import java.awt.datatransfer.Clipboard;
019: import java.awt.event.ActionEvent;
020: import java.awt.event.ActionListener;
021: import java.awt.event.WindowEvent;
022: import java.awt.event.WindowAdapter;
023:
024: import java.util.Date;
025: import java.text.DateFormat;
026:
027: import com.ibm.richtext.textpanel.MTextPanel;
028: import com.ibm.richtext.awtui.TextFrame;
029:
030: public class ITestTextPanel extends Frame implements ActionListener {
031:
032: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
033: private static long fgOpCount = 0;
034:
035: private TestTextPanel fTest;
036:
037: private MTextPanel fTextPanel;
038: private Frame fTextFrame;
039: private Clipboard fClipboard;
040: private Button fExersize, fStressTest, fResize;
041:
042: public static void main(String[] args) {
043:
044: Date startDate = new Date();
045:
046: try {
047: Clipboard clipboard = new Clipboard("ITextTestPanel");
048: TextFrame frame = new TextFrame(null, "Interactive Test",
049: clipboard);
050: MTextPanel panel = frame.getTextPanel();
051:
052: new ITestTextPanel(panel, frame, clipboard).show();
053: } finally {
054: DateFormat df = DateFormat.getDateTimeInstance();
055: System.out.println("Start time: " + df.format(startDate));
056: System.out.println("End Time: " + df.format(new Date()));
057: System.out.println("Op count: " + fgOpCount);
058: }
059: }
060:
061: public ITestTextPanel(MTextPanel panel, Frame frame,
062: Clipboard clipboard) {
063:
064: fTextPanel = panel;
065: fTest = new TestTextPanel(fTextPanel);
066: fClipboard = clipboard;
067:
068: setLayout(new GridLayout(0, 1));
069:
070: fTextFrame = frame;
071: fTextFrame.setSize(350, 500);
072: fTextFrame.show();
073:
074: // initialize UI:
075: fExersize = new Button("Exercise");
076: fExersize.addActionListener(this );
077: add(fExersize);
078:
079: fStressTest = new Button("Stress Test");
080: fStressTest.addActionListener(this );
081: add(fStressTest);
082:
083: pack();
084:
085: addWindowListener(new WindowAdapter() {
086: public void windowActivated(WindowEvent e) {
087: //activateTextFrame();
088: }
089:
090: public void windowClosing(WindowEvent e) {
091: System.exit(0);
092: }
093: });
094:
095: setSize(280, 150);
096: }
097:
098: private void activateTextFrame() {
099:
100: fTextFrame.toFront();
101: }
102:
103: public void actionPerformed(ActionEvent event) {
104:
105: Object source = event.getSource();
106: activateTextFrame();
107: Date startDate = new Date();
108: boolean exitedNormally = false;
109:
110: try {
111: if (source == fExersize) {
112: fTest.incRandSeed();
113: for (int i = 0; i < 100; i++) {
114: selectOperation(fTextFrame, fClipboard);
115: }
116: } else if (source == fStressTest) {
117: fTest.incRandSeed();
118: while (true) {
119: selectOperation(fTextFrame, fClipboard);
120: }
121: }
122: exitedNormally = true;
123: } finally {
124: if (!exitedNormally) {
125: DateFormat df = DateFormat.getDateTimeInstance();
126: System.out.println("Start time: "
127: + df.format(startDate));
128: System.out
129: .println("End Time: " + df.format(new Date()));
130: System.out.println("Rand seed: " + fTest.getRandSeed());
131: System.out.println("Op count: " + fgOpCount);
132: }
133: }
134: }
135:
136: /**
137: * Perform a random operation on the MTextPanel. Frame can
138: * be null.
139: */
140: private static final int OP_COUNT = 15;
141:
142: public void selectOperation(Frame frame, Clipboard fClipboard) {
143:
144: int op = fTest.randInt(OP_COUNT);
145:
146: switch (op) {
147:
148: case 0:
149: fTest._testSetSelection();
150: break;
151:
152: case 1:
153: fTest._testModifications(TestTextPanel.MOD_TEXT, true);
154: break;
155:
156: case 2:
157: fTest._testEditMenuOperations(fClipboard);
158: break;
159:
160: case 3:
161: fTest._testModFlag(fTextPanel.getCommandLogSize());
162: break;
163:
164: case 4:
165: fTest.applyCharacterStyle();
166: break;
167:
168: case 5:
169: fTest.applyParagraphStyle();
170: break;
171:
172: case 6:
173: case 7:
174: case 8:
175: case 9:
176: fTest.typeKeys();
177: break;
178:
179: case 10:
180: fTest.selectText();
181: break;
182:
183: case 11:
184: fTest.undoRedo();
185: break;
186:
187: case 12:
188: //if (frame != null) {
189: // fTest.resizeFrame(frame);
190: // break;
191: //}
192:
193: case 13:
194: fTest.applyKeyRemap();
195: break;
196:
197: case 14:
198: fTest._testCommandLogControl();
199: break;
200:
201: default:
202: throw new Error("OP_COUNT is incorrect");
203: }
204: fgOpCount++;
205: }
206:
207: }
|