1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cli_bridgetest_inprocess.cs,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 using System
.Collections
;
35 using unoidl
.com
.sun
.star
.uno
;
36 using unoidl
.com
.sun
.star
.lang
;
37 using unoidl
.com
.sun
.star
.container
;
40 //==============================================================================
41 internal class Factory
:
42 WeakComponentBase
, XSingleComponentFactory
, XServiceInfo
44 private String m_service
;
46 private System
.Reflection
.ConstructorInfo m_ctor
;
48 public Factory( Type type
, String service
)
52 m_ctor
= type
.GetConstructor(
53 new Type
[] { typeof (XComponentContext) }
);
56 public Object
createInstanceWithContext( XComponentContext xContext
)
58 return m_ctor
.Invoke( new Object
[] { xContext }
);
61 public Object
createInstanceWithArgumentsAndContext(
62 uno
.Any
[] args
, XComponentContext xContext
)
64 return m_ctor
.Invoke( new Object
[] { xContext }
);
67 public bool supportsService( String name
)
69 return m_service
.Equals( name
);
72 public String
[] getSupportedServiceNames()
74 return new String
[] { m_service }
;
77 public String
getImplementationName()
79 return m_type
.ToString();
84 /** This executable does the same as the batch file starting via uno.exe,
85 but via bootstrapping native UNO.
87 public class BridgeTest
89 public static int Main( String
[] args
)
91 // System.Diagnostics.Debugger.Launch();
94 string bootstrap_ini
= "cli_bridgetest_inprocess.ini";
100 "\n\ncli_bridgetest_inprocess [bootstrap file] \n\n"
101 + "bootstrap file \n"
102 + "\t contains the entries UNO_TYPES and UNO_SERVICES.\n"
103 + "\t If a file is not provided than it is assumed that a\n"
104 + "\t cli_bridgetest_inprocess.ini file can be found in the\n "
105 + "\t current working directory.\n"
111 bootstrap_ini
= args
[0];
115 // bootstrap native UNO
116 XComponentContext xContext
=
117 Bootstrap
.defaultBootstrap_InitialComponentContext(
118 bootstrap_ini
, null );
120 using (new uno
.util
.DisposeGuard( (XComponent
) xContext
))
122 XSet xSet
= (XSet
) xContext
.getServiceManager();
125 typeof (XSingleComponentFactory
),
127 typeof (cs_testobj
.BridgeTestObject
),
128 "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) );
131 typeof (XSingleComponentFactory
),
133 typeof (cs_testobj
.BridgeTest
),
134 "com.sun.star.test.bridge.cli_uno.CsBridgeTest" ) ) );
138 "\n[cli bridgetest] C# client calls C# object [hack]");
139 cs_testobj.BridgeTest.perform_test (new cs_testobj.BridgeTestObject( xContext ));
143 // direct unbridged test
144 // get client object via singleton entry
147 test_client
= new cs_testobj
.BridgeTest( xContext
);
148 xClient
= (XMain
) test_client
;
150 "\n[cli bridgetest] 1. C# client calls C# object");
151 // run with CLI target object
154 "com.sun.star.test.bridge.cli_uno.CsTestObject" } );
157 // uno -ro uno_services.rdb -ro uno_types.rdb
158 // -s com.sun.star.test.bridge.BridgeTest
159 // -- com.sun.star.test.bridge.cli_uno.TestObject
163 xContext
.getServiceManager().createInstanceWithContext(
164 "com.sun.star.test.bridge.BridgeTest", xContext
);
165 xClient
= (XMain
) test_client
;
167 "\n[cli bridgetest] 2. C++ client (native) calls C# object");
168 // run with CLI target object
171 "com.sun.star.test.bridge.cli_uno.CsTestObject",
172 "noCurrentContext"} );
175 // uno -ro uno_services.rdb -ro uno_types.rdb
176 // -s com.sun.star.test.bridge.cli_uno.BridgeTest
177 // -- com.sun.star.test.bridge.CppTestObject
181 xContext
.getServiceManager().createInstanceWithContext(
182 "com.sun.star.test.bridge.cli_uno.CsBridgeTest",
184 xClient
= (XMain
) test_client
;
186 "\n[cli bridgetest] 3. C# client calls C++ object (native)");
187 // run with native target object
189 new String
[] { "com.sun.star.test.bridge.CppTestObject" }
);
192 // uno -ro uno_services.rdb -ro uno_types.rdb
193 // -s com.sun.star.test.bridge.cli_uno.VbBridgeTest
194 // -- com.sun.star.test.bridge.CppTestObject
197 xContext.getServiceManager().createInstanceWithContext(
198 "com.sun.star.test.bridge.cli_uno.VbBridgeTest",
200 xClient = (XMain) test_client;
202 "\n[cli bridgetest] 4. Visual Basic client calls C++ (native) object" );
203 // run with native target object
205 new String [] { "com.sun.star.test.bridge.CppTestObject" } ); */
208 // uno -ro uno_services.rdb -ro uno_types.rdb
209 // -s com.sun.star.test.bridge.BridgeTest
210 // -- com.sun.star.test.bridge.cli_uno.VbTestObject
213 // xContext.getServiceManager().createInstanceWithContext(
214 // "com.sun.star.test.bridge.BridgeTest", xContext );
215 // xClient = (XMain) test_client;
216 // Console.WriteLine(
217 // "[cli bridgetest] Visual Basic client: {0}",
218 // xClient.ToString() );
219 // // run with native target object
222 // "com.sun.star.test.bridge.cli_uno.VbTestObject" } );
225 // uno -ro uno_services.rdb -ro uno_types.rdb
226 // -s com.sun.star.test.bridge.cli_uno.CppBridgeTest
227 // -- com.sun.star.test.bridge.CppTestObject
229 xContext.getServiceManager().createInstanceWithContext(
230 "com.sun.star.test.bridge.cli_uno.CppBridgeTest",
232 xClient = (XMain) test_client;
234 "\n[cli bridgetest] 6. CLI C++ client calls C++ object (native)");
235 // run with native target object
237 new String [] { "com.sun.star.test.bridge.CppTestObject" } );*/
240 catch (System
.Exception exc
)
242 GC
.WaitForPendingFinalizers();
243 System
.Console
.WriteLine( exc
);
247 GC
.WaitForPendingFinalizers();
248 System
.Console
.WriteLine( "====> all tests ok." );