1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 // Test.cpp : Defines the entry point for the console application.
23 #include "../XCallback_Impl/XCallback_Impl.h"
24 #include "../XCallback_Impl/XCallback_Impl_i.c"
27 BEGIN_OBJECT_MAP(ObjectMap
)
32 int main(int argc
, char* argv
[])
35 if( FAILED( hr
=CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
)))
37 _tprintf(_T("CoInitializeEx failed \n"));
42 _Module
.Init( ObjectMap
, GetModuleHandle( NULL
));
44 if( FAILED(hr
=doTest()))
47 const TCHAR
* errMsg
= err
.ErrorMessage();
48 MessageBox( NULL
, errMsg
, "Test failed", MB_ICONERROR
);
64 CComPtr
<IUnknown
> spUnk
;
65 hr
= spUnk
.CoCreateInstance(L
"com.sun.star.ServiceManager");
69 CComDispatchDriver
manager( spUnk
);
70 CComVariant
param( L
"oletest.OleTest");
72 hr
= manager
.Invoke1((LPCOLESTR
)L
"createInstance", ¶m
, &retVal
);
74 CComDispatchDriver
oletest( retVal
.punkVal
);
78 hr
= spUnk
.CoCreateInstance(L
"XCallback_Impl.Callback");
82 CComQIPtr
<IDispatch
> paramDisp(spUnk
);
88 CComVariant
param1( paramDisp
);
89 CComVariant
param2(1);
91 // oletest calls XCallback::func1
92 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
93 // XCallback::returnInterface
95 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
96 // XCallback::outInterface
98 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
99 // XCallback::outStruct
101 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
102 // XCallback::outEnum
104 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
105 // XCallback::outSeqAny
107 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
110 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
111 // XCallback::outBool
113 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
114 // XCallback::outChar
116 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
117 // XCallback::outString
119 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
120 // XCallback::outFloat
122 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
123 // XCallback::outDouble
125 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
126 // XCallback::outByte
128 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
129 // XCallback::outShort
131 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
132 // XCallback::outLong
134 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
135 // XCallback::outValuesMixed
137 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
138 // XCallback::outValuesAll
140 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
142 // XCallback::outSeqByte
143 // Does not work currently because Sequences are always converted to
144 // SAFEARRAY( VARIANT)
146 // hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
149 // in / out parameters
151 // XCallback::inoutInterface
153 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
154 // XCallback::inoutStruct
156 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
157 // XCallback::inoutEnum
159 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
160 // XCallback::inoutSeqAny
162 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
163 // XCallback::inoutAny
165 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
166 // XCallback::inoutBool
168 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
169 // XCallback::inoutChar
171 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
172 // XCallback::inoutString
174 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
175 // XCallback::inoutFloat
177 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
178 // XCallback::inoutDouble
180 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
181 // XCallback::inoutByte
183 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
184 // XCallback::inoutShort
186 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
187 // XCallback::inoutLong
189 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
190 // XCallback::inoutValuesAll
192 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
196 // XCallback::inValues
198 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
199 // XCallback::inSeqByte
200 // SAFEARRAY( VARIANT)
202 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
203 //XCallback::inSeqXEventListener
205 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
207 // The UNO test component OleTest calls on XCallback_Impl.Callback directly
208 // that is the COM object has not been past a parameter but rather OleTest
209 // creates the COM object itself
211 // XCallback::outValuesAll
212 // does not work currently
214 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
215 // XCallback::inoutValuesAll
217 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
218 // XCallback::inoutValues
220 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
222 // XCallback::inValues
224 hr
= oletest
.Invoke2(L
"testInterface", ¶m1
, ¶m2
);
226 // Test a COM object which implements several interfaces.
229 CComQIPtr
<IDispatch
> dispSimple
;
230 hr
= dispSimple
.CoCreateInstance(L
"XCallback_Impl.Simple");
231 CComVariant
varSimple( dispSimple
);
233 hr
= oletest
.Invoke2(L
"testInterface2", &varSimple
, ¶m2
);
237 // VARIANT CComVariant VT_UNKNOWN VT_DISPATCH V_UI1 CComDispatchDriver WINAPI
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */