aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/efl_mono/ValueEolian.cs
blob: 4d33dfacde939354381142b874b936d42dd885e2 (plain) (blame)
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
#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());


    }
}
#pragma warning restore 1591
}