1 16 17 package org.apache.taglibs.standard.lang.jstl.test; 18 19 import java.io.BufferedInputStream ; 20 import java.io.BufferedOutputStream ; 21 import java.io.DataInput ; 22 import java.io.DataInputStream ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.PrintStream ; 28 29 import javax.servlet.jsp.JspException ; 30 31 import org.apache.taglibs.standard.lang.jstl.Evaluator; 32 33 49 50 public class ParserTest 51 { 52 56 60 65 public ParserTest () 66 { 67 } 68 69 75 public static void runTests (DataInput pIn, 76 PrintStream pOut) 77 throws IOException 78 { 79 while (true) { 80 String str = pIn.readLine (); 81 if (str == null) break; 82 if (str.startsWith ("#") || 83 "".equals (str.trim ())) { 84 pOut.println (str); 85 } 86 else { 87 if ("@@non-ascii".equals (str)) { 90 str = "\u1111"; 91 } 92 93 pOut.println ("Attribute value: " + str); 94 try { 95 String result = Evaluator.parseAndRender (str); 96 pOut.println ("Parses to: " + result); 97 } 98 catch (JspException exc) { 99 pOut.println ("Causes an error: " + exc.getMessage ()); 100 } 101 } 102 } 103 104 } 105 106 112 public static void runTests (File pInputFile, 113 File pOutputFile) 114 throws IOException 115 { 116 FileInputStream fin = null; 117 FileOutputStream fout = null; 118 try { 119 fin = new FileInputStream (pInputFile); 120 BufferedInputStream bin = new BufferedInputStream (fin); 121 DataInputStream din = new DataInputStream (bin); 122 123 try { 124 fout = new FileOutputStream (pOutputFile); 125 BufferedOutputStream bout = new BufferedOutputStream (fout); 126 PrintStream pout = new PrintStream (bout); 127 128 runTests (din, pout); 129 130 pout.flush (); 131 } 132 finally { 133 if (fout != null) { 134 fout.close (); 135 } 136 } 137 } 138 finally { 139 if (fin != null) { 140 fin.close (); 141 } 142 } 143 } 144 145 151 public static boolean isDifferentFiles (DataInput pIn1, 152 DataInput pIn2) 153 throws IOException 154 { 155 while (true) { 156 String str1 = pIn1.readLine (); 157 String str2 = pIn2.readLine (); 158 if (str1 == null && 159 str2 == null) { 160 return false; 161 } 162 else if (str1 == null || 163 str2 == null) { 164 return true; 165 } 166 else { 167 if (!str1.equals (str2)) { 168 return true; 169 } 170 } 171 } 172 } 173 174 180 public static boolean isDifferentFiles (File pFile1, 181 File pFile2) 182 throws IOException 183 { 184 FileInputStream fin1 = null; 185 try { 186 fin1 = new FileInputStream (pFile1); 187 BufferedInputStream bin1 = new BufferedInputStream (fin1); 188 DataInputStream din1 = new DataInputStream (bin1); 189 190 FileInputStream fin2 = null; 191 try { 192 fin2 = new FileInputStream (pFile2); 193 BufferedInputStream bin2 = new BufferedInputStream (fin2); 194 DataInputStream din2 = new DataInputStream (bin2); 195 196 return isDifferentFiles (din1, din2); 197 } 198 finally { 199 if (fin2 != null) { 200 fin2.close (); 201 } 202 } 203 } 204 finally { 205 if (fin1 != null) { 206 fin1.close (); 207 } 208 } 209 } 210 211 218 public static void main (String [] pArgs) 219 throws IOException 220 { 221 if (pArgs.length != 2 && 222 pArgs.length != 3) { 223 usage (); 224 System.exit (1); 225 } 226 227 File in = new File (pArgs [0]); 228 File out = new File (pArgs [1]); 229 230 runTests (in, out); 231 232 if (pArgs.length > 2) { 233 File compare = new File (pArgs [2]); 234 if (isDifferentFiles (out, compare)) { 235 System.out.println ("Test failure - output file " + 236 out + 237 " differs from expected output file " + 238 compare); 239 } 240 else { 241 System.out.println ("tests passed"); 242 } 243 } 244 } 245 246 static void usage () 248 { 249 System.err.println ("usage: java org.apache.taglibs.standard.lang.jstl.test.ParserTest {input file} {output file} [{compare file}]"); 250 } 251 252 254 } 255 | Popular Tags |