KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > uihandlerserver > InputGestureTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
16  */

17
18 package org.netbeans.lib.uihandlerserver;
19
20 import java.io.DataInputStream JavaDoc;
21 import java.io.DataOutputStream JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Random JavaDoc;
30 import java.util.SortedMap JavaDoc;
31 import java.util.TreeMap JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 import java.util.logging.LogRecord JavaDoc;
34 import java.util.logging.Logger JavaDoc;
35 import org.netbeans.junit.NbTestCase;
36 import org.netbeans.lib.uihandler.InputGesture;
37 import org.netbeans.lib.uihandler.LogRecords;
38
39 /**
40  *
41  * @author Jaroslav Tulach
42  */

43 public class InputGestureTest extends NbTestCase {
44     private Logger JavaDoc LOG;
45     
46     public InputGestureTest(String JavaDoc testName) {
47         super(testName);
48     }
49     
50     protected Level JavaDoc logLevel() {
51         return Level.INFO;
52     }
53     
54     protected int timeOut() {
55         return 0; //5000;
56
}
57
58     protected void setUp() throws Exception JavaDoc {
59         LOG = Logger.getLogger("TEST-" + getName());
60     }
61
62     protected void tearDown() throws Exception JavaDoc {
63     }
64
65     public void testReadALogAndTestInputGestures() throws Exception JavaDoc {
66         InputStream JavaDoc is = getClass().getResourceAsStream("NB1216449736.0");
67         SortedMap JavaDoc<Integer JavaDoc,InputGesture> expectedGestures = new TreeMap JavaDoc<Integer JavaDoc,InputGesture>();
68         expectedGestures.put(35, InputGesture.MENU);
69         expectedGestures.put(59, InputGesture.KEYBOARD);
70         expectedGestures.put(66, InputGesture.MENU);
71         expectedGestures.put(80, InputGesture.MENU);
72         expectedGestures.put(81, InputGesture.MENU);
73         expectedGestures.put(177, InputGesture.KEYBOARD);
74         expectedGestures.put(197, InputGesture.KEYBOARD);
75         expectedGestures.put(205, InputGesture.MENU);
76         for (int cnt = 0;; cnt++) {
77             LOG.log(Level.INFO, "Reading {0}th record", cnt);
78             LogRecord JavaDoc r = LogRecords.read(is);
79             if (r == null) {
80                 break;
81             }
82             if (r.getSequenceNumber() > expectedGestures.lastKey()) {
83                 break;
84             }
85             LOG.log(Level.INFO, "Read {0}th record, seq {1}", new Object JavaDoc[] { cnt, r.getSequenceNumber() });
86
87             InputGesture g = InputGesture.valueOf(r);
88             InputGesture exp = expectedGestures.get((int)r.getSequenceNumber());
89             assertEquals(cnt + ": For: " + r.getSequenceNumber() + " txt:\n`"+ r.getMessage() +
90                 "\nkey: " + r.getResourceBundleName()
91                 , exp, g);
92         }
93         is.close();
94     }
95
96     public void testReadAToolbar() throws Exception JavaDoc {
97         InputStream JavaDoc is = getClass().getResourceAsStream("NB_PROF634066243");
98         SortedMap JavaDoc<Integer JavaDoc,InputGesture> expectedGestures = new TreeMap JavaDoc<Integer JavaDoc,InputGesture>();
99         expectedGestures.put(62, InputGesture.TOOLBAR);
100         expectedGestures.put(63, InputGesture.MENU);
101         for (int cnt = 0;; cnt++) {
102             LOG.log(Level.INFO, "Reading {0}th record", cnt);
103             LogRecord JavaDoc r = LogRecords.read(is);
104             if (r == null) {
105                 break;
106             }
107             if (r.getSequenceNumber() > expectedGestures.lastKey()) {
108                 break;
109             }
110             LOG.log(Level.INFO, "Read {0}th record, seq {1}", new Object JavaDoc[] { cnt, r.getSequenceNumber() });
111
112             InputGesture g = InputGesture.valueOf(r);
113             InputGesture exp = expectedGestures.get((int)r.getSequenceNumber());
114             assertEquals(cnt + ": For: " + r.getSequenceNumber() + " txt:\n`"+ r.getMessage() +
115                 "\nkey: " + r.getResourceBundleName()
116                 , exp, g);
117         }
118         is.close();
119     }
120 }
121
Popular Tags