summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Methodical/refany/array1.cs
blob: 3322903c3d8ee5482e7b2ac33223f35e88c16dd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace JitTest
{
    internal class Test
    {
        private static void TestRef(TypedReference _ref)
        {
            if (__reftype(_ref) == typeof(Array))
            {
                for (int i = 0; i < __refvalue(_ref, Array).Length; i++)
                    __refvalue(_ref, Array).SetValue(new Test(), i);
            }
            if (__reftype(_ref) == typeof(long[]))
            {
                for (int i = 0; i < __refvalue(_ref, long[]).Length; i++)
                    __refvalue(_ref, long[])[i]++;
            }
            if (__reftype(_ref) == typeof(ulong[,]))
            {
                for (int i = 0; i < 2; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        __refvalue(_ref, ulong[,])[i, j]--;
                    }
                }
            }
            if (__reftype(_ref) == typeof(ulong[][]))
            {
                for (int i = 0; i < 2; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        __refvalue(_ref, ulong[][])[i][j]--;
                    }
                }
            }
        }

        private static int Main()
        {
            Array genericArray = Array.CreateInstance(typeof(Test), 16);
            TestRef(__makeref(genericArray));
            for (int i = 0; i < 16; i++)
            {
                if (genericArray.GetValue(i) == null ||
                    genericArray.GetValue(i).GetType() != typeof(Test))
                    return 1;
            }

            long[] al = new long[] { 1, 2, 3 };
            TestRef(__makeref(al));
            if (al[0] != 2 || al[1] != 3 || al[2] != 4)
                return 2;

            ulong[,] aul2 = new ulong[,] { { 1, 2, 3 }, { 4, 5, 6 } };
            TestRef(__makeref(aul2));
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (aul2[i, j] != (ulong)(i * 3 + j))
                        return 3;
                }
            }

            ulong[][] aul1 = new ulong[][] { new ulong[] { 1, 2, 3 }, new ulong[] { 4, 5, 6 } };
            TestRef(__makeref(aul1));
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (aul1[i][j] != (ulong)(i * 3 + j))
                        return 3;
                }
            }

            return 100;
        }
    }
}