Revision: 1758
          http://svn.sourceforge.net/vexi/?rev=1758&view=rev
Author:   mkpg2
Date:     2007-03-27 01:45:17 -0700 (Tue, 27 Mar 2007)

Log Message:
-----------
Tests. Download test was just working through main(), not suite().

Modified Paths:
--------------
    core/trunk/org.vexi.core/src_junit/test/core/TestCore.java
    core/trunk/org.vexi.core/src_junit/test/core/download/TestDownload.java
    core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java

Modified: core/trunk/org.vexi.core/src_junit/test/core/TestCore.java
===================================================================
--- core/trunk/org.vexi.core/src_junit/test/core/TestCore.java  2007-03-27 
07:30:24 UTC (rev 1757)
+++ core/trunk/org.vexi.core/src_junit/test/core/TestCore.java  2007-03-27 
08:45:17 UTC (rev 1758)
@@ -3,6 +3,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import test.core.biscuits.TestBiscuits;
+import test.core.download.TestDownload;
 import test.core.general.TestGeneral;
 import test.core.linenumbering.TestLineNumbering;
 import test.core.namespace_vars.TestNamespaceVars;
@@ -16,13 +17,14 @@
 
        static public Test suite() {
                TestSuite suite = new 
TestSuite(JSTestSuite.nameFromClass(TestCore.class));
+               suite.addTest(TestBiscuits.suite());
+               suite.addTest(TestDownload.suite());
                suite.addTest(TestGeneral.suite());
+               suite.addTest(TestLineNumbering.suite());
                suite.addTest(TestNamespaceVars.suite());
                suite.addTest(TestPreapply.suite());
-               suite.addTest(TestLineNumbering.suite());
+               suite.addTest(TestStream.suite());
                suite.addTest(TestThread.suite());
-               suite.addTest(TestBiscuits.suite());
-               suite.addTest(TestStream.suite());
                return suite;
        }
 }

Modified: 
core/trunk/org.vexi.core/src_junit/test/core/download/TestDownload.java
===================================================================
--- core/trunk/org.vexi.core/src_junit/test/core/download/TestDownload.java     
2007-03-27 07:30:24 UTC (rev 1757)
+++ core/trunk/org.vexi.core/src_junit/test/core/download/TestDownload.java     
2007-03-27 08:45:17 UTC (rev 1758)
@@ -13,18 +13,44 @@
 import junit.framework.TestCase;
 import test.core.CoreTestCase;
 import test.core.CoreTestSuite;
+import test.js.JSTestSuite;
 import testdeployment.NanoHTTPD;
 
 /**
  * @author mike
  */
