1 import com
.sun
.star
.comp
.servicemanager
.ServiceManager
;
3 import com
.sun
.star
.lang
.XMultiServiceFactory
;
4 import com
.sun
.star
.lang
.XMultiComponentFactory
;
5 import com
.sun
.star
.connection
.XConnector
;
6 import com
.sun
.star
.connection
.XConnection
;
8 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
9 import com
.sun
.star
.uno
.UnoRuntime
;
10 import com
.sun
.star
.uno
.XInterface
;
11 import com
.sun
.star
.uno
.XNamingService
;
12 import com
.sun
.star
.uno
.XComponentContext
;
14 import com
.sun
.star
.container
.*;
15 import com
.sun
.star
.beans
.*;
16 import com
.sun
.star
.lang
.*;
18 import storagetesting
.*;
20 public class StorageFunctionality
{
22 public static void main( String args
[] )
24 // connect to the office
25 String sConnectionString
= "uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService";
27 // It is possible to use a different connection string, passed as argument
28 if ( args
.length
== 1 ) {
29 sConnectionString
= args
[0];
32 XMultiServiceFactory xMSF
= null;
34 // create connection(s) and get multiservicefactory
36 xMSF
= connect( sConnectionString
);
40 System
.out
.println( "Error: Couldn't get MSF!" );
43 } catch( Exception e
) {
44 System
.out
.println( "Error: Couldn't get MSF, exception: " + e
);
48 XSingleServiceFactory xStorageFactory
= null;
51 Object oStorageFactory
= xMSF
.createInstance( "com.sun.star.embed.StorageFactory" );
52 xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
55 if ( xStorageFactory
== null )
57 System
.out
.println( "Error: Can not get storage factory!" );
63 System
.out
.println( "Error: Can't get storage factory, exception: " + e
+ "!" );
67 boolean bTestsPassed
= true;
69 final int nNumTests
= 9;
70 StorageTest pTests
[] = new StorageTest
[nNumTests
];
71 pTests
[0] = (StorageTest
) new Test01( xMSF
, xStorageFactory
);
72 pTests
[1] = (StorageTest
) new Test02( xMSF
, xStorageFactory
);
73 pTests
[2] = (StorageTest
) new Test03( xMSF
, xStorageFactory
);
74 pTests
[3] = (StorageTest
) new Test04( xMSF
, xStorageFactory
);
75 pTests
[4] = (StorageTest
) new Test05( xMSF
, xStorageFactory
);
76 pTests
[5] = (StorageTest
) new Test06( xMSF
, xStorageFactory
);
77 pTests
[6] = (StorageTest
) new Test07( xMSF
, xStorageFactory
);
78 pTests
[7] = (StorageTest
) new Test08( xMSF
, xStorageFactory
);
79 pTests
[8] = (StorageTest
) new Test09( xMSF
, xStorageFactory
);
81 System
.out
.println( "\nstart testing\n" );
83 for ( int nInd
= 0; nInd
< nNumTests
; nInd
++ )
85 String sTestName
= "Test" + ( ( nInd
< 9 ) ?
"0" : "" ) + ( nInd
+ 1 );
87 System
.out
.println( "======= Storage test " + sTestName
+ " started!" );
88 if ( pTests
[nInd
].test() )
89 System
.out
.println( "======= Storage test " + sTestName
+ " passed!" );
92 System
.out
.println( "======= Storage test " + sTestName
+ " failed!" );
98 System
.out
.println( "\ntesting passed" );
100 System
.out
.println( "\ntesting failed" );
102 System
.out
.println( "done" );
108 public static XMultiServiceFactory
connect( String sConnectStr
)
109 throws com
.sun
.star
.uno
.Exception
,
110 com
.sun
.star
.uno
.RuntimeException
,
113 // Get component context
114 XComponentContext xComponentContext
=
115 com
.sun
.star
.comp
.helper
.Bootstrap
.createInitialComponentContext(
118 // initial serviceManager
119 XMultiComponentFactory xLocalServiceManager
=
120 xComponentContext
.getServiceManager();
122 // create a connector, so that it can contact the office
123 Object oUrlResolver
= xLocalServiceManager
.createInstanceWithContext(
124 "com.sun.star.bridge.UnoUrlResolver", xComponentContext
);
125 XUnoUrlResolver xUrlResolver
= (XUnoUrlResolver
)UnoRuntime
.queryInterface(
126 XUnoUrlResolver
.class, oUrlResolver
);
128 Object oInitialObject
= xUrlResolver
.resolve( sConnectStr
);
129 XNamingService xName
= (XNamingService
)UnoRuntime
.queryInterface(
130 XNamingService
.class, oInitialObject
);
132 XMultiServiceFactory xMSF
= null;
133 if( xName
!= null ) {
134 System
.err
.println( "got the remote naming service !" );
135 Object oMSF
= xName
.getRegisteredObject("StarOffice.ServiceManager" );
137 xMSF
= (XMultiServiceFactory
)
138 UnoRuntime
.queryInterface( XMultiServiceFactory
.class, oMSF
);
141 System
.out
.println( "Error: Can't get XNamingService interface from url resolver!" );