001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
027: */
028:
029: package org.netbeans.lib.uihandlerserver;
030:
031: import java.io.ByteArrayInputStream;
032: import java.io.InputStream;
033: import java.util.SortedMap;
034: import java.util.TreeMap;
035: import java.util.logging.Level;
036: import java.util.logging.LogRecord;
037: import java.util.logging.Logger;
038: import org.netbeans.junit.NbTestCase;
039: import org.netbeans.lib.uihandler.InputGesture;
040: import org.netbeans.lib.uihandler.TestHandler;
041:
042: /**
043: *
044: * @author Jaroslav Tulach
045: */
046: public class InputGestureTest extends NbTestCase {
047: private Logger LOG;
048:
049: public InputGestureTest(String testName) {
050: super (testName);
051: }
052:
053: protected Level logLevel() {
054: return Level.INFO;
055: }
056:
057: protected int timeOut() {
058: return 0; //5000;
059: }
060:
061: protected void setUp() throws Exception {
062: LOG = Logger.getLogger("TEST-" + getName());
063: }
064:
065: protected void tearDown() throws Exception {
066: }
067:
068: public void testIsLowLevelAction() throws Exception {
069: String s = "<record>n"
070: + "<date>2007-03-27T18:45:54</date>n"
071: + "<millis>1175013954455</millis>n"
072: + "<sequence>1236</sequence>n"
073: + "<level>FINE</level>n"
074: + "<thread>13</thread>n"
075: + "<message>UI_ACTION_EDITOR</message>n"
076: + "<param>java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=null,when=1175013954453,modifiers=] on org.openide.text.QuietEditorPane[,0,-2250,1086x12960,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@1976f3a,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=java.awt.Color[r=255,g=255,b=255],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=java.awt.Insets[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],kit=org.netbeans.modules.editor.java.JavaKit@b8df14,typeHandlers=]</param>n"
077: + "<param>java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=null,when=1175013954453,modifiers=] on org.openide.text.QuietEditorPane[,0,-1500,1086x12960,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@1976f3a,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=java.awt.Color[r=255,g=255,b=255],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=java.awt.Insets[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],kit=org.netbeans.modules.editor.java.JavaKit@b8df14,typeHandlers=]</param>n"
078: + "<param>org.netbeans.editor.BaseKit$PageDownAction@596079</param>n"
079: + "<param>org.netbeans.editor.BaseKit$PageDownAction@596079</param>n"
080: + "<param>page-down</param>n" + "</record>";
081:
082: InputStream is = new ByteArrayInputStream(s.getBytes());
083: TestHandler records = new TestHandler(is);
084: LogRecord r = records.read();
085: assertNotNull(r);
086:
087: assertNull("No gesture", InputGesture.valueOf(r));
088: }
089:
090: public void testReadALogAndTestInputGestures() throws Exception {
091: InputStream is = getClass().getResourceAsStream(
092: "NB1216449736.0");
093: SortedMap<Integer, InputGesture> expectedGestures = new TreeMap<Integer, InputGesture>();
094: expectedGestures.put(35, InputGesture.MENU);
095: expectedGestures.put(59, InputGesture.KEYBOARD);
096: expectedGestures.put(66, InputGesture.MENU);
097: expectedGestures.put(80, InputGesture.MENU);
098: expectedGestures.put(81, InputGesture.MENU);
099: expectedGestures.put(177, InputGesture.KEYBOARD);
100: expectedGestures.put(197, InputGesture.KEYBOARD);
101: expectedGestures.put(205, InputGesture.MENU);
102: TestHandler records = new TestHandler(is);
103: for (int cnt = 0;; cnt++) {
104: LOG.log(Level.INFO, "Reading {0}th record", cnt);
105: LogRecord r = records.read();
106: if (r == null) {
107: break;
108: }
109: if (r.getSequenceNumber() > expectedGestures.lastKey()) {
110: break;
111: }
112: LOG.log(Level.INFO, "Read {0}th record, seq {1}",
113: new Object[] { cnt, r.getSequenceNumber() });
114:
115: InputGesture g = InputGesture.valueOf(r);
116: InputGesture exp = expectedGestures.get((int) r
117: .getSequenceNumber());
118: assertEquals(cnt + ": For: " + r.getSequenceNumber()
119: + " txt:\n`" + r.getMessage() + "\nkey: "
120: + r.getResourceBundleName(), exp, g);
121: }
122: is.close();
123: }
124:
125: public void testReadAToolbar() throws Exception {
126: InputStream is = getClass().getResourceAsStream(
127: "NB_PROF634066243");
128: SortedMap<Integer, InputGesture> expectedGestures = new TreeMap<Integer, InputGesture>();
129: expectedGestures.put(62, InputGesture.TOOLBAR);
130: expectedGestures.put(63, InputGesture.MENU);
131: TestHandler records = new TestHandler(is);
132: for (int cnt = 0;; cnt++) {
133: LOG.log(Level.INFO, "Reading {0}th record", cnt);
134: LogRecord r = records.read();
135: if (r == null) {
136: break;
137: }
138: if (r.getSequenceNumber() > expectedGestures.lastKey()) {
139: break;
140: }
141: LOG.log(Level.INFO, "Read {0}th record, seq {1}",
142: new Object[] { cnt, r.getSequenceNumber() });
143:
144: InputGesture g = InputGesture.valueOf(r);
145: InputGesture exp = expectedGestures.get((int) r
146: .getSequenceNumber());
147: assertEquals(cnt + ": For: " + r.getSequenceNumber()
148: + " txt:\n`" + r.getMessage() + "\nkey: "
149: + r.getResourceBundleName(), exp, g);
150: }
151: is.close();
152: }
153: }
|