[metadata] Fix leaks when handling a few attributes (#16675)
[mono-project.git] / mcs / tests / test-580.cs
blobe1712837a7d43ac433de56564adb43b0daf8f8e6
1 using System;
3 public class Bla {
5 public static void BuildNode (ref string label)
7 string s = "a";
8 label += s + s + s + s;
11 public static void BuildNode (ref string[] label)
13 string s = "a";
14 int idx = 0;
15 label[idx++] += s + s + s + s;
18 public static void BuildNode_B (ref object label)
20 string s = "b";
21 label += s + s;
24 public static string BuildNode_C (ref string label)
26 string[] a = new string [2];
27 int i = 0;
28 a [0] = "a";
29 string s = "b";
31 a [i++] += label + s + s + s;
32 return a [i - 1];
35 public static string BuildNode_D ()
37 System.Collections.ArrayList values = new System.Collections.ArrayList ();
38 for (int i = 0; i < 6; i++)
39 values.Add (i);
40 string[] strs = new string [values.Count];
41 int idx = 0;
42 foreach (int val in values) {
43 strs [idx] = "Value:";
44 strs [idx++] += val.ToString ();
47 return strs [5];
50 public static void BuildNode_E (ref string[,] label)
52 string s = "a";
53 int idx = 0;
54 label = new string [1, 1];
55 label[idx++, idx - 1] += s + s + s + s;
58 static bool Test_Object ()
60 int a = 0;
61 object[] o_a = new string[] { "A" };
62 o_a [a++] += "Z";
63 if ((string) o_a [0] != "AZ")
64 return false;
66 a = 0;
67 object[,] o_a2 = new string[,] { { "X" } };
68 o_a2[a++, 0] += "Z";
69 if ((string) o_a2 [0, 0] != "XZ")
70 return false;
72 return true;
75 static bool Test_Decimal ()
77 decimal[,] da = new decimal[,] { { 5, 6 } };
78 da[0,0] = 6.7m;
79 da[0,0] += 1.2m;
81 if (da [0,0] != 7.9m)
82 return false;
84 return true;
87 public static int Main ()
89 String str = "test";
91 BuildNode (ref str);
92 Console.WriteLine (str);
93 if (str != "testaaaa")
94 return 1;
96 object ostr = "test";
97 BuildNode_B (ref ostr);
98 Console.WriteLine (ostr);
99 if (ostr.ToString () != "testbb")
100 return 2;
102 str = "test";
103 string res = BuildNode_C (ref str);
104 Console.WriteLine (str);
105 if (str != "test")
106 return 3;
108 Console.WriteLine (res);
109 if (res != "atestbbb")
110 return 4;
112 string[] sa = new string [1];
113 BuildNode (ref sa);
114 Console.WriteLine (sa [0]);
115 if (sa [0] != "aaaa")
116 return 5;
118 str = BuildNode_D ();
119 Console.WriteLine (str);
120 if (str != "Value:5")
121 return 6;
123 string[,] sa2 = null;
124 BuildNode_E (ref sa2);
125 Console.WriteLine (sa2 [0, 0]);
126 if (sa2 [0,0] != "aaaa")
127 return 7;
129 if (!Test_Object ())
130 return 8;
132 if (!Test_Decimal ())
133 return 9;
135 return 0;