Welcome to mirror list, hosted at ThFree Co, Russian Federation.

debugger-valuetypes-test.cs « wasm « sdks - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d1ee58d0f89a9c2c9b42e8a0f013c70a6c25be2 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using System.Threading.Tasks;
namespace DebuggerTests {
	public class ValueTypesTest { //Only append content to this class as the test suite depends on line info

		public static void MethodWithLocalStructs ()
		{
			var ss_local = new SimpleStruct ("set in MethodWithLocalStructs", 1, DateTimeKind.Utc);
			var gs_local = new GenericStruct<ValueTypesTest> { StringField = "gs_local#GenericStruct<ValueTypesTest>#StringField" };

			ValueTypesTest vt_local = new ValueTypesTest {
				StringField = "string#0",
				SimpleStructField = new SimpleStruct ("SimpleStructField#string#0", 5, DateTimeKind.Local),
				SimpleStructProperty = new SimpleStruct ("SimpleStructProperty#string#0", 2, DateTimeKind.Utc), DT = new DateTime (2020, 1, 2, 3, 4, 5), RGB = RGB.Blue
			};
			Console.WriteLine ($"Using the struct: {ss_local.gs.StringField}, gs: {gs_local.StringField}, {vt_local.StringField}");
		}

		public static void TestStructsAsMethodArgs ()
		{
			var ss_local = new SimpleStruct ("ss_local#SimpleStruct#string#0", 5, DateTimeKind.Local);
			var ss_ret = MethodWithStructArgs ("TestStructsAsMethodArgs#label", ss_local, 3);
			Console.WriteLine ($"got back ss_local: {ss_local.gs.StringField}, ss_ret: {ss_ret.gs.StringField}");
		}

		static SimpleStruct MethodWithStructArgs (string label, SimpleStruct ss_arg, int x)
		{
			Console.WriteLine ($"- ss_arg: {ss_arg.str_member}");
			ss_arg.Kind = DateTimeKind.Utc;
			ss_arg.str_member = $"ValueTypesTest#MethodWithStructArgs#updated#ss_arg#str_member";
			ss_arg.gs.StringField = $"ValueTypesTest#MethodWithStructArgs#updated#gs#StringField#{x}";
			return ss_arg;
		}

		public static async Task<bool> MethodWithLocalStructsStaticAsync ()
		{
			var ss_local = new SimpleStruct ("set in MethodWithLocalStructsStaticAsync", 1, DateTimeKind.Utc);
			var gs_local = new GenericStruct<int> {
						StringField = "gs_local#GenericStruct<ValueTypesTest>#StringField",
						List = new System.Collections.Generic.List<int> { 5, 3 },
						Options = Options.Option2

			};

			var result = await ss_local.AsyncMethodWithStructArgs (gs_local);
			Console.WriteLine ($"Using the struct: {ss_local.gs.StringField}, result: {result}");

			return result;
		}

		public string StringField;
		public SimpleStruct SimpleStructProperty { get; set; }
		public SimpleStruct SimpleStructField;

		public struct SimpleStruct
		{
			public string str_member;
			public DateTime dt;
			public GenericStruct<DateTime> gs;
			public DateTimeKind Kind;

			public SimpleStruct (string str, int f, DateTimeKind kind)
			{
				str_member = $"{str}#SimpleStruct#str_member";
				dt = new DateTime (2020+f, 1+f, 2+f, 3+f, 5+f, 6+f);
				gs = new GenericStruct<DateTime> {
					StringField = $"{str}#SimpleStruct#gs#StringField",
					List = new System.Collections.Generic.List<DateTime> { new DateTime (2010+f, 2+f, 3+f, 10+f, 2+f, 3+f) },
					Options = Options.Option1
				};
				Kind = kind;
			}

			public Task<bool> AsyncMethodWithStructArgs (GenericStruct<int> gs)
			{
				Console.WriteLine ($"placeholder line for a breakpoint");
				if (gs.List.Count > 0)
					return Task.FromResult (true);

				return Task.FromResult (false);
			}
		}

