You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by fu...@apache.org on 2006/04/17 22:36:13 UTC

svn commit: r394771 - in /db/derby/code/branches/10.1/java: testing/org/apache/derbyTesting/functionTests/harness/ testing/org/apache/derbyTesting/functionTests/tests/lang/ tools/org/apache/derby/iapi/tools/i18n/ tools/org/apache/derby/impl/tools/ij/

Author: fuzzylogic
Date: Mon Apr 17 13:36:11 2006
New Revision: 394771

URL: http://svn.apache.org/viewcvs?rev=394771&view=rev
Log:
DERBY-658: Improve test harness' ability to run on platforms with non-ASCII
native encoding.

Committed for Myrna Van Lunteren <m....@gmail.com>

Modified:
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/CopySuppFiles.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/FileCompare.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunList.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/SkipTest.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/coalesceTests.java
    db/derby/code/branches/10.1/java/tools/org/apache/derby/iapi/tools/i18n/LocalizedResource.java
    db/derby/code/branches/10.1/java/tools/org/apache/derby/impl/tools/ij/utilMain.java

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/CopySuppFiles.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/CopySuppFiles.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/CopySuppFiles.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/CopySuppFiles.java Mon Apr 17 13:36:11 2006
@@ -66,17 +66,32 @@
 		    fw.close();
 		    suppFile = new File(f.getCanonicalPath());
 		}
+                // need to make a guess so we copy text files to local encoding
+                // on non-ascii systems...
+                if ((fileName.indexOf("sql") > 0) || (fileName.indexOf("txt") > 0) || (fileName.indexOf(".view") > 0))
+                {
+                    BufferedReader inFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+                    PrintWriter pw = new PrintWriter
+                        ( new BufferedWriter(new FileWriter(suppFile), 10000), true );
+                    int c;
+                    while ((c = inFile.read()) != -1)
+                        pw.write(c); 
+                    pw.flush();
+                    pw.close();
+                }
+                else
+                {
 
-
-    			FileOutputStream fos = new FileOutputStream(suppFile);
-                byte[] data = new byte[4096];
-                int len;
-    			while ((len = is.read(data)) != -1)
-    			{
-    			    fos.write(data, 0, len);
-    			}
-    			fos.close();
-			}
+                    FileOutputStream fos = new FileOutputStream(suppFile);
+                    byte[] data = new byte[4096];
+                    int len;
+                    while ((len = is.read(data)) != -1)
+                    {
+                        fos.write(data, 0, len);
+                    }
+                    fos.close();
+                }
+            }
         }
 	}
 }

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/FileCompare.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/FileCompare.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/FileCompare.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/FileCompare.java Mon Apr 17 13:36:11 2006
@@ -203,6 +203,20 @@
 		        System.out.println("SED Error: " + cfe.getMessage());
 		    }
 		}
+        else
+        { 
+            // read in in fixed format, but write out relying on default encoding 
+            File encodedOutFile = new File(outDir, testBase + ".tmpmstr");
+            BufferedReader inFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            PrintWriter pw = new PrintWriter
+                ( new BufferedWriter(new FileWriter(encodedOutFile), 10000), true );
+            int c;
+            while ((c = inFile.read()) != -1)
+                pw.write(c);
+            pw.flush();
+            pw.close();
+            is = new FileInputStream(encodedOutFile);
+        } 
         
         // Define the input and output files
         outFile = new BufferedReader(new FileReader(outfile));

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunList.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunList.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunList.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunList.java Mon Apr 17 13:36:11 2006
@@ -226,7 +226,7 @@
             }
 
             // Create a BufferedReader to read the list of tests to run
