efl

Форк
0
/
Value.cs 
1728 строк · 59.0 Кб
1
/*
2
 * Copyright 2019 by its authors. See AUTHORS.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
#define CODE_ANALYSIS
17

18
#pragma warning disable 1591
19

20
using System;
21
using System.Linq;
22
using System.Diagnostics.CodeAnalysis;
23
using System.Collections.Generic;
24

25
namespace TestSuite {
26

27

28
[SuppressMessage("Gendarme.Rules.Portability", "DoNotHardcodePathsRule")]
29
public static class TestEinaValue {
30

31
    public static void TestByteSimple()
32
    {
33
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Byte)) {
34
            byte val = 0xff;
35
            Test.Assert(v.Set(val));
36
            byte x;
37
            Test.Assert(v.Get(out x));
38
            Test.AssertEquals(val, x);
39
        }
40
    }
41

42
    public static void TestSByteSimple()
43
    {
44
        using (Eina.Value v = new Eina.Value(Eina.ValueType.SByte)) {
45
            sbyte val = -45;
46
            Test.Assert(v.Set(val));
47
            sbyte x;
48
            Test.Assert(v.Get(out x));
49
            Test.AssertEquals(val, x);
50
        }
51
    }
52

53
    public static void TestShortSimple()
54
    {
55
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Short)) {
56
            short val = -128;
57
            Test.Assert(v.Set(val));
58
            short x;
59
            Test.Assert(v.Get(out x));
60
            Test.AssertEquals(val, x);
61
        }
62
    }
63

64
    public static void TestUShortSimple()
65
    {
66
        using (Eina.Value v = new Eina.Value(Eina.ValueType.UShort)) {
67
            ushort val = 0xff55;
68
            Test.Assert(v.Set(val));
69
            ushort x;
70
            Test.Assert(v.Get(out x));
71
            Test.AssertEquals(val, x);
72
        }
73
    }
74

75
    public static void TestLongSimple()
76
    {
77
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Long)) {
78
            long val = 0xdeadbeef;
79
            Test.Assert(v.Set(val));
80
            long x;
81
            Test.Assert(v.Get(out x));
82
            Test.AssertEquals(val, x);
83
        }
84
    }
85

86
    public static void TestULongSimple()
87
    {
88
        using (Eina.Value v = new Eina.Value(Eina.ValueType.ULong)) {
89
            ulong val = 0xdeadbeef;
90
            Test.Assert(v.Set(val));
91
            ulong x;
92
            Test.Assert(v.Get(out x));
93
            Test.AssertEquals(val, x);
94
        }
95
    }
96

97
    public static void TestFloatSimple()
98
    {
99
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Float)) {
100
            float val = 1.609344f;
101
            Test.Assert(v.Set(val));
102
            float x;
103
            Test.Assert(v.Get(out x));
104
            Test.AssertAlmostEquals(val, x);
105
        }
106
    }
107

108
    public static void TestDoubleSimple()
109
    {
110
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Double)) {
111
            double val = 1.609344;
112
            Test.Assert(v.Set(val));
113
            double  x;
114
            Test.Assert(v.Get(out x));
115
            Test.AssertAlmostEquals(val, x);
116
        }
117
    }
118

119

120
    public static void TestIntSimple()
121
    {
122
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
123
            Test.Assert(v.Set(32));
124
            int x;
125
            Test.Assert(v.Get(out x));
126
            Test.AssertEquals(32, x);
127

128
            Test.Assert(v.Set(-45));
129
            Test.Assert(v.Get(out x));
130
            Test.AssertEquals(-45, x);
131
        }
132
    }
133

134
    public static void TestUIntSimple()
135
    {
136
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
137
            Test.Assert(v.Set(0xdeadbeef));
138
            uint x = 0;
139
            Test.Assert(v.Get(out x));
140
            Test.AssertEquals(0xdeadbeef, x);
141
        }
142
    }
143

144
    public static void TestStringSimple()
145
    {
146
        using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) {
147
            string expected_str = "Hello";
148
            Test.Assert(v.Set(expected_str));
149
            string str = null;
150
            Test.Assert(v.Get(out str));
151
            Test.AssertEquals(expected_str, str);
152
        }
153
    }
154

155
    public static void TestErrorSimple()
156
    {
157
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Error)) {
158
            Eina.Error error = new Eina.Error(Eina.Error.NO_ERROR);
159
            Test.Assert(v.Set(error));
160
            Eina.Error x;
161
            Test.Assert(v.Get(out x));
162
            Test.AssertEquals(error, x);
163
        }
164
    }
165

166
    public static void TestObjectSimple()
167
    {
168
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Object))
169
        {
170
            var obj = new Dummy.TestObject();
171
            Test.Assert(v.Set(obj));
172
            Efl.Object target;
173
            Test.Assert(v.Get(out target));
174
            Test.AssertEquals(target, obj);
175
            target.Dispose();
176
            obj.Dispose();
177
        }
178
    }
179

180
    // Efl.Object conversions are made explicit to avoid ambiguity between
181
    // Set(Efl.Object) and Set(Value) when dealing with classes derived from
182
    // Efl.Object.
183
    public static void TestObjectImplicit()
184
    {
185
        var obj = new Dummy.TestObject();
186
        var v = (Eina.Value)obj;
187
        Test.AssertEquals(v.GetValueType(), Eina.ValueType.Object);
188
        Efl.Object target = (Efl.Object)v;
189

190
        Test.AssertEquals(target, obj);
191
    }
192

193
    public static void TestSetWrongType()
194
    {
195
        using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) {
196
            Test.AssertRaises<ArgumentException>(() => v.Set(42));
197
            Test.AssertNotRaises<ArgumentException>(() => v.Set("Wumpus"));
198
            Test.Assert(v.Setup(Eina.ValueType.Int32));
199
            Test.AssertRaises<ArgumentException>(() => v.Set("Wat?"));
200
            Test.AssertNotRaises<ArgumentException>(() => v.Set(1984));
201
        }
202
    }
203

204
    public static void TestValueSetup()
205
    {
206
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
207
            Test.Assert(v.Set(44));
208
            int x = 0;
209
            Test.Assert(v.Get(out x));
210
            Test.AssertEquals(44, x);
211
            v.Setup(Eina.ValueType.String);
212

213
            string str = "Hello";
214
            Test.Assert(v.Get(out str));
215
            Test.AssertNull(str);
216
        }
217
    }
218

219
    public static void TestValueDispose()
220
    {
221
        Eina.Value v = new Eina.Value(Eina.ValueType.Int32);
222
        v.Dispose();
223
        Test.AssertRaises<ObjectDisposedException>(() => v.ToString());
224
        Test.AssertRaises<ObjectDisposedException>(() => v.Set(24));
225
    }
226

227
    private delegate bool BoolRet();
228
    public static void TestValueOptionalInt()
229
    {
230
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
231
            Test.Assert(a.Optional);
232
            Test.Assert(a.OptionalEmpty); // By default, optional values are empty
233

234
            // Sets expectation
235
            int expected = 1984;
236
            Test.Assert(a.Set(expected));
237
            Test.Assert(a.Optional);
238
            Test.Assert(!a.OptionalEmpty);
239

240
            Test.Assert(a.Reset());
241
            Test.Assert(a.OptionalEmpty);
242

243
            expected = -4891;
244
            Test.Assert(a.Set(expected)); // Set() automatically infers the subtype from the argument.
245
            Test.Assert(!a.OptionalEmpty);
246

247
            int actual = 0;
248
            Test.Assert(a.Get(out actual));
249
            Test.AssertEquals(expected, actual);
250
        }
251
    }
252
    public static void TestValueOptionalUint()
253
    {
254
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
255
            Test.Assert(a.Optional);
256
            Test.Assert(a.OptionalEmpty); // By default, optional values are empty
257

258
            // Sets expectation
259
            uint expected = 1984;
260
            Test.Assert(a.Set(expected));
261
            Test.Assert(a.Optional);
262
            Test.Assert(!a.OptionalEmpty);
263

264
            Test.Assert(a.Reset());
265
            Test.Assert(a.OptionalEmpty);
266

267
            expected = 0xdeadbeef;
268
            Test.Assert(a.Set(expected));
269
            Test.Assert(!a.OptionalEmpty);
270

271
            uint actual = 0;
272
            Test.Assert(a.Get(out actual));
273
            Test.AssertEquals(expected, actual);
274
        }
275
    }
276
    public static void TestValueOptionalString()
277
    {
278
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32)) {
279
            Test.Assert(!a.Optional);
280
            BoolRet dummy = () => a.OptionalEmpty;
281
            Test.AssertRaises<Eina.InvalidValueTypeException>(() => dummy());
282
        }
283

284
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
285
            Test.Assert(a.Optional);
286
            Test.Assert(a.OptionalEmpty); // By default, optional values are empty
287

288
            // Sets expectation
289
            string expected = "Hello, world!";
290
            Test.Assert(a.Set(expected));
291
            Test.Assert(a.Optional);
292
            Test.Assert(!a.OptionalEmpty);
293

294
            Test.Assert(a.Reset());
295
            Test.Assert(a.OptionalEmpty);
296

297
            expected = "!dlrow olleH";
298
            Test.Assert(a.Set(expected));
299
            Test.Assert(!a.OptionalEmpty);
300

301
            string actual = String.Empty;
302
            Test.Assert(a.Get(out actual));
303
            Test.AssertEquals(expected, actual);
304
        }
305
    }
306

307
    public static void TestValueOptionalObject()
308
    {
309
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Object)) {
310
            Test.Assert(!a.Optional);
311
            BoolRet dummy = () => a.OptionalEmpty;
312
            Test.AssertRaises<Eina.InvalidValueTypeException>(() => dummy());
313
        }
314

315
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
316
            Test.Assert(a.Optional);
317
            Test.Assert(a.OptionalEmpty); // By default, optional values are empty
318

319
            // Sets expectation
320
            Efl.Object expected = new Dummy.TestObject();
321
            Test.Assert(a.Set(expected));
322
            Test.Assert(a.Optional);
323
            Test.Assert(!a.OptionalEmpty);
324

325
            Test.Assert(a.Reset());
326
            Test.Assert(a.OptionalEmpty);
327

328
            Test.Assert(a.Set(expected));
329
            Test.Assert(!a.OptionalEmpty);
330

331
            Efl.Object received = null;
332
            Test.Assert(a.Get(out received));
333
            Test.AssertEquals(expected, received);
334
            received.Dispose();
335
            expected.Dispose();
336
        }
337
    }
338

339
    public static void TestValueOptionalArrays()
340
    {
341
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional))
342
        using (Eina.Value expected = new Eina.Value(Eina.ValueType.Array,
343
                                                 Eina.ValueType.Int32))
344
        {
345

346
            Test.Assert(a.Optional);
347
            Test.Assert(a.OptionalEmpty); // By default, optional values are empty
348

349
            // Sets expectation
350
            Test.Assert(expected.Append(-1));
351
            Test.Assert(expected.Append(0));
352
            Test.Assert(expected.Append(2));
353

354
            Test.Assert(a.Set(expected));
355
            Test.Assert(a.Optional);
356
            Test.Assert(!a.OptionalEmpty);
357

358
            Test.Assert(a.Reset());
359
            Test.Assert(a.OptionalEmpty);
360

361
            expected.Append(-42);
362
            Test.Assert(a.Set(expected));
363
            Test.Assert(!a.OptionalEmpty);
364

365
            Eina.Value actual = null;
366
            Test.Assert(a.Get(out actual));
367
            Test.AssertEquals(expected, actual);
368

369
            Test.Assert(a.Reset());
370
            Test.Assert(a.Set(expected));
371
            actual.Dispose();
372
        }
373
    }
374
    public static void TestValueOptionalLists()
375
    {
376
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional))
377
        using (Eina.Value expected = new Eina.Value(Eina.ValueType.List,
378
                                                 Eina.ValueType.Int32))
379
        {
380

381
            Test.Assert(a.Optional);
382
            Test.Assert(a.OptionalEmpty); // By default, optional values are empty
383

384
            // Sets expectation
385
            Test.Assert(expected.Append(-1));
386
            Test.Assert(expected.Append(0));
387
            Test.Assert(expected.Append(2));
388

389
            Test.Assert(a.Set(expected));
390
            Test.Assert(a.Optional);
391
            Test.Assert(!a.OptionalEmpty);
392

393
            Test.Assert(a.Reset());
394
            Test.Assert(a.OptionalEmpty);
395

396
            expected.Append(-42);
397
            Test.Assert(a.Set(expected));
398
            Test.Assert(!a.OptionalEmpty);
399

400
            Eina.Value actual = null;
401
            Test.Assert(a.Get(out actual));
402
            Test.AssertEquals(expected, actual);
403
            actual.Dispose();
404
        }
405
    }
406

407
    public static void TestValueCompareInts()
408
    {
409
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32))
410
        using (Eina.Value b = new Eina.Value(Eina.ValueType.Int32)) {
411
            Test.Assert(a.Set(123));
412
            Test.Assert(b.Set(123));
413
            Test.AssertEquals(0, a.CompareTo(b));
414

415
            Test.Assert(a.Set(-10));
416
            Test.AssertLessThan(a, b);
417

418
            Test.Assert(a.Set(123));
419
            Test.Assert(b.Set(10));
420
            Test.AssertGreaterThan(a, b);
421
        }
422
    }
423

424
    public static void TestValueComparisonEquals()
425
    {
426
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32))
427
        using (Eina.Value b = new Eina.Value(Eina.ValueType.Int32))
428
        using (Eina.Value c = new Eina.Value(Eina.ValueType.Int32)) {
429
            Test.Assert(a.Set(1));
430
            Test.Assert(b.Set(1));
431
            Test.Assert(c.Set(1));
432

433
            Test.Assert(a.Equals(a), "A equals A");
434
            Test.Assert(a.Equals(b) == b.Equals(a), "A equals B == B equals A");
435
            Test.Assert(a.Equals(b) == b.Equals(c) == a.Equals(c));
436

437
            Test.Assert(b.Set(0));
438
            Test.Assert(a.Equals(b) == b.Equals(a), "A equals B == B equals A");
439

440
            Test.Assert(a.Equals(null) == false, "A == null");
441
        }
442
    }
443

444
    public static void TestValueComparisonOverloadEquals()
445
    {
446
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32))
447
        using (Eina.Value b = new Eina.Value(Eina.ValueType.Int32)) {
448
            Test.Assert(a.Set(1));
449
            Test.Assert(b.Set(1));
450

451
            Test.Assert(a == b);
452
            Test.Assert(!(a != b));
453
            Test.Assert(b == a);
454
            Test.Assert(!(b != a));
455

456
            Test.Assert(b.Set(42));
457

458
            Test.Assert(a != b);
459
            Test.Assert(!(a == b));
460
            Test.Assert(b != a);
461
            Test.Assert(!(b == a));
462

463
            Test.Assert(b.Set(42));
464

465
        }
466
    }
467

468
    public static void TestValueComparisonOverloadLessGreater()
469
    {
470
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32))
471
        using (Eina.Value b = new Eina.Value(Eina.ValueType.Int32)) {
472
            Test.Assert(a.Set(1));
473
            Test.Assert(b.Set(0));
474

475
            Test.Assert(a > b);
476
            Test.Assert(!(a <= b));
477
            Test.Assert(!(a < b));
478
            Test.Assert(a >= b);
479
            Test.Assert(b < a);
480
            Test.Assert(!(b >= a));
481
            Test.Assert(!(b > a));
482
            Test.Assert(b <= a);
483

484
            Test.AssertEquals(a > b, !(a <= b));
485
            Test.AssertEquals(!(a < b), a >= b);
486
            Test.AssertEquals(b < a, !(b >= a));
487
            Test.AssertEquals(!(b > a), b <= a);
488
        }
489
    }
490

491
    public static void TestValueCompareStrings()
492
    {
493
        using (Eina.Value a = new Eina.Value(Eina.ValueType.String))
494
        using (Eina.Value b = new Eina.Value(Eina.ValueType.String)) {
495
            Test.Assert(a.Set("aaa"));
496
            Test.Assert(b.Set("aaa"));
497
            Test.AssertEquals(0, a.CompareTo(b));
498

499
            Test.Assert(a.Set("abc"));
500
            Test.Assert(b.Set("acd"));
501
            Test.AssertLessThan(a, b);
502

503
            Test.Assert(a.Set("acd"));
504
            Test.Assert(b.Set("abc"));
505
            Test.AssertGreaterThan(a, b);
506
        }
507
    }
508

509
    public static void TestValueCompareArray()
510
    {
511
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32))
512
        using (Eina.Value b = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32)) {
513

514
            Test.AssertEquals(a, b);
515

516
            Test.Assert(a.Append(0));
517
            Test.Assert(a.Append(1));
518
            Test.Assert(a.Append(5));
519
            Test.Assert(a.Append(42));
520

521
            Test.Assert(b.Append(0));
522
            Test.Assert(b.Append(1));
523
            Test.Assert(b.Append(5));
524
            Test.Assert(b.Append(42));
525

526
            Test.AssertEquals(a, b);
527

528
            a[0] = -1;
529
            Test.Assert(!a.Equals(b));
530
            Test.AssertLessThan(a, b);
531

532
            a[0] = 10;
533
            Test.AssertGreaterThan(a, b);
534

535
            a[0] = 0;
536
            Test.AssertEquals(a, b);
537

538
            // bigger arrays are greater
539
            Test.Assert(b.Append(0));
540
            Test.AssertLessThan(a, b);
541

542
            Test.Assert(a.Append(0));
543
            Test.Assert(a.Append(0));
544
            Test.AssertGreaterThan(a, b);
545

546
            // bigger arrays are greater, unless an element says other wise
547
            b[0] = 10;
548
            Test.AssertGreaterThan(b, a);
549
        }
550
    }
551

552
    public static void TestValueCompareList()
553
    {
554
        using (Eina.Value a = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32))
555
        using (Eina.Value b = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32)) {
556

557
            Test.AssertEquals(a, b);
558

559
            Test.Assert(a.Append(0));
560
            Test.Assert(a.Append(1));
561
            Test.Assert(a.Append(5));
562
            Test.Assert(a.Append(42));
563

564
            Test.Assert(b.Append(0));
565
            Test.Assert(b.Append(1));
566
            Test.Assert(b.Append(5));
567
            Test.Assert(b.Append(42));
568

569
            Test.AssertEquals(a, b);
570

571
            a[0] = -1;
572
            Test.Assert(!a.Equals(b));
573
            Test.AssertLessThan(a, b);
574

575
            a[0] = 10;
576
            Test.AssertGreaterThan(a, b);
577

578
            a[0] = 0;
579
            Test.AssertEquals(a, b);
580

581
            // bigger arrays are greater
582
            Test.Assert(b.Append(0));
583
            Test.AssertLessThan(a, b);
584

585
            Test.Assert(a.Append(0));
586
            Test.Assert(a.Append(0));
587
            Test.AssertGreaterThan(a, b);
588

589
            // bigger arrays are greater, unless an element says other wise
590
            b[0] = 10;
591
            Test.AssertGreaterThan(b, a);
592
        }
593
    }
594

595
    /* public static void TestValueCompareHash() */
