1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 import java.io.Reader ; 25 import java.io.StringReader ; 26 import java.io.StringWriter ; 27 import junit.framework.Assert; 28 import org.netbeans.junit.NbTestCase; 29 import org.openide.ErrorManager; 30 import org.openide.windows.IOProvider; 31 import org.openide.windows.InputOutput; 32 import org.openide.windows.OutputListener; 33 import org.openide.windows.OutputWriter; 34 35 38 public class InputOutputProviderImpl extends IOProvider { 39 40 static NbTestCase running; 41 42 43 public InputOutputProviderImpl() {} 44 45 public static void registerCase(NbTestCase r) { 46 running = r; 47 } 48 49 public InputOutput getIO(String name, boolean newIO) { 50 return new IO(name); 51 } 52 53 public OutputWriter getStdOut() { 54 Assert.assertNotNull("A test case must be registered", running); 55 return new OW("stdout"); 56 } 57 58 private static class OW extends OutputWriter { 59 60 private ErrorManager err; 61 62 public OW(String prefix) { 63 super(new StringWriter ()); 64 err = ErrorManager.getDefault().getInstance("output[" + prefix + "]"); 65 } 66 67 public void println(String s, OutputListener l) throws IOException { 68 write("println: " + s + " listener: " + l); 69 flush(); 70 } 71 72 public void reset() throws IOException { 73 write("Internal reset"); 74 flush(); 75 } 76 77 public void write(char[] buf, int off, int len) { 78 write(new String (buf, off, len)); 79 } 80 81 public void write(int c) { 82 write(String.valueOf((char)c)); 83 } 84 85 public void write(char[] buf) { 86 write(buf, 0, buf.length); 87 } 88 89 public void write(String s, int off, int len) { 90 write(s.substring(off, off + len)); 91 } 92 public void write(String s) { 93 err.log(s); 94 } 95 } 96 97 private static class IO implements InputOutput { 98 99 private OW w; 100 private boolean closed; 101 102 public IO(String n) { 103 w = new OW(n); 104 w.write("Created IO named '" + n + "'"); 105 w.flush(); 106 } 107 108 public OutputWriter getOut() { 109 return w; 110 } 111 112 public Reader getIn() { 113 w.write("Creating reader"); 114 return new StringReader (""); 115 } 116 117 public OutputWriter getErr() { 118 return w; 119 } 120 121 public void closeInputOutput() { 122 w.write("closeInputOutput"); 123 closed = true; 124 } 125 126 public boolean isClosed() { 127 w.write("isClosed"); 128 return closed; 129 } 130 131 public void setOutputVisible(boolean value) { 132 w.write("setOutputVisible: " + value); 133 } 134 135 public void setErrVisible(boolean value) { 136 w.write("setErrVisible: " + value); 137 } 138 139 public void setInputVisible(boolean value) { 140 w.write("setInputVisible: " + value); 141 } 142 143 public void select() { 144 w.write("select"); 145 } 146 147 public boolean isErrSeparated() { 148 return false; 149 } 150 151 public void setErrSeparated(boolean value) {} 152 153 public boolean isFocusTaken() { 154 return false; 155 } 156 157 public void setFocusTaken(boolean value) {} 158 159 public Reader flushReader() { 160 return getIn(); 161 } 162 163 } 164 } 165 | Popular Tags |