forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kernel.cs
301 lines (263 loc) · 10.6 KB
/
Kernel.cs
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Cosmos.TestRunner;
using Sys = Cosmos.System;
namespace SimpleStructsAndArraysTest
{
public class Kernel: Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully.");
}
//[StructLayout(LayoutKind.Explicit, Size = 10)]
//private struct MyStruct
//{
// public MyStruct(short a, short b, short c, short d, short e)
// {
// A = a;
// B = b;
// C = c;
// D = d;
// E = e;
// }
// [FieldOffset(0)]
// public short A;
// [FieldOffset(2)]
// public short B;
// [FieldOffset(4)]
// public short C;
// [FieldOffset(6)]
// public short D;
// [FieldOffset(8)]
// public short E;
//}
//private static T GetValue<T>(T[] arr, int index)
//{
// return arr[index];
//}
//private static void TestStep1()
//{
// //var xItem = xQueue.Dequeue();
// //Console.Write("Char: ");
// //Console.WriteLine(xResult.KeyChar);
// var xItem = new MyStruct
// {
// A = 1,
// B = 2,
// C = 3,
// D = 4,
// E = 5
// };
// var xArray = new MyStruct[1];
// xArray[0] = xItem;
// //xArray[0] = new MyStruct(1, 2, 3, 4, 5);
// xItem = xArray[0];
// Assert.IsTrue(xItem.A == 1, "xItem.A == 1");
// Console.Write("A: ");
// Console.WriteLine(xItem.A);
// Assert.IsTrue(xItem.B == 2, "xItem.B == 2");
// Console.Write("B: ");
// Console.WriteLine(xItem.B);
// Assert.IsTrue(xItem.C == 3, "xItem.C == 3");
// Console.Write("C: ");
// Console.WriteLine(xItem.C);
// Assert.IsTrue(xItem.D == 4, "xItem.D == 4");
// Console.Write("D: ");
// Console.WriteLine(xItem.D);
// Assert.IsTrue(xItem.E == 5, "xItem.E == 5");
// Console.Write("E: ");
// Console.WriteLine(xItem.E);
// //xItem = new MyStruct(6, 7, 8, 9, 10);
// Console.WriteLine("Next: ");
// //xItem = xQueue.Dequeue();
// //Console.Write("Char: ");
// //Console.WriteLine(xResult.KeyChar);
// //var xArray = new MyStruct[0];
// //xArray[0] = new MyStruct(1, 2, 3, 4, 5);
// var xItem2 = GetValue(xArray, 0);
// Assert.IsTrue(xItem2.A == 1, "xItem2.A == 1");
// Console.Write("A: ");
// Console.WriteLine(xItem2.A);
// Assert.IsTrue(xItem2.B == 2, "xItem2.B == 2");
// Console.Write("B: ");
// Console.WriteLine(xItem2.B);
// Assert.IsTrue(xItem2.C == 3, "xItem2.C == 3");
// Console.Write("C: ");
// Console.WriteLine(xItem2.C);
// Assert.IsTrue(xItem2.D == 4, "xItem2.D == 4");
// Console.Write("D: ");
// Console.WriteLine(xItem2.D);
// Assert.IsTrue(xItem2.E == 5, "xItem2.E == 5");
// Console.Write("E: ");
// Console.WriteLine(xItem2.E);
//}
//private class KVPClass
//{
// public int Key;
// public int Value;
//}
//private struct KVPStruct
//{
// public int Key;
// public int Value;
//}
//private class OurList<T>
//{
// private int _size;
// private int _version;
// private T[] _items;
// private object _syncRoot;
// public OurList()
// {
// this._items = new T[0];
// }
// public void Add(T item)
// {
// if (this._size == this._items.Length)
// {
// this.EnsureCapacity(this._size + 1);
// }
// T[] arg_36_0 = this._items;
// int size = this._size;
// this._size = size + 1;
// arg_36_0[size] = item;
// this._version++;
// }
// private void EnsureCapacity(int min)
// {
// if (this._items.Length < min)
// {
// int num = (this._items.Length == 0) ? 4 : (this._items.Length * 2);
// if (num > 2146435071)
// {
// num = 2146435071;
// }
// if (num < min)
// {
// num = min;
// }
// this.Capacity = num;
// }
// }
// public int Capacity
// {
// get
// {
// return this._items.Length;
// }
// set
// {
// if (value < this._size)
// {
// throw new Exception("Capacity is smaller than size!");
// }
// if (value != this._items.Length)
// {
// if (value > 0)
// {
// T[] array = new T[value];
// if (this._size > 0)
// {
// Array.Copy(this._items, 0, array, 0, this._size);
// }
// this._items = array;
// return;
// }
// this._items = new T[0];
// }
// }
// }
// public T this[int index]
// {
// get
// {
// Assert.IsTrue(index == ExpectedIndex, "index == " + ExpectedIndex);
// if (index >= this._size)
// {
// throw new Exception("Out of range!");
// }
// return this._items[index];
// }
// }
// public static int ExpectedIndex;
//}
//protected static void TestOurList()
//{
// Assert.IsTrue(true, "Start of test");
// var xListClasses = new OurList<KVPClass>();
// var xListStructs = new OurList<KVPStruct>();
// xListClasses.Add(new KVPClass {Key = 1, Value = 2});
// xListClasses.Add(new KVPClass {Key = 2, Value = 5});
// OurList<KVPClass>.ExpectedIndex = 0;
// var xListItem = xListClasses[0];
// Assert.AreEqual(1, xListItem.Key, "xListClasses[0].Key == 1");
// Assert.AreEqual(2, xListItem.Value, "xListClasses[0].Value == 2");
// OurList<KVPClass>.ExpectedIndex = 1;
// xListItem = xListClasses[1];
// Assert.AreEqual(2, xListItem.Key, "xListClasses[1].Key == 2");
// Assert.AreEqual(5, xListItem.Value, "xListClasses[1].Value == 5");
// xListStructs.Add(new KVPStruct {Key = 1, Value = 2});
// xListStructs.Add(new KVPStruct {Key = 2, Value = 5});
// OurList<KVPStruct>.ExpectedIndex = 0;
// var xStructItem = xListStructs[0];
// Assert.AreEqual(1, xStructItem.Key, "xListStructs[0].Key == 1");
// Assert.AreEqual(2, xStructItem.Value, "xListStructs[0].Value == 2");
// OurList<KVPStruct>.ExpectedIndex = 1;
// xStructItem = xListStructs[1];
// Assert.AreEqual(2, xStructItem.Key, "xListStructs[1].Key == 2");
// Assert.AreEqual(5, xStructItem.Value, "xListStructs[1].Value == 5");
//}
//protected static void TestStandardList()
//{
// Assert.IsTrue(true, "Start of test");
// var xListClasses = new List<KVPClass>();
// var xListStructs = new List<KVPStruct>();
// xListClasses.Add(new KVPClass { Key = 1, Value = 2 });
// xListClasses.Add(new KVPClass { Key = 2, Value = 5 });
// var xListItem = xListClasses[0];
// Assert.AreEqual(1, xListItem.Key, "xListClasses[0].Key == 1");
// Assert.AreEqual(2, xListItem.Value, "xListClasses[0].Value == 2");
// xListItem = xListClasses[1];
// Assert.AreEqual(2, xListItem.Key, "xListClasses[1].Key == 2");
// Assert.AreEqual(5, xListItem.Value, "xListClasses[1].Value == 5");
// xListStructs.Add(new KVPStruct { Key = 1, Value = 2 });
// xListStructs.Add(new KVPStruct { Key = 2, Value = 5 });
// var xStructItem = xListStructs[0];
// Assert.AreEqual(1, xStructItem.Key, "xListStructs[0].Key == 1");
// Assert.AreEqual(2, xStructItem.Value, "xListStructs[0].Value == 2");
// xStructItem = xListStructs[1];
// Assert.AreEqual(2, xStructItem.Key, "xListStructs[1].Key == 2");
// Assert.AreEqual(5, xStructItem.Value, "xListStructs[1].Value == 5");
//}
//protected static void TestMultidimensionalArray()
//{
// var xTestMultidimensionalArray = new int[2, 2];
// xTestMultidimensionalArray[0, 0] = 1;
// xTestMultidimensionalArray[0, 1] = 2;
// xTestMultidimensionalArray[1, 0] = 3;
// xTestMultidimensionalArray[1, 1] = 4;
// Assert.IsTrue(xTestMultidimensionalArray.Length == 4, "Size of array is 4.");
// Assert.IsTrue(xTestMultidimensionalArray[0, 0] == 1, "Index [0, 0] == 1");
// Assert.IsTrue(xTestMultidimensionalArray[0, 1] == 2, "Index [0, 1] == 2");
// Assert.IsTrue(xTestMultidimensionalArray[1, 0] == 3, "Index [1, 0] == 3");
// Assert.IsTrue(xTestMultidimensionalArray[1, 1] == 4, "Index [1, 1] == 4");
//}
protected override void Run()
{
//TestStep1();
//TestOurList();
//Assert.IsTrue(true, "After TestOurList");
//TestStandardList();
//Assert.IsTrue(true, "After TestStandardList");
//TestMultidimensionalArray();
//Assert.IsTrue(true, "After TestMultidimensionalArray");
ConstrainedTest.MutateStructTest();
Assert.IsTrue(true, "After MutateTestStruct");
TestController.Completed();
}
}
}