-            runlistFile = new BufferedReader(new InputStreamReader(is));
+            runlistFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
             if (runlistFile == null)
             {
                 System.out.println("The suite runall file could not be read.");

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java Mon Apr 17 13:36:11 2006
@@ -133,7 +133,7 @@
 	static String testOutName; // output name without path or extension (optional)
 	static String passFileName; // file listing passed tests
 	static String failFileName; // file listing failed tests
-	static String JCCOutName; //file name for JCC corrected master
+	static String tempMasterName; //file name for JCC corrected/local encoded master
     static File passFile;
     static File failFile;
 	static String shutdownurl = "";
@@ -150,7 +150,7 @@
     static File runDir; // where test is run and where support files are expected
     static File canonDir; // allows setting master dir other than default
     static File tmpOutFile; // tmp output file (before sed)
-    static File JCCOutFile; // master file processed for JCC
+    static File tempMasterFile; // master file processed for JCC/local encoding
     static File stdOutFile; // for tests with useoutput false
     static File finalOutFile; // final output file (after sed)
     static File appPropFile; // testname_app.properties or default
@@ -630,7 +630,7 @@
 
             // Read the test file and copy it to the outDir
             // except for multi tests (for multi we just need to locate it)
-            BufferedReader in = new BufferedReader(new InputStreamReader(is));
+            BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
             if (upgradetest)
 		
                 //these calls to getCanonicalPath catch IOExceptions as a workaround to
@@ -752,10 +752,10 @@
 
         // Create a .tmp file for doing sed later to create testBase.out
         tmpOutFile = new File(outDir, testOutName + ".tmp");
-		if (NetServer.isClientConnection(framework))
-		{
-			JCCOutName = testOutName+".tmpmstr";
-		}
+        // Always create a .tmpmstr in local encoding so we can do Diff in locale encoding
+        // With Network server, this also will get adjusted for displaywidth
+//TODO: always, except when setting a special property to force .out creation in UTF-8?
+			tempMasterName = testOutName+".tmpmstr";
 
 		// Define the .out file which will be created by massaging the tmp.out
 		finalOutFile = new File(outDir, testOutName + ".out");
@@ -788,12 +788,9 @@
         // Delete any old .out or .tmp files
         if (tmpOutFile.exists())
             status = tmpOutFile.delete();
-		if (NetServer.isClientConnection(framework))
-		{
-        	JCCOutFile = new File(outDir, JCCOutName);
-        	if (JCCOutFile.exists())
-            	status = JCCOutFile.delete();
-		}
+        tempMasterFile = new File (outDir, tempMasterName);
+        if (tempMasterFile.exists())
+            status = tempMasterFile.delete();
         if (finalOutFile.exists())
             status = finalOutFile.delete();
         if (diffFile.exists())
@@ -1768,8 +1765,8 @@
         //printWriter.close();
         //printWriter = null;
 
-        //Always cleanup the script files
-        if ( !(script == null) && (script.exists()) )
+        //Always cleanup the script files - except when keepfiles is true
+        if ( !(script == null) && (script.exists()) && (!keepfiles) )
         {
             status = script.delete();
             //System.out.println("Status was: " + status);
@@ -1799,12 +1796,11 @@
             status = finalOutFile.delete();
             if (skiptest == false)
                 status = diffFile.delete();
-			// delete JCC filtered master file
-			if (NetServer.isClientConnection(framework))
-			{
-        		JCCOutFile = new File(outDir, JCCOutName);
-            	status = JCCOutFile.delete();
-			}
+
+            // delete the copied (and, for network server, modified) master file
+            tempMasterFile = new File(outDir, tempMasterName);
+            status = tempMasterFile.delete();
+
             if (deleteBaseDir)
             {
                 if (useCommonDB == false) 
@@ -2064,18 +2060,23 @@
         Vector v = jvm.getCommandLine();
         if ( ij.startsWith("ij") )
         {
-            // as of cn1411-20030930, the system takes the default console encoding
-            // which in the US, on windows, is Cp437.
-            // Sun on the other hand, always forces a console encoding of 1252.
-            // To get the same result for ibm141 & jdk14*, we need to force 
-            // the console encoding to Cp1252 for ij tests.
-            // see beetle 5475.
-            v.addElement("-Dconsole.encoding=Cp1252" );
+            // As of cn1411-20030930 IBM jvm the system takes the default
+            // console encoding, which in the US, on windows, is Cp437.
+            // Sun jvms, however, always force a console encoding of 1252.
+            // To get the same result for ibm141 & jdk14*, the harness needs to
+            // force the console encoding to Cp1252 for ij tests - unless 
+            // we're on non-ascii systems.
+            String isNotAscii = System.getProperty("platform.notASCII");
+            if ( isNotAscii == null || (isNotAscii.equals("false")))
+                v.addElement("-Dconsole.encoding=Cp1252" );
             v.addElement("org.apache.derby.tools." + ij);
             if (ij.equals("ij"))
             {
-                v.addElement("-fr");
-                v.addElement(scriptFileName);
+                // TODO is there a setting/property we could check after which 
+                // we can use v.addElement("-fr"); (read from classpath)
+                // then we can also use v.addElement(scriptFile);
+                v.addElement("-f");
+                v.addElement(outDir.toString() + File.separatorChar + scriptFileName);
             }
             v.addElement("-p");
             v.addElement(propString);

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java Mon Apr 17 13:36:11 2006
@@ -300,7 +300,7 @@
         if (is == null)
             inFile = new BufferedReader(new FileReader(srcFile));
         else
-            inFile = new BufferedReader(new InputStreamReader(is));
+            inFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
         outFile = new PrintWriter
         ( new BufferedWriter(new FileWriter(dstFile), 10000), true );
 

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/SkipTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/SkipTest.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/SkipTest.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/harness/SkipTest.java Mon Apr 17 13:36:11 2006
@@ -53,7 +53,7 @@
         }
         
         // Create a BufferedReader to read the list of tests to skip
-        BufferedReader listFile = new BufferedReader(new InputStreamReader(is));
+        BufferedReader listFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
         String str = "";
         // Read the list of tests to skip, compare to testName
         while ( (str = listFile.readLine()) != null )

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/coalesceTests.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/coalesceTests.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/coalesceTests.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/coalesceTests.java Mon Apr 17 13:36:11 2006
@@ -1147,18 +1147,18 @@
     } catch(Exception ex) {}
 			s.executeUpdate("create table tC (cbd1 char(254) for bit data, cbd2 char(40) for bit data, vcbd1 varchar(253) for bit data, vcbd2 varchar(2000) for bit data, lvcbd1 long varchar for bit data, lvcbd2 long varchar for bit data, blob1 BLOB(200), blob2 BLOB(33K))");
 			ps = conn.prepareStatement("insert into tC values (?,?,?,?,?,?,?,?)");
-			ps.setBytes(1, "cbd1 not null".getBytes());
-			ps.setBytes(2, "cbd2 not null".getBytes());
-			ps.setBytes(3, "vcbd1 not null".getBytes());
-			ps.setBytes(4, "vcbd2 not null".getBytes());
-			ps.setBytes(5, "lvcbd1 not null".getBytes());
-			ps.setBytes(6, "lvcbd2 not null".getBytes());
-			ps.setBytes(7, "blob1 not null".getBytes());
-			ps.setBytes(8, "blob2 not null".getBytes());
+			ps.setBytes(1, "cbd1 not null".getBytes("US-ASCII"));
+			ps.setBytes(2, "cbd2 not null".getBytes("US-ASCII"));
+			ps.setBytes(3, "vcbd1 not null".getBytes("US-ASCII"));
+			ps.setBytes(4, "vcbd2 not null".getBytes("US-ASCII"));
+			ps.setBytes(5, "lvcbd1 not null".getBytes("US-ASCII"));
+			ps.setBytes(6, "lvcbd2 not null".getBytes("US-ASCII"));
+			ps.setBytes(7, "blob1 not null".getBytes("US-ASCII"));
+			ps.setBytes(8, "blob2 not null".getBytes("US-ASCII"));
 			ps.executeUpdate();
-			ps.setBytes(1, "cbd1 not null but cbd2 is".getBytes());
+			ps.setBytes(1, "cbd1 not null but cbd2 is".getBytes("US-ASCII"));
 			ps.setBytes(2, null);
-			ps.setBytes(3, "vcbd1 not null but vcbd2 is".getBytes());
+			ps.setBytes(3, "vcbd1 not null but vcbd2 is".getBytes("US-ASCII"));
 			ps.setBytes(4, null);
 			ps.setBytes(5, null);
 			ps.setBytes(6, null);
@@ -1166,13 +1166,13 @@
 			ps.setBytes(8, null);
 			ps.executeUpdate();
 			ps.setBytes(1, null);
-			ps.setBytes(2, "cbd2 not null but cbd1 is".getBytes());
+			ps.setBytes(2, "cbd2 not null but cbd1 is".getBytes("US-ASCII"));
 			ps.setBytes(3, null);
-			ps.setBytes(4, "vcbd2 not null but vcbd1 is".getBytes());
-			ps.setBytes(5, "lvcbd1 not null again".getBytes());
-			ps.setBytes(6, "lvcbd2 not null again".getBytes());
-			ps.setBytes(7, "blob1 not null again".getBytes());
-			ps.setBytes(8, "blob2 not null again".getBytes());
+			ps.setBytes(4, "vcbd2 not null but vcbd1 is".getBytes("US-ASCII"));
+			ps.setBytes(5, "lvcbd1 not null again".getBytes("US-ASCII"));
+			ps.setBytes(6, "lvcbd2 not null again".getBytes("US-ASCII"));
+			ps.setBytes(7, "blob1 not null again".getBytes("US-ASCII"));
+			ps.setBytes(8, "blob2 not null again".getBytes("US-ASCII"));
 			ps.executeUpdate();
 			ps.setBytes(1, null);
 			ps.setBytes(2, null);
@@ -1467,12 +1467,9 @@
 				try{
 				row.append(s.getString(i));
 				} catch(SQLException ex){
-					if (ex.getSQLState().equals("22005")) {
-						if (s.getBytes(i) != null)
-                row.append(new String(s.getBytes(i)));
-						else
-                row.append(s.getBytes(i));
-					} else throw ex;
+					if (ex.getSQLState().equals("22005")) 
+					    row.append("Invalid Conversion Error\n");
+					else throw ex;
 				}
 			}
 			row.append("}\n");

Modified: db/derby/code/branches/10.1/java/tools/org/apache/derby/iapi/tools/i18n/LocalizedResource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/tools/org/apache/derby/iapi/tools/i18n/LocalizedResource.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/tools/org/apache/derby/iapi/tools/i18n/LocalizedResource.java (original)
+++ db/derby/code/branches/10.1/java/tools/org/apache/derby/iapi/tools/i18n/LocalizedResource.java Mon Apr 17 13:36:11 2006
@@ -212,6 +212,7 @@
 		timeSize=len;
 
 	}
