bump product version to 5.0.4.1
[LibreOffice.git] / testtools / source / bridgetest / cli / cli_bridgetest_inprocess.cs
blob1cb4f319e7476b3240d43604b62c1172d9f00d70
1 /*
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 .
19 using System;
20 using System.Collections;
21 using uno;
22 using uno.util;
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;
33 private Type m_type;
34 private System.Reflection.ConstructorInfo m_ctor;
36 public Factory( Type type, String service )
38 m_service = service;
39 m_type = type;
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();
80 try
82 string bootstrap_ini = "cli_bridgetest_inprocess.ini";
83 if (args.Length > 0)
85 if (args[0] == "/?")
87 Console.WriteLine(
88 "\n\ncli_bridgetest_inprocess [bootstrap file] \n\n"
89 + "bootstrap file \n"
90 + "\t contains the entries UNO_TYPES and UNO_SERVICES.\n"
91 + "\t If a file is not provided than 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"
95 return 0;
97 else
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();
111 xSet.insert(
112 new uno.Any(
113 typeof (XSingleComponentFactory),
114 new Factory(
115 typeof (cs_testobj.BridgeTestObject),
116 "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) );
117 xSet.insert(
118 new uno.Any(
119 typeof (XSingleComponentFactory),
120 new Factory(
121 typeof (vb_testobj.VBBridgeTestObject),
122 "com.sun.star.test.bridge.cli_uno.VbTestObject" ) ) );
123 xSet.insert(
124 new uno.Any(
125 typeof (XSingleComponentFactory),
126 new Factory(
127 typeof (cpp_bridgetest.BridgeTest),
128 "com.sun.star.test.bridge.cli_uno.CppBridgeTest" ) ) );
129 xSet.insert(
130 new uno.Any(
131 typeof (XSingleComponentFactory),
132 new Factory(
133 typeof (cs_testobj.BridgeTest),
134 "com.sun.star.test.bridge.cli_uno.CsBridgeTest" ) ) );
135 xSet.insert(
136 new uno.Any(
137 typeof (XSingleComponentFactory),
138 new Factory(
139 typeof (vb_bridetest.BridgeTest),
140 "com.sun.star.test.bridge.cli_uno.VbBridgeTest" ) ) );
142 // I.
143 // direct unbridged test
144 // get client object via singleton entry
145 Object test_client;
146 XMain xClient;
147 test_client = new cs_testobj.BridgeTest( xContext );
148 xClient = (XMain) test_client;
149 Console.WriteLine(
150 "\n[cli bridgetest] 1. C# client calls C# object");
151 // run with CLI target object
152 xClient.run(
153 new String [] {
154 "com.sun.star.test.bridge.cli_uno.CsTestObject" } );
156 // II:
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
161 // get native client
162 test_client =
163 xContext.getServiceManager().createInstanceWithContext(
164 "com.sun.star.test.bridge.BridgeTest", xContext );
165 xClient = (XMain) test_client;
166 Console.WriteLine(
167 "\n[cli bridgetest] 2. C++ client (native) calls C# object");
168 // run with CLI target object
169 xClient.run(
170 new String [] {
171 "com.sun.star.test.bridge.cli_uno.CsTestObject",
172 "noCurrentContext"} );
174 // III:
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
179 // get CLI client
180 test_client =
181 xContext.getServiceManager().createInstanceWithContext(
182 "com.sun.star.test.bridge.cli_uno.CsBridgeTest",
183 xContext );
184 xClient = (XMain) test_client;
185 Console.WriteLine(
186 "\n[cli bridgetest] 3. C# client calls C++ object (native)");
187 // run with native target object
188 xClient.run(
189 new String [] { "com.sun.star.test.bridge.CppTestObject" } );
191 // IV:
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
195 // get CLI client
196 test_client =
197 xContext.getServiceManager().createInstanceWithContext(
198 "com.sun.star.test.bridge.cli_uno.VbBridgeTest",
199 xContext );
200 xClient = (XMain) test_client;
201 Console.WriteLine(
202 "\n[cli bridgetest] 4. Visual Basic client calls C++ (native) object" );
203 // run with native target object
204 xClient.run(
205 new String [] { "com.sun.star.test.bridge.CppTestObject" } );
207 // V:
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
211 // get CLI client
212 // test_client =
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
220 // xClient.run(
221 // new String [] {
222 // "com.sun.star.test.bridge.cli_uno.VbTestObject" } );
224 // VI:
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
228 test_client =
229 xContext.getServiceManager().createInstanceWithContext(
230 "com.sun.star.test.bridge.cli_uno.CppBridgeTest",
231 xContext );
232 xClient = (XMain) test_client;
233 Console.WriteLine(
234 "\n[cli bridgetest] 6. CLI C++ client calls C++ object (native)");
235 // run with native target object
236 xClient.run(
237 new String [] { "com.sun.star.test.bridge.CppTestObject" } );
240 catch (System.Exception exc)
242 GC.WaitForPendingFinalizers();
243 System.Console.WriteLine( exc );
244 return -1;
247 GC.WaitForPendingFinalizers();
248 System.Console.WriteLine( "====> all tests ok." );
249 return 0;