596
    /* { */
597
    /*     Test.Assert(false, "Implement me."); */
598
    /* } */
599

600
    public static void TestValueToString()
601
    {
602
        using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32)) {
603
            int i = -12345;
604
            string x = $"{i}";
605
            Test.Assert(a.Set(i));
606
            Test.AssertEquals(x, a.ToString());
607

608
            uint u = 0xdeadbeef;
609
            x = $"{u}";
610
            Test.Assert(a.Setup(Eina.ValueType.UInt32));
611
            Test.Assert(a.Set(u));
612
            Test.AssertEquals(x, a.ToString());
613

614
            string s = "Hello, Johnny!";
615
            x = s;
616
            Test.Assert(a.Setup(Eina.ValueType.String));
617
            Test.Assert(a.Set(s));
618
            Test.AssertEquals(x, a.ToString());
619
        }
620
    }
621

622
    public static void TestValueConvertInt()
623
    {
624
        using (Eina.Value from = new Eina.Value(Eina.ValueType.Int32))
625
        using (Eina.Value to = new Eina.Value(Eina.ValueType.UInt32)) {
626
            int source = 0x7FFFFFFF;
627
            uint target_uint;
628
            int target_int;
629
            string target_str;
630
            string source_str = $"{source}";
631

632
            Test.Assert(from.Set(source));
633
            Test.Assert(from.ConvertTo(to));
634
            Test.Assert(to.Get(out target_uint));
635
            Test.AssertEquals(target_uint, (uint)source);
636

637
            Test.Assert(to.Setup(Eina.ValueType.Int32));
638
            Test.Assert(from.ConvertTo(to));
639
            Test.Assert(to.Get(out target_int));
640
            Test.AssertEquals(target_int, source);
641

642
            Test.Assert(to.Setup(Eina.ValueType.String));
643
            Test.Assert(from.ConvertTo(to));
644
            Test.Assert(to.Get(out target_str));
645
            Test.AssertEquals(target_str, source_str);
646

647
            // FIXME Add tests for failing ConvertTo() calls when downcasting
648
            // to smaller types
649
        }
650
    }
