xref: /AOO41X/main/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.cs (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir using System;
29*cdf0e10cSrcweir using System.Collections;
30*cdf0e10cSrcweir using uno;
31*cdf0e10cSrcweir using uno.util;
32*cdf0e10cSrcweir using unoidl.com.sun.star.uno;
33*cdf0e10cSrcweir using unoidl.com.sun.star.lang;
34*cdf0e10cSrcweir using unoidl.com.sun.star.container;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //==============================================================================
38*cdf0e10cSrcweir internal class Factory :
39*cdf0e10cSrcweir     WeakComponentBase, XSingleComponentFactory, XServiceInfo
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir     private String m_service;
42*cdf0e10cSrcweir     private Type m_type;
43*cdf0e10cSrcweir     private System.Reflection.ConstructorInfo m_ctor;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     public Factory( Type type, String service )
46*cdf0e10cSrcweir     {
47*cdf0e10cSrcweir         m_service = service;
48*cdf0e10cSrcweir         m_type = type;
49*cdf0e10cSrcweir         m_ctor = type.GetConstructor(
50*cdf0e10cSrcweir             new Type [] { typeof (XComponentContext) } );
51*cdf0e10cSrcweir     }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     public Object createInstanceWithContext( XComponentContext xContext )
54*cdf0e10cSrcweir     {
55*cdf0e10cSrcweir         return m_ctor.Invoke( new Object [] { xContext } );
56*cdf0e10cSrcweir     }
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     public Object createInstanceWithArgumentsAndContext(
59*cdf0e10cSrcweir         uno.Any [] args, XComponentContext xContext )
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         return m_ctor.Invoke( new Object [] { xContext } );
62*cdf0e10cSrcweir     }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     public bool supportsService( String name )
65*cdf0e10cSrcweir     {
66*cdf0e10cSrcweir         return m_service.Equals( name );
67*cdf0e10cSrcweir     }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     public String [] getSupportedServiceNames()
70*cdf0e10cSrcweir     {
71*cdf0e10cSrcweir         return new String [] { m_service };
72*cdf0e10cSrcweir     }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     public String getImplementationName()
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         return m_type.ToString();
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir /** This executable does the same as the batch file starting via uno.exe,
82*cdf0e10cSrcweir     but via bootstrapping native UNO.
83*cdf0e10cSrcweir */
84*cdf0e10cSrcweir public class BridgeTest
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     public static int Main( String [] args )
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir //       System.Diagnostics.Debugger.Launch();
89*cdf0e10cSrcweir         try
90*cdf0e10cSrcweir 		{
91*cdf0e10cSrcweir 			string bootstrap_ini = "cli_bridgetest_inprocess.ini";
92*cdf0e10cSrcweir 			if (args.Length > 0)
93*cdf0e10cSrcweir 			{
94*cdf0e10cSrcweir 				if (args[0] == "/?")
95*cdf0e10cSrcweir 				{
96*cdf0e10cSrcweir 					Console.WriteLine(
97*cdf0e10cSrcweir 						"\n\ncli_bridgetest_inprocess [bootstrap file] \n\n"
98*cdf0e10cSrcweir 						+ "bootstrap file \n"
99*cdf0e10cSrcweir 						+ "\t contains the entries UNO_TYPES and UNO_SERVICES.\n"
100*cdf0e10cSrcweir 						+ "\t If a file is not provided than it is assumed that a\n"
101*cdf0e10cSrcweir 						+ "\t cli_bridgetest_inprocess.ini file can be found in the\n "
102*cdf0e10cSrcweir 						+ "\t current working directory.\n"
103*cdf0e10cSrcweir 						);
104*cdf0e10cSrcweir 					return 0;
105*cdf0e10cSrcweir 				}
106*cdf0e10cSrcweir 				else
107*cdf0e10cSrcweir 				{
108*cdf0e10cSrcweir 					bootstrap_ini = args[0];
109*cdf0e10cSrcweir 				}
110*cdf0e10cSrcweir 			}
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir             // bootstrap native UNO
113*cdf0e10cSrcweir             XComponentContext xContext =
114*cdf0e10cSrcweir                 Bootstrap.defaultBootstrap_InitialComponentContext(
115*cdf0e10cSrcweir                     bootstrap_ini, null );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir             using (new uno.util.DisposeGuard( (XComponent) xContext ))
118*cdf0e10cSrcweir             {
119*cdf0e10cSrcweir                 XSet xSet = (XSet) xContext.getServiceManager();
120*cdf0e10cSrcweir                 xSet.insert(
121*cdf0e10cSrcweir                     new uno.Any(
122*cdf0e10cSrcweir                         typeof (XSingleComponentFactory),
123*cdf0e10cSrcweir                         new Factory(
124*cdf0e10cSrcweir                             typeof (cs_testobj.BridgeTestObject),
125*cdf0e10cSrcweir                             "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) );
126*cdf0e10cSrcweir                 xSet.insert(
127*cdf0e10cSrcweir                     new uno.Any(
128*cdf0e10cSrcweir                         typeof (XSingleComponentFactory),
129*cdf0e10cSrcweir                         new Factory(
130*cdf0e10cSrcweir                             typeof (vb_testobj.VBBridgeTestObject),
131*cdf0e10cSrcweir                             "com.sun.star.test.bridge.cli_uno.VbTestObject" ) ) );
132*cdf0e10cSrcweir                 xSet.insert(
133*cdf0e10cSrcweir                     new uno.Any(
134*cdf0e10cSrcweir                         typeof (XSingleComponentFactory),
135*cdf0e10cSrcweir                         new Factory(
136*cdf0e10cSrcweir                             typeof (cpp_bridgetest.BridgeTest),
137*cdf0e10cSrcweir                             "com.sun.star.test.bridge.cli_uno.CppBridgeTest" ) ) );
138*cdf0e10cSrcweir                 xSet.insert(
139*cdf0e10cSrcweir                     new uno.Any(
140*cdf0e10cSrcweir                         typeof (XSingleComponentFactory),
141*cdf0e10cSrcweir                         new Factory(
142*cdf0e10cSrcweir                             typeof (cs_testobj.BridgeTest),
143*cdf0e10cSrcweir                             "com.sun.star.test.bridge.cli_uno.CsBridgeTest" ) ) );
144*cdf0e10cSrcweir                 xSet.insert(
145*cdf0e10cSrcweir                     new uno.Any(
146*cdf0e10cSrcweir                         typeof (XSingleComponentFactory),
147*cdf0e10cSrcweir                         new Factory(
148*cdf0e10cSrcweir                             typeof (vb_bridetest.BridgeTest),
149*cdf0e10cSrcweir                             "com.sun.star.test.bridge.cli_uno.VbBridgeTest" ) ) );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir                 // I.
152*cdf0e10cSrcweir                 // direct unbridged test
153*cdf0e10cSrcweir                 // get client object via singleton entry
154*cdf0e10cSrcweir                 Object test_client;
155*cdf0e10cSrcweir                 XMain xClient;
156*cdf0e10cSrcweir                 test_client = new cs_testobj.BridgeTest( xContext );
157*cdf0e10cSrcweir                 xClient = (XMain) test_client;
158*cdf0e10cSrcweir                 Console.WriteLine(
159*cdf0e10cSrcweir                     "\n[cli bridgetest] 1. C# client calls C# object");
160*cdf0e10cSrcweir                 // run with CLI target object
161*cdf0e10cSrcweir                 xClient.run(
162*cdf0e10cSrcweir                     new String [] {
163*cdf0e10cSrcweir                     "com.sun.star.test.bridge.cli_uno.CsTestObject" } );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir                 // II:
166*cdf0e10cSrcweir                 // uno -ro uno_services.rdb -ro uno_types.rdb
167*cdf0e10cSrcweir                 //     -s com.sun.star.test.bridge.BridgeTest
168*cdf0e10cSrcweir                 //     -- com.sun.star.test.bridge.cli_uno.TestObject
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir                 // get native client
171*cdf0e10cSrcweir                 test_client =
172*cdf0e10cSrcweir                     xContext.getServiceManager().createInstanceWithContext(
173*cdf0e10cSrcweir                         "com.sun.star.test.bridge.BridgeTest", xContext );
174*cdf0e10cSrcweir                 xClient = (XMain) test_client;
175*cdf0e10cSrcweir                 Console.WriteLine(
176*cdf0e10cSrcweir                     "\n[cli bridgetest] 2. C++ client (native) calls C# object");
177*cdf0e10cSrcweir                 // run with CLI target object
178*cdf0e10cSrcweir                 xClient.run(
179*cdf0e10cSrcweir                     new String [] {
180*cdf0e10cSrcweir                     "com.sun.star.test.bridge.cli_uno.CsTestObject",
181*cdf0e10cSrcweir 					"noCurrentContext"} );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir                 // III:
184*cdf0e10cSrcweir                 // uno -ro uno_services.rdb -ro uno_types.rdb
185*cdf0e10cSrcweir                 //     -s com.sun.star.test.bridge.cli_uno.BridgeTest
186*cdf0e10cSrcweir                 //     -- com.sun.star.test.bridge.CppTestObject
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir                 // get CLI client
189*cdf0e10cSrcweir                 test_client =
190*cdf0e10cSrcweir                     xContext.getServiceManager().createInstanceWithContext(
191*cdf0e10cSrcweir                         "com.sun.star.test.bridge.cli_uno.CsBridgeTest",
192*cdf0e10cSrcweir                         xContext );
193*cdf0e10cSrcweir                 xClient = (XMain) test_client;
194*cdf0e10cSrcweir                 Console.WriteLine(
195*cdf0e10cSrcweir                     "\n[cli bridgetest] 3. C# client calls C++ object (native)");
196*cdf0e10cSrcweir                 // run with native target object
197*cdf0e10cSrcweir                 xClient.run(
198*cdf0e10cSrcweir                     new String [] { "com.sun.star.test.bridge.CppTestObject" } );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir                 // IV:
201*cdf0e10cSrcweir                 // uno -ro uno_services.rdb -ro uno_types.rdb
202*cdf0e10cSrcweir                 //     -s com.sun.star.test.bridge.cli_uno.VbBridgeTest
203*cdf0e10cSrcweir                 //     -- com.sun.star.test.bridge.CppTestObject
204*cdf0e10cSrcweir                 // get CLI client
205*cdf0e10cSrcweir                 test_client =
206*cdf0e10cSrcweir                     xContext.getServiceManager().createInstanceWithContext(
207*cdf0e10cSrcweir                         "com.sun.star.test.bridge.cli_uno.VbBridgeTest",
208*cdf0e10cSrcweir                         xContext );
209*cdf0e10cSrcweir                 xClient = (XMain) test_client;
210*cdf0e10cSrcweir                 Console.WriteLine(
211*cdf0e10cSrcweir                     "\n[cli bridgetest] 4. Visual Basic client calls C++ (native) object" );
212*cdf0e10cSrcweir                 // run with native target object
213*cdf0e10cSrcweir                 xClient.run(
214*cdf0e10cSrcweir                     new String [] { "com.sun.star.test.bridge.CppTestObject" } );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir                 // V:
217*cdf0e10cSrcweir                 // uno -ro uno_services.rdb -ro uno_types.rdb
218*cdf0e10cSrcweir                 //     -s com.sun.star.test.bridge.BridgeTest
219*cdf0e10cSrcweir                 //     -- com.sun.star.test.bridge.cli_uno.VbTestObject
220*cdf0e10cSrcweir                 // get CLI client
221*cdf0e10cSrcweir //                 test_client =
222*cdf0e10cSrcweir //                     xContext.getServiceManager().createInstanceWithContext(
223*cdf0e10cSrcweir //                         "com.sun.star.test.bridge.BridgeTest", xContext );
224*cdf0e10cSrcweir //                 xClient = (XMain) test_client;
225*cdf0e10cSrcweir //                 Console.WriteLine(
226*cdf0e10cSrcweir //                     "[cli bridgetest] Visual Basic client: {0}",
227*cdf0e10cSrcweir //                     xClient.ToString() );
228*cdf0e10cSrcweir //                 // run with native target object
229*cdf0e10cSrcweir //                 xClient.run(
230*cdf0e10cSrcweir //                     new String [] {
231*cdf0e10cSrcweir //                     "com.sun.star.test.bridge.cli_uno.VbTestObject" } );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir                 // VI:
234*cdf0e10cSrcweir                 // uno -ro uno_services.rdb -ro uno_types.rdb
235*cdf0e10cSrcweir                 // -s com.sun.star.test.bridge.cli_uno.CppBridgeTest
236*cdf0e10cSrcweir                 // -- com.sun.star.test.bridge.CppTestObject
237*cdf0e10cSrcweir                 test_client =
238*cdf0e10cSrcweir                     xContext.getServiceManager().createInstanceWithContext(
239*cdf0e10cSrcweir                         "com.sun.star.test.bridge.cli_uno.CppBridgeTest",
240*cdf0e10cSrcweir                         xContext );
241*cdf0e10cSrcweir                 xClient = (XMain) test_client;
242*cdf0e10cSrcweir                 Console.WriteLine(
243*cdf0e10cSrcweir                     "\n[cli bridgetest] 6. CLI C++ client calls C++ object (native)");
244*cdf0e10cSrcweir                 // run with native target object
245*cdf0e10cSrcweir                 xClient.run(
246*cdf0e10cSrcweir                     new String [] { "com.sun.star.test.bridge.CppTestObject" } );
247*cdf0e10cSrcweir             }
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir         catch (System.Exception exc)
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir             GC.WaitForPendingFinalizers();
252*cdf0e10cSrcweir             System.Console.WriteLine( exc );
253*cdf0e10cSrcweir             return -1;
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         GC.WaitForPendingFinalizers();
257*cdf0e10cSrcweir         System.Console.WriteLine( "====> all tests ok." );
258*cdf0e10cSrcweir         return 0;
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir }
261