merge the formfield patch from ooo-build
[ooovba.git] / extensions / test / ole / unoTocomCalls / Test / Test.cpp
bloba6dbf546da9f58f98d8ab71bef007c38e61b9e5b
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: Test.cpp,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
30 // Test.cpp : Defines the entry point for the console application.
33 #include "stdafx.h"
34 #include "../XCallback_Impl/XCallback_Impl.h"
35 #include "../XCallback_Impl/XCallback_Impl_i.c"
37 CComModule _Module;
38 BEGIN_OBJECT_MAP(ObjectMap)
39 END_OBJECT_MAP()
41 HRESULT doTest();
43 int main(int argc, char* argv[])
45 HRESULT hr;
46 if( FAILED( hr=CoInitialize(NULL)))
48 _tprintf(_T("CoInitialize failed \n"));
49 return -1;
53 _Module.Init( ObjectMap, GetModuleHandle( NULL));
55 if( FAILED(hr=doTest()))
57 _com_error err( hr);
58 const TCHAR * errMsg= err.ErrorMessage();
59 MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
63 _Module.Term();
64 CoUninitialize();
67 return 0;
71 HRESULT doTest()
73 HRESULT hr= S_OK;
75 CComPtr<IUnknown> spUnk;
76 hr= spUnk.CoCreateInstance(L"com.sun.star.ServiceManager");
77 if( FAILED( hr))
78 return hr;
80 CComDispatchDriver manager( spUnk);
81 CComVariant param( L"oletest.OleTest");
82 CComVariant retVal;
83 hr= manager.Invoke1((LPCOLESTR)L"createInstance", &param, &retVal );
85 CComDispatchDriver oletest( retVal.punkVal);
87 spUnk.Release();
89 hr= spUnk.CoCreateInstance(L"XCallback_Impl.Callback");
90 if( FAILED( hr))
91 return hr;
93 CComQIPtr<IDispatch> paramDisp(spUnk);
96 //######################################################################
97 // out parameters
98 //######################################################################
99 CComVariant param1( paramDisp);
100 CComVariant param2(1);
102 // oletest calls XCallback::func1
103 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
104 // XCallback::returnInterface
105 param2= 2;
106 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
107 // XCallback::outInterface
108 param2= 3;
109 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
110 // XCallback::outStruct
111 param2= 4;
112 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
113 // XCallback::outEnum
114 param2= 5;
115 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
116 // XCallback::outSeqAny
117 param2= 6;
118 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
119 // XCallback::outAny
120 param2= 7;
121 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
122 // XCallback::outBool
123 param2= 8;
124 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
125 // XCallback::outChar
126 param2= 9;
127 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
128 // XCallback::outString
129 param2= 10;
130 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
131 // XCallback::outFloat
132 param2= 11;
133 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
134 // XCallback::outDouble
135 param2= 12;
136 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
137 // XCallback::outByte
138 param2= 13;
139 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
140 // XCallback::outShort
141 param2= 14;
142 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
143 // XCallback::outLong
144 param2= 15;
145 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
146 // XCallback::outValuesMixed
147 param2= 30;
148 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
149 // XCallback::outValuesAll
150 param2= 31;
151 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
153 // XCallback::outSeqByte
154 // Does not work currently because Sequences are always converted to
155 // SAFEARRAY( VARIANT)
156 // param2= 32;
157 // hr= oletest.Invoke2(L"testInterface", &param1, &param2);
159 //######################################################################
160 // in / out parameters
161 //######################################################################
162 // XCallback::inoutInterface
163 param2= 100;
164 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
165 // XCallback::inoutStruct
166 param2= 101;
167 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
168 // XCallback::inoutEnum
169 param2= 102;
170 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
171 // XCallback::inoutSeqAny
172 param2= 103;
173 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
174 // XCallback::inoutAny
175 param2= 104;
176 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
177 // XCallback::inoutBool
178 param2= 105;
179 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
180 // XCallback::inoutChar
181 param2= 106;
182 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
183 // XCallback::inoutString
184 param2= 107;
185 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
186 // XCallback::inoutFloat
187 param2= 108;
188 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
189 // XCallback::inoutDouble
190 param2= 109;
191 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
192 // XCallback::inoutByte
193 param2= 110;
194 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
195 // XCallback::inoutShort
196 param2= 111;
197 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
198 // XCallback::inoutLong
199 param2= 112;
200 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
201 // XCallback::inoutValuesAll
202 param2=120;
203 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
204 //######################################################################
205 // in parameters
206 //######################################################################
207 // XCallback::inValues
208 param2= 200;
209 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
210 // XCallback::inSeqByte
211 // SAFEARRAY( VARIANT)
212 param2= 201;
213 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
214 //XCallback::inSeqXEventListener
215 param2= 202;
216 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
217 //######################################################################
218 // The UNO test component OleTest calls on XCallback_Impl.Callback directly
219 // that is the COM object has not been past a parameter but rather OleTest
220 // creates the COM object itself
221 //######################################################################
222 // XCallback::outValuesAll
223 // does not work currently
224 param2= 300;
225 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
226 // XCallback::inoutValuesAll
227 param2= 301;
228 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
229 // XCallback::inoutValues
230 param2= 302;
231 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
233 // XCallback::inValues
234 param2= 303;
235 hr= oletest.Invoke2(L"testInterface", &param1, &param2);
236 //######################################################################
237 // Test a COM object which implements several interfaces.
238 //######################################################################
240 CComQIPtr<IDispatch> dispSimple;
241 hr= dispSimple.CoCreateInstance(L"XCallback_Impl.Simple");
242 CComVariant varSimple( dispSimple);
243 param2= 0;
244 hr= oletest.Invoke2(L"testInterface2", &varSimple, &param2);
246 return hr;
248 // VARIANT CComVariant VT_UNKNOWN VT_DISPATCH V_UI1 CComDispatchDriver WINAPI