summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono/ValueEolian.cs
blob: 305de71dc2f04c9b9ce8ec2d19ad6366db17f89d (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
/*
 * 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.
 */
#define CODE_ANALYSIS

// Disable warning about missing docs when generating docs
#pragma warning disable 1591

using System;

namespace TestSuite {


public static class TestEinaValueEolian {
    public static void TestEolianEinaValueInReturn()
    {
        var obj = new Dummy.TestObject();

        using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
            v.Set(42);
            obj.SetValuePtr(v);
            Test.AssertEquals(Eina.Ownership.Managed, v.Ownership);

            Eina.Value v_received = obj.GetValuePtrOwn();
            Test.AssertEquals(Eina.Ownership.Managed, v_received.Ownership);
            Test.AssertEquals(v, v_received);
            v_received.Dispose();
        }
    }

    public static void TestEolianEinaValueInOwn()
    {
        var obj = new Dummy.TestObject();

        using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
            v.Set(2001);
            Test.AssertEquals(Eina.Ownership.Managed, v.Ownership);

            obj.SetValuePtrOwn(v);
            Test.AssertEquals(Eina.Ownership.Unmanaged, v.Ownership);

            Eina.Value v_received = obj.GetValuePtr();
            Test.AssertEquals(Eina.Ownership.Unmanaged, v_received.Ownership);

            Test.AssertEquals(v, v_received);

            obj.ClearValue();
        }
    }

    public static void TestEolianEinaValueOut()
    {
        var obj = new Dummy.TestObject();

        using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) {
            Eina.Value v_out = null;

            v.Set("hello!");
            obj.SetValuePtr(v);
            obj.OutValuePtr(out v_out);

            Test.AssertEquals(v, v_out);
            Test.AssertEquals(Eina.Ownership.Unmanaged, v_out.Ownership);
        }
    }

    public static void TestEolianEinaValueOutOwn()
    {
        var obj = new Dummy.TestObject();

        using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) {
            Eina.Value v_out = null;

            v.Set("hello!");
            obj.SetValuePtr(v);
            obj.OutValuePtrOwn(out v_out);

            Test.AssertEquals(v, v_out);
            Test.AssertEquals(Eina.Ownership.Managed, v_out.Ownership);
        }
    }

    public static void TestEolianEinaValueOutByValue()
    {
        var obj = new Dummy.TestObject();

        using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) {
            Eina.Value v_out = null;

            v.Set("hello!");
            obj.SetValue(v);
            obj.OutValue(out v_out);

            Test.AssertEquals(v, v_out);
            Test.AssertEquals(Eina.Ownership.Managed, v_out.Ownership);
        }
    }

    private class ValueHandler : Dummy.TestObject
    {
        public Eina.Value value;

        public ValueHandler() : base(null)
        {
            value = null;
        }

        public override void SetValue(Eina.Value value)
        {
            this.value = value;
        }
    }

    public static void TestEolianEinaValueByValueConst()
    {
        ValueHandler obj = new ValueHandler();
        using (Eina.Value val = new Eina.Value(Eina.ValueType.String)) {
            obj.CallSetValue(val);
            Test.AssertEquals(val, obj.value);
        }
    }

    public static void TestEolianEinaValueImplicitOperators()
    {
        var obj = new Dummy.TestObject();
        int payload = 1999;
        obj.SetValue(payload);

        var expected = new Eina.Value(1999);
        var received = new Eina.Value(Eina.ValueType.String);

        obj.OutValue(out received);
        Test.AssertEquals(expected, received);
        Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType());

        int i = received;
        Test.AssertEquals(i, 1999);

        expected = new Eina.Value("Hallo");
        obj.SetValue("Hallo");

        obj.OutValue(out received);
        Test.AssertEquals(expected, received);
        Test.AssertEquals(Eina.ValueType.String, received.GetValueType());

        string s = received;
        Test.AssertEquals(s, "Hallo");

        // Casting
        expected = new Eina.Value((double)15);
        obj.SetValue((double)15);

        obj.OutValue(out received);
        Test.AssertEquals(expected, received);
        Test.AssertEquals(Eina.ValueType.Double, received.GetValueType());

        // Check for 0
        // This is a special value, since C# can silently convert it to an enum
        // leading to collisions with Eina.ValueType
        expected = new Eina.Value(0);
        obj.SetValue(0);
        obj.OutValue(out received);
        Test.AssertEquals(expected, received);
        Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType());
    }

// ValueType in eolian context is beta, so not allowed.
// Value does not have this problem as it is used as any_value/any_value_ref
#if EFL_BETA
    public static void TestEolianEinaValueTypeMarshalling()
    {
        var obj = new Dummy.TestObject();

        var values = Enum.GetValues(typeof(Eina.ValueType));
        foreach (Eina.ValueType type in values)
        {
            Test.AssertEquals(type, obj.MirrorValueType(type));
        }
    }
#endif
}
#pragma warning restore 1591
}