summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono/Structs.cs
blob: 66d4e3a015b5f0e92a610d41a9402e4131991f8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
 * Copyright 2019 by its authors. See AUTHORS.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Runtime.InteropServices;
using System.Linq;

using static EinaTestData.BaseData;
using static TestSuite.StructHelpers;

namespace TestSuite
{

internal class TestStructs
{
    // Test cases //

    // Default initialization (C# side)

    private static void simple_default_instantiation()
    {
        var simple = new Dummy.StructSimple();
        checkZeroedStructSimple(simple);
    }

#if EFL_BETA
    private static void complex_default_instantiation()
    {
        var complex = new Dummy.StructComplex();
        checkZeroedStructComplex(complex);
    }
#endif

    public static void parameter_initialization()
    {
        var simple = new Dummy.StructSimple(0x1, 0x2, (char)0x3, 0x4, 0x5);
        Test.AssertEquals(0x1, simple.Fbyte);
        Test.AssertEquals(0x2, simple.Fubyte);
        Test.AssertEquals(0x3, simple.Fchar);
        Test.AssertEquals(0x4, simple.Fshort);
        Test.AssertEquals(0x5, simple.Fushort);
        Test.AssertEquals(0, simple.Fint);
    }

    // As parameters

    public static void simple_in()
    {
        var simple = structSimpleWithValues();
        var t = new Dummy.TestObject();
        bool r = t.StructSimpleIn(simple);
        Test.Assert(r, "Function returned false");
    }

    /*
    public static void simple_ptr_in()
    {
        var simple = structSimpleWithValues();
        int original = simple.Fint;
        simple.Fmstring = "Struct Ptr In";
        var t = new Dummy.TestObject();
        Test.Assert(t.StructSimplePtrIn(ref simple));
        Test.AssertEquals(-original, simple.Fint);
        Test.AssertEquals("nI rtP tcurtS", simple.Fmstring);
    }

    public static void simple_ptr_in_own()
    {
        var simple = structSimpleWithValues();
        int original = simple.Fint;
        simple.Fmstring = "Struct Ptr In Own";
        var t = new Dummy.TestObject();
        Dummy.StructSimple result = t.StructSimplePtrInOwn(ref simple);
        Test.AssertEquals(-original, result.Fint);
        Test.AssertEquals("nwO nI rtP tcurtS", result.Fmstring);
    }
    */

    public static void simple_out()
    {
        var simple = new Dummy.StructSimple();
        var t = new Dummy.TestObject();
        bool r = t.StructSimpleOut(out simple);
        Test.Assert(r, "Function returned false");
        checkStructSimple(simple);
    }

    /*
    public static void simple_ptr_out()
    {
        Dummy.StructSimple simple;
        var t = new Dummy.TestObject();
        Dummy.StructSimple result = t.StructSimplePtrOut(out simple);
        Test.AssertEquals(result.Fint, simple.Fint);
        Test.AssertEquals(result.Fstring, simple.Fstring);
    }

    public static void simple_ptr_out_own()
    {
        Dummy.StructSimple simple;
        var t = new Dummy.TestObject();
        Dummy.StructSimple result = t.StructSimplePtrOutOwn(out simple);
        Test.AssertEquals(result.Fint, simple.Fint);
        Test.AssertEquals(simple.Fstring, "Ptr Out Own");
    }
    */

    public static void simple_return()
    {
        var t = new Dummy.TestObject();
        var simple = t.StructSimpleReturn();
        checkStructSimple(simple);
    }

    /*
    public static void simple_ptr_return()
    {
        var t = new Dummy.TestObject();
        var simple = t.StructSimplePtrReturn();
        Test.AssertEquals(simple.Fstring, "Ret Ptr");
    }

    public static void simple_ptr_return_own()
    {
        var t = new Dummy.TestObject();
        var simple = t.StructSimplePtrReturnOwn();
        Test.AssertEquals(simple.Fstring, "Ret Ptr Own");
    }
    */

    public class StructReturner : Dummy.TestObject
    {
        public Dummy.StructSimple received;
        public bool called;

        public StructReturner() : base(null)
        {
            called = false;
            received = default(Dummy.StructSimple);
        }

        public override bool StructSimpleIn(Dummy.StructSimple simple)
        {
            called = true;
            received = simple;

            return true;
        }

        /*
        public override bool StructSimplePtrIn(ref Dummy.StructSimple simple)
        {
            called = true;
            simple.Fstring = "Virtual Struct Ptr In";
            return true;
        }

        public override Dummy.StructSimple StructSimplePtrInOwn(ref Dummy.StructSimple simple)
        {
            called = true;
            received = simple;
            return received;
        }
        */

        public override bool StructSimpleOut(out Dummy.StructSimple simple) {
            called = true;
            simple = new Dummy.StructSimple();
            simple.Fstring = "Virtual Struct Out";
            return true;
        }