-public class TestDownload{
+public class TestDownload extends CoreTestSuite{
 
-    public static Test suite() {
-       //return CoreTestSuite.suite(TestDownload.class);
-       return null;
+    public TestDownload() {
+               super(TestDownload.class);
+       }
+
+       public static Test suite() {
+       return JSTestSuite.suite(new TestDownload());
     }
+
+    public static void main(String[] args) throws Throwable {
+       CoreTestSuite cts = new TestDownload();
+       TestCase t = cts.createTestCase(cts.getResourceDirs(), "splashtest.t");
+       t.runBare();
+       }
+
+    public TestCase createTestCase(String[] resourceDirs, String fileName) {
+       return new CoreTestCase(resourceDirs, fileName){
+               protected void setUp() throws Exception {
+                       createDotVexi(new 
File(NanoHTTPD.class.getResource(".").getPath()));
+               NanoHTTPD.start();
+               }
+               
+               protected void tearDown() throws Exception {
+                       NanoHTTPD.stop();
+               }
+       };
+    }
     
+    
+    
+       
     static private void createDotVexi(File root) throws IOException{
        
        File dotVexi = new File(root, "example.vexi");
@@ -74,13 +100,4 @@
         }
     }
     
-    public static void main(String[] args) throws Throwable {
-       createDotVexi(new File(NanoHTTPD.class.getResource(".").getPath()));
-       
-       NanoHTTPD.start();
-       
-       CoreTestSuite cts = new CoreTestSuite(TestDownload.class);
-       TestCase t = cts.createTestCase(cts.getResourceDirs(), "splashtest.t");
-       t.runBare();
-       }
 }

Modified: core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java
===================================================================
--- core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java    
2007-03-27 07:30:24 UTC (rev 1757)
+++ core/trunk/org.vexi.core/src_junit/testdeployment/NanoHTTPD.java    
2007-03-27 08:45:17 UTC (rev 1758)
@@ -4,6 +4,8 @@
 import java.util.*;
 import java.net.*;
 
+import org.ibex.util.Log;
+
 import test.core.download.TestDownload;
 
 /**
@@ -48,7 +50,7 @@
  */
 public class NanoHTTPD
 {
-       static boolean log = false;
+       //static int logLevel = Log.INFO;
        
        static public int PORT = 7070;
        private static NanoHTTPD singleton;
@@ -57,6 +59,11 @@
                if(singleton==null) singleton = new NanoHTTPD(PORT);
        }
        
+       static public void stop() throws IOException{
+               if(singleton!=null) singleton.myThread.interrupt();
+               singleton = null;
+       }
+               
        
        // ==================================================
        // API parts
@@ -78,20 +85,20 @@
         */
        public Response serve( String uri, String method, Properties header, 
Properties parms )
        {
-               if(log) System.out.println( method + " '" + uri + "' " );
+               Log.info(NanoHTTPD.class, method + " '" + uri + "' " );
 
                Enumeration e = header.propertyNames();
                while ( e.hasMoreElements())
                {
                        String value = (String)e.nextElement();
-                       if(log) System.out.println( "  HDR: '" + value + "' = 
'" +
+                       Log.info(NanoHTTPD.class, "  HDR: '" + value + "' = '" +
                                                                
header.getProperty( value ) + "'" );
                }
                e = parms.propertyNames();
                while ( e.hasMoreElements())
                {
                        String value = (String)e.nextElement();
-                       if(log) System.out.println( "  PRM: '" + value + "' = 
'" +
+                       Log.info(NanoHTTPD.class, "  PRM: '" + value + "' = '" +
                                                                
parms.getProperty( value ) + "'" );
                }
                
@@ -199,21 +206,22 @@
                myTcpPort = port;
 
                final ServerSocket ss = new ServerSocket( myTcpPort );
-               Thread t = new Thread( new Runnable()
+               myThread = new Thread( new Runnable()
                        {
                                public void run()
                                {
                                        try
                                        {
-                                               while( true )
+                                               while( !Thread.interrupted() )
                                                        new HTTPSession( 
ss.accept());
                                        }
                                        catch ( IOException ioe )
                                        {}
+                                       System.out.println("NanoHTTPD, finished 
serving");
                                }
                        });
-               t.setDaemon( true );
-               t.start();
+               myThread.setDaemon( true );
+               myThread.start();
        }
 
        /**
@@ -221,7 +229,7 @@
         */
        public static void main( String[] args )
        {
-               if(log) System.out.println( "NanoHTTPD 1.04 (C) 2001,2005 Jarno 
Elonen\n" +
+               Log.info(NanoHTTPD.class, "NanoHTTPD 1.04 (C) 2001,2005 Jarno 
Elonen\n" +
                                                        "(Command line options: 
[port] [--licence])\n" );
 
                // Show licence if requested
@@ -230,7 +238,7 @@
                if ( args[i].toLowerCase().endsWith( "licence" ))
                {
                        lopt = i;
-                       if(log) System.out.println( LICENCE + "\n" );
+                       Log.info(NanoHTTPD.class,  LICENCE + "\n" );
                }
 
                // Change port if requested
@@ -240,7 +248,7 @@
 
                if ( args.length > 1 &&
                         args[1].toLowerCase().endsWith( "licence" ))
-                               if(log) System.out.println( LICENCE + "\n" );
+                        Log.info(NanoHTTPD.class, LICENCE + "\n" );
 
                NanoHTTPD nh = null;
                try
@@ -253,9 +261,9 @@
                        System.exit( -1 );
                }
 
-               if(log) System.out.println( "Now serving files in port " + port 
+ " from \"" +
+               Log.info(NanoHTTPD.class, "Now serving files in port " + port + 
" from \"" +
                                nh.myFileDir.getAbsolutePath() + "\"" );
-               if(log) System.out.println( "Hit Enter to stop.\n" );
+               Log.info(NanoHTTPD.class, "Hit Enter to stop.\n" );
 
                try { System.in.read(); } catch( Throwable t ) {};
        }
@@ -515,6 +523,7 @@
 
        private int myTcpPort;
        File myFileDir;
+       Thread myThread;
 
        // ==================================================
        // File server code


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to