651

652
    public static void TestValueConvertUInt()
653
    {
654
        using (Eina.Value from = new Eina.Value(Eina.ValueType.UInt32))
655
        using (Eina.Value to = new Eina.Value(Eina.ValueType.UInt32)) {
656
            uint source = 0xFFFFFFFF;
657
            uint target_uint;
658
            string target_str;
659
            string source_str = $"{source}";
660

661
            Test.Assert(from.Set(source));
662
            Test.Assert(from.ConvertTo(to));
663
            Test.Assert(to.Get(out target_uint));
664
            Test.AssertEquals(target_uint, source);
665

666
            Test.Assert(to.Setup(Eina.ValueType.Int32));
667
            Test.Assert(!from.ConvertTo(to));
668

669
            Test.Assert(to.Setup(Eina.ValueType.String));
670
            Test.Assert(from.ConvertTo(to));
671
            Test.Assert(to.Get(out target_str));
672
            Test.AssertEquals(target_str, source_str);
673

674
            // FIXME Add tests for failing ConvertTo() calls when downcasting
675
            // to smaller types
676
        }
677
    }
678

679
    public static void TestValueContainerConstructorWrongArgs()
680
    {
681
        Test.AssertRaises<ArgumentException>(() => {
682
            using (Eina.Value array = new Eina.Value(Eina.ValueType.String, Eina.ValueType.String)) { }
683
        });
684
    }
685

686
    public static void TestValueContainerWithNonContainerAccess()
687
    {
688
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Int32)) {
689
            Test.AssertRaises<Eina.InvalidValueTypeException>(() => array[0] = 1);
690
            object val = null;
691
            Test.AssertRaises<Eina.InvalidValueTypeException>(() => val = array[0]);
692
        }
693
    }
694

695
    public static void TestValueArrayOfSByte()
696
    {
697
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.SByte)) {
698
            Test.AssertEquals(0, array.Count());
699
            Test.Assert(array.Append(0));
700
            Test.AssertEquals(1, array.Count());
701
            Test.Assert(array.Append(1));
702
            Test.AssertEquals(2, array.Count());
703
            Test.Assert(array.Append(5));
704
            Test.AssertEquals(3, array.Count());
705
            Test.Assert(array.Append(42));
706
            Test.AssertEquals(4, array.Count());
707

708

709
            Test.AssertEquals((sbyte)array[0], 0);
710
            Test.AssertEquals((sbyte)array[1], 1);
711
            Test.AssertEquals((sbyte)array[2], 5);
712
            Test.AssertEquals((sbyte)array[3], 42);
713

714
            array[0] = 120;
715
            array[1] = -42;
716
            Test.AssertEquals(4, array.Count());
717

718
            Test.AssertEquals((sbyte)array[0], 120);
719
            Test.AssertEquals((sbyte)array[1], -42);
720
            Test.AssertEquals((sbyte)array[2], 5);
721
            Test.AssertEquals((sbyte)array[3], 42);
722

723
            Test.AssertEquals("[120, -42, 5, 42]", array.ToString());
724
        }
725
    }
726

727
    public static void TestValueArrayOfByte()
