ooo-build r14177 - in trunk/extensions/coooder: . source/org/openoffice/coooder/comp source/org/openoffice/coooder/comp/test source/org/openoffice/coooder/comp/test/base source/org/openoffice/coooder/comp/ui tests tests/expected



Author: cbosdo
Date: Wed Oct  1 16:38:56 2008
New Revision: 14177
URL: http://svn.gnome.org/viewvc/ooo-build?rev=14177&view=rev

Log:
Beginning of a unit test infrastructure for the extension
Added forgotten license headers in some classes

Added:
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/AllTests.java   (contents, props changed)
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/SyntaxTest.java   (contents, props changed)
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/Bootstrap.java   (contents, props changed)
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/UnoTestCase.java   (contents, props changed)
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/UnoTestSuite.java   (contents, props changed)
   trunk/extensions/coooder/tests/
   trunk/extensions/coooder/tests/css.txt   (contents, props changed)
   trunk/extensions/coooder/tests/expected/
   trunk/extensions/coooder/tests/expected/css.html   (contents, props changed)
   trunk/extensions/coooder/tests/expected/java.html   (contents, props changed)
   trunk/extensions/coooder/tests/java.txt   (contents, props changed)
Modified:
   trunk/extensions/coooder/.classpath
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/SetNode.java
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/AbstractDialog.java
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/LanguageDialog.java
   trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/ParseTriggerImpl.java

Modified: trunk/extensions/coooder/.classpath
==============================================================================
--- trunk/extensions/coooder/.classpath	(original)
+++ trunk/extensions/coooder/.classpath	Wed Oct  1 16:38:56 2008
@@ -3,6 +3,7 @@
 	<classpathentry kind="src" path="source"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="build"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
 	<classpathentry kind="con" path="org.openoffice.ide.eclipse.java.OOO_CONTAINER/OpenOffice.org 2.4"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: trunk/extensions/coooder/source/org/openoffice/coooder/comp/SetNode.java
==============================================================================
--- trunk/extensions/coooder/source/org/openoffice/coooder/comp/SetNode.java	(original)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/SetNode.java	Wed Oct  1 16:38:56 2008
@@ -1,3 +1,21 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 package org.openoffice.coooder.comp;
 
 import org.openoffice.coooder.HighlightingException;

Added: trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/AllTests.java
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/AllTests.java	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,40 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package org.openoffice.coooder.comp.test;
+
+import org.openoffice.coooder.comp.test.base.UnoTestSuite;
+
+import junit.framework.Test;
+
+
+public class AllTests  {
+
+    public static Test suite() {
+        
+        // The tests to run by the suite
+        Class[] testClasses = new Class[] {
+                DummyTest.class
+        };
+        
+        // Create the test suite
+        UnoTestSuite suite = new UnoTestSuite(testClasses);
+        
+        return suite;
+    }
+}