		public struct GenericStruct<T>
		{
			public System.Collections.Generic.List<T> List;
			public string StringField;

			public Options Options { get; set; }
		}

		public DateTime DT { get; set; }
		public RGB RGB;

		public static void MethodWithLocalsForToStringTest (bool call_other)
		{
			var dt0 = new DateTime (2020, 1, 2, 3, 4, 5);
			var dt1 = new DateTime (2010, 5, 4, 3, 2, 1);
			var ts = dt0 - dt1;
			var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0));
			decimal dec = 123987123;
			var guid = new Guid ("3d36e07e-ac90-48c6-b7ec-a481e289d014");

			var dts = new DateTime [] {
				new DateTime (1983, 6, 7, 5, 6, 10),
				new DateTime (1999, 10, 15, 1, 2, 3)
			};

			var obj = new ClassForToStringTests {
				DT = new DateTime (2004, 10, 15, 1, 2, 3),
				DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0)),
				TS = ts,
				Dec = 1239871,
				Guid = guid
			};

			var sst = new StructForToStringTests {
				DT = new DateTime (2004, 10, 15, 1, 2, 3),
				DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0)),
				TS = ts,
				Dec = 1239871,
				Guid = guid
			};
			Console.WriteLine ($"MethodWithLocalsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
			if (call_other)
				MethodWithArgumentsForToStringTest (call_other, dt0, dt1, ts, dto, dec, guid, dts, obj, sst);
		}

		static void MethodWithArgumentsForToStringTest (
			bool call_other, // not really used, just to help with using common code in the tests
			DateTime dt0, DateTime dt1, TimeSpan ts, DateTimeOffset dto, decimal dec,
			Guid guid, DateTime[] dts, ClassForToStringTests obj, StructForToStringTests sst)
		{
			Console.WriteLine ($"MethodWithArgumentsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
		}

		public static async Task MethodWithLocalsForToStringTestAsync (bool call_other)
		{
			var dt0 = new DateTime (2020, 1, 2, 3, 4, 5);
			var dt1 = new DateTime (2010, 5, 4, 3, 2, 1);
			var ts = dt0 - dt1;
			var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0));
			decimal dec = 123987123;
			var guid = new Guid ("3d36e07e-ac90-48c6-b7ec-a481e289d014");

			var dts = new DateTime [] {
				new DateTime (1983, 6, 7, 5, 6, 10),
				new DateTime (1999, 10, 15, 1, 2, 3)
			};

			var obj = new ClassForToStringTests {
				DT = new DateTime (2004, 10, 15, 1, 2, 3),
				DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0)),
				TS = ts,
				Dec = 1239871,
				Guid = guid
			};

			var sst = new StructForToStringTests {
				DT = new DateTime (2004, 10, 15, 1, 2, 3),
				DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0)),
				TS = ts,
				Dec = 1239871,
				Guid = guid
			};
			Console.WriteLine ($"MethodWithLocalsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
			if (call_other)
				await MethodWithArgumentsForToStringTestAsync (call_other, dt0, dt1, ts, dto, dec, guid, dts, obj, sst);
		}

		static async Task MethodWithArgumentsForToStringTestAsync (
			bool call_other, // not really used, just to help with using common code in the tests
			DateTime dt0, DateTime dt1, TimeSpan ts, DateTimeOffset dto, decimal dec,
			Guid guid, DateTime[] dts, ClassForToStringTests obj, StructForToStringTests sst)
		{
			Console.WriteLine ($"MethodWithArgumentsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
		}

	}

	class ClassForToStringTests
	{
		public DateTime DT;
		public DateTimeOffset DTO;
		public TimeSpan TS;
		public decimal Dec;
		public Guid Guid;
	}

	struct StructForToStringTests
	{
		public DateTime DT;
		public DateTimeOffset DTO;
		public TimeSpan TS;
		public decimal Dec;
		public Guid Guid;
	}

	public enum RGB
	{
		Red, Green, Blue
	}

	[Flags]
	public enum Options
	{
		None = 0,
		Option1 = 1,
		Option2 = 2,
		Option3 = 4,

		All = Option1 | Option3
	}
}