728
    {
729
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Byte)) {
730
            Test.AssertEquals(0, array.Count());
731
            Test.Assert(array.Append(0));
732
            Test.AssertEquals(1, array.Count());
733
            Test.Assert(array.Append(1));
734
            Test.AssertEquals(2, array.Count());
735
            Test.Assert(array.Append(5));
736
            Test.AssertEquals(3, array.Count());
737
            Test.Assert(array.Append(42));
738
            Test.AssertEquals(4, array.Count());
739

740

741
            Test.AssertEquals((byte)array[0], 0);
742
            Test.AssertEquals((byte)array[1], 1);
743
            Test.AssertEquals((byte)array[2], 5);
744
            Test.AssertEquals((byte)array[3], 42);
745

746
            array[0] = 155;
747
            array[1] = 42;
748
            Test.AssertEquals(4, array.Count());
749

750
            Test.AssertEquals((byte)array[0], 155);
751
            Test.AssertEquals((byte)array[1], 42);
752
            Test.AssertEquals((byte)array[2], 5);
753
            Test.AssertEquals((byte)array[3], 42);
754

755
            Test.AssertEquals("[155, 42, 5, 42]", array.ToString());
756

757
            Test.AssertRaises<OverflowException>(() => array[0] = 123214);
758
        }
759
    }
760

761
    public static void TestValueArrayOfInts()
762
    {
763
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32)) {
764
            Test.AssertEquals(0, array.Count());
765
            Test.Assert(array.Append(0));
766
            Test.AssertEquals(1, array.Count());
767
            Test.Assert(array.Append(1));
768
            Test.AssertEquals(2, array.Count());
769
            Test.Assert(array.Append(5));
770
            Test.AssertEquals(3, array.Count());
771
            Test.Assert(array.Append(42));
772
            Test.AssertEquals(4, array.Count());
773

774

775
            Test.AssertEquals((int)array[0], 0);
776
            Test.AssertEquals((int)array[1], 1);
777
            Test.AssertEquals((int)array[2], 5);
778
            Test.AssertEquals((int)array[3], 42);
779

780
            array[0] = 1984;
781
            array[1] = -42;
782
            Test.AssertEquals(4, array.Count());
783

784
            Test.AssertEquals((int)array[0], 1984);
785
            Test.AssertEquals((int)array[1], -42);
786
            Test.AssertEquals((int)array[2], 5);
787
            Test.AssertEquals((int)array[3], 42);
788

789
            Test.AssertEquals("[1984, -42, 5, 42]", array.ToString());
790
        }
791
    }
792

793
    public static void TestValueArrayOfInt64s()
794
    {
795
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int64)) {
796
            Test.AssertEquals(0, array.Count());
797
            Test.Assert(array.Append(0));
798
            Test.AssertEquals(1, array.Count());
799
            Test.Assert(array.Append(10000000000));
800
            Test.AssertEquals(2, array.Count());
801
            Test.Assert(array.Append(5));
802
            Test.AssertEquals(3, array.Count());
803
            Test.Assert(array.Append(42));
804
            Test.AssertEquals(4, array.Count());
805

806

807
            Test.AssertEquals((long)array[0], 0);
808
            Test.AssertEquals((long)array[1], 10000000000);
809
            Test.AssertEquals((long)array[2], 5);
810
            Test.AssertEquals((long)array[3], 42);
811

812
            array[0] = 1984;
813
            array[1] = -42;
814
            Test.AssertEquals(4, array.Count());
815

816
            Test.AssertEquals((long)array[0], 1984);
817
            Test.AssertEquals((long)array[1], -42);
818
            Test.AssertEquals((long)array[2], 5);
819
            Test.AssertEquals((long)array[3], 42);
820

821
            Test.AssertEquals("[1984, -42, 5, 42]", array.ToString());
822
        }
823
    }
824

825
    public static void TestValueArrayOfUInts()
826
    {
827

828
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.UInt32)) {
829
            Test.Assert(array.Append(2));
830
            Test.AssertEquals((uint)array[0], (uint)2);
831
            Test.AssertRaises<OverflowException>(() => array[0] = -1);
832
        }
833
    }
834

835
    public static void TestValueArrayOfStrings()
836
    {
837

838
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.String)) {
839

840
            Test.Assert(array.Append("hello"));
841
            Test.Assert(array.Append("world"));
842

843
            Test.AssertEquals((string)array[0], "hello");
844
            Test.AssertEquals((string)array[1], "world");
845

846
            array[0] = "efl";
847
            array[1] = "rocks";
848

849
            Test.AssertEquals((string)array[0], "efl");
850
            Test.AssertEquals((string)array[1], "rocks");
851
        }
852
    }
853

854
    public static void TestValueArrayOfObjects()
855
    {
856

857
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Object)) {
858

859
            var a = new Dummy.TestObject();
860
            var b = new Dummy.TestObject();
861

862
            Test.Assert(array.Append(a));
863
            Test.Assert(array.Append(b));
864

865
            Test.AssertEquals((Efl.Object)array[0], a);
866
            Test.AssertEquals((Efl.Object)array[1], b);
867

868
            var c = new Dummy.TestObject();
869
            array[0] = c;
870
            array[1] = b;
871

872
            Test.AssertEquals((Efl.Object)array[0], c);
873
            Test.AssertEquals((Efl.Object)array[1], b);
874
            c.Dispose();
875
            b.Dispose();
876
            a.Dispose();
877
        }
878
    }
879

880
    public static void TestInsertValueArrayOfSByte()
881
    {
882
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.SByte)) {
883
            Test.AssertEquals(0, array.Count());
884
            Test.Assert(!array.Insert(0, 3));
885
            Test.Assert(!array.Insert(0, 1));
886
            Test.Assert(!array.Insert(-123, 12));
887
            Test.AssertEquals(0, array.Count());
888

889
            Test.Assert(array.Insert(0, 0));
890
            Test.AssertEquals(1, array.Count());
891
            Test.Assert(array.Insert(6, 1));
892
            Test.AssertEquals(2, array.Count());
893
            Test.Assert(array.Insert(-122, 0));
894
            Test.AssertEquals(3, array.Count());
895
            Test.Assert(array.Insert(30, 1));
896
            Test.AssertEquals(4, array.Count());
897

898
            Test.AssertEquals((sbyte)array[0], (sbyte)-122);
899
            Test.AssertEquals((sbyte)array[1], (sbyte)30);
900
            Test.AssertEquals((sbyte)array[2], (sbyte)0);
901
            Test.AssertEquals((sbyte)array[3], (sbyte)6);
902

903
            array[0] = 120;
904
            array[1] = -42;
905
            Test.AssertEquals(4, array.Count());
906

907
            Test.AssertEquals((sbyte)array[0], (sbyte)120);
908
            Test.AssertEquals((sbyte)array[1], (sbyte)-42);
909
            Test.AssertEquals((sbyte)array[2], (sbyte)0);
910
            Test.AssertEquals((sbyte)array[3], (sbyte)6);
911

912
            Test.AssertEquals("[120, -42, 0, 6]", array.ToString());
913
        }
914
    }
915

916
    public static void TestInsertValueArrayOfByte()
917
    {
918
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Byte)) {
919
            Test.AssertEquals(0, array.Count());
920
            Test.Assert(!array.Insert(0, 3));
921
            Test.Assert(!array.Insert(0, 1));
922
            Test.Assert(!array.Insert(123, 12));
923
            Test.AssertEquals(0, array.Count());
924

925
            Test.Assert(array.Insert(0, 0));
926
            Test.AssertEquals(1, array.Count());
927
            Test.Assert(array.Insert(6, 1));
928
            Test.AssertEquals(2, array.Count());
929
            Test.Assert(array.Insert(122, 0));
930
            Test.AssertEquals(3, array.Count());
931
            Test.Assert(array.Insert(30, 1));
932
            Test.AssertEquals(4, array.Count());
933

934
            Test.AssertEquals((byte)array[0], (byte)122);
935
            Test.AssertEquals((byte)array[1], (byte)30);
936
            Test.AssertEquals((byte)array[2], (byte)0);
937
            Test.AssertEquals((byte)array[3], (byte)6);
938

939
            array[0] = 120;
940
            array[1] = 42;
941
            Test.AssertEquals(4, array.Count());
942

943
            Test.AssertEquals((byte)array[0], (byte)120);
944
            Test.AssertEquals((byte)array[1], (byte)42);
945
            Test.AssertEquals((byte)array[2], (byte)0);
946
            Test.AssertEquals((byte)array[3], (byte)6);
947

948
            Test.AssertEquals("[120, 42, 0, 6]", array.ToString());
949
        }