Added: trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/SyntaxTest.java
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/SyntaxTest.java	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,118 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package org.openoffice.coooder.comp.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.openoffice.coooder.XHighlighter;
+import org.openoffice.coooder.XLanguage;
+import org.openoffice.coooder.theLanguagesManager;
+import org.openoffice.coooder.comp.test.base.UnoTestCase;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.FrameSearchFlag;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.view.XSelectionSupplier;
+
+
+public class SyntaxTest extends UnoTestCase {
+
+    public void testSyntaxHighlighting() {
+        try {
+            // Generate the document
+            XTextDocument xDoc = generateDocument("css");
+            
+            // Highlight the selection
+            highlight("css");
+
+            // Compare with the geshi generated file
+            compareWithGeshi(xDoc, "css");
+        
+        } catch (Exception e) {
+            fail("Shouldn't have thrown an exception");
+        }
+    }
+
+    private XTextDocument generateDocument(String pLanguage) throws Exception {
+        // Create a new text document
+        XTextDocument xDoc = loadDocument("private:factory/swriter");
+
+        // Copy the test string in the document
+        String testString = readTestFile(pLanguage);
+        xDoc.getText().setString(testString);
+        
+        // Select the whole inserted text
+        Object oController = xDoc.getCurrentController();
+        XSelectionSupplier xSelSupplier = (XSelectionSupplier)UnoRuntime.queryInterface(
+                XSelectionSupplier.class, oController);
+        xSelSupplier.select(xDoc.getText());
+        
+        return xDoc;
+    }
+
+    private void highlight(String pLanguage) throws Exception {
+        XMultiComponentFactory xMngr = getContext().getServiceManager();
+        Object oHighlighter = xMngr.createInstanceWithContext(
+                "org.openoffice.coooder.Highlighter", getContext());
+        XHighlighter xHL = (XHighlighter)UnoRuntime.queryInterface(XHighlighter.class, oHighlighter);
+        
+        XLanguage xLang = theLanguagesManager.get(getContext()).getLanguage(pLanguage);
+        xHL.setLanguage(xLang);
+        
+        // There is no need of a progress monitor here.
+        xHL.parse(null);
+    }
+    
+    private void compareWithGeshi(XTextDocument pDoc, String pLanguage) {
+        // TODO Load the HTML document generated by Geshi
+        
+        
+        // TODO Loop over each character and compare its color, wont weight and slant
+    }
+
+    private String readTestFile(String pLanguage) throws Exception {
+        String pwd = System.getenv("user.dir");
+        File file = new File(pwd, pLanguage + ".txt");
+        
+        FileInputStream fi = new FileInputStream(file);
+        byte[] buf = new byte[fi.available()];
+        fi.read(buf);
+        String text = new String(buf);
+        
+        return text;
+    }
+
+    private XTextDocument loadDocument(String pUrl) throws Exception {
+        XMultiComponentFactory xMngr = getContext().getServiceManager();
+        Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", getContext());
+        XComponentLoader xLoader = (XComponentLoader)UnoRuntime.queryInterface(
+                XComponentLoader.class, oDesktop);
+
+        XComponent xDoc = xLoader.loadComponentFromURL(pUrl, "_default", 
+                FrameSearchFlag.ALL, new PropertyValue[0]);
+        
+        XTextDocument xTextDoc = (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xDoc);
+        return xTextDoc;
+    }
+}

