--- Begin Message ---
Hi Mikhail,
Thanks very much for your reply. I have fixed the problem on
SimpleFileAccess and all the other similar problems in the tests, and
restructured the test code a little. Now I have another problem: I
cannot get XTempFile by querying TempFile ( please see error.log ).
To confirm this, I ran the following StarBasic macro in my installed OOo
build, only to find out that XTempFile is not among the supported
interfaces.
------------------------------------------------------------
REM ***** BASIC *****
Sub Main
oTempFile = createUnoService( "com.sun.star.io.TempFile" )
msgbox oTempFile.dbg_supportedInterfaces()
End Sub
------------------------------------------------------------
I did remember to modify the udkapi and unotools modules before I built
all the projects. Could you please tell me what has gone wrong?
BTW I checked
/cygdrive/f/OOo/SRC680_m217/solver/680/wntmsci10.pro/bin/OOoRunner.jar
and it is available. And the problem still exists. So I'm still looking
forward to further advice on this. Thanks in advance. :-)
Best Regards,
Felix.
Mikhail Voitenko 写道:
> Hi Felix,
>
> Sorry for the delay with the answer, I had to finish some important
> tasks. Please see my comments inline.
>
> Zhang Xiaofei wrote:
>
>> I might need your help to deal with my problem running the tests in
>> cygwin environment, I get the "java.lang.NoClassFoundError" exception
>> even when I try to run the example tests in /package/qa/storages
>> (please read cyg_err.log for the details). Although I can run the
>> example tests in 4nt (after I reconfigured the build environment in 4nt).
>>
>> So I think maybe the cause is something relevant to the environment,
>> but I don't know what exactly it is. Could you please give me some
>> suggestions so that I can test in cygwin?
>>
> The error message states that the Runner class is not found. So first I
> would check that the mentioned in the command line
> /cygdrive/f/OOo/SRC680_m217/solver/680/wntmsci10.pro/bin/OOoRunner.jar
> file is available.
>
>
>> Another problem is that I get the "Cannot get simple file access!"
>> exception when I try to run it in 4nt, I guess this is probably caused
>> by the unit test itself. Could you please tell me what did I do wrong
>> in the test's code? Thanks very much in advance.
>>
> I am not sure that this is exactly the problem, but in the provided
> source code there is a direct cast to "XSimpleFileAccess2" interface.
> "UnoRuntime.QueryInterface()" should be used to get interface from an
> object. Please see the implementation in the
> package/qa/storages/StorageUnitTest.java as an example. Please try
> whether it helps.
>
> Best Regards,
> Mikhail.
>
>
#*************************************************************************
#
# 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;
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.ucb.XSimpleFileAccess2;
import com.sun.star.uno.UnoRuntime;
/* 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
{
Object oSFA = m_xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess" );
m_xSFA = ( XSimpleFileAccess2 )UnoRuntime.queryInterface( XSimpleFileAccess2.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() );
}
};
package complex.tempfile;
import complexlib.ComplexTestCase;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ucb.XSimpleFileAccess2;
import com.sun.star.io.XTempFile;
import com.sun.star.uno.UnoRuntime;
import share.LogWriter;
public class Test01 implements TempFileTest {
XMultiServiceFactory m_xMSF = null;
XSimpleFileAccess2 m_xSFA = null;
TestHelper m_aTestHelper = null;
public Test01(XMultiServiceFactory xMSF, XSimpleFileAccess2 xSFA, LogWriter aLogWriter) {
m_xMSF = xMSF;
m_xSFA = xSFA;
m_aTestHelper = new TestHelper(aLogWriter, "Test01: ");
}
public boolean test() {
XTempFile xTempFile = null;
String sFileNameFromURL = 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 );
} 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;
}
sFileNameFromURL = m_aTestHelper.GetTempFileURL( xTempFile );
//compare the file name with the name in the URL.
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 );
}
try {
//compare the file name with the name in the URL.
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.WriteBytesWithStream( pBytesIn, xTempFile );
//check the result by reading from the service.
m_aTestHelper.ReadBytesWithStream( 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.ucb.XSimpleFileAccess2;
import com.sun.star.io.*;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.uno.UnoRuntime;
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() {
Object oTempFile = null;
XTempFile xTempFile = null;
String sFileNameFromURL = 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 );
} catch(Exception e) {
m_aTestHelper.Error( "Cannot create TempFile. exception: " + e );
return false;
}
//***********************************************************
if ( oTempFile != null ) {
m_aTestHelper.Error( "Object not null." );
}
XInputStream xInputStream = ( XInputStream )UnoRuntime.queryInterface( XInputStream.class,
oTempFile );
if ( xInputStream != null ) {
m_aTestHelper.Error( "Got XInputStream." );
}
XOutputStream xOutputStream = ( XOutputStream )UnoRuntime.queryInterface( XOutputStream.class,
oTempFile );
if ( xOutputStream != null ) {
m_aTestHelper.Error( "Got XOutputStream." );
}
XTruncate xTruncate = ( XTruncate )UnoRuntime.queryInterface( XTruncate.class,
oTempFile );
if ( xTruncate != null ) {
m_aTestHelper.Error( "Got XTruncate." );
}
XServiceInfo xServiceInfo = ( XServiceInfo )UnoRuntime.queryInterface( XServiceInfo.class,
oTempFile );
if ( xServiceInfo != null ) {
m_aTestHelper.Error( "Got XServiceInfo." );
}
try {
XMultiServiceFactory xMultiServiceFactory = ( XMultiServiceFactory )UnoRuntime.queryInterface( XMultiServiceFactory.class,
oTempFile );
} catch ( Exception e ){
m_aTestHelper.Error( "excetion: " + e );
}
if ( xTempFile == null ) {
m_aTestHelper.Error( "Cannot get XTempFile interface." );
return false;
}
//***********************************************************
try {
//write something.
byte pBytesIn[] = {};
for( int i = 0; i < 9; i++) {
pBytesIn[i] = 77;
}
m_aTestHelper.WriteBytesWithStream( pBytesIn, xTempFile );
//get the URL.
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.io.*;
import com.sun.star.uno.AnyConverter;
import com.sun.star.ucb.XSimpleFileAccess2;
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 XTempFile CreateTempFile( XMultiServiceFactory xMSF ) {
XTempFile xTempFile = null;
try {
Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
xTempFile = (XTempFile) UnoRuntime.queryInterface( XTempFile.class,
oTempFile );
if ( xTempFile == null ) {
Error( "Cannot get XTempFile interface." );
}
XInputStream xIpS;
if ( (xIpS = (XInputStream) UnoRuntime.queryInterface( XInputStream.class, oTempFile )) != null ) {
Error ( "Can get XInputStream though." );
}
} 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 WriteBytesWithStream( 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 ReadBytesWithStream( 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 );
}
}
dmake: Executing shell macro: echo %_cwd
dmake: Executing shell macro: echo %_4ver
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
dmake: Executing shell macro: -ls -1 $(JARDIR) | $(GREP) "^$i"
java -cp
.;..\..\..\wntmsci10.pro\class;d:\OOEnv\J2SDK1~1.2_0\jre\lib\rt.jar;.;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\ridl.jar;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\unoil.jar;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\jurt.jar;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\juh.jar;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\jut.jar;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\java_uno.jar;f:\OOo\SRC680_m217\solver\680\wntmsci10.pro\bin\OOoRunner.jar
org.openoffice.Runner -TestBase java_complex -o
complex.tempfile.TempFileUnitTest TempFileTest TestHelper Test01 Test02
TestJob: -o complex.tempfile.TempFileUnitTest
Searching Class: complex.tempfile.TempFileUnitTest
Got test: [EMAIL PROTECTED]
LOG> Log started 25.06.2007 - 14:40:33
LOG> Starting ExecuteTest01
LOG> Test01: Error: Cannot get XTempFile interface.
LOG> Test01 failed!
LOG> Finished ExecuteTest01
LOG> Starting ExecuteTest02
LOG> Test02: Error: Object not null.
LOG> Test02: Error: Got XInputStream.
LOG> Test02: Error: Got XOutputStream.
LOG> Test02: Error: Got XTruncate.
LOG> Test02: Error: Got XServiceInfo.
LOG> Test02: Error: Cannot get XTempFile interface.
LOG> Test02 failed!
LOG> Finished ExecuteTest02
***** State for complex.tempfile.TempFileUnitTest ******
ExecuteTest01 - Test01 failed!
ExecuteTest02 - Test02 failed!
Whole unit: PASSED.FAILED
********************************************************
Job -o complex.tempfile.TempFileUnitTest failed
'---* tg_merge.mk *---'
dmake: Error: -- D:\OOEnv\4NT400\4NT.EXE: No error
--- End Message ---