950
    }
951

952
    public static void TestInsertValueArrayOfInts()
953
    {
954
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32)) {
955
            Test.AssertEquals(0, array.Count());
956
            Test.Assert(!array.Insert(0, 3));
957
            Test.Assert(!array.Insert(0, 1));
958
            Test.Assert(!array.Insert(123, 12));
959
            Test.AssertEquals(0, array.Count());
960

961
            Test.Assert(array.Insert(0, 0));
962
            Test.AssertEquals(1, array.Count());
963
            Test.Assert(array.Insert(1, 1));
964
            Test.AssertEquals(2, array.Count());
965
            Test.Assert(array.Insert(5, 0));
966
            Test.AssertEquals(3, array.Count());
967
            Test.Assert(array.Insert(42, 1));
968
            Test.AssertEquals(4, array.Count());
969

970
            Test.AssertEquals((int)array[0], (int)5);
971
            Test.AssertEquals((int)array[1], (int)42);
972
            Test.AssertEquals((int)array[2], (int)0);
973
            Test.AssertEquals((int)array[3], (int)1);
974

975
            array[0] = 1984;
976
            array[1] = -42;
977
            Test.AssertEquals(4, array.Count());
978

979
            Test.AssertEquals((int)array[0], (int)1984);
980
            Test.AssertEquals((int)array[1], (int)-42);
981
            Test.AssertEquals((int)array[2], (int)0);
982
            Test.AssertEquals((int)array[3], (int)1);
983

984
            Test.AssertEquals("[1984, -42, 0, 1]", array.ToString());
985
        }
986
    }
987

988
    public static void TestInsertValueArrayOfInt64s()
989
    {
990
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int64)) {
991
            Test.AssertEquals(0, array.Count());
992
            Test.Assert(!array.Insert(0, 3));
993
            Test.Assert(!array.Insert(0, 1));
994
            Test.Assert(!array.Insert(123, 12));
995
            Test.AssertEquals(0, array.Count());
996

997
            Test.Assert(array.Insert(0,0));
998
            Test.AssertEquals(1, array.Count());
999
            Test.Assert(array.Insert(10000000000,1));
1000
            Test.AssertEquals(2, array.Count());
1001
            Test.Assert(array.Insert(5,0));
1002
            Test.AssertEquals(3, array.Count());
1003
            Test.Assert(array.Insert(42,1));
1004
            Test.AssertEquals(4, array.Count());
1005

1006
            Test.AssertEquals((long)array[0], (long)5);
1007
            Test.AssertEquals((long)array[1], (long)42);
1008
            Test.AssertEquals((long)array[2], (long)0);
1009
            Test.AssertEquals((long)array[3], (long)10000000000);
1010

1011
            array[0] = 1984;
1012
            array[1] = -42;
1013
            Test.AssertEquals(4, array.Count());
1014

1015
            Test.AssertEquals((long)array[0], (long)1984);
1016
            Test.AssertEquals((long)array[1], (long)-42);
1017
            Test.AssertEquals((long)array[2], (long)0);
1018
            Test.AssertEquals((long)array[3], (long)10000000000);
1019

1020
            Test.AssertEquals("[1984, -42, 0, 10000000000]", array.ToString());
1021
        }
1022
    }
1023

1024
    public static void TestInsertValueArrayOfUInts()
1025
    {
1026

1027
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.UInt32)) {
1028
            Test.AssertEquals(0, array.Count());
1029
            Test.Assert(!array.Insert(0, 3));
1030
            Test.Assert(!array.Insert(0, 1));
1031
            Test.Assert(!array.Insert(123, 12));
1032
            Test.AssertEquals(0, array.Count());
1033

1034
            Test.Assert(array.Insert(0,0));
1035
            Test.AssertEquals(1, array.Count());
1036
            Test.Assert(array.Insert(7,1));
1037
            Test.AssertEquals(2, array.Count());
1038
            Test.Assert(array.Insert(5,0));
1039
            Test.AssertEquals(3, array.Count());
1040
            Test.Assert(array.Insert(42,1));
1041
            Test.AssertEquals(4, array.Count());
1042

1043
            Test.AssertEquals((uint)array[0], (uint)5);
1044
            Test.AssertEquals((uint)array[1], (uint)42);
1045
            Test.AssertEquals((uint)array[2], (uint)0);
1046
            Test.AssertEquals((uint)array[3], (uint)7);
1047

1048
            array[0] = 1984;
1049
            array[1] = 100;
1050
            Test.AssertEquals(4, array.Count());
1051

1052
            Test.AssertEquals((uint)array[0], (uint)1984);
1053
            Test.AssertEquals((uint)array[1], (uint)100);
1054
            Test.AssertEquals((uint)array[2], (uint)0);
1055
            Test.AssertEquals((uint)array[3], (uint)7);
1056

1057
            Test.AssertEquals("[1984, 100, 0, 7]", array.ToString());
1058
        }
1059
    }
1060

1061
    public static void TestInsertValueArrayOfStrings()
1062
    {
1063

1064
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.String)) {
1065

1066
            Test.AssertEquals(0, array.Count());
1067
            Test.Assert(!array.Insert("hello",3));
1068
            Test.Assert(!array.Insert("world",12));
1069
            Test.AssertEquals(0, array.Count());
1070

1071
            Test.Assert(array.Insert("hello",0));
1072
            Test.Assert(array.Insert("world",1));
1073
            Test.Assert(array.Insert("first",0));
1074
            Test.Assert(array.Insert("sec",1));
1075

1076
            Test.AssertEquals((string)array[0], (string)"first");
1077
            Test.AssertEquals((string)array[1], (string)"sec");
1078
            Test.AssertEquals((string)array[2], (string)"hello");
1079
            Test.AssertEquals((string)array[3], (string)"world");
1080

1081
            array[0] = "efl";
1082
            array[1] = "rocks";
1083
            Test.AssertEquals(4, array.Count());
1084

1085
            Test.AssertEquals((string)array[0], (string)"efl");
1086
            Test.AssertEquals((string)array[1], (string)"rocks");
1087
            Test.AssertEquals((string)array[2], (string)"hello");
1088
            Test.AssertEquals((string)array[3], (string)"world");
1089
        }
1090
    }
1091

1092
    public static void TestInsertValueArrayOfObjects()
1093
    {
1094

1095
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Object)) {
1096

1097
            var a = new Dummy.TestObject();
1098
            var b = new Dummy.TestObject();
1099
            var c = new Dummy.TestObject();
1100
            var d = new Dummy.TestObject();
1101

1102
            Test.AssertEquals(0, array.Count());
1103
            Test.Assert(!array.Insert(a,12));
1104
            Test.Assert(!array.Insert(b,3));
1105
            Test.AssertEquals(0, array.Count());
1106

1107
            Test.Assert(array.Insert(a,0));
1108
            Test.Assert(array.Insert(b,1));
1109
            Test.Assert(array.Insert(c,0));
1110
            Test.Assert(array.Insert(d,1));
1111

1112
            Test.AssertEquals((Efl.Object)array[0], c);
1113
            Test.AssertEquals((Efl.Object)array[1], d);
1114
            Test.AssertEquals((Efl.Object)array[2], a);
1115
            Test.AssertEquals((Efl.Object)array[3], b);
1116

1117
            array[0] = a;
1118
            array[1] = b;
1119

1120
            Test.AssertEquals((Efl.Object)array[0], a);
1121
            Test.AssertEquals((Efl.Object)array[1], b);
1122
            Test.AssertEquals((Efl.Object)array[2], a);
1123
            Test.AssertEquals((Efl.Object)array[3], b);
1124

1125
            d.Dispose();
1126
            c.Dispose();
1127
            b.Dispose();
1128
            a.Dispose();
1129
        }
1130
    }
1131

1132
    public static void TestInsertValueListOfSByte()
