db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r593635 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/tests/tools/SysinfoCPCheckTest.java testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java tools/org/apache/derby/impl/tools/sysinfo/Main.java
Date Fri, 09 Nov 2007 19:39:48 GMT
Author: myrnavl
Date: Fri Nov  9 11:39:48 2007
New Revision: 593635

URL: http://svn.apache.org/viewvc?rev=593635&view=rev
Log:
DERBY-2903 ; adding init() to sysinfo.Main.java's call to 
   LocalizedResource.getInstance() ensures that if sysinfo has a clean 
   one that does not get affected by any earlier calls to init.
   After this, the redirections of system.out work correctly in a loop, so
   adjusting the test to do away with the hoky annotating and unraveling of
   the output; also now sequence of tests in tools._Suite no longer matters.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/SysinfoCPCheckTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/SysinfoCPCheckTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/SysinfoCPCheckTest.java?rev=593635&r1=593634&r2=593635&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/SysinfoCPCheckTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/SysinfoCPCheckTest.java
Fri Nov  9 11:39:48 2007
@@ -91,87 +91,77 @@
         final String[][] tstargs = {
                 // empty string; should check all; what to check? Just check top
                 // to ensure it recognizes it needs to check all.
-                {null, "0", "Testing for presence of all Derby-related librari" +
-                    "es; typically, only some are needed.", null, "0"},
-                    // incorrect syntax, or 'args' - should return usage
-                    {"a", "0", "USAGE: java org.apache.derby.tools.sysinfo -cp [" +
-                        " [ embedded ][ server ][ client] [ db2driver ] [ tools ]" +
-                        " [  anyClass.class ] ]", null, "1"},
-                        {"embedded", "6", Success, "derby.jar", "2"}, 
-                        {"server", "10", Success, "derbynet.jar", "3"},
-                        {"tools", "6", Success, "derbytools.jar", "4"},
-                        {"client", "6", Success, "derbyclient.jar", "5"},
-                        // let's not test the following valid value, it's likely to fail:
-                        // {"db2driver", "6", Success, "db2jcc.jar"},
-                        {thisclass, "6", Success, "SysinfoCPCheckTest", "6"},
-                        // neg tst, hope this doesn't exist
-                        {"nonexist.class", "6", "    (nonexist not found.)", null, "7"}
+                {null, "0", "Testing for presence of all Derby-related " +
+                    "libraries; typically, only some are needed.", null},
+                // incorrect syntax, or 'args' - should return usage
+                {"a", "0", "USAGE: java org.apache.derby.tools.sysinfo -cp [" +
+                    " [ embedded ][ server ][ client] [ db2driver ] [ tools ]" +
+                    " [  anyClass.class ] ]", null},
+                {"embedded", "6", Success, "derby.jar"}, 
+                {"server", "10", Success, "derbynet.jar"},
+                {"tools", "6", Success, "derbytools.jar"},
+                {"client", "6", Success, "derbyclient.jar"},
+                // let's not test the following valid value, it will 
+                // fail if db2jcc.jar is not on CLASSPATH
+                //{"db2driver", "6", Success, "db2jcc.jar"},
+                {thisclass, "6", Success, "SysinfoCPCheckTest"},
+                // neg tst, hope this doesn't exist
+                {"nonexist.class", "6", "    (nonexist not found.)", null}
         };
 
-        // First obtain the output of all sysinfo commands we want to test
-        // we print a number for each of the commands to test for unraveling
-        // them later.
-
         final String outputEncoding = "US-ASCII";
 
         PrintStream out = System.out;
-        try {
-            PrintStream testOut = new PrintStream(getOutputStream(),
-                    false, outputEncoding);
-            setSystemOut(testOut);
-        } catch (UnsupportedEncodingException uee) {
-            uee.printStackTrace();
-        }
 
-        for (int tst=0; tst<tstargs.length ; tst++)
+        int tst=0;
+        for (tst=0; tst<tstargs.length ; tst++)
         {
+            // First obtain the output for the sysinfo command
+            try {
+                PrintStream testOut = new PrintStream(getOutputStream(),
+                    false, outputEncoding);
+                setSystemOut(testOut);
+            } catch (UnsupportedEncodingException uee) {
+                uee.printStackTrace();
+            }
+
             if (!checkClientOrServer(tstargs[tst][0]))
                 continue;
 
-            // print out a number to unravel the fulloutput later
-            System.out.println(tstargs[tst][4]);
-
-            // The first command has only 1 arg
+            // First command has only 1 arg, prevent NPE with if/else block 
             if (tstargs[tst][0] == null)
-                org.apache.derby.tools.sysinfo.main(
-                    new String[] {"-cp"} );
+                org.apache.derby.tools.sysinfo.main(new String[] {"-cp"} );
             else
                 org.apache.derby.tools.sysinfo.main(
                     new String[] {"-cp", tstargs[tst][0]} );
-        }
-
-        setSystemOut(out);
-
-        rawBytes.flush();
-        rawBytes.close();
 