+
 	public LocalizedInput getNewInput(InputStream i) {
 		try {
 			if (encode != null)
@@ -222,6 +223,16 @@
 		}
 		return new LocalizedInput(i);
 	}
+
+	public LocalizedInput getNewEncodedInput(InputStream i, String encoding) {
+		try {
+	          return new LocalizedInput(i,encoding);
+		}
+		catch (UnsupportedEncodingException e){
+			
+		}
+		return new LocalizedInput(i);
+        }
 
 	public LocalizedOutput getNewOutput(OutputStream o){
 		try {

Modified: db/derby/code/branches/10.1/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/tools/org/apache/derby/impl/tools/ij/utilMain.java?rev=394771&r1=394770&r2=394771&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/tools/org/apache/derby/impl/tools/ij/utilMain.java (original)
+++ db/derby/code/branches/10.1/java/tools/org/apache/derby/impl/tools/ij/utilMain.java Mon Apr 17 13:36:11 2006
@@ -541,7 +541,7 @@
 		if (is==null) throw ijException.resourceNotFound();
 		oldGrabbers.push(commandGrabber[currCE]);
 	    commandGrabber[currCE] = 
-                new StatementFinder(langUtil.getNewInput(new BufferedInputStream(is, BUFFEREDFILESIZE)));
+                new StatementFinder(langUtil.getNewEncodedInput(new BufferedInputStream(is, BUFFEREDFILESIZE), "UTF8"));
 		fileInput = true;
 	}