Update ooo320-m1
[ooovba.git] / testtools / source / bridgetest / cli / cli_bridgetest_inprocess.cs
blob7e5c514e3e5c4eee1f07f2f2534cda95e9a2770c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cli_bridgetest_inprocess.cs,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
31 using System;
32 using System.Collections;
33 using uno;
34 using uno.util;
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;
45 private Type m_type;
46 private System.Reflection.ConstructorInfo m_ctor;
48 public Factory( Type type, String service )
50 m_service = service;
51 m_type = type;
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();
92 try
94 string bootstrap_ini = "cli_bridgetest_inprocess.ini";
95 if (args.Length > 0)
97 if (args[0] == "/?")
99 Console.WriteLine(
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"
107 return 0;
109 else
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();
123 xSet.insert(
124 new uno.Any(
125 typeof (XSingleComponentFactory),
126 new Factory(
127 typeof (cs_testobj.BridgeTestObject),
128 "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) );
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" ) ) );
136 /* {
137 Console.WriteLine(
138 "\n[cli bridgetest] C# client calls C# object [hack]");
139 cs_testobj.BridgeTest.perform_test (new cs_testobj.BridgeTestObject( xContext ));
140 } */
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;