-        byte[] testRawBytes = rawBytes.toByteArray();
+            setSystemOut(out);
 
-        String s = null;
+            rawBytes.flush();
+            rawBytes.close();
 
-        try {
+            byte[] testRawBytes = rawBytes.toByteArray();
 
-            BufferedReader sysinfoOutput = new BufferedReader(
-                new InputStreamReader(
-                    new ByteArrayInputStream(testRawBytes),
-                        outputEncoding));
+            //System.out.println("cp command: -cp " + tstargs[tst][0]);
 
-            s = sysinfoOutput.readLine();
+            String s = null;
 
-            // evaluate the output
-            for (int tst=0; tst<tstargs.length ; tst++)
-            {
-                //System.out.println("cp command: -cp " + tstargs[tst][0]);
+            try {
+                BufferedReader sysinfoOutput = new BufferedReader(
+                    new InputStreamReader(
+                        new ByteArrayInputStream(testRawBytes),
+                            outputEncoding));
 
+                // evaluate the output
                 // compare the sentence picked
 
                 // first one is a bit different - is classpath dependent, so
                 // we're not going to look through all lines.
-                if (tstargs[tst][4].equals("0"))
+                if (tstargs[tst][0]==null)
                 {
                     s=sysinfoOutput.readLine();
                     assertEquals(tstargs[tst][2], s);
-                    while (!s.equals(tstargs[tst+1][4]))
+                    while (s != null)
                     {
                         s=sysinfoOutput.readLine();
                     }
@@ -181,9 +171,6 @@
                 if (!checkClientOrServer(tstargs[tst][0]))
                     continue;
 
-                if (!s.equals(tstargs[tst][4]))
-                    fail("out of sync with expected lines, indicates a problem");
-
                 // get the appropriate line for the full line comparison
                 int linenumber = Integer.parseInt(tstargs[tst][1]);
 
@@ -201,7 +188,7 @@
                 }
                 if (tstargs[tst][3] != null && !found)
                     fail ("did not find the string searched for: " + 
-                            tstargs[tst][3] + " for command -cp: " + tstargs[tst][0]);
+                         tstargs[tst][3] + " for command -cp: " + tstargs[tst][0]);
 
                 // read the line to be compared
                 s = sysinfoOutput.readLine();
@@ -215,11 +202,11 @@
 
                 // read one more line - should be the next command's sequence number
                 s = sysinfoOutput.readLine();
-            }
 
-            sysinfoOutput.close();
-        } catch (Exception e) {
-            e.printStackTrace();
+                sysinfoOutput.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java?rev=593635&r1=593634&r2=593635&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
Fri Nov  9 11:39:48 2007
@@ -45,18 +45,13 @@
 
         TestSuite suite = new TestSuite("tools");
 
-        // warning: SysinfoCPCheckTest reassigns System.out, and if
-        // one places this test after a test that runs 'runSQLCommands'
-        // (e.g. IJRunScriptTest, or ImportExportTest), the System.out
-        // never gets the redirected info.
-        // commenting out, as it's not working in Sun's nightlies - see DERBY-3152
-        //suite.addTest(SysinfoCPCheckTest.suite());
         suite.addTest(IJRunScriptTest.suite());
         suite.addTest(ImportExportTest.suite());
         suite.addTest(ImportExportBinaryDataTest.suite());
         suite.addTest(ImportExportLobTest.suite());
         suite.addTest(ImportExportProcedureTest.suite());
         suite.addTest(ToolScripts.suite());
+        suite.addTest(SysinfoCPCheckTest.suite());
 
         // SysinfoAPITest currently fails when run against jars, so is
         // disabled. Only the first jar file on the classpath properly

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java?rev=593635&r1=593634&r2=593635&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java Fri Nov 
9 11:39:48 2007
@@ -93,7 +93,7 @@
   */
   public static void main(String args[]) {
         // adjust the application in accordance with derby.ui.locale and derby.ui.codeset
-        LocalizedResource.getInstance();
+        LocalizedResource.getInstance().init();
 
 		LocalizedOutput out;
 



Mime
View raw message