1133
    {
1134
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.SByte)) {
1135
            Test.AssertEquals(0, list.Count());
1136
            Test.Assert(!list.Insert(0, 3));
1137
            Test.Assert(!list.Insert(0, 1));
1138
            Test.Assert(!list.Insert(-123, 12));
1139
            Test.AssertEquals(0, list.Count());
1140

1141
            Test.Assert(list.Insert(0, 0));
1142
            Test.AssertEquals(1, list.Count());
1143
            Test.Assert(list.Insert(6, 1));
1144
            Test.AssertEquals(2, list.Count());
1145
            Test.Assert(list.Insert(-122, 0));
1146
            Test.AssertEquals(3, list.Count());
1147
            Test.Assert(list.Insert(30, 1));
1148
            Test.AssertEquals(4, list.Count());
1149

1150
            Test.AssertEquals((sbyte)list[0], (sbyte)-122);
1151
            Test.AssertEquals((sbyte)list[1], (sbyte)30);
1152
            Test.AssertEquals((sbyte)list[2], (sbyte)0);
1153
            Test.AssertEquals((sbyte)list[3], (sbyte)6);
1154

1155
            list[0] = 120;
1156
            list[1] = -42;
1157
            Test.AssertEquals(4, list.Count());
1158

1159
            Test.AssertEquals((sbyte)list[0], (sbyte)120);
1160
            Test.AssertEquals((sbyte)list[1], (sbyte)-42);
1161
            Test.AssertEquals((sbyte)list[2], (sbyte)0);
1162
            Test.AssertEquals((sbyte)list[3], (sbyte)6);
1163

1164
            Test.AssertEquals("[120, -42, 0, 6]", list.ToString());
1165
        }
1166
    }
1167

1168
    public static void TestInsertValueListOfByte()
1169
    {
1170
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Byte)) {
1171
            Test.AssertEquals(0, list.Count());
1172
            Test.Assert(!list.Insert(0, 3));
1173
            Test.Assert(!list.Insert(0, 1));
1174
            Test.Assert(!list.Insert(123, 12));
1175
            Test.AssertEquals(0, list.Count());
1176

1177
            Test.Assert(list.Insert(0, 0));
1178
            Test.AssertEquals(1, list.Count());
1179
            Test.Assert(list.Insert(6, 1));
1180
            Test.AssertEquals(2, list.Count());
1181
            Test.Assert(list.Insert(122, 0));
1182
            Test.AssertEquals(3, list.Count());
1183
            Test.Assert(list.Insert(30, 1));
1184
            Test.AssertEquals(4, list.Count());
1185

1186
            Test.AssertEquals((byte)list[0], (byte)122);
1187
            Test.AssertEquals((byte)list[1], (byte)30);
1188
            Test.AssertEquals((byte)list[2], (byte)0);
1189
            Test.AssertEquals((byte)list[3], (byte)6);
1190

1191
            list[0] = 120;
1192
            list[1] = 42;
1193
            Test.AssertEquals(4, list.Count());
1194

1195
            Test.AssertEquals((byte)list[0], (byte)120);
1196
            Test.AssertEquals((byte)list[1], (byte)42);
1197
            Test.AssertEquals((byte)list[2], (byte)0);
1198
            Test.AssertEquals((byte)list[3], (byte)6);
1199

1200
            Test.AssertEquals("[120, 42, 0, 6]", list.ToString());
1201
        }
1202
    }
1203

1204
    public static void TestInsertValueListOfInts()
1205
    {
1206
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32)) {
1207
            Test.AssertEquals(0, list.Count());
1208
            Test.Assert(!list.Insert(0, 3));
1209
            Test.Assert(!list.Insert(0, 1));
1210
            Test.Assert(!list.Insert(123, 12));
1211
            Test.AssertEquals(0, list.Count());
1212

1213
            Test.Assert(list.Insert(0, 0));
1214
            Test.AssertEquals(1, list.Count());
1215
            Test.Assert(list.Insert(1, 1));
1216
            Test.AssertEquals(2, list.Count());
1217
            Test.Assert(list.Insert(5, 0));
1218
            Test.AssertEquals(3, list.Count());
1219
            Test.Assert(list.Insert(42, 1));
1220
            Test.AssertEquals(4, list.Count());
1221

1222
            Test.AssertEquals((int)list[0], (int)5);
1223
            Test.AssertEquals((int)list[1], (int)42);
1224
            Test.AssertEquals((int)list[2], (int)0);
1225
            Test.AssertEquals((int)list[3], (int)1);
1226

1227
            list[0] = 1984;
1228
            list[1] = -42;
1229
            Test.AssertEquals(4, list.Count());
1230

1231
            Test.AssertEquals((int)list[0], (int)1984);
1232
            Test.AssertEquals((int)list[1], (int)-42);
1233
            Test.AssertEquals((int)list[2], (int)0);
1234
            Test.AssertEquals((int)list[3], (int)1);
1235

1236
            Test.AssertEquals("[1984, -42, 0, 1]", list.ToString());
1237
        }
1238
    }
1239

1240
    public static void TestInsertValueListOfInt64s()
1241
    {
1242
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int64)) {
1243
            Test.AssertEquals(0, list.Count());
1244
            Test.Assert(!list.Insert(0, 3));
1245
            Test.Assert(!list.Insert(0, 1));
1246
            Test.Assert(!list.Insert(123, 12));
1247
            Test.AssertEquals(0, list.Count());
1248

1249
            Test.Assert(list.Insert(0,0));
1250
            Test.AssertEquals(1, list.Count());
1251
            Test.Assert(list.Insert(10000000000,1));
1252
            Test.AssertEquals(2, list.Count());
1253
            Test.Assert(list.Insert(5,0));
1254
            Test.AssertEquals(3, list.Count());
1255
            Test.Assert(list.Insert(42,1));
1256
            Test.AssertEquals(4, list.Count());
1257

1258
            Test.AssertEquals((long)list[0], (long)5);
1259
            Test.AssertEquals((long)list[1], (long)42);
1260
            Test.AssertEquals((long)list[2], (long)0);
1261
            Test.AssertEquals((long)list[3], (long)10000000000);
1262

1263
            list[0] = 1984;
1264
            list[1] = -42;
1265
            Test.AssertEquals(4, list.Count());
1266

1267
            Test.AssertEquals((long)list[0], (long)1984);
1268
            Test.AssertEquals((long)list[1], (long)-42);
1269
            Test.AssertEquals((long)list[2], (long)0);
1270
            Test.AssertEquals((long)list[3], (long)10000000000);
1271

1272
            Test.AssertEquals("[1984, -42, 0, 10000000000]", list.ToString());
1273
        }
1274
    }
1275

1276
    public static void TestInsertValueListOfUInts()
1277
    {
1278

1279
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.UInt32)) {
1280
            Test.AssertEquals(0, list.Count());
1281
            Test.Assert(!list.Insert(0, 3));
1282
            Test.Assert(!list.Insert(0, 1));
1283
            Test.Assert(!list.Insert(123, 12));
1284
            Test.AssertEquals(0, list.Count());
1285

1286
            Test.Assert(list.Insert(0,0));
1287
            Test.AssertEquals(1, list.Count());
1288
            Test.Assert(list.Insert(7,1));
1289
            Test.AssertEquals(2, list.Count());
1290
            Test.Assert(list.Insert(5,0));
1291
            Test.AssertEquals(3, list.Count());
1292
            Test.Assert(list.Insert(42,1));
1293
            Test.AssertEquals(4, list.Count());
1294

1295
            Test.AssertEquals((uint)list[0], (uint)5);
1296
            Test.AssertEquals((uint)list[1], (uint)42);
1297
            Test.AssertEquals((uint)list[2], (uint)0);
1298
            Test.AssertEquals((uint)list[3], (uint)7);
1299

1300
            list[0] = 1984;
1301
            list[1] = 100;
1302
            Test.AssertEquals(4, list.Count());
1303

1304
            Test.AssertEquals((uint)list[0], (uint)1984);
1305
            Test.AssertEquals((uint)list[1], (uint)100);
1306
            Test.AssertEquals((uint)list[2], (uint)0);
1307
            Test.AssertEquals((uint)list[3], (uint)7);
1308

1309
            Test.AssertEquals("[1984, 100, 0, 7]", list.ToString());
1310
        }
1311
    }
1312

