1 19 package org.netbeans.modules.java.editor.semantic; 20 21 import java.awt.Dialog ; 22 import java.awt.event.WindowAdapter ; 23 import java.awt.event.WindowEvent ; 24 import java.awt.event.WindowListener ; 25 import java.io.BufferedReader ; 26 import java.io.File ; 27 import java.io.FileInputStream ; 28 import java.io.FileReader ; 29 import java.io.IOException ; 30 import java.io.InputStreamReader ; 31 import java.io.Reader ; 32 import java.text.ParseException ; 33 import java.util.ArrayList ; 34 import java.util.Collections ; 35 import java.util.List ; 36 import java.util.concurrent.CountDownLatch ; 37 import javax.swing.JDialog ; 38 import javax.swing.JFrame ; 39 import javax.swing.SwingUtilities ; 40 import javax.swing.text.BadLocationException ; 41 import javax.swing.text.StyledDocument ; 42 import javax.swing.text.html.HTMLDocument ; 43 import org.netbeans.junit.NbTestCase; 44 45 49 public class ShowGoldenFiles extends NbTestCase { 50 51 52 public ShowGoldenFiles(String name) { 53 super(name); 54 } 55 56 public void testX() throws Exception { 57 main(null); 58 } 59 60 private static List <HighlightImpl> parse(StyledDocument doc, File highlights) throws IOException , ParseException , BadLocationException { 61 if (!highlights.exists()) 62 return Collections.emptyList(); 63 64 BufferedReader bis = new BufferedReader (new InputStreamReader (new FileInputStream (highlights))); 65 List <HighlightImpl> result = new ArrayList <HighlightImpl>(); 66 String line = null; 67 68 while ((line = bis.readLine()) != null) { 69 result.add(HighlightImpl.parse(doc, line)); 70 } 71 72 return result; 73 } 74 75 private static StyledDocument loadDocument(File file) throws IOException , BadLocationException { 76 StringBuffer sb = new StringBuffer (); 77 Reader r = new FileReader (file); 78 int c; 79 80 while ((c = r.read()) != (-1)) { 81 sb.append((char) c); 82 } 83 84 StyledDocument result = new HTMLDocument (); 86 result.insertString(0, sb.toString(), null); 87 88 return result; 89 } 90 91 public static void main(String [] args) throws Exception { 92 String className = "DetectorTest"; 93 String testName = "testReadWriteUseArgumentOfAbstractMethod"; 94 } 95 96 public static void run(String className, String testName, String fileName) throws Exception { 97 final File golden = new File ("/space/nm/java/editor/test/unit/data/goldenfiles/org/netbeans/modules/java/editor/semantic/" + className + "/" + testName + ".pass"); 98 final File test = new File ("/tmp/tests/org.netbeans.modules.java.editor.semantic." + className + "/" + testName + "/" + testName + ".out"); 99 final File source = new File ("/tmp/tests/org.netbeans.modules.java.editor.semantic." + className + "/" + testName + "/test/" + fileName + ".java"); 100 101 final StyledDocument doc = loadDocument(source); 102 final List <HighlightImpl> goldenHighlights = parse(doc, golden); 103 final List <HighlightImpl> testHighlights = parse(doc, test); 104 105 Runnable show = new Runnable () { 106 public void run() { 107 JDialog d = new JDialog (); 108 109 d.setModal(true); 110 111 ShowGoldenFilesPanel panel = new ShowGoldenFilesPanel(d); 112 113 panel.setDocument(doc, goldenHighlights, testHighlights, golden, test); 114 115 d.getContentPane().add(panel); 116 117 d.show(); 118 } 119 }; 120 121 if (SwingUtilities.isEventDispatchThread()) { 122 show.run(); 123 } else { 124 SwingUtilities.invokeAndWait(show); 125 } 126 } 127 128 } 129 | Popular Tags |