18
#pragma warning disable 1591
22
using System.Diagnostics.CodeAnalysis;
23
using System.Collections.Generic;
28
[SuppressMessage("Gendarme.Rules.Portability", "DoNotHardcodePathsRule")]
29
public static class TestEinaValue {
31
public static void TestByteSimple()
33
using (Eina.Value v = new Eina.Value(Eina.ValueType.Byte)) {
35
Test.Assert(v.Set(val));
37
Test.Assert(v.Get(out x));
38
Test.AssertEquals(val, x);
42
public static void TestSByteSimple()
44
using (Eina.Value v = new Eina.Value(Eina.ValueType.SByte)) {
46
Test.Assert(v.Set(val));
48
Test.Assert(v.Get(out x));
49
Test.AssertEquals(val, x);
53
public static void TestShortSimple()
55
using (Eina.Value v = new Eina.Value(Eina.ValueType.Short)) {
57
Test.Assert(v.Set(val));
59
Test.Assert(v.Get(out x));
60
Test.AssertEquals(val, x);
64
public static void TestUShortSimple()
66
using (Eina.Value v = new Eina.Value(Eina.ValueType.UShort)) {
68
Test.Assert(v.Set(val));
70
Test.Assert(v.Get(out x));
71
Test.AssertEquals(val, x);
75
public static void TestLongSimple()
77
using (Eina.Value v = new Eina.Value(Eina.ValueType.Long)) {
78
long val = 0xdeadbeef;
79
Test.Assert(v.Set(val));
81
Test.Assert(v.Get(out x));
82
Test.AssertEquals(val, x);
86
public static void TestULongSimple()
88
using (Eina.Value v = new Eina.Value(Eina.ValueType.ULong)) {
89
ulong val = 0xdeadbeef;
90
Test.Assert(v.Set(val));
92
Test.Assert(v.Get(out x));
93
Test.AssertEquals(val, x);
97
public static void TestFloatSimple()
99
using (Eina.Value v = new Eina.Value(Eina.ValueType.Float)) {
100
float val = 1.609344f;
101
Test.Assert(v.Set(val));
103
Test.Assert(v.Get(out x));
104
Test.AssertAlmostEquals(val, x);
108
public static void TestDoubleSimple()
110
using (Eina.Value v = new Eina.Value(Eina.ValueType.Double)) {
111
double val = 1.609344;
112
Test.Assert(v.Set(val));
114
Test.Assert(v.Get(out x));
115
Test.AssertAlmostEquals(val, x);
120
public static void TestIntSimple()
122
using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
123
Test.Assert(v.Set(32));
125
Test.Assert(v.Get(out x));
126
Test.AssertEquals(32, x);
128
Test.Assert(v.Set(-45));
129
Test.Assert(v.Get(out x));
130
Test.AssertEquals(-45, x);
134
public static void TestUIntSimple()
136
using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
137
Test.Assert(v.Set(0xdeadbeef));
139
Test.Assert(v.Get(out x));
140
Test.AssertEquals(0xdeadbeef, x);
144
public static void TestStringSimple()
146
using (Eina.Value v = new Eina.Value(Eina.ValueType.String)) {
147
string expected_str = "Hello";
148
Test.Assert(v.Set(expected_str));
150
Test.Assert(v.Get(out str));
151
Test.AssertEquals(expected_str, str);
155
public static void TestErrorSimple()
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));
161
Test.Assert(v.Get(out x));
162
Test.AssertEquals(error, x);
166
public static void TestObjectSimple()
168
using (Eina.Value v = new Eina.Value(Eina.ValueType.Object))
170
var obj = new Dummy.TestObject();
171
Test.Assert(v.Set(obj));
173
Test.Assert(v.Get(out target));
174
Test.AssertEquals(target, obj);
183
public static void TestObjectImplicit()
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;
190
Test.AssertEquals(target, obj);
193
public static void TestSetWrongType()
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));
204
public static void TestValueSetup()
206
using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
207
Test.Assert(v.Set(44));
209
Test.Assert(v.Get(out x));
210
Test.AssertEquals(44, x);
211
v.Setup(Eina.ValueType.String);
213
string str = "Hello";
214
Test.Assert(v.Get(out str));
215
Test.AssertNull(str);
219
public static void TestValueDispose()
221
Eina.Value v = new Eina.Value(Eina.ValueType.Int32);
223
Test.AssertRaises<ObjectDisposedException>(() => v.ToString());
224
Test.AssertRaises<ObjectDisposedException>(() => v.Set(24));
227
private delegate bool BoolRet();
228
public static void TestValueOptionalInt()
230
using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
231
Test.Assert(a.Optional);
232
Test.Assert(a.OptionalEmpty);
236
Test.Assert(a.Set(expected));
237
Test.Assert(a.Optional);
238
Test.Assert(!a.OptionalEmpty);
240
Test.Assert(a.Reset());
241
Test.Assert(a.OptionalEmpty);
244
Test.Assert(a.Set(expected));
245
Test.Assert(!a.OptionalEmpty);
248
Test.Assert(a.Get(out actual));
249
Test.AssertEquals(expected, actual);
252
public static void TestValueOptionalUint()
254
using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
255
Test.Assert(a.Optional);
256
Test.Assert(a.OptionalEmpty);
259
uint expected = 1984;
260
Test.Assert(a.Set(expected));
261
Test.Assert(a.Optional);
262
Test.Assert(!a.OptionalEmpty);
264
Test.Assert(a.Reset());
265
Test.Assert(a.OptionalEmpty);
267
expected = 0xdeadbeef;
268
Test.Assert(a.Set(expected));
269
Test.Assert(!a.OptionalEmpty);
272
Test.Assert(a.Get(out actual));
273
Test.AssertEquals(expected, actual);
276
public static void TestValueOptionalString()
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());
284
using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
285
Test.Assert(a.Optional);
286
Test.Assert(a.OptionalEmpty);
289
string expected = "Hello, world!";
290
Test.Assert(a.Set(expected));
291
Test.Assert(a.Optional);
292
Test.Assert(!a.OptionalEmpty);
294
Test.Assert(a.Reset());
295
Test.Assert(a.OptionalEmpty);
297
expected = "!dlrow olleH";
298
Test.Assert(a.Set(expected));
299
Test.Assert(!a.OptionalEmpty);
301
string actual = String.Empty;
302
Test.Assert(a.Get(out actual));
303
Test.AssertEquals(expected, actual);
307
public static void TestValueOptionalObject()
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());
315
using (Eina.Value a = new Eina.Value(Eina.ValueType.Optional)) {
316
Test.Assert(a.Optional);
317
Test.Assert(a.OptionalEmpty);
320
Efl.Object expected = new Dummy.TestObject();
321
Test.Assert(a.Set(expected));
322
Test.Assert(a.Optional);
323
Test.Assert(!a.OptionalEmpty);
325
Test.Assert(a.Reset());
326
Test.Assert(a.OptionalEmpty);
328
Test.Assert(a.Set(expected));
329
Test.Assert(!a.OptionalEmpty);
331
Efl.Object received = null;
332
Test.Assert(a.Get(out received));
333
Test.AssertEquals(expected, received);
339
public static void TestValueOptionalArrays()
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))
346
Test.Assert(a.Optional);
347
Test.Assert(a.OptionalEmpty);
350
Test.Assert(expected.Append(-1));
351
Test.Assert(expected.Append(0));
352
Test.Assert(expected.Append(2));
354
Test.Assert(a.Set(expected));
355
Test.Assert(a.Optional);
356
Test.Assert(!a.OptionalEmpty);
358
Test.Assert(a.Reset());
359
Test.Assert(a.OptionalEmpty);
361
expected.Append(-42);
362
Test.Assert(a.Set(expected));
363
Test.Assert(!a.OptionalEmpty);
365
Eina.Value actual = null;
366
Test.Assert(a.Get(out actual));
367
Test.AssertEquals(expected, actual);
369
Test.Assert(a.Reset());
370
Test.Assert(a.Set(expected));
374
public static void TestValueOptionalLists()
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))
381
Test.Assert(a.Optional);
382
Test.Assert(a.OptionalEmpty);
385
Test.Assert(expected.Append(-1));
386
Test.Assert(expected.Append(0));
387
Test.Assert(expected.Append(2));
389
Test.Assert(a.Set(expected));
390
Test.Assert(a.Optional);
391
Test.Assert(!a.OptionalEmpty);
393
Test.Assert(a.Reset());
394
Test.Assert(a.OptionalEmpty);
396
expected.Append(-42);
397
Test.Assert(a.Set(expected));
398
Test.Assert(!a.OptionalEmpty);
400
Eina.Value actual = null;
401
Test.Assert(a.Get(out actual));
402
Test.AssertEquals(expected, actual);
407
public static void TestValueCompareInts()
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));
415
Test.Assert(a.Set(-10));
416
Test.AssertLessThan(a, b);
418
Test.Assert(a.Set(123));
419
Test.Assert(b.Set(10));
420
Test.AssertGreaterThan(a, b);
424
public static void TestValueComparisonEquals()
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));
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));
437
Test.Assert(b.Set(0));
438
Test.Assert(a.Equals(b) == b.Equals(a), "A equals B == B equals A");
440
Test.Assert(a.Equals(null) == false, "A == null");
444
public static void TestValueComparisonOverloadEquals()
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));
452
Test.Assert(!(a != b));
454
Test.Assert(!(b != a));
456
Test.Assert(b.Set(42));
459
Test.Assert(!(a == b));
461
Test.Assert(!(b == a));
463
Test.Assert(b.Set(42));
468
public static void TestValueComparisonOverloadLessGreater()
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));
476
Test.Assert(!(a <= b));
477
Test.Assert(!(a < b));
480
Test.Assert(!(b >= a));
481
Test.Assert(!(b > a));
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);
491
public static void TestValueCompareStrings()
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));
499
Test.Assert(a.Set("abc"));
500
Test.Assert(b.Set("acd"));
501
Test.AssertLessThan(a, b);
503
Test.Assert(a.Set("acd"));
504
Test.Assert(b.Set("abc"));
505
Test.AssertGreaterThan(a, b);
509
public static void TestValueCompareArray()
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)) {
514
Test.AssertEquals(a, b);
516
Test.Assert(a.Append(0));
517
Test.Assert(a.Append(1));
518
Test.Assert(a.Append(5));
519
Test.Assert(a.Append(42));
521
Test.Assert(b.Append(0));
522
Test.Assert(b.Append(1));
523
Test.Assert(b.Append(5));
524
Test.Assert(b.Append(42));
526
Test.AssertEquals(a, b);
529
Test.Assert(!a.Equals(b));
530
Test.AssertLessThan(a, b);
533
Test.AssertGreaterThan(a, b);
536
Test.AssertEquals(a, b);
539
Test.Assert(b.Append(0));
540
Test.AssertLessThan(a, b);
542
Test.Assert(a.Append(0));
543
Test.Assert(a.Append(0));
544
Test.AssertGreaterThan(a, b);
548
Test.AssertGreaterThan(b, a);
552
public static void TestValueCompareList()
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)) {
557
Test.AssertEquals(a, b);
559
Test.Assert(a.Append(0));
560
Test.Assert(a.Append(1));
561
Test.Assert(a.Append(5));
562
Test.Assert(a.Append(42));
564
Test.Assert(b.Append(0));
565
Test.Assert(b.Append(1));
566
Test.Assert(b.Append(5));
567
Test.Assert(b.Append(42));
569
Test.AssertEquals(a, b);
572
Test.Assert(!a.Equals(b));
573
Test.AssertLessThan(a, b);
576
Test.AssertGreaterThan(a, b);
579
Test.AssertEquals(a, b);
582
Test.Assert(b.Append(0));
583
Test.AssertLessThan(a, b);
585
Test.Assert(a.Append(0));
586
Test.Assert(a.Append(0));
587
Test.AssertGreaterThan(a, b);
591
Test.AssertGreaterThan(b, a);
600
public static void TestValueToString()
602
using (Eina.Value a = new Eina.Value(Eina.ValueType.Int32)) {
605
Test.Assert(a.Set(i));
606
Test.AssertEquals(x, a.ToString());
610
Test.Assert(a.Setup(Eina.ValueType.UInt32));
611
Test.Assert(a.Set(u));
612
Test.AssertEquals(x, a.ToString());
614
string s = "Hello, Johnny!";
616
Test.Assert(a.Setup(Eina.ValueType.String));
617
Test.Assert(a.Set(s));
618
Test.AssertEquals(x, a.ToString());
622
public static void TestValueConvertInt()
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;
630
string source_str = $"{source}";
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);
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);
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);
652
public static void TestValueConvertUInt()
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;
659
string source_str = $"{source}";
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);
666
Test.Assert(to.Setup(Eina.ValueType.Int32));
667
Test.Assert(!from.ConvertTo(to));
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);
679
public static void TestValueContainerConstructorWrongArgs()
681
Test.AssertRaises<ArgumentException>(() => {
682
using (Eina.Value array = new Eina.Value(Eina.ValueType.String, Eina.ValueType.String)) { }
686
public static void TestValueContainerWithNonContainerAccess()
688
using (Eina.Value array = new Eina.Value(Eina.ValueType.Int32)) {
689
Test.AssertRaises<Eina.InvalidValueTypeException>(() => array[0] = 1);
691
Test.AssertRaises<Eina.InvalidValueTypeException>(() => val = array[0]);
695
public static void TestValueArrayOfSByte()
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());
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);
716
Test.AssertEquals(4, array.Count());
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);
723
Test.AssertEquals("[120, -42, 5, 42]", array.ToString());
727
public static void TestValueArrayOfByte()
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());
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);
748
Test.AssertEquals(4, array.Count());
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);
755
Test.AssertEquals("[155, 42, 5, 42]", array.ToString());
757
Test.AssertRaises<OverflowException>(() => array[0] = 123214);
761
public static void TestValueArrayOfInts()
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());
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);
782
Test.AssertEquals(4, array.Count());
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);
789
Test.AssertEquals("[1984, -42, 5, 42]", array.ToString());
793
public static void TestValueArrayOfInt64s()
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());
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);
814
Test.AssertEquals(4, array.Count());
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);
821
Test.AssertEquals("[1984, -42, 5, 42]", array.ToString());
825
public static void TestValueArrayOfUInts()
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);
835
public static void TestValueArrayOfStrings()
838
using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.String)) {
840
Test.Assert(array.Append("hello"));
841
Test.Assert(array.Append("world"));
843
Test.AssertEquals((string)array[0], "hello");
844
Test.AssertEquals((string)array[1], "world");
849
Test.AssertEquals((string)array[0], "efl");
850
Test.AssertEquals((string)array[1], "rocks");
854
public static void TestValueArrayOfObjects()
857
using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Object)) {
859
var a = new Dummy.TestObject();
860
var b = new Dummy.TestObject();
862
Test.Assert(array.Append(a));
863
Test.Assert(array.Append(b));
865
Test.AssertEquals((Efl.Object)array[0], a);
866
Test.AssertEquals((Efl.Object)array[1], b);
868
var c = new Dummy.TestObject();
872
Test.AssertEquals((Efl.Object)array[0], c);
873
Test.AssertEquals((Efl.Object)array[1], b);
880
public static void TestInsertValueArrayOfSByte()
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());
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());
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);
905
Test.AssertEquals(4, array.Count());
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);
912
Test.AssertEquals("[120, -42, 0, 6]", array.ToString());
916
public static void TestInsertValueArrayOfByte()
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());
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());
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);
941
Test.AssertEquals(4, array.Count());
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);
948
Test.AssertEquals("[120, 42, 0, 6]", array.ToString());
952
public static void TestInsertValueArrayOfInts()
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());
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());
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);
977
Test.AssertEquals(4, array.Count());
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);
984
Test.AssertEquals("[1984, -42, 0, 1]", array.ToString());
988
public static void TestInsertValueArrayOfInt64s()
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());
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());
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);
1013
Test.AssertEquals(4, array.Count());
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);
1020
Test.AssertEquals("[1984, -42, 0, 10000000000]", array.ToString());
1024
public static void TestInsertValueArrayOfUInts()
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());
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());
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);
1050
Test.AssertEquals(4, array.Count());
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);
1057
Test.AssertEquals("[1984, 100, 0, 7]", array.ToString());
1061
public static void TestInsertValueArrayOfStrings()
1064
using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.String)) {
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());
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));
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");
1083
Test.AssertEquals(4, array.Count());
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");
1092
public static void TestInsertValueArrayOfObjects()
1095
using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Object)) {
1097
var a = new Dummy.TestObject();
1098
var b = new Dummy.TestObject();
1099
var c = new Dummy.TestObject();
1100
var d = new Dummy.TestObject();
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());
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));
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);
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);
1132
public static void TestInsertValueListOfSByte()
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());
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());
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);
1157
Test.AssertEquals(4, list.Count());
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);
1164
Test.AssertEquals("[120, -42, 0, 6]", list.ToString());
1168
public static void TestInsertValueListOfByte()
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());
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());
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);
1193
Test.AssertEquals(4, list.Count());
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);
1200
Test.AssertEquals("[120, 42, 0, 6]", list.ToString());
1204
public static void TestInsertValueListOfInts()
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());
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());
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);
1229
Test.AssertEquals(4, list.Count());
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);
1236
Test.AssertEquals("[1984, -42, 0, 1]", list.ToString());
1240
public static void TestInsertValueListOfInt64s()
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());
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());
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);
1265
Test.AssertEquals(4, list.Count());
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);
1272
Test.AssertEquals("[1984, -42, 0, 10000000000]", list.ToString());
1276
public static void TestInsertValueListOfUInts()
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());
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());
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);
1302
Test.AssertEquals(4, list.Count());
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);
1309
Test.AssertEquals("[1984, 100, 0, 7]", list.ToString());
1313
public static void TestInsertValueListOfStrings()
1316
using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.String)) {
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());
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));
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");
1335
Test.AssertEquals(4, list.Count());
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");
1344
public static void TestInsertValueListOfObjects()
1347
using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.Object)) {
1349
var a = new Dummy.TestObject();
1350
var b = new Dummy.TestObject();
1351
var c = new Dummy.TestObject();
1352
var d = new Dummy.TestObject();
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());
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));
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);
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);
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]);
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());
1405
using (Eina.Value array = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.UInt32))
1406
Test.AssertEquals(Eina.ValueType.UInt32, array.GetValueSubType());
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)) {
1413
other.ConvertTo(array);
1414
Test.AssertEquals(100, (int)array[0]);
1415
Test.AssertEquals("[100]", array.ToString());
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());
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);
1439
Test.AssertEquals(4, list.Count());
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);
1446
Test.AssertEquals("[1984, -42, 5, 42]", list.ToString());
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);
1455
using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.String)) {
1457
Test.Assert(list.Append("hello"));
1458
Test.Assert(list.Append("world"));
1460
Test.AssertEquals((string)list[0], "hello");
1461
Test.AssertEquals((string)list[1], "world");
1466
Test.AssertEquals((string)list[0], "efl");
1467
Test.AssertEquals((string)list[1], "rocks");
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]);
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());
1491
using (Eina.Value list = new Eina.Value(Eina.ValueType.List, Eina.ValueType.UInt32))
1492
Test.AssertEquals(Eina.ValueType.UInt32, list.GetValueSubType());
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)) {
1499
other.ConvertTo(list);
1500
Test.AssertEquals(100, (int)list[0]);
1501
Test.AssertEquals("[100]", list.ToString());
1505
public static void TestStringThroughValue() {
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);
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");
1520
empty.Setup(Eina.ValueType.Int32);
1523
Test.Assert(!empty.Empty, "Values already set-up must not be empty.");
1526
Test.Assert(!empty.Empty, "Values with payload must not be empty.");
1530
public static void TestValueCopy() {
1531
Eina.Value v2 = null;
1534
using (Eina.Value v = new Eina.Value(Eina.ValueType.Int32)) {
1535
Test.Assert(v.Set(raw_val));
1537
v2 = new Eina.Value(v);
1541
Test.Assert(v2.Get(out rec_val));
1542
Test.AssertEquals(raw_val, rec_val);
1573
public static class TestValueFromObject
1576
private class Holder
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; }
1584
public static void TestConversionFromToObject()
1586
var source = new Holder {
1590
Obj = new Dummy.TestObject(),
1594
var prop = source.GetType().GetProperty("Name");
1595
var v = new Eina.Value(prop.GetValue(source));
1597
Test.AssertEquals(v.GetValueType(), Eina.ValueType.String);
1598
Test.AssertEquals((string)v, prop.GetValue(source));
1600
Test.Assert(v.Set("New value"));
1601
prop.SetValue(source, v.Unwrap());
1602
Test.AssertEquals(prop.GetValue(source), "New value");
1606
var prop = source.GetType().GetProperty("Factor");
1607
var v = new Eina.Value(prop.GetValue(source));
1609
Test.AssertEquals(v.GetValueType(), Eina.ValueType.Double);
1610
Test.AssertAlmostEquals((double)v, (double)prop.GetValue(source));
1612
Test.Assert(v.Set(2.78));
1613
prop.SetValue(source, v.Unwrap());
1614
Test.AssertEquals(prop.GetValue(source), 2.78);
1618
var prop = source.GetType().GetProperty("Number");
1619
var v = new Eina.Value(prop.GetValue(source));
1621
Test.AssertEquals(v.GetValueType(), Eina.ValueType.Int32);
1622
Test.AssertEquals((int)v, prop.GetValue(source));
1624
Test.Assert(v.Set(2012));
1625
prop.SetValue(source, v.Unwrap());
1626
Test.AssertEquals(prop.GetValue(source), 2012);
1630
var prop = source.GetType().GetProperty("Obj");
1631
var v = new Eina.Value(prop.GetValue(source));
1633
Test.AssertEquals(v.GetValueType(), Eina.ValueType.Object);
1634
Test.AssertEquals((Efl.Object)v, prop.GetValue(source));
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);
1644
private class ComplexHolder
1646
public IEnumerable<int> Bag { get; set; }
1647
public IEnumerable<Efl.Object> BagOfObjects { get; set; }
1650
public static void TestContainerFromToObject()
1652
var initialBag = new Eina.Array<int>();
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);
1662
Test.AssertEquals(v.GetValueType(), Eina.ValueType.Array);
1663
Test.AssertEquals(v.GetValueSubType(), Eina.ValueType.Int32);
1665
Test.AssertEquals(v[0], initialBag[0]);
1666
Test.AssertEquals(v[1], initialBag[1]);
1667
Test.AssertEquals(v[2], initialBag[2]);
1673
prop.SetValue(source, v.Unwrap());
1675
IEnumerable<int> newVal = prop.GetValue(source) as IEnumerable<int>;
1676
var toCheck = newVal.ToList();
1678
Test.AssertEquals(toCheck[0], 100);
1679
Test.AssertEquals(toCheck[1], 200);
1680
Test.AssertEquals(toCheck[2], 300);
1684
public static void TestObjectContainerFromToObject()
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);
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);
1699
Test.AssertEquals(v.GetValueType(), Eina.ValueType.Array);
1700
Test.AssertEquals(v.GetValueSubType(), Eina.ValueType.Object);
1702
Test.AssertEquals(v[0], initialBag[0]);
1703
Test.AssertEquals(v[1], initialBag[1]);
1704
Test.AssertEquals(v[2], initialBag[2]);
1706
var first = new Dummy.TestObject();
1707
var second = new Dummy.TestObject();
1708
var third = new Dummy.TestObject();
1713
prop.SetValue(source, v.Unwrap());
1715
IEnumerable<Efl.Object> newVal = prop.GetValue(source) as IEnumerable<Efl.Object>;
1716
var toCheck = newVal.ToList();
1718
Test.AssertEquals(toCheck[0], first);
1719
Test.AssertEquals(toCheck[1], second);
1720
Test.AssertEquals(toCheck[2], third);
1727
#pragma warning restore 1591