Added: trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/Bootstrap.java
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/Bootstrap.java	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,337 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: Bootstrap.java,v $
+ * $Revision: 1.16 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package org.openoffice.coooder.comp.test.base;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Random;
+
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.helper.BootstrapException;
+import com.sun.star.comp.helper.ComponentContext;
+import com.sun.star.comp.helper.ComponentContextEntry;
+import com.sun.star.comp.loader.JavaLoader;
+import com.sun.star.container.XSet;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.util.NativeLibraryLoader;
+import com.sun.star.loader.XImplementationLoader;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+/** Bootstrap offers functionality to obtain a context or simply
+    a service manager.
+    The service manager can create a few basic services, whose implementations  are:
+    <ul>
+    <li>com.sun.star.comp.loader.JavaLoader</li>
+    <li>com.sun.star.comp.urlresolver.UrlResolver</li>
+    <li>com.sun.star.comp.bridgefactory.BridgeFactory</li>
+    <li>com.sun.star.comp.connections.Connector</li>
+    <li>com.sun.star.comp.connections.Acceptor</li>
+    <li>com.sun.star.comp.servicemanager.ServiceManager</li>
+    </ul>
+
+    Other services can be inserted into the service manager by
+    using its XSet interface:
+    <pre>
+        XSet xSet = (XSet)UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
+        // insert the service manager
+        xSet.insert( aSingleComponentFactory );
+    </pre>
+    
+    @author cbosdo Changed the class for a better control of the bootstrap using a custom classloader
+*/  
+public class Bootstrap {
+    
+    private static void insertBasicFactories(
+        XSet xSet, XImplementationLoader xImpLoader )
+        throws Exception
+    {
+        // insert the factory of the loader        
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.loader.JavaLoader", null, null, null ) );
+        
+        // insert the factory of the URLResolver        
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) );
+        
+        // insert the bridgefactory
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null ) );
+        
+        // insert the connector
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.connections.Connector", null, null, null ) );
+        
+        // insert the acceptor
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.connections.Acceptor", null, null, null ) );
+    }
+    
+    /** Bootstraps an initial component context with service manager and basic
+        jurt components inserted.
+        @param context_entries the hash table contains mappings of entry names (type string) to
+        context entries (type class ComponentContextEntry).
+        @return a new context.
+    */
+    static public XComponentContext createInitialComponentContext( Hashtable context_entries )
+        throws Exception
+    {
+        XImplementationLoader xImpLoader = (XImplementationLoader)UnoRuntime.queryInterface(
+            XImplementationLoader.class, new JavaLoader() );
+        
+        // Get the factory of the ServiceManager
+        XSingleComponentFactory smgr_fac = (XSingleComponentFactory)UnoRuntime.queryInterface(
+            XSingleComponentFactory.class, xImpLoader.activate(
+                "com.sun.star.comp.servicemanager.ServiceManager", null, null, null ) );
+        
+        // Create an instance of the ServiceManager
+        XMultiComponentFactory xSMgr = (XMultiComponentFactory)UnoRuntime.queryInterface(
+            XMultiComponentFactory.class, smgr_fac.createInstanceWithContext( null ) );
+        
+        // post init loader
+        XInitialization xInit = (XInitialization)UnoRuntime.queryInterface(
+            XInitialization.class, xImpLoader );
+        Object[] args = new Object [] { xSMgr };
+        xInit.initialize( args );
+        
+        // initial component context
+        if (context_entries == null)
+            context_entries = new Hashtable( 1 );
+        // add smgr
+        context_entries.put(
+            "/singletons/com.sun.star.lang.theServiceManager",
+            new ComponentContextEntry( null, xSMgr ) );
+        // ... xxx todo: add standard entries
+        XComponentContext xContext = new ComponentContext( context_entries, null );
+        
+        // post init smgr
+        xInit = (XInitialization)UnoRuntime.queryInterface(
+            XInitialization.class, xSMgr );
+        args = new Object [] { null, xContext }; // no registry, default context
+        xInit.initialize( args );
+        
+        XSet xSet = (XSet)UnoRuntime.queryInterface( XSet.class, xSMgr );
+        // insert the service manager
+        xSet.insert( smgr_fac );
+        // and basic jurt factories
+        insertBasicFactories( xSet, xImpLoader );
+        
+        return xContext;
+    }
+    
+    /**
+     * Bootstraps a servicemanager with the jurt base components registered.
+     * <p>
+     * @return     a freshly boostrapped service manager
+     * @see        com.sun.star.lang.ServiceManager
+     */
+    static public XMultiServiceFactory createSimpleServiceManager() throws Exception
+    {
+        return (XMultiServiceFactory)UnoRuntime.queryInterface(
+            XMultiServiceFactory.class, createInitialComponentContext( null ).getServiceManager() );
+    }
+    
+    
+    /** Bootstraps the initial component context from a native UNO installation.
+        
+        @see cppuhelper/defaultBootstrap_InitialComponentContext()
+    */
+    static public final XComponentContext defaultBootstrap_InitialComponentContext()
+        throws Exception
+    {
+        return defaultBootstrap_InitialComponentContext( null, null );
+    }
+    /** Bootstraps the initial component context from a native UNO installation.
+        
+        @param ini_file
+               ini_file (may be null: uno.rc besides cppuhelper lib)
+        @param bootstrap_parameters
+               bootstrap parameters (maybe null)
+               
+        @see cppuhelper/defaultBootstrap_InitialComponentContext()
+    */
+    static public final XComponentContext defaultBootstrap_InitialComponentContext(
+        String ini_file, Hashtable bootstrap_parameters )
+        throws Exception
+    {
+        // jni convenience: easier to iterate over array than calling Hashtable
+        String pairs [] = null;
+        if (null != bootstrap_parameters)
+        {
+            pairs = new String [ 2 * bootstrap_parameters.size() ];
+            Enumeration keys = bootstrap_parameters.keys();
+            int n = 0;
+            while (keys.hasMoreElements())
+            {
+                String name = (String)keys.nextElement();
+                pairs[ n++ ] = name;
+                pairs[ n++ ] = (String)bootstrap_parameters.get( name );
+            }
+        }
+        
+        if (! m_loaded_juh)
+        {
+            System.loadLibrary( "juh" );
+            m_loaded_juh = true;
+        }
+        return (XComponentContext)UnoRuntime.queryInterface(
+            XComponentContext.class,
+            cppuhelper_bootstrap(
+                ini_file, pairs, Bootstrap.class.getClassLoader() ) );
+    }
+    
+    static private boolean m_loaded_juh = false;
+    static private native Object cppuhelper_bootstrap(
+        String ini_file, String bootstrap_parameters [], ClassLoader loader )
+        throws Exception;
+
+    /**
+     * Bootstraps the component context from a UNO installation.
+     *   
+     * @return a bootstrapped component context.
+     * 
+     * @since UDK 3.1.0
+     */    
+    public static final XComponentContext bootstrap(URLClassLoader loader)
+        throws BootstrapException {
+        
+        XComponentContext xContext = null;
+        
+        try {
+            // create default local component context                
+            XComponentContext xLocalContext =
+                createInitialComponentContext( null );
+            if ( xLocalContext == null )
+                throw new BootstrapException( "no local component context!" );
+            
+            // find office executable relative to this class's class loader
+            String sOffice =
+                System.getProperty( "os.name" ).startsWith( "Windows" ) ?
+                "soffice.exe" : "soffice";            
+            File fOffice = NativeLibraryLoader.getResource( loader, sOffice );
+            if ( fOffice == null )
+                throw new BootstrapException( "no office executable found!" );
+
+            // create random pipe name
+            String sPipeName = "uno" +
+                Long.toString( (new Random()).nextLong() & 0x7fffffffffffffffL );
+            
+            // create call with arguments
+            String[] cmdArray = new String[7];
+            cmdArray[0] = fOffice.getPath();
+            cmdArray[1] = "-nologo";
+            cmdArray[2] = "-nodefault";
+            cmdArray[3] = "-norestore";
+            cmdArray[4] = "-nocrashreport";
+            cmdArray[5] = "-nolockcheck";
+            cmdArray[6] = "-accept=pipe,name=" + sPipeName + ";urp;";
+            
+            // start office process
+            Process p = Runtime.getRuntime().exec( cmdArray );
+            pipe( p.getInputStream(), System.out, "CO> " );
+            pipe( p.getErrorStream(), System.err, "CE> " );
+            
+            // initial service manager
+            XMultiComponentFactory xLocalServiceManager =
+                xLocalContext.getServiceManager();
+            if ( xLocalServiceManager == null )
+                throw new BootstrapException( "no initial service manager!" );
+            
+            // create a URL resolver
+            XUnoUrlResolver xUrlResolver =
+                UnoUrlResolver.create( xLocalContext );
+            
+            // connection string
+            String sConnect = "uno:pipe,name=" + sPipeName +
+                ";urp;StarOffice.ComponentContext";
+            
+            // wait until office is started
+            for (int i = 0;; ++i) {
+                try {
+                    // try to connect to office
+                    Object context = xUrlResolver.resolve( sConnect );
+                    xContext = (XComponentContext) UnoRuntime.queryInterface(
+                        XComponentContext.class, context);
+                    if ( xContext == null )
+                        throw new BootstrapException( "no component context!" );
+                    break;
+                } catch ( com.sun.star.connection.NoConnectException ex ) {
+                    // Wait 500 ms, then try to connect again, but do not wait
+                    // longer than 5 min (= 600 * 500 ms) total:
+                    if (i == 600) {
+                        throw new BootstrapException(ex.toString());
+                    }
+                    Thread.sleep( 500 );
+                }
+            }
+        } catch ( BootstrapException e ) {
+            throw e;
+        } catch ( java.lang.RuntimeException e ) {
+            throw e;
+        } catch ( java.lang.Exception e ) {
+            throw new BootstrapException( e );
+        }
+        
+        return xContext;
+    }
+
+    private static void pipe(
+        final InputStream in, final PrintStream out, final String prefix ) {
+        
+        new Thread( "Pipe: " + prefix) {
+            public void run() {
+                BufferedReader r = new BufferedReader(
+                    new InputStreamReader( in ) );
+                try {
+                    for ( ; ; ) {
+                        String s = r.readLine();
+                        if ( s == null ) {
+                            break;
+                        }
+                        out.println( prefix + s );
+                    }
+                } catch ( java.io.IOException e ) {
+                    e.printStackTrace( System.err );
+                }
+            }
+        }.start();
+    }
+}

