Correctly marshal structure return values in member functions on Win-x64 and Win...
[platform/upstream/coreclr.git] / tests / src / Interop / COM / NativeServer / NumericTesting.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 #pragma once
6
7 #include <type_traits>
8 #include <limits>
9 #include "Servers.h"
10
11 class NumericTesting : public UnknownImpl, public INumericTesting
12 {
13 public:
14     DEF_FUNC(Add_Byte)(
15         /*[in]*/ unsigned char a,
16         /*[in]*/ unsigned char b,
17         /*[out,retval]*/ unsigned char * pRetVal)
18     {
19         *pRetVal = static_cast<unsigned char>(a + b);
20         return S_OK;
21     }
22     DEF_FUNC(Add_Short)(
23         /*[in]*/ short a,
24         /*[in]*/ short b,
25         /*[out,retval]*/ short * pRetVal)
26     {
27         *pRetVal = static_cast<short>(a + b);
28         return S_OK;
29     }
30     DEF_FUNC(Add_UShort)(
31         /*[in]*/ unsigned short a,
32         /*[in]*/ unsigned short b,
33         /*[out,retval]*/ unsigned short * pRetVal)
34     {
35         *pRetVal = static_cast<unsigned short>(a + b);
36         return S_OK;
37     }
38     DEF_FUNC(Add_Int)(
39         /*[in]*/ int a,
40         /*[in]*/ int b,
41         /*[out,retval]*/ int * pRetVal)
42     {
43         *pRetVal = a + b;
44         return S_OK;
45     }
46     DEF_FUNC(Add_UInt)(
47         /*[in]*/ unsigned int a,
48         /*[in]*/ unsigned int b,
49         /*[out,retval]*/ unsigned int * pRetVal)
50     {
51         *pRetVal = a + b;
52         return S_OK;
53     }
54     DEF_FUNC(Add_Long)(
55         /*[in]*/ __int64 a,
56         /*[in]*/ __int64 b,
57         /*[out,retval]*/ __int64 * pRetVal)
58     {
59         *pRetVal = a + b;
60         return S_OK;
61     }
62     DEF_FUNC(Add_ULong)(
63         /*[in]*/ unsigned __int64 a,
64         /*[in]*/ unsigned __int64 b,
65         /*[out,retval]*/ unsigned __int64 * pRetVal)
66     {
67         *pRetVal = a + b;
68         return S_OK;
69     }
70     DEF_FUNC(Add_Float)(
71         /*[in]*/ float a,
72         /*[in]*/ float b,
73         /*[out,retval]*/ float * pRetVal)
74     {
75         *pRetVal = a + b;
76         return S_OK;
77     }
78     DEF_FUNC(Add_Double)(
79         /*[in]*/ double a,
80         /*[in]*/ double b,
81         /*[out,retval]*/ double * pRetVal)
82     {
83         *pRetVal = a + b;
84         return S_OK;
85     }
86     DEF_FUNC(Add_Byte_Ref)(
87         /*[in]*/ unsigned char a,
88         /*[in]*/ unsigned char b,
89         /*[in,out]*/ unsigned char * c)
90     {
91         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
92             return E_UNEXPECTED;
93         *c = static_cast<unsigned char>(a + b);
94         return S_OK;
95     }
96     DEF_FUNC(Add_Short_Ref)(
97         /*[in]*/ short a,
98         /*[in]*/ short b,
99         /*[in,out]*/ short * c)
100     {
101         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
102             return E_UNEXPECTED;
103         *c = static_cast<short>(a + b);
104         return S_OK;
105     }
106     DEF_FUNC(Add_UShort_Ref)(
107         /*[in]*/ unsigned short a,
108         /*[in]*/ unsigned short b,
109         /*[in,out]*/ unsigned short * c)
110     {
111         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
112             return E_UNEXPECTED;
113         *c = static_cast<unsigned short>(a + b);
114         return S_OK;
115     }
116     DEF_FUNC(Add_Int_Ref)(
117         /*[in]*/ int a,
118         /*[in]*/ int b,
119         /*[in,out]*/ int * c)
120     {
121         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
122             return E_UNEXPECTED;
123         *c = a + b;
124         return S_OK;
125     }
126     DEF_FUNC(Add_UInt_Ref)(
127         /*[in]*/ unsigned int a,
128         /*[in]*/ unsigned int b,
129         /*[in,out]*/ unsigned int * c)
130     {
131         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
132             return E_UNEXPECTED;
133         *c = a + b;
134         return S_OK;
135     }
136     DEF_FUNC(Add_Long_Ref)(
137         /*[in]*/ __int64 a,
138         /*[in]*/ __int64 b,
139         /*[in,out]*/ __int64 * c)
140     {
141         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
142             return E_UNEXPECTED;
143         *c = a + b;
144         return S_OK;
145     }
146     DEF_FUNC(Add_ULong_Ref)(
147         /*[in]*/ unsigned __int64 a,
148         /*[in]*/ unsigned __int64 b,
149         /*[in,out]*/ unsigned __int64 * c)
150     {
151         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
152             return E_UNEXPECTED;
153         *c = a + b;
154         return S_OK;
155     }
156     DEF_FUNC(Add_Float_Ref)(
157         /*[in]*/ float a,
158         /*[in]*/ float b,
159         /*[in,out]*/ float * c)
160     {
161         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
162             return E_UNEXPECTED;
163         *c = a + b;
164         return S_OK;
165     }
166     DEF_FUNC(Add_Double_Ref)(
167         /*[in]*/ double a,
168         /*[in]*/ double b,
169         /*[in,out]*/ double * c)
170     {
171         if (*c != std::numeric_limits<std::remove_reference<decltype(*c)>::type>::max())
172             return E_UNEXPECTED;
173         *c = a + b;
174         return S_OK;
175     }
176     DEF_FUNC(Add_Byte_Out)(
177         /*[in]*/ unsigned char a,
178         /*[in]*/ unsigned char b,
179         /*[out]*/ unsigned char * c)
180     {
181         *c = static_cast<unsigned char>(a + b);
182         return S_OK;
183     }
184     DEF_FUNC(Add_Short_Out)(
185         /*[in]*/ short a,
186         /*[in]*/ short b,
187         /*[out]*/ short * c)
188     {
189         *c = static_cast<short>(a + b);
190         return S_OK;
191     }
192     DEF_FUNC(Add_UShort_Out)(
193         /*[in]*/ unsigned short a,
194         /*[in]*/ unsigned short b,
195         /*[out]*/ unsigned short * c)
196     {
197         *c = static_cast<unsigned short>(a + b);
198         return S_OK;
199     }
200     DEF_FUNC(Add_Int_Out)(
201         /*[in]*/ int a,
202         /*[in]*/ int b,
203         /*[out]*/ int * c)
204     {
205         *c = a + b;
206         return S_OK;
207     }
208     DEF_FUNC(Add_UInt_Out)(
209         /*[in]*/ unsigned int a,
210         /*[in]*/ unsigned int b,
211         /*[out]*/ unsigned int * c)
212     {
213         *c = a + b;
214         return S_OK;
215     }
216     DEF_FUNC(Add_Long_Out)(
217         /*[in]*/ __int64 a,
218         /*[in]*/ __int64 b,
219         /*[out]*/ __int64 * c)
220     {
221         *c = a + b;
222         return S_OK;
223     }
224     DEF_FUNC(Add_ULong_Out)(
225         /*[in]*/ unsigned __int64 a,
226         /*[in]*/ unsigned __int64 b,
227         /*[out]*/ unsigned __int64 * c)
228     {
229         *c = a + b;
230         return S_OK;
231     }
232     DEF_FUNC(Add_Float_Out)(
233         /*[in]*/ float a,
234         /*[in]*/ float b,
235         /*[out]*/ float * c)
236     {
237         *c = a + b;
238         return S_OK;
239     }
240     DEF_FUNC(Add_Double_Out)(
241         /*[in]*/ double a,
242         /*[in]*/ double b,
243         /*[out]*/ double * c)
244     {
245         *c = a + b;
246         return S_OK;
247     }
248
249     DEF_FUNC(Add_ManyInts11)(
250         /*[in]*/ int i1,
251         /*[in]*/ int i2,
252         /*[in]*/ int i3,
253         /*[in]*/ int i4,
254         /*[in]*/ int i5,
255         /*[in]*/ int i6,
256         /*[in]*/ int i7,
257         /*[in]*/ int i8,
258         /*[in]*/ int i9,
259         /*[in]*/ int i10,
260         /*[in]*/ int i11,
261         /*[out]*/ int * result )
262     {
263         *result = i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11;
264         return S_OK;
265     }
266
267     DEF_FUNC(Add_ManyInts12)(
268         /*[in]*/ int i1,
269         /*[in]*/ int i2,
270         /*[in]*/ int i3,
271         /*[in]*/ int i4,
272         /*[in]*/ int i5,
273         /*[in]*/ int i6,
274         /*[in]*/ int i7,
275         /*[in]*/ int i8,
276         /*[in]*/ int i9,
277         /*[in]*/ int i10,
278         /*[in]*/ int i11,
279         /*[in]*/ int i12,
280         /*[out]*/ int * result )
281     {
282         *result = i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12;
283         return S_OK;
284     }
285
286     virtual COM_DECLSPEC_NOTHROW SizeF STDMETHODCALLTYPE MakeSize(
287         /*[in]*/ float width,
288         /*[in]*/ float height)
289     {
290         return { width, height };
291     }
292
293     virtual COM_DECLSPEC_NOTHROW Size STDMETHODCALLTYPE MakeSizeSmall(
294         /*[in]*/ BYTE width,
295         /*[in]*/ BYTE height)
296     {
297         return { width, height };
298     }
299
300     virtual COM_DECLSPEC_NOTHROW HFA_4 STDMETHODCALLTYPE MakeHFA(
301         /*[in]*/ float x,
302         /*[in]*/ float y,
303         /*[in]*/ float z,
304         /*[in]*/ float w
305     )
306     {
307         return { x, y, z, w };
308     }
309
310 public: // IUnknown
311     STDMETHOD(QueryInterface)(
312         /* [in] */ REFIID riid,
313         /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR *__RPC_FAR *ppvObject)
314     {
315         return DoQueryInterface(riid, ppvObject, static_cast<INumericTesting *>(this));
316     }
317
318     DEFINE_REF_COUNTING();
319 };