--- Begin Message ---
Hi Mikhail,
This is the new version of the unit tests, could you please help me to
check them?
BTW I wish you have a good vacation. :-)
Best Regards,
Felix.
#*************************************************************************
#
# OpenOffice.org - a multi-platform office productivity suite
#
# $RCSfile: makefile.mk,v $
#
# $Revision: 1.11 $
#
# last change: $Author: obo $ $Date: 2006/10/13 11:46:54 $
#
# The Contents of this file are made available subject to
# the terms of GNU Lesser General Public License Version 2.1.
#
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2005 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#*************************************************************************
PRJ = ..$/..$/..
TARGET = TempFileUnitTest
PRJNAME = unotools
PACKAGE = complex$/tempfile
# --- Settings -----------------------------------------------------
.INCLUDE: settings.mk
#----- compile .java files -----------------------------------------
JARFILES = ridl.jar unoil.jar jurt.jar juh.jar jut.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)
package complex.tempfile;
import complex.tempfile.*;
public interface TempFileTest {
boolean test();
}
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: StorageUnitTest.java,v $
*
* $Revision: 1.10 $
*
* last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
package complex.tempfile;
import complexlib.ComplexTestCase;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.ucb.XSimpleFileAccess2;
import com.sun.star.io.XTempFile;
import complex.tempfile.*;
/* Document.
*/
public class TempFileUnitTest extends ComplexTestCase {
private XMultiServiceFactory m_xMSF = null;
private XSimpleFileAccess2 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
{
m_xSFA = (XSimpleFileAccess2)m_xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess" );
}
catch ( Exception e )
{
failed ( "Cannot get simple file access!" );
}
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() );
}
};
package complex.tempfile;
import complex.tempfile.*;
import complexlib.ComplexTestCase;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.ucb.XSimpleFileAccess2;
import com.sun.star.io.*;
import share.LogWriter;
public class Test01 implements TempFileTest {
XMultiServiceFactory m_xMSF;
XSimpleFileAccess2 m_xSFA;
TestHelper m_aTestHelper;
private LogWriter log;
public Test01(XMultiServiceFactory xMSF, XSimpleFileAccess2 xSFA, LogWriter aLogWriter) {
m_xMSF = xMSF;
m_xSFA = xSFA;
m_aTestHelper = new TestHelper(aLogWriter, "Test01: ");
}
public boolean test() {
try {
//create a temporary file, retrieve the tempfile URL.
XTempFile xTempFile = m_aTestHelper.CreateTempFile( m_xMSF );
String sFileNameFromURL = m_aTestHelper.GetTempFileURL( xTempFile );
//compare the file name with the name in the URL.
String sFileName = m_aTestHelper.GetTempFileName( xTempFile );
if ( sFileName != sFileNameFromURL ) {
m_aTestHelper.Error( "File name and URL are not the same. The file name is "
+ sFileName + ", while the URL is " + sFileNameFromURL );
}
//write to the stream using the service.
byte pBytesIn[] = {};
byte pBytesOut1[][] = {};
byte pBytesOut2[][] = {};
for( int i = 0; i < 9; i++) {
pBytesIn[i] = 77;
}
m_aTestHelper.WriteBytesToStream( pBytesIn, xTempFile );
//check the result by reading from the service.
m_aTestHelper.ReadBytesFromStream( pBytesOut1, 9, xTempFile );
for ( int i = 0; i < 3; i++ )
for ( int j = 0; j < 3; j++ ) {
if ( pBytesOut1[i][j] != 77 ) {
m_aTestHelper.Error ( "The temp file outputs wrong data!" );
}
}
//check the result by reading from the file directly.
m_aTestHelper.ReadDirectlyFromTempFile ( pBytesOut2, 9, m_xSFA, sFileNameFromURL );
for ( int i = 0; i < 3; i++ )
for ( int j = 0; j < 3; j++ ) {
if ( pBytesOut1[i][j] != 77 ) {
m_aTestHelper.Error ( "The temp file has wrong data!" );
}
}
//close the object(by closing input and output), check that the file was removed.
m_aTestHelper.CloseTempFile( xTempFile );
if( m_aTestHelper.IfTempFileExists( m_xSFA, sFileNameFromURL ) == false ) {
m_aTestHelper.Error( "TempFile mistakenly removed. " );
}
} catch ( Exception e ) {
m_aTestHelper.Error( "Exception: " + e );
return false;
}
return true;
}
}
package complex.tempfile;
import complexlib.ComplexTestCase;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.ucb.XSimpleFileAccess2;
import complex.tempfile.*;
import com.sun.star.io.*;
import share.LogWriter;
public class Test02 implements TempFileTest {
XMultiServiceFactory m_xMSF;
XSimpleFileAccess2 m_xSFA;
TestHelper m_aTestHelper;
public Test02(XMultiServiceFactory xMSF, XSimpleFileAccess2 xSFA, LogWriter aLogWriter) {
m_xMSF = xMSF;
m_xSFA = xSFA;
m_aTestHelper = new TestHelper(aLogWriter, "Test02: ");
}
public boolean test() {
try {
//create a temporary file.
XTempFile xTempFile = m_aTestHelper.CreateTempFile( m_xMSF );
//write something.
byte pBytes[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
xTempFile.getOutputStream().writeBytes( pBytes );
//get the URL.
String sFileNameFromURL = 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.
if( m_aTestHelper.IfTempFileExists( m_xSFA, sFileNameFromURL ) == false ) {
m_aTestHelper.Error( "TempFile mistakenly removed. " );
}
} catch ( Exception e) {
m_aTestHelper.Error("Exception: " + e);
return false;
}
return false;
}
}
package complex.tempfile;
import complexlib.ComplexTestCase;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.ucb.XSimpleFileAccess2;
import com.sun.star.io.*;
import complex.tempfile.*;
import com.sun.star.uno.AnyConverter;
import com.sun.star.ucb.*;
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 XTempFile CreateTempFile( XMultiServiceFactory xMSF ) {
XTempFile xTempFile = null;
try {
xTempFile = (XTempFile) xMSF.createInstance( "com.sun.star.io.TempFile" );
if ( xTempFile == null ) {
Error( "Cannot create TempFile!" );
}
} catch(Exception e) {
Error( "Cannot create TempFile! exception: " + e );
}
return xTempFile;
}
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 void WriteBytesToStream( byte [] pBytes, XTempFile xTempFile ) {
try {
xTempFile.seek( 0 );
XOutputStream xOutTemp = xTempFile.getOutputStream();
if ( xOutTemp == null ) {
Error( "Cannot get output stream!" );
} else {
xOutTemp.writeBytes( pBytes );
}
} catch ( Exception e ) {
Error( "Cannot write to stream, exception: " + e );
}
}
public void ReadBytesFromStream( byte [][] pBytes, int nBytes, XTempFile xTempFile ) {
try {
//truncate before readBytes?
XInputStream xInTemp = xTempFile.getInputStream();
if ( xInTemp == null ) {
Error( "Cannot get input stream from tempfile!" );
} else {
xInTemp.readBytes( pBytes, nBytes );
}
} catch ( Exception e ) {
Error( "Cannot read from stream, 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();
} catch( Exception e ) {
Error( "Cannot close input stream! exception:" + e );
}
}
public boolean IfTempFileExists( XSimpleFileAccess2 xSFA, String sFileURL ) {
boolean b = false;
try {
b = xSFA.exists( sFileURL );
} catch( Exception e ) {
Error( "" );
}
return b;
}
public void ReadDirectlyFromTempFile( byte [][] pBytes, int nBytes, XSimpleFileAccess2 xSFA, String sTempFileURL )
{
try
{
XInputStream xInTemp = xSFA.openFileRead( sTempFileURL );
if ( xInTemp == null )
{
Error ( "Cannot creat input stream from URL!" );
} else {
xInTemp.readBytes( pBytes, nBytes );
}
}
catch ( Exception e)
{
Error( "Cannot read from stream, exception: " + e );
}
}
{
}
public void Error( String sError ) {
m_aLogWriter.println( m_sTestPrefix + "Error: " + sError );
}
public void Message( String sMessage ) {
m_aLogWriter.println( m_sTestPrefix + sMessage );
}
}
--- End Message ---