1313
    public static void TestInsertValueListOfStrings()
1314
    {
1315

1316
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.String)) {
1317

1318
            Test.AssertEquals(0, list.Count());
1319
            Test.Assert(!list.Insert("Nice",2));
1320
            Test.Assert(!list.Insert("efl",5));
1321
            Test.AssertEquals(0, list.Count());
1322

1323
            Test.Assert(list.Insert("hello",0));
1324
            Test.Assert(list.Insert("world",1));
1325
            Test.Assert(list.Insert("first",0));
1326
            Test.Assert(list.Insert("sec",1));
1327

1328
            Test.AssertEquals((string)list[0], (string)"first");
1329
            Test.AssertEquals((string)list[1], (string)"sec");
1330
            Test.AssertEquals((string)list[2], (string)"hello");
1331
            Test.AssertEquals((string)list[3], (string)"world");
1332

1333
            list[0] = "efl";
1334
            list[1] = "rocks";
1335
            Test.AssertEquals(4, list.Count());
1336

1337
            Test.AssertEquals((string)list[0], (string)"efl");
1338
            Test.AssertEquals((string)list[1], (string)"rocks");
1339
            Test.AssertEquals((string)list[2], (string)"hello");
1340
            Test.AssertEquals((string)list[3], (string)"world");
1341
        }
1342
    }
1343

1344
    public static void TestInsertValueListOfObjects()
1345
    {
1346

1347
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Object)) {
1348

1349
            var a = new Dummy.TestObject();
1350
            var b = new Dummy.TestObject();
1351
            var c = new Dummy.TestObject();
1352
            var d = new Dummy.TestObject();
1353

1354
            Test.AssertEquals(0, list.Count());
1355
            Test.Assert(!list.Insert(a,6));
1356
            Test.Assert(!list.Insert(b,1));
1357
            Test.Assert(!list.Insert(c,7));
1358
            Test.AssertEquals(0, list.Count());
1359

1360
            Test.Assert(list.Insert(a,0));
1361
            Test.Assert(list.Insert(b,1));
1362
            Test.Assert(list.Insert(c,0));
1363
            Test.Assert(list.Insert(d,1));
1364

1365
            Test.AssertEquals((Efl.Object)list[0], c);
1366
            Test.AssertEquals((Efl.Object)list[1], d);
1367
            Test.AssertEquals((Efl.Object)list[2], a);
1368
            Test.AssertEquals((Efl.Object)list[3], b);
1369

1370
            list[0] = a;
1371
            list[1] = b;
1372

1373
            Test.AssertEquals((Efl.Object)list[0], a);
1374
            Test.AssertEquals((Efl.Object)list[1], b);
1375
            Test.AssertEquals((Efl.Object)list[2], a);
1376
            Test.AssertEquals((Efl.Object)list[3], b);
1377

1378
            d.Dispose();
1379
            c.Dispose();
1380
            b.Dispose();
1381
            a.Dispose();
1382
        }
1383
    }
1384

1385
    public static void TestArrayOutOfBounds() {
1386
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32)) {
1387
            object placeholder = null;
1388
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => array[0] = 1);
1389
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[0]);
1390
            Test.Assert(array.Append(0));
1391
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => array[0] = 1);
1392
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[0]);
1393
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => array[1] = 1);
1394
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[1]);
1395
            Test.Assert(array.Append(0));
1396
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => array[1] = 1);
1397
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = array[1]);
1398
        }
1399
    }
1400

1401
    public static void TestValueArraySubType() {
1402
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32))
1403
            Test.AssertEquals(Eina.ValueType.Int32, array.GetValueSubType());
1404

1405
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.UInt32))
1406
            Test.AssertEquals(Eina.ValueType.UInt32, array.GetValueSubType());
1407
    }
1408

1409
    public static void TestValueArrayConvert() {
1410
        using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32))
1411
        using (Eina.Value other = new Eina.Value(Eina.ValueType.Int32)) {
1412
            other.Set(100);
1413
            other.ConvertTo(array);
1414
            Test.AssertEquals(100, (int)array[0]);
1415
            Test.AssertEquals("[100]", array.ToString());
1416
        }
1417
    }
1418

1419
    public static void TestValueList() {
1420
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32)) {
1421
            Test.AssertEquals(0, list.Count());
1422
            Test.Assert(list.Append(0));
1423
            Test.AssertEquals(1, list.Count());
1424
            Test.Assert(list.Append(1));
1425
            Test.AssertEquals(2, list.Count());
1426
            Test.Assert(list.Append(5));
1427
            Test.AssertEquals(3, list.Count());
1428
            Test.Assert(list.Append(42));
1429
            Test.AssertEquals(4, list.Count());
1430

1431

1432
            Test.AssertEquals((int)list[0], 0);
1433
            Test.AssertEquals((int)list[1], 1);
1434
            Test.AssertEquals((int)list[2], 5);
1435
            Test.AssertEquals((int)list[3], 42);
1436

1437
            list[0] = 1984;
1438
            list[1] = -42;
1439
            Test.AssertEquals(4, list.Count());
1440

1441
            Test.AssertEquals((int)list[0], 1984);
1442
            Test.AssertEquals((int)list[1], -42);
1443
            Test.AssertEquals((int)list[2], 5);
1444
            Test.AssertEquals((int)list[3], 42);
1445

1446
            Test.AssertEquals("[1984, -42, 5, 42]", list.ToString());
1447
        }
1448

1449
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.UInt32)) {
1450
            Test.Assert(list.Append(2));
1451
            Test.AssertEquals((uint)list[0], (uint)2);
1452
            Test.AssertRaises<OverflowException>(() => list[0] = -1);
1453
        }
1454

1455
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.String)) {
1456

1457
            Test.Assert(list.Append("hello"));
1458
            Test.Assert(list.Append("world"));
1459

1460
            Test.AssertEquals((string)list[0], "hello");
1461
            Test.AssertEquals((string)list[1], "world");
1462

1463
            list[0] = "efl";
1464
            list[1] = "rocks";
1465

1466
            Test.AssertEquals((string)list[0], "efl");
1467
            Test.AssertEquals((string)list[1], "rocks");
1468
        }
1469
    }
1470

1471
    public static void TestListOutOfBounds() {
1472
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32)) {
1473
            object placeholder = null;
1474
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => list[0] = 1);
1475
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[0]);
1476
            Test.Assert(list.Append(0));
1477
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => list[0] = 1);
1478
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[0]);
1479
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => list[1] = 1);
1480
            Test.AssertRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[1]);
1481
            Test.Assert(list.Append(0));
1482
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => list[1] = 1);
1483
            Test.AssertNotRaises<System.ArgumentOutOfRangeException>(() => placeholder = list[1]);
1484
        }
1485
    }
1486

1487
    public static void TestValueListSubType() {
1488
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32))
1489
            Test.AssertEquals(Eina.ValueType.Int32, list.GetValueSubType());
1490

1491
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.UInt32))
1492
            Test.AssertEquals(Eina.ValueType.UInt32, list.GetValueSubType());
1493
    }
1494

1495
    public static void TestValueListConvert() {
1496
        using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Int32))
1497
        using (Eina.Value other = new Eina.Value(Eina.ValueType.Int32)) {
1498
            other.Set(100);
1499
            other.ConvertTo(list);
1500
            Test.AssertEquals(100, (int)list[0]);
1501
            Test.AssertEquals("[100]", list.ToString());
1502
        }
1503
    }
1504

1505
    public static void TestStringThroughValue() {
1506
        // Check if Value_Native->Value doesn't try to free the pointed string.
1507
        using (Eina.Value value_ptr = new Eina.Value(Eina.ValueType.String)) {
1508
            string payload = "Something";
1509
            value_ptr.Set(payload);
1510
            Eina.ValueNative byvalue = value_ptr;
1511
            Eina.Value another_value_ptr = byvalue;
1512
            Test.AssertEquals(value_ptr, another_value_ptr);
1513
        }
1514
    }
1515