        /*
        public override Dummy.StructSimple StructSimplePtrOut(out Dummy.StructSimple simple) {
            called = true;
            // No way to explicitly define the ownership of the parameter.
            simple = new Dummy.StructSimple();
            simple.Fstring = "Virtual Struct Ptr Out";
            return simple;
        }

        public override Dummy.StructSimple StructSimplePtrOutOwn(out Dummy.StructSimple simple) {
            called = true;
            // No way to explicitly define the ownership of the parameter.
            simple = new Dummy.StructSimple();
            simple.Fstring = "Virtual Struct Ptr Out Own";
            return simple;
        }
        */

        public override Dummy.StructSimple StructSimpleReturn()
        {
            called = true;
            var simple = new Dummy.StructSimple();
            simple.Fstring = "Virtual Struct Return";
            return simple;
        }

        /*
        public override Dummy.StructSimple StructSimplePtrReturn()
        {
            called = true;
            var simple = new Dummy.StructSimple();
            simple.Fstring = "Virtual Struct Ptr Return";
            return simple;
        }

        public override Dummy.StructSimple StructSimplePtrReturnOwn()
        {
            called = true;
            var simple = new Dummy.StructSimple();
            simple.Fstring = "Virtual Struct Ptr Return Own";
            return simple;
        }
        */
    }

    public static void simple_in_virtual()
    {
        StructReturner t = new StructReturner();
        var simple = structSimpleWithValues();
        simple.Fstring = "Virtual Struct In";

        t.CallStructSimpleIn(simple);
        Test.Assert(t.called);
        Test.AssertEquals(simple.Fstring, t.received.Fstring);
    }

    /*
    public static void simple_ptr_in_virtual()
    {
        StructReturner t = new StructReturner();
        var simple = structSimpleWithValues();
        string reference = "Virtual Struct Ptr In";

        t.CallStructSimplePtrIn(ref simple);
        Test.Assert(t.called);
        Test.AssertEquals(simple.Fstring, reference);
    }

    public static void simple_ptr_in_own_virtual()
    {
        StructReturner t = new StructReturner();
        var simple = structSimpleWithValues();
        simple.Fstring = "Virtual Struct Ptr In Own";

        t.CallStructSimplePtrInOwn(ref simple);
        Test.Assert(t.called);
        Test.AssertEquals(t.received.Fstring, simple.Fstring);
    }
    */

    public static void simple_out_virtual()
    {
        StructReturner t = new StructReturner();
        Dummy.StructSimple simple;
        t.CallStructSimpleOut(out simple);
        Test.Assert(t.called, "override was not called");
        Test.AssertEquals("Virtual Struct Out", simple.Fstring);
    }

    /*
    public static void simple_ptr_out_virtual()
    {
        StructReturner t = new StructReturner();
        Dummy.StructSimple simple;
        t.CallStructSimplePtrOut(out simple);
        Test.Assert(t.called, "override was not called");
        Test.AssertEquals("Virtual Struct Ptr Out", simple.Fstring);
    }

    public static void simple_ptr_out_own_virtual()
    {
        StructReturner t = new StructReturner();
        Dummy.StructSimple simple;
        t.CallStructSimplePtrOutOwn(out simple);
        Test.Assert(t.called, "override was not called");
        Test.AssertEquals("Virtual Struct Ptr Out Own", simple.Fstring);
    }
    */

    public static void simple_return_virtual()
    {
        StructReturner t = new StructReturner();
        Dummy.StructSimple simple = t.CallStructSimpleReturn();
        Test.Assert(t.called, "override was not called");
        Test.AssertEquals("Virtual Struct Return", simple.Fstring);
    }

    /*
    public static void simple_ptr_return_virtual()
    {
        StructReturner t = new StructReturner();
        Dummy.StructSimple simple = t.CallStructSimplePtrReturn();
        Test.Assert(t.called, "override was not called");
        Test.AssertEquals("Virtual Struct Ptr Return", simple.Fstring);
    }

    public static void simple_ptr_return_own_virtual()
    {
        StructReturner t = new StructReturner();
        Dummy.StructSimple simple = t.CallStructSimplePtrReturnOwn();
        Test.Assert(t.called, "override was not called");
        Test.AssertEquals("Virtual Struct Ptr Return Own", simple.Fstring);
    }
    */

#if EFL_BETA
    // Complex Structs
    public static void complex_in()
    {
        var complex = structComplexWithValues();
        var t = new Dummy.TestObject();
        bool r = t.StructComplexIn(complex);
        Test.Assert(r, "Function returned false");
    }

    // public static void complex_ptr_in()
    // {
    // }

    // public static void complex_ptr_in_own()
    // {
    // }

    public static void complex_out()
    {
        var complex = new Dummy.StructComplex();
        var t = new Dummy.TestObject();
        bool r = t.StructComplexOut(out complex);
        Test.Assert(r, "Function returned false");
        checkStructComplex(complex);
    }

    // public static void complex_ptr_out()
    // {
    // }

    // public static void complex_ptr_out_own()
    // {
    // }

    public static void complex_return()
    {
        var t = new Dummy.TestObject();
        var complex = t.StructComplexReturn();
        checkStructComplex(complex);
    }
#endif
    // public static void complex_ptr_return()
    // {
    // }

    // public static void complex_ptr_return_own()
    // {
    // }
}

}