1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Test.cpp,v $
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.
34 #include "../XCallback_Impl/XCallback_Impl.h"
35 #include "../XCallback_Impl/XCallback_Impl_i.c"
38 BEGIN_OBJECT_MAP(ObjectMap
)
43 int main(int argc
, char* argv
[])
46 if( FAILED( hr
=CoInitialize(NULL
)))
48 _tprintf(_T("CoInitialize failed \n"));
53 _Module
.Init( ObjectMap
, GetModuleHandle( NULL
));
55 if( FAILED(hr
=doTest()))
58 const TCHAR
* errMsg
= err
.ErrorMessage();
59 MessageBox( NULL
, errMsg
, "Test failed", MB_ICONERROR
);
75 CComPtr
<IUnknown
> spUnk
;
76 hr
= spUnk
.CoCreateInstance(L
"com.sun.star.ServiceManager");
80 CComDispatchDriver
manager( spUnk
);
81 CComVariant
param( L
"oletest.OleTest");
83 hr
= manager
.Invoke1((LPCOLESTR
)L
"createInstance", ¶m
, &retVal
);
85 CComDispatchDriver
oletest( retVal
.punkVal
);
89 hr
= spUnk
.CoCreateInstance(L
"XCallback_Impl.Callback");
93 CComQIPtr
<IDispatch
> paramDisp(spUnk
);
96 //######################################################################
98 //######################################################################
99 CComVariant
param1( paramDisp
);
100 CComVariant
param2(1);
102 // oletest calls XCallback::func1
103 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
104 // XCallback::returnInterface
106 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
107 // XCallback::outInterface
109 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
110 // XCallback::outStruct
112 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
113 // XCallback::outEnum
115 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
116 // XCallback::outSeqAny
118 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
121 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
122 // XCallback::outBool
124 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
125 // XCallback::outChar
127 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
128 // XCallback::outString
130 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
131 // XCallback::outFloat
133 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
134 // XCallback::outDouble
136 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
137 // XCallback::outByte
139 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
140 // XCallback::outShort
142 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
143 // XCallback::outLong
145 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
146 // XCallback::outValuesMixed
148 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
149 // XCallback::outValuesAll
151 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
153 // XCallback::outSeqByte
154 // Does not work currently because Sequences are always converted to
155 // SAFEARRAY( VARIANT)
157 // hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
159 //######################################################################
160 // in / out parameters
161 //######################################################################
162 // XCallback::inoutInterface
164 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
165 // XCallback::inoutStruct
167 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
168 // XCallback::inoutEnum
170 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
171 // XCallback::inoutSeqAny
173 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
174 // XCallback::inoutAny
176 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
177 // XCallback::inoutBool
179 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
180 // XCallback::inoutChar
182 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
183 // XCallback::inoutString
185 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
186 // XCallback::inoutFloat
188 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
189 // XCallback::inoutDouble
191 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
192 // XCallback::inoutByte
194 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
195 // XCallback::inoutShort
197 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
198 // XCallback::inoutLong
200 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
201 // XCallback::inoutValuesAll
203 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
204 //######################################################################
206 //######################################################################
207 // XCallback::inValues
209 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
210 // XCallback::inSeqByte
211 // SAFEARRAY( VARIANT)
213 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
214 //XCallback::inSeqXEventListener
216 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
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
225 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
226 // XCallback::inoutValuesAll
228 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
229 // XCallback::inoutValues
231 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
233 // XCallback::inValues
235 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
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
);
244 hr
= oletest
.Invoke2(L
"testInterface2", &varSimple
, ¶m2
);
248 // VARIANT CComVariant VT_UNKNOWN VT_DISPATCH V_UI1 CComDispatchDriver WINAPI