diff options
Diffstat (limited to 'unotools/qa/complex/tempfile')
-rw-r--r-- | unotools/qa/complex/tempfile/TempFileTest.java | 34 | ||||
-rw-r--r-- | unotools/qa/complex/tempfile/TempFileUnitTest.java | 88 | ||||
-rw-r--r-- | unotools/qa/complex/tempfile/Test01.java | 123 | ||||
-rw-r--r-- | unotools/qa/complex/tempfile/Test02.java | 103 | ||||
-rw-r--r-- | unotools/qa/complex/tempfile/TestHelper.java | 228 | ||||
-rw-r--r-- | unotools/qa/complex/tempfile/makefile.mk | 89 |
6 files changed, 665 insertions, 0 deletions
diff --git a/unotools/qa/complex/tempfile/TempFileTest.java b/unotools/qa/complex/tempfile/TempFileTest.java new file mode 100644 index 000000000000..cc3cc19231b0 --- /dev/null +++ b/unotools/qa/complex/tempfile/TempFileTest.java @@ -0,0 +1,34 @@ +/************************************************************************* + * + * 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: TempFileTest.java,v $ + * $Revision: 1.4 $ + * + * 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 complex.tempfile; + +public interface TempFileTest { + boolean test(); +} diff --git a/unotools/qa/complex/tempfile/TempFileUnitTest.java b/unotools/qa/complex/tempfile/TempFileUnitTest.java new file mode 100644 index 000000000000..3bac1809af7b --- /dev/null +++ b/unotools/qa/complex/tempfile/TempFileUnitTest.java @@ -0,0 +1,88 @@ +/************************************************************************* + * + * 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: TempFileUnitTest.java,v $ + * $Revision: 1.3 $ + * + * 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 complex.tempfile; + +import complexlib.ComplexTestCase; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.UnoRuntime; + +/* Document. + */ + +public class TempFileUnitTest extends ComplexTestCase { + private XMultiServiceFactory m_xMSF = null; + private XSimpleFileAccess m_xSFA = null; + + public String[] getTestMethodNames() { + return new String[] { + "ExecuteTest01", + "ExecuteTest02"}; + } + + public String getTestObjectName() { + return "TempFileUnitTest"; + } + + public void before() { + m_xMSF = (XMultiServiceFactory)param.getMSF(); + if ( m_xMSF == null ) { + failed ( "Cannot create service factory!" ); + } + try + { + Object oSFA = m_xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess" ); + m_xSFA = ( XSimpleFileAccess )UnoRuntime.queryInterface( XSimpleFileAccess.class, + oSFA ); + } + catch ( Exception e ) + { + failed ( "Cannot get simple file access! Exception: " + e); + } + if ( m_xSFA == null ) { + failed ( "Cannot get simple file access!" ); + } + } + + public void after() { + m_xMSF = null; + m_xSFA = null; + } + + public void ExecuteTest01() { + TempFileTest aTest = new Test01( m_xMSF, m_xSFA, log ); + assure( "Test01 failed!", aTest.test() ); + } + + public void ExecuteTest02() { + TempFileTest aTest = new Test02( m_xMSF, m_xSFA, log ); + assure( "Test02 failed!", aTest.test() ); + } +};
\ No newline at end of file diff --git a/unotools/qa/complex/tempfile/Test01.java b/unotools/qa/complex/tempfile/Test01.java new file mode 100644 index 000000000000..350127158033 --- /dev/null +++ b/unotools/qa/complex/tempfile/Test01.java @@ -0,0 +1,123 @@ +/************************************************************************* + * + * 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: Test01.java,v $ + * $Revision: 1.4 $ + * + * 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 complex.tempfile; + +import complexlib.ComplexTestCase; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.io.*; +import com.sun.star.uno.UnoRuntime; +import java.util.Random; + +import share.LogWriter; + +public class Test01 implements TempFileTest { + LogWriter m_aLogWriter; + XMultiServiceFactory m_xMSF = null; + XSimpleFileAccess m_xSFA = null; + TestHelper m_aTestHelper = null; + + public Test01(XMultiServiceFactory xMSF, XSimpleFileAccess xSFA, LogWriter aLogWriter) { + m_xMSF = xMSF; + m_xSFA = xSFA; + m_aTestHelper = new TestHelper(aLogWriter, "Test01: "); + } + + public boolean test() { + XTempFile xTempFile = null; + XTruncate xTruncate = null; + String sFileURL = null; + String sFileName = null; + //create a temporary file. + try { + Object oTempFile = m_xMSF.createInstance( "com.sun.star.io.TempFile" ); + xTempFile = (XTempFile) UnoRuntime.queryInterface( XTempFile.class, + oTempFile ); + m_aTestHelper.Message( "Tempfile created." ); + xTruncate = (XTruncate)UnoRuntime.queryInterface( XTruncate.class, + oTempFile ); + } catch( Exception e ) { + m_aTestHelper.Error( "Cannot create TempFile. exception: " + e ); + return false; + } + + //retrieve the tempfile URL + if ( xTempFile == null ) { + m_aTestHelper.Error( "Cannot get XTempFile interface." ); + return false; + } + + try { + //compare the file name with the name in the URL. + sFileURL = m_aTestHelper.GetTempFileURL( xTempFile ); + sFileName = m_aTestHelper.GetTempFileName( xTempFile ); + m_aTestHelper.CompareFileNameAndURL( sFileName, sFileURL ); + + //write to the stream using the service. + byte pBytesIn[] = new byte[9]; + byte pBytesOut1[][] = new byte [1][9]; + byte pBytesOut2[][] = new byte [1][9]; + Random oRandom = new Random(); + oRandom.nextBytes( pBytesIn ); + m_aTestHelper.WriteBytesWithStream( pBytesIn, xTempFile ); + + //check the result by reading from the service. + xTempFile.seek(0); + m_aTestHelper.ReadBytesWithStream( pBytesOut1, pBytesIn.length + 1, xTempFile ); + for ( int i = 0; i < pBytesIn.length ; i++ ) { + if ( pBytesOut1[0][i] != pBytesIn[i] ) { + m_aTestHelper.Error( "Tempfile outputs false data!" ); + } + } + + //check the result by reading from the file directly. + m_aTestHelper.ReadDirectlyFromTempFile( pBytesOut2, pBytesIn.length + 1, m_xSFA, sFileURL ); + for ( int i = 0; i < pBytesIn.length; i++ ) { + if ( pBytesOut2[0][i] != pBytesIn[i] ) { + m_aTestHelper.Error( "Tempfile contains false data!" ); + } + } + + //close the object(by closing input and output), check that the file was removed. + xTempFile.setRemoveFile( false ); + m_aTestHelper.CloseTempFile( xTempFile ); + if( !m_aTestHelper.IfTempFileExists( m_xSFA, sFileURL ) ) { + m_aTestHelper.Error( "TempFile mistakenly removed. " ); + } else { + m_aTestHelper.KillTempFile( sFileURL, m_xSFA ); + } + } catch ( Exception e ) { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + return true; + } +} diff --git a/unotools/qa/complex/tempfile/Test02.java b/unotools/qa/complex/tempfile/Test02.java new file mode 100644 index 000000000000..9667544afd5b --- /dev/null +++ b/unotools/qa/complex/tempfile/Test02.java @@ -0,0 +1,103 @@ +/************************************************************************* + * + * 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: Test02.java,v $ + * $Revision: 1.4 $ + * + * 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 complex.tempfile; + +import complexlib.ComplexTestCase; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.io.*; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.uno.UnoRuntime; +import java.util.Random; +import share.LogWriter; + +public class Test02 implements TempFileTest { + + XMultiServiceFactory m_xMSF; + XSimpleFileAccess m_xSFA; + TestHelper m_aTestHelper; + + public Test02(XMultiServiceFactory xMSF, XSimpleFileAccess xSFA, LogWriter aLogWriter) { + m_xMSF = xMSF; + m_xSFA = xSFA; + m_aTestHelper = new TestHelper(aLogWriter, "Test02: "); + } + + public boolean test() { + Object oTempFile = null; + XTempFile xTempFile = null; + XTruncate xTruncate = null; + String sFileURL = null; + String sFileName = null; + //create a temporary file. + try { + oTempFile = m_xMSF.createInstance( "com.sun.star.io.TempFile" ); + xTempFile = (XTempFile) UnoRuntime.queryInterface( XTempFile.class, + oTempFile ); + m_aTestHelper.Message( "Tempfile created." ); + xTruncate = (XTruncate)UnoRuntime.queryInterface( XTruncate.class, + oTempFile ); + } catch(Exception e) { + m_aTestHelper.Error( "Cannot create TempFile. exception: " + e ); + return false; + } + try { + //write something. + byte pBytesIn[] = new byte[9]; + byte pBytesOut[][] = new byte[1][9]; + Random oRandom = new Random(); + oRandom.nextBytes( pBytesIn ); + m_aTestHelper.WriteBytesWithStream( pBytesIn, xTempFile ); + + //get the URL. + sFileURL = m_aTestHelper.GetTempFileURL( xTempFile ); + + //let the service not to remove the URL. + m_aTestHelper.SetTempFileRemove( xTempFile, false ); + + //close the tempfile by closing input and output. + m_aTestHelper.CloseTempFile( xTempFile ); + + //check that the file is still available. + //xTempFile.seek(0); + m_aTestHelper.ReadDirectlyFromTempFile( pBytesOut, pBytesIn.length + 1, m_xSFA, sFileURL ); + for ( int i = 0; i < pBytesIn.length; i++ ) { + if ( pBytesOut[0][i] != pBytesIn[i] ) { + m_aTestHelper.Error( "Tempfile contains false data!" ); + } + } + } catch ( Exception e) { + m_aTestHelper.Error("Exception: " + e); + return false; + } + return true; + } +} diff --git a/unotools/qa/complex/tempfile/TestHelper.java b/unotools/qa/complex/tempfile/TestHelper.java new file mode 100644 index 000000000000..ce7ba959096e --- /dev/null +++ b/unotools/qa/complex/tempfile/TestHelper.java @@ -0,0 +1,228 @@ +/************************************************************************* + * + * 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: TestHelper.java,v $ + * $Revision: 1.4 $ + * + * 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 complex.tempfile; + +import complexlib.ComplexTestCase; +import com.sun.star.lang.XMultiServiceFactory; + +import com.sun.star.io.*; + +import com.sun.star.uno.AnyConverter; +import com.sun.star.ucb.XSimpleFileAccess; +import com.sun.star.uno.UnoRuntime; +import share.LogWriter; + +public class TestHelper { + LogWriter m_aLogWriter; + String m_sTestPrefix; + + public TestHelper( LogWriter aLogWriter, String sTestPrefix ) { + m_aLogWriter = aLogWriter; + m_sTestPrefix = sTestPrefix; + } + public void SetTempFileRemove( XTempFile xTempFile, boolean b ) { + try { + xTempFile.setRemoveFile( b ); + } catch( Exception e ) { + Error( "Cannot set TempFileRemove. exception: " + e ); + } + } + + public boolean GetTempFileRemove ( XTempFile xTempFile ) { + boolean b = false; + try { + b = xTempFile.getRemoveFile(); + } catch( Exception e) { + Error( "Cannot get TempFileRemove. exception: " + e ); + } + return b; + } + + public String GetTempFileURL ( XTempFile xTempFile ) { + String sTempFileURL = null; + try { + sTempFileURL = AnyConverter.toString( xTempFile.getUri() ); + } catch (Exception e) { + Error ( "Cannot get TempFileURL. exception: " + e ); + } + if ( sTempFileURL == null || sTempFileURL == "" ) { + Error ( "Temporary file not valid." ); + } + return sTempFileURL; + } + + public String GetTempFileName( XTempFile xTempFile ) { + String sTempFileName = null; + try { + sTempFileName = AnyConverter.toString( xTempFile.getResourceName() ); + } catch ( Exception e ) { + Error( "Cannot get TempFileName. exception: " + e ); + } + if ( sTempFileName == null || sTempFileName == "") { + Error( "Temporary file not valid." ); + } + return sTempFileName; + } + + public boolean CompareFileNameAndURL ( String sTempFileName, String sTempFileURL ) { + boolean bRet = false; + try { + bRet = sTempFileURL.endsWith( sTempFileName.replaceAll( "\\\\" , "/" ) ); + Message ( "Compare file name and URL: " + + ( bRet ? "OK." : "ERROR: FILE NAME AND URL DO NOT MATCH." ) ); + } + catch ( Exception e ) { + Error ( "exception: " + e); + } + return bRet; + } + + public void WriteBytesWithStream( byte [] pBytes, XTempFile xTempFile ) { + try { + XOutputStream xOutTemp = xTempFile.getOutputStream(); + if ( xOutTemp == null ) { + Error( "Cannot get output stream." ); + } else { + xOutTemp.writeBytes( pBytes ); + Message ( "Write to tempfile successfully." ); + } + } catch ( Exception e ) { + Error( "Cannot write to stream. exception: " + e ); + } + } + + public void ReadBytesWithStream( byte [][] pBytes, int nBytes, XTempFile xTempFile ) { + try { + XInputStream xInTemp = xTempFile.getInputStream(); + if ( xInTemp == null ) { + Error( "Cannot get input stream from tempfile." ); + } else { + xInTemp.readBytes( pBytes, nBytes ); + Message ( "Read from tempfile successfully." ); + } + } catch ( Exception e ) { + Error( "Cannot read from stream. exception: " + e ); + } + } + public void ReadDirectlyFromTempFile( byte [][] pBytes, int nBytes, XSimpleFileAccess xSFA, String sTempFileURL ) + { + try + { + if ( xSFA != null ) { + XInputStream xInTemp = xSFA.openFileRead( sTempFileURL ); + if ( xInTemp != null ) + { + xInTemp.readBytes( pBytes, nBytes ); + xInTemp.closeInput(); + Message ( "Read directly from tempfile successfully." ); + } else { + Error ( "Cannot creat input stream from URL." ); + } + } + } + catch ( Exception e) + { + Error( "Exception caught in TestHelper." + + "ReadDirectlyFromTempFile(). exception: " + e ); + } + } + + public void CloseTempFile( XTempFile xTempFile ) { + XOutputStream xOutTemp = null; + XInputStream xInTemp = null; + try { + xOutTemp = xTempFile.getOutputStream(); + if ( xOutTemp == null ) { + Error( "Cannot get output stream." ); + } + } catch ( Exception e ) { + Error( "Cannot get output stream. exception:" + e ); + } + try { + xOutTemp.closeOutput(); + } catch( Exception e ) { + Error( "Cannot close output stream. exception:" + e ); + } + try { + xInTemp = xTempFile.getInputStream(); + if ( xInTemp == null ) { + Error( "Cannot get input stream." ); + } + } catch ( Exception e ) { + Error( "Cannot get input stream. exception:" + e ); + } + try { + xInTemp.closeInput(); + Message ( "Tempfile closed successfully." ); + } catch( Exception e ) { + Error( "Cannot close input stream. exception:" + e ); + } + } + + public void KillTempFile ( String sTempFileURL, XSimpleFileAccess xSFA ) { + try { + if ( sTempFileURL != null ) { + if ( xSFA != null ) { + xSFA.kill( sTempFileURL ); + Message ( "Tempfile killed successfully." ); + } + } + } + catch ( Exception e ) { + Error ( "Exception caught in TestHelper." + + "KillTempFile(): " + e); + } + } + + public boolean IfTempFileExists( XSimpleFileAccess xSFA, String sTempFileURL ) { + boolean bRet = false; + try { + if ( sTempFileURL != null ) { + if ( xSFA != null ) { + bRet = xSFA.exists( sTempFileURL ); + Message ( "Tempfile " + ( bRet ? "still " : "no longer " ) + "exists." ); + } + } + } + catch( Exception e ) { + Error( "Exception caught in TestHelper." + + "IfTempFileExists(): " + e ); + } + return bRet; + } + + public void Error( String sError ) { + m_aLogWriter.println( m_sTestPrefix + "Error: " + sError ); + } + + public void Message( String sMessage ) { + m_aLogWriter.println( m_sTestPrefix + sMessage ); + } +} diff --git a/unotools/qa/complex/tempfile/makefile.mk b/unotools/qa/complex/tempfile/makefile.mk new file mode 100644 index 000000000000..0a8f51e7e71b --- /dev/null +++ b/unotools/qa/complex/tempfile/makefile.mk @@ -0,0 +1,89 @@ +#************************************************************************* +# +# 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: makefile.mk,v $ +# +# $Revision: 1.3.20.1 $ +# +# 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. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = TempFileUnitTest +PRJNAME = unotools +PACKAGE = complex$/tempfile + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar + +JAVAFILES =\ + TempFileUnitTest.java\ + TempFileTest.java\ + TestHelper.java\ + Test01.java\ + Test02.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# start an office if the parameter is set for the makefile +.IF "$(OFFICE)" == "" +CT_APPEXECCOMMAND = +.ELSE +CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" +.ENDIF + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +RUN: run + +run: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_TEST) + + |