1 19 20 package org.netbeans.test.java; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import java.net.URL ; 26 import javax.swing.text.StyledDocument ; 27 import org.netbeans.jellytools.EditorWindowOperator; 28 import org.netbeans.jellytools.JellyTestCase; 29 import org.netbeans.jemmy.util.PNGEncoder; 30 import org.openide.cookies.EditorCookie; 32 import org.openide.cookies.SaveCookie; 33 import org.openide.filesystems.Repository; 34 import org.openide.loaders.DataObject; 35 import org.openide.util.SharedClassObject; 36 37 38 41 public abstract class XGUIRunner extends JellyTestCase implements Go { 42 43 protected String name; 44 45 protected String packageName; 46 47 public XGUIRunner(java.lang.String testName) { 48 super(testName); 49 } 50 51 public void waitEditorOpened() { 52 new EditorWindowOperator().getEditor(name); 53 } 54 55 public void testRun() { 56 DataObject DO = null; 57 String fullName = packageName + "." + name; 60 61 boolean ok = true; 62 63 try { 64 ok = go(fullName, new PrintWriter (getLog())); 65 if (!ok) { 66 getLog().println("go() failed"); 67 } 68 69 DO = DataObject.find(Repository.getDefault().findResource(fullName.replace('.','/') + ".java")); 70 ((SaveCookie) DO.getCookie(SaveCookie.class)).save(); 71 } catch (Exception e) { 72 ok = false; 73 e.printStackTrace(getLog()); 74 } 75 76 ok = writeResult(DO); 77 try { 78 DO.delete(); 79 } catch (IOException e){ 80 assertTrue(e.toString(), false); 81 } 82 83 assertTrue("See .log file for details", ok); 84 compareReferenceFiles(); 85 } 86 87 public File getGoldenFile(String filename) { 88 String fullClassName = this.getClass().getName(); 89 String className = fullClassName; 90 int lastDot = fullClassName.lastIndexOf('.'); 91 if (lastDot != -1) { 92 className = fullClassName.substring(lastDot+1); 93 } 94 String goldenFileName = className+".pass"; 95 URL url = this.getClass().getResource(goldenFileName); 96 assertNotNull("Golden file "+goldenFileName+" cannot be found",url); 97 String resString = convertNBFSURL(url); 98 File goldenFile = new File (resString); 99 return goldenFile; 100 } 101 102 protected boolean writeResult(DataObject DO) { 103 String result = ""; 104 try { 105 EditorCookie ec=(EditorCookie)(DO.getCookie(EditorCookie.class)); 106 StyledDocument doc=ec.openDocument(); 107 result=doc.getText(0, doc.getLength()); 108 result=Common.unify(result); 109 } catch (Exception e){ 110 e.printStackTrace(getLog()); 111 return false; 112 } 113 114 getRef().print(result); 115 return true; 116 } 117 118 } 119 | Popular Tags |