2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 using System
.Collections
;
23 using unoidl
.com
.sun
.star
.uno
;
24 using unoidl
.com
.sun
.star
.lang
;
25 using unoidl
.com
.sun
.star
.container
;
29 internal class Factory
:
30 WeakComponentBase
, XSingleComponentFactory
, XServiceInfo
32 private String m_service
;
34 private System
.Reflection
.ConstructorInfo m_ctor
;
36 public Factory( Type type
, String service
)
40 m_ctor
= type
.GetConstructor(
41 new Type
[] { typeof (XComponentContext) }
);
44 public Object
createInstanceWithContext( XComponentContext xContext
)
46 return m_ctor
.Invoke( new Object
[] { xContext }
);
49 public Object
createInstanceWithArgumentsAndContext(
50 uno
.Any
[] args
, XComponentContext xContext
)
52 return m_ctor
.Invoke( new Object
[] { xContext }
);
55 public bool supportsService( String name
)
57 return m_service
.Equals( name
);
60 public String
[] getSupportedServiceNames()
62 return new String
[] { m_service }
;
65 public String
getImplementationName()
67 return m_type
.ToString();
72 /** This executable does the same as the batch file starting via uno.exe,
73 but via bootstrapping native UNO.
75 public class BridgeTest
77 public static int Main( String
[] args
)
79 // System.Diagnostics.Debugger.Launch();
82 string bootstrap_ini
= "cli_bridgetest_inprocess.ini";
88 "\n\ncli_bridgetest_inprocess [bootstrap file] \n\n"
90 + "\t contains the entries UNO_TYPES and UNO_SERVICES.\n"
91 + "\t If a file is not provided then it is assumed that a\n"
92 + "\t cli_bridgetest_inprocess.ini file can be found in the\n "
93 + "\t current working directory.\n"
99 bootstrap_ini
= args
[0];
103 // bootstrap native UNO
104 XComponentContext xContext
=
105 Bootstrap
.defaultBootstrap_InitialComponentContext(
106 bootstrap_ini
, null );
108 using (new uno
.util
.DisposeGuard( (XComponent
) xContext
))
110 XSet xSet
= (XSet
) xContext
.getServiceManager();
113 typeof (XSingleComponentFactory
),
115 typeof (cs_testobj
.BridgeTestObject
),
116 "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) );
119 typeof (XSingleComponentFactory
),
121 typeof (vb_testobj
.VBBridgeTestObject
),
122 "com.sun.star.test.bridge.cli_uno.VbTestObject" ) ) );
125 typeof (XSingleComponentFactory
),
127 typeof (cpp_bridgetest
.BridgeTest
),
128 "com.sun.star.test.bridge.cli_uno.CppBridgeTest" ) ) );
131 typeof (XSingleComponentFactory
),
133 typeof (cs_testobj
.BridgeTest
),
134 "com.sun.star.test.bridge.cli_uno.CsBridgeTest" ) ) );
137 typeof (XSingleComponentFactory
),
139 typeof (vb_bridetest
.BridgeTest
),
140 "com.sun.star.test.bridge.cli_uno.VbBridgeTest" ) ) );
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." );