1516
    public static void TestValueEmpty() {
1517
        using (Eina.Value empty = new Eina.Value(Eina.ValueType.Empty)) {
1518
            Test.Assert(empty.Empty, "Value must be empty");
1519

1520
            empty.Setup(Eina.ValueType.Int32);
1521

1522
            // Values already set-up are not empty. For this kind of empty, use Optional
1523
            Test.Assert(!empty.Empty, "Values already set-up must not be empty.");
1524

1525
            empty.Set(42);
1526
            Test.Assert(!empty.Empty, "Values with payload must not be empty.");
1527
        }
1528
    }
1529

1530
    public static void TestValueCopy() {
1531
        Eina.Value v2 = null;
1532
        int raw_val = 42;
1533

1534
        using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
1535
            Test.Assert(v.Set(raw_val));
1536

1537
            v2 = new Eina.Value(v);
1538
        }
1539

1540
        int rec_val;
1541
        Test.Assert(v2.Get(out rec_val));
1542
        Test.AssertEquals(raw_val, rec_val);
1543
        v2.Dispose();
1544
    }
1545

1546
    // FIXME Add remaining list tests
1547

1548
    /* public static void TestValueHash() { */
1549
    /*     Test.Assert(false, "Implement me."); */
1550
    /* } */
1551

1552
    /* public static void TestValueTimeVal() { */
1553
    /*     Test.Assert(false, "Implement me."); */
1554
    /* } */
1555

1556
    /* public static void TestValueBlob() { */
1557
    /*     Test.Assert(false, "Implement me."); */
1558
    /* } */
1559

1560
    /* public static void TestValueStruct() { */
1561
    /*     Test.Assert(false, "Implement me."); */
1562
    /* } */
1563

1564
    /* public static void TestValueArrayOfStructs() { */
1565
    /*     Test.Assert(false, "Implement me."); */
1566
    /* } */
1567

1568
    /* public static void TestValueOptionalStructMembers() { */
1569
    /*     Test.Assert(false, "Implement me."); */
1570
    /* } */
1571
}
1572

1573
public static class TestValueFromObject
1574
{
1575

1576
    private class Holder
1577
    {
1578
        public int Number { get; set; }
1579
        public double Factor { get; set; }
1580
        public string Name { get; set; }
1581
        public Efl.Object Obj { get; set; }
1582
    }
1583

1584
    public static void TestConversionFromToObject()
1585
    {
1586
        var source = new Holder {
1587
            Number = 1984,
1588
            Factor = 3.14,
1589
            Name = "Orwell",
1590
            Obj = new Dummy.TestObject(),
1591
        };
1592

1593
        {
1594
            var prop = source.GetType().GetProperty("Name");
1595
            var v = new Eina.Value(prop.GetValue(source));
1596

1597
            Test.AssertEquals(v.GetValueType(), Eina.ValueType.String);
1598
            Test.AssertEquals((string)v, prop.GetValue(source));
1599

1600
            Test.Assert(v.Set("New value"));
1601
            prop.SetValue(source, v.Unwrap());
1602
            Test.AssertEquals(prop.GetValue(source), "New value");
1603
        }
1604

1605
        {
1606
            var prop = source.GetType().GetProperty("Factor");
1607
            var v = new Eina.Value(prop.GetValue(source));
1608

1609
            Test.AssertEquals(v.GetValueType(), Eina.ValueType.Double);
1610
            Test.AssertAlmostEquals((double)v, (double)prop.GetValue(source));
1611

1612
            Test.Assert(v.Set(2.78));
1613
            prop.SetValue(source, v.Unwrap());
1614
            Test.AssertEquals(prop.GetValue(source), 2.78);
1615
        }
1616

1617
        {
1618
            var prop = source.GetType().GetProperty("Number");
1619
            var v = new Eina.Value(prop.GetValue(source));
1620

1621
            Test.AssertEquals(v.GetValueType(), Eina.ValueType.Int32);
1622
            Test.AssertEquals((int)v, prop.GetValue(source));
1623

1624
            Test.Assert(v.Set(2012));
1625
            prop.SetValue(source, v.Unwrap());
1626
            Test.AssertEquals(prop.GetValue(source), 2012);
1627
        }
1628

1629
        {
1630
            var prop = source.GetType().GetProperty("Obj");
1631
            var v = new Eina.Value(prop.GetValue(source));
1632

1633
            Test.AssertEquals(v.GetValueType(), Eina.ValueType.Object);
1634
            Test.AssertEquals((Efl.Object)v, prop.GetValue(source));
1635

1636
            var newObj = new Dummy.TestObject();
1637
            Test.Assert(v.Set(newObj));
1638
            prop.SetValue(source, v.Unwrap());
1639
            Test.AssertEquals(prop.GetValue(source), newObj);
1640
            newObj.Dispose();
1641
        }
1642
    }
1643

1644
    private class ComplexHolder
1645
    {
1646
        public IEnumerable<int> Bag { get; set; }
1647
        public IEnumerable<Efl.Object> BagOfObjects { get; set; }
1648
    }
1649

1650
    public static void TestContainerFromToObject()
1651
    {
1652
        var initialBag = new Eina.Array<int>();
1653
        initialBag.Push(2);
1654
        initialBag.Push(4);
1655
        initialBag.Push(6);
1656

1657
        var source = new ComplexHolder { Bag = initialBag };
1658
        var prop = source.GetType().GetProperty("Bag");
1659
        var v = new Eina.Value(prop.GetValue(source));
1660
        Test.AssertEquals(prop.GetValue(source), initialBag);
1661

1662
        Test.AssertEquals(v.GetValueType(), Eina.ValueType.Array);
1663
        Test.AssertEquals(v.GetValueSubType(), Eina.ValueType.Int32);
1664

1665
        Test.AssertEquals(v[0], initialBag[0]);
1666
        Test.AssertEquals(v[1], initialBag[1]);
1667
        Test.AssertEquals(v[2], initialBag[2]);
1668

1669
        v[0] = 100;
1670
        v[1] = 200;
1671
        v[2] = 300;
1672

1673
        prop.SetValue(source, v.Unwrap());
1674

1675
        IEnumerable<int> newVal = prop.GetValue(source) as IEnumerable<int>;
1676
        var toCheck = newVal.ToList();
1677

1678
        Test.AssertEquals(toCheck[0], 100);
1679
        Test.AssertEquals(toCheck[1], 200);
1680
        Test.AssertEquals(toCheck[2], 300);
1681
        v.Dispose();
1682
    }
1683

1684
    public static void TestObjectContainerFromToObject()
1685
    {
1686
        var initialBag = new Eina.Array<Efl.Object>();
1687
        var tmp1 = new Dummy.TestObject();
1688
        var tmp2 = new Dummy.TestObject();
1689
        var tmp3 = new Dummy.TestObject();
1690
        initialBag.Push(tmp1);
1691
        initialBag.Push(tmp2);
1692
        initialBag.Push(tmp3);
1693

1694
        var source = new ComplexHolder { BagOfObjects = initialBag };
1695
        var prop = source.GetType().GetProperty("BagOfObjects");
1696
        var v = new Eina.Value(prop.GetValue(source));
1697
        Test.AssertEquals(prop.GetValue(source), initialBag);
1698

1699
        Test.AssertEquals(v.GetValueType(), Eina.ValueType.Array);
1700
        Test.AssertEquals(v.GetValueSubType(), Eina.ValueType.Object);
1701

1702
        Test.AssertEquals(v[0], initialBag[0]);
1703
        Test.AssertEquals(v[1], initialBag[1]);
1704
        Test.AssertEquals(v[2], initialBag[2]);
1705

1706
        var first = new Dummy.TestObject();
1707
        var second = new Dummy.TestObject();
1708
        var third = new Dummy.TestObject();
1709
        v[0] = first;
1710
        v[1] = second;
1711
        v[2] = third;
1712

1713
        prop.SetValue(source, v.Unwrap());
1714

1715
        IEnumerable<Efl.Object> newVal = prop.GetValue(source) as IEnumerable<Efl.Object>;
1716
        var toCheck = newVal.ToList();
1717

1718
        Test.AssertEquals(toCheck[0], first);
1719
        Test.AssertEquals(toCheck[1], second);
1720
        Test.AssertEquals(toCheck[2], third);
1721
        tmp3.Dispose();
1722
        tmp2.Dispose();
1723
        tmp1.Dispose();
1724
        v.Dispose();
1725
    }
1726
}
1727
#pragma warning restore 1591
1728
}
1729

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.