1 17 18 package org.netbeans.lib.uihandlerserver; 19 20 import java.io.DataInputStream ; 21 import java.io.DataOutputStream ; 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.FileOutputStream ; 25 import java.io.InputStream ; 26 import java.lang.reflect.Method ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import java.util.Random ; 30 import java.util.SortedMap ; 31 import java.util.TreeMap ; 32 import java.util.logging.Level ; 33 import java.util.logging.LogRecord ; 34 import java.util.logging.Logger ; 35 import org.netbeans.junit.NbTestCase; 36 import org.netbeans.lib.uihandler.InputGesture; 37 import org.netbeans.lib.uihandler.LogRecords; 38 39 43 public class InputGestureTest extends NbTestCase { 44 private Logger LOG; 45 46 public InputGestureTest(String testName) { 47 super(testName); 48 } 49 50 protected Level logLevel() { 51 return Level.INFO; 52 } 53 54 protected int timeOut() { 55 return 0; } 57 58 protected void setUp() throws Exception { 59 LOG = Logger.getLogger("TEST-" + getName()); 60 } 61 62 protected void tearDown() throws Exception { 63 } 64 65 public void testReadALogAndTestInputGestures() throws Exception { 66 InputStream is = getClass().getResourceAsStream("NB1216449736.0"); 67 SortedMap <Integer ,InputGesture> expectedGestures = new TreeMap <Integer ,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 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 [] { 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 { 97 InputStream is = getClass().getResourceAsStream("NB_PROF634066243"); 98 SortedMap <Integer ,InputGesture> expectedGestures = new TreeMap <Integer ,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 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 [] { 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 |