Added: trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/UnoTestCase.java
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/UnoTestCase.java	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,69 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package org.openoffice.coooder.comp.test.base;
+
+import junit.framework.TestCase;
+
+import com.sun.star.uno.XComponentContext;
+
+/**
+ * Base for all test cases to use along with { link UnoTestSuite}.
+ * 
+ * @author cbosdo
+ *
+ */
+public abstract class UnoTestCase extends TestCase {
+    
+    /**
+     * Default constructor.
+     */
+    public UnoTestCase() {
+        super();
+    }
+
+    /**
+     * Constructor to use to run only one test
+     *  
+     * @param pName the test name
+     */
+    public UnoTestCase(String pName) {
+        super(pName);
+    }
+    
+
+    private XComponentContext mContext;
+
+    /**
+     * Set the office context to use in the tests.
+     * 
+     * @param pContext the remote office context
+     */
+    public void setContext(XComponentContext pContext) {
+        mContext = pContext;
+    }
+    
+    /**
+     * Get the office context to use in the tests.
+     * 
+     * @return the remote office context
+     */
+    protected XComponentContext getContext() {
+        return mContext;
+    }
+}

Added: trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/UnoTestSuite.java
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/test/base/UnoTestSuite.java	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,144 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */package org.openoffice.coooder.comp.test.base;
+
+ 
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import com.sun.star.frame.XDesktop;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+/**
+ * This is a test suite for an OOo extension unit tests: 
+ * it bootstraps an OOo instance and handles the connection with it.
+ * 
+ * The extension to test has to be already installed on OOo for the
+ * current user.
+ * 
+ * @author cbosdo
+ *
+ */
+public class UnoTestSuite extends TestSuite {
+    
+    private XComponentContext mContext;
+    private boolean mHandleConnection = false;
+    
+    
+    public UnoTestSuite() {
+        super();
+    }
+
+    public UnoTestSuite(Class pTheClass, String pName) {
+        super(pTheClass, pName);
+    }
+
+    public UnoTestSuite(Class pTheClass) {
+        super(pTheClass);
+    }
+
+    public UnoTestSuite(Class[] pClasses, String pName) {
+        super(pClasses, pName);
+    }
+
+    public UnoTestSuite(Class[] pClasses) {
+        // Override to create UnoTestSuites instead of TestSuites
+        for (int i= 0; i < pClasses.length; i++) {
+            addTest(new UnoTestSuite(pClasses[i]));
+        }
+    }
+
+    public UnoTestSuite(String pName) {
+        super(pName);
+    }
+    
+    public void run(TestResult pResult) {
+        
+        try {
+            startOffice();
+            
+            super.run(pResult);
+        } catch (Exception e) {
+            System.err.println("Unable to run the tests");
+            e.printStackTrace();
+        }
+        
+        stopOffice();
+    }
+    
+    public void runTest(Test pTest, TestResult pResult) {
+        // Try to set the context on the test
+        if (pTest instanceof UnoTestCase) {
+            ((UnoTestCase)pTest).setContext(mContext);
+        } else if (pTest instanceof UnoTestSuite) {
+            UnoTestSuite suite = (UnoTestSuite)pTest;
+            suite.setContext(mContext);
+        }
+        
+        super.runTest(pTest, pResult);
+    }
+    
+    protected void setContext(XComponentContext pContext) {
+        mContext = pContext;
+    }
+    
+    protected void setHandleConnection(boolean pHandle) {
+        mHandleConnection = pHandle;
+    }
+    
+    /**
+     * Starts openoffice.org only if the context isn't set.
+     * 
+     * @throws Exception if anything wrong happens when starting the office
+     */
+    private void startOffice() throws Exception {
+        if (mContext == null) {
+            String path = System.getProperty("openoffice.program.path");
+            if (path == null) {
+                throw new Exception("The openoffice.install.path variable is missing");
+            }
+
+            File baseDir = new File(path);
+            URLClassLoader classLoader = new URLClassLoader(new URL[]{baseDir.toURI().toURL()});
+            mContext = Bootstrap.bootstrap(classLoader);
+            mHandleConnection = true;
+        }
+    }
+    
+    private void stopOffice() {
+        try {
+            if (mContext != null && mHandleConnection) {
+                // Only the uno test suite which started the office can stop it
+                XMultiComponentFactory xMngr = mContext.getServiceManager();
+                Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", mContext);
+                XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+                
+                xDesktop.terminate();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

Modified: trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/AbstractDialog.java
==============================================================================
--- trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/AbstractDialog.java	(original)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/AbstractDialog.java	Wed Oct  1 16:38:56 2008
@@ -1,3 +1,21 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 package org.openoffice.coooder.comp.ui;
 
 import com.sun.star.awt.MessageBoxButtons;

Modified: trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/LanguageDialog.java
==============================================================================
--- trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/LanguageDialog.java	(original)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/LanguageDialog.java	Wed Oct  1 16:38:56 2008
@@ -1,3 +1,21 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 package org.openoffice.coooder.comp.ui;
 
 import org.openoffice.coooder.theLanguagesManager;

Modified: trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/ParseTriggerImpl.java
==============================================================================
--- trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/ParseTriggerImpl.java	(original)
+++ trunk/extensions/coooder/source/org/openoffice/coooder/comp/ui/ParseTriggerImpl.java	Wed Oct  1 16:38:56 2008
@@ -1,3 +1,21 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  CÃdric Bosdonnat cedricbosdo openoffice org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 package org.openoffice.coooder.comp.ui;
 
 import java.util.Calendar;

Added: trunk/extensions/coooder/tests/css.txt
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/tests/css.txt	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,7 @@
+.xformsItem 
+{ 
+/*  border: 1px dashed blue; */ 
+    margin-right: 2px; 
+    clear: both; 
+    aqua: toto;
+}

Added: trunk/extensions/coooder/tests/expected/css.html
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/tests/expected/css.html	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,8 @@
+<pre class="css"><span style="color: #6666ff;">.xformsItem</span> 
+<span style="color: #66cc66;">&#123;</span> 
+<span style="color: #808080; font-style: italic;">/*  border: 1px dashed blue; */</span> 
+    <span style="color: #000000; font-weight: bold;">margin-right</span>: <span style="color: #933;">2px</span>; 
+    <span style="color: #000000; font-weight: bold;">clear</span>: <span style="color: #993333;">both</span>; 
+    <span style="color: #000000; font-weight: bold;">aqua</span>: toto;
+<span style="color: #66cc66;">&#125;</span>
+&nbsp;</pre>
\ No newline at end of file

Added: trunk/extensions/coooder/tests/expected/java.html
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/tests/expected/java.html	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,40 @@
+<pre class="java"><span style="color: #808080; font-style: italic;">/**
+ * Highlighter implementation using the GeSHi algorithm adapted to OpenOffice.org API.
+ * 
+ * @author cbosdonnat
+ */</span>
+<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> HighlighterImpl <span style="color: #000000; font-weight: bold;">extends</span> WeakBase <span style="color: #000000; font-weight: bold;">implements</span> XServiceInfo, XHighlighter <span style="color: #66cc66;">&#123;</span>
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky";><span style="color: #aaaadd; font-weight: bold;">String</span></a> IMPLEMENTATION_NAME = HighlighterImpl.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky";><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> SERVICE_NAMES = <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">&quot;org.openoffice.coooder.Highlighter&quot;</span> <span style="color: #66cc66;">&#125;</span>;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #993333;">int</span> OPEN = <span style="color: #cc66cc;">0</span>;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #993333;">int</span> CLOSE = <span style="color: #cc66cc;">1</span>;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky";><span style="color: #aaaadd; font-weight: bold;">String</span></a> NUMBER_REGEX = <span style="color: #ff0000;">&quot;[-+]?<span style="color: #000099; font-weight: bold;">\\</span>b(?:[0-9]*<span style="color: #000099; font-weight: bold;">\\</span>.)?[0-9]+<span style="color: #000099; font-weight: bold;">\\</span>b&quot;</span>;
+&nbsp;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> XComponentContext mContext;
+    <span style="color: #000000; font-weight: bold;">private</span> XLanguage mLanguage;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">private</span> CompiledPatternsCache mPatternsCache;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">private</span> XTextRange mSelectionStart;
+    <span style="color: #000000; font-weight: bold;">private</span> XTextDocument mTextDocument;
+    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> mLength;
+&nbsp;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">public</span> HighlighterImpl<span style="color: #66cc66;">&#40;</span>XComponentContext pContext<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
+        mContext = pContext;
+        mPatternsCache = <span style="color: #000000; font-weight: bold;">new</span> CompiledPatternsCache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
+    <span style="color: #66cc66;">&#125;</span>;
+&nbsp;
+    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> XSingleComponentFactory __getComponentFactory<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky";><span style="color: #aaaadd; font-weight: bold;">String</span></a> pImplementationName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
+        XSingleComponentFactory xFactory = <span style="color: #000000; font-weight: bold;">null</span>;
+&nbsp;
+        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>pImplementationName.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>IMPLEMENTATION_NAME<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
+            xFactory = Factory.<span style="color: #006600;">createComponentFactory</span><span style="color: #66cc66;">&#40;</span>HighlighterImpl.<span style="color: #000000; font-weight: bold;">class</span>, SERVICE_NAMES<span style="color: #66cc66;">&#41;</span>;   
+        <span style="color: #66cc66;">&#125;</span>
+        <span style="color: #000000; font-weight: bold;">return</span> xFactory;
+    <span style="color: #66cc66;">&#125;</span>
+<span style="color: #66cc66;">&#125;</span></pre>
\ No newline at end of file

Added: trunk/extensions/coooder/tests/java.txt
==============================================================================
--- (empty file)
+++ trunk/extensions/coooder/tests/java.txt	Wed Oct  1 16:38:56 2008
@@ -0,0 +1,40 @@
+/**
+ * Highlighter implementation using the GeSHi algorithm adapted to OpenOffice.org API.
+ * 
+ * @author cbosdonnat
+ */
+public final class HighlighterImpl extends WeakBase implements XServiceInfo, XHighlighter {
+    
+    private static final String IMPLEMENTATION_NAME = HighlighterImpl.class.getName();
+    private static final String[] SERVICE_NAMES = { "org.openoffice.coooder.Highlighter" };
+    
+    private static final int OPEN = 0;
+    private static final int CLOSE = 1;
+    
+    private static final String NUMBER_REGEX = "[-+]?\\b(?:[0-9]*\\.)?[0-9]+\\b";
+    
+    
+    private final XComponentContext mContext;
+    private XLanguage mLanguage;
+    
+    private CompiledPatternsCache mPatternsCache;
+
+    private XTextRange mSelectionStart;
+    private XTextDocument mTextDocument;
+    private int mLength;
+    
+
+    public HighlighterImpl(XComponentContext pContext) {
+        mContext = pContext;
+        mPatternsCache = new CompiledPatternsCache();
+    };
+
+    public static XSingleComponentFactory __getComponentFactory(String pImplementationName) {
+        XSingleComponentFactory xFactory = null;
+
+        if (pImplementationName.equals(IMPLEMENTATION_NAME)) {
+            xFactory = Factory.createComponentFactory(HighlighterImpl.class, SERVICE_NAMES);   
+        }
+        return xFactory;
+    }
+}
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]