diff options
Diffstat (limited to 'sot/qa/complex/olesimplestorage')
-rw-r--r-- | sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java | 5 | ||||
-rw-r--r-- | sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java | 70 | ||||
-rw-r--r-- | sot/qa/complex/olesimplestorage/Test01.java | 126 | ||||
-rw-r--r-- | sot/qa/complex/olesimplestorage/TestHelper.java | 26 | ||||
-rw-r--r-- | sot/qa/complex/olesimplestorage/makefile.mk | 88 |
5 files changed, 315 insertions, 0 deletions
diff --git a/sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java b/sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java new file mode 100644 index 000000000000..a2d8bee83713 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/OLESimpleStorageTest.java @@ -0,0 +1,5 @@ +package complex.olesimplestorage; + +public interface OLESimpleStorageTest { + boolean test(); +} diff --git a/sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java b/sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java new file mode 100644 index 000000000000..8494f3fb0ba3 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/OLESimpleStorageUnitTest.java @@ -0,0 +1,70 @@ +/************************************************************************* + * + * 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: OLESimpleStorageUnitTest.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.olesimplestorage; + +import complexlib.ComplexTestCase; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; + +/* Document. + */ + +public class OLESimpleStorageUnitTest extends ComplexTestCase { + private XMultiServiceFactory m_xMSF = null; + + public String[] getTestMethodNames() { + return new String[] { + "ExecuteTest01"}; + } + + public String getTestObjectName() { + return "OLESimpleStorageUnitTest"; + } + + public void before () { + try { + m_xMSF = (XMultiServiceFactory)param.getMSF(); + } catch ( Exception e ){ + failed ( "Cannot create service factory!" ); + } + if ( m_xMSF == null ) { + failed ( "Cannot create service factory!" ); + } + } + + public void after () { + m_xMSF = null; + } + + public void ExecuteTest01() { + OLESimpleStorageTest aTest = new Test01( m_xMSF, log ); + assure( "Test01 failed!", aTest.test() ); + } +}
\ No newline at end of file diff --git a/sot/qa/complex/olesimplestorage/Test01.java b/sot/qa/complex/olesimplestorage/Test01.java new file mode 100644 index 000000000000..c9010e61231a --- /dev/null +++ b/sot/qa/complex/olesimplestorage/Test01.java @@ -0,0 +1,126 @@ +package complex.olesimplestorage; + +import complexlib.ComplexTestCase; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.io.XInputStream; +import com.sun.star.io.XOutputStream; +import com.sun.star.io.XTempFile; +import com.sun.star.embed.XOLESimpleStorage; +import com.sun.star.uno.UnoRuntime; + +import java.util.Random; +import share.LogWriter; + +public class Test01 implements OLESimpleStorageTest +{ + XMultiServiceFactory m_xMSF = null; + TestHelper m_aTestHelper = null; + final int pStreamCnt = 5; + final int pBytesCnt = 10; + + public Test01 ( XMultiServiceFactory xMSF, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper (aLogWriter, "Test01: "); + } + + public boolean test () + { + try + { + //create a new temporary stream + Object oTempFile = m_xMSF.createInstance ( "com.sun.star.io.TempFile" ); + XTempFile xTempFile = (XTempFile) UnoRuntime.queryInterface ( XTempFile.class, oTempFile ); + m_aTestHelper.Message ( "A new temporary stream created." ); + + //create OLESimpleStorage based on it + Object pArgs[] = new Object[2]; + pArgs[0] = (Object) xTempFile; + pArgs[1] = new Boolean( true ); + Object oOLESimpleStorage = m_xMSF.createInstanceWithArguments ( "com.sun.star.embed.OLESimpleStorage", pArgs ); + XOLESimpleStorage xOLESimpleStorage = (XOLESimpleStorage) UnoRuntime.queryInterface ( XOLESimpleStorage.class, oOLESimpleStorage ); + m_aTestHelper.Message ( "OLESimpleStorage based on XStream created." ); + + //fill it with some streams + Object oStream[] = new Object[pStreamCnt]; + byte pBytesIn[][][] = new byte [pStreamCnt][1][pBytesCnt]; + byte pBytesOut[][] = new byte [pStreamCnt][pBytesCnt]; + XTempFile xTempStream[] = new XTempFile[pStreamCnt]; + Random oRandom = new Random (); + final String sSubStreamPrefix = "SubStream"; + for ( int i = 0; i < pStreamCnt; i++ ) + { + oRandom.nextBytes (pBytesOut[i]); + oStream[i] = m_xMSF.createInstance ( "com.sun.star.io.TempFile" ); + xTempStream[i] = (XTempFile) UnoRuntime.queryInterface ( XTempFile.class, oStream[i] ); + xTempStream[i].getOutputStream ().writeBytes (pBytesOut[i]); + xTempStream[i].seek (0); + m_aTestHelper.Message ( "Substream " + i + " initialized." ); + if (xOLESimpleStorage.hasByName (sSubStreamPrefix + i)) + { + xOLESimpleStorage.replaceByName ( sSubStreamPrefix + i, xTempStream[i] ); + } + else + { + xOLESimpleStorage.insertByName ( sSubStreamPrefix + i, xTempStream[i] ); + m_aTestHelper.Message ( "Substream " + i + " inserted." ); + } + } + + //commit the storage and close it + xOLESimpleStorage.commit (); + m_aTestHelper.Message ( "Storage commited." ); + xOLESimpleStorage.dispose (); + for ( int i = 0; i < pStreamCnt; ++i ) + { + xTempStream[i].setRemoveFile ( true ); + xTempStream[i].getInputStream ().closeInput (); + xTempStream[i].getOutputStream ().closeOutput (); + } + m_aTestHelper.Message ( "Storage closed." ); + + //open the same stream with the constructor for inputstream + pArgs[0] = (Object)xTempFile.getInputStream (); + oOLESimpleStorage = m_xMSF.createInstanceWithArguments ( "com.sun.star.embed.OLESimpleStorage", pArgs ); + xOLESimpleStorage = (XOLESimpleStorage)UnoRuntime.queryInterface ( XOLESimpleStorage.class, oOLESimpleStorage ); + m_aTestHelper.Message ( "Storage reopened, based on XInputStream." ); + + //check that all the streams contain correct information + m_aTestHelper.Message ( "Checking data contained in all the substreams..." ); + for ( int i = 0; i < pStreamCnt; ++i ) + { + if ( xOLESimpleStorage.hasByName (sSubStreamPrefix + i) ) + { + xTempStream[i] = (XTempFile)UnoRuntime.queryInterface ( + XTempFile.class, xOLESimpleStorage.getByName (sSubStreamPrefix + i) ); + xTempStream[i].seek (0); + xTempStream[i].getInputStream ().readBytes (pBytesIn[i], pBytesIn[i][0].length + 1 ); + for ( int j = 0; j < pBytesCnt; ++j ) + { + if ( pBytesIn[i][0][j] != pBytesOut[i][j] ) + { + m_aTestHelper.Error ( "Stream " + i + " byte " + j + ": INCORRECT DATA!"); + return false; + } + else + { + m_aTestHelper.Message ( "Stream " + i + " byte " + j + ": CORRECT." ); + } + } + } + else + { + m_aTestHelper.Error( "Stream " + i + " is lost!"); + return false; + } + } + m_aTestHelper.Message ( "All substreams contain correct data. SUCCESS." ); + } + catch ( Exception e ) + { + m_aTestHelper.Error ( "Exception: " + e ); + } + return true; + } +} diff --git a/sot/qa/complex/olesimplestorage/TestHelper.java b/sot/qa/complex/olesimplestorage/TestHelper.java new file mode 100644 index 000000000000..4b29ed15e393 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/TestHelper.java @@ -0,0 +1,26 @@ +package complex.olesimplestorage; + +import share.LogWriter; + +public class TestHelper +{ + LogWriter m_aLogWriter; + String m_sTestPrefix; + + /** Creates a new instance of TestHelper */ + public TestHelper ( LogWriter aLogWriter, String sTestPrefix ) + { + m_aLogWriter = aLogWriter; + m_sTestPrefix = sTestPrefix; + } + + 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/sot/qa/complex/olesimplestorage/makefile.mk b/sot/qa/complex/olesimplestorage/makefile.mk new file mode 100644 index 000000000000..baee53428854 --- /dev/null +++ b/sot/qa/complex/olesimplestorage/makefile.mk @@ -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: makefile.mk,v $ +# +# $Revision: 1.3.10.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 = OLESimpleStorageUnitTest +PRJNAME = sot +PACKAGE = complex$/olesimplestorage + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar + +JAVAFILES =\ + OLESimpleStorageUnitTest.java\ + OLESimpleStorageTest.java\ + TestHelper.java\ + Test01.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) + + |