-
Notifications
You must be signed in to change notification settings - Fork 656
/
TestMainForm.cs
258 lines (233 loc) · 9.62 KB
/
TestMainForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Forms;
using ILRuntime.CLR.TypeSystem;
using ILRuntime.Runtime.Enviorment;
using ILRuntimeTest.Test;
using ILRuntimeTest.TestBase;
using ILRuntimeTest.TestFramework;
namespace ILRuntimeTest
{
public partial class TestMainForm : Form
{
TestSession session;
private Assembly _assembly;
private List<TestResultInfo> _resList = new List<TestResultInfo>();
private ListViewItemSelectionChangedEventArgs _selectItemArgs = null;
private bool _isLoadAssembly;
public TestMainForm()
{
InitializeComponent();
ColumnHeader[] row1 =
{
new ColumnHeader() {Name = "TestName", Text = "TestName", Width = 300},
new ColumnHeader() {Name = "Result", Text = "TestResult", Width = 200},
//new ColumnHeader() {Name = "Run", Text = "Click", Width = 200},
};
listView1.Columns.AddRange(row1);
listView1.View = View.Details;
}
private void OnBtnRun(object sender, EventArgs e)
{
//if (_assembly != null)
//{
// //types
// var types = _assembly.GetTypes();
// foreach (var type in types)
// {
// if (type.IsGenericTypeDefinition)
// continue;
// //methods
// var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
// foreach (var methodInfo in methods)
// {
// string fullName = string.Format("{0}.{1}", type.Namespace, type.Name);
// //Console.WriteLine("call the method:{0},return type {1},params count{2}", fullName + "." + methodInfo.Name, methodInfo.ReturnType, methodInfo.GetParameters().Length);
// //目前只支持无参数,无返回值测试
// if (methodInfo.GetParameters().Length == 0)
// {
// var testUnit = new StaticTestUnit();
// testUnit.Init(_app, fullName, methodInfo.Name);
// testUnit.Run();
// _resList.Add(testUnit.CheckResult());
// }
// }
// }
//}
if (session == null)
return;
if (session.TestList.Count <= 0)
return;
_resList.Clear();
foreach (var unit in session.TestList)
{
unit.Run(true);
_resList.Add(unit.CheckResult());
}
listView1.Items.Clear();
StringBuilder sb = new StringBuilder();
foreach (var resInfo in _resList)
{
sb.Append("Test:");
sb.AppendLine(resInfo.TestName);
sb.Append("TestResult:");
sb.AppendLine(resInfo.Result == TestResults.Failed && resInfo.HasTodo ? $"{resInfo.Result}(Has TODO)" : resInfo.Result.ToString());
sb.AppendLine("Log:");
sb.AppendLine(resInfo.Message);
sb.AppendLine("=======================");
var item = new ListViewItem(resInfo.TestName);
item.SubItems.Add(resInfo.Result.ToString());
switch (resInfo.Result)
{
case TestResults.Pass:
case TestResults.Ignored:
item.BackColor = Color.Green;
break;
case TestResults.Failed:
if(resInfo.HasTodo)
item.BackColor = Color.Yellow;
else
item.BackColor = Color.Red;
break;
}
listView1.Items.Add(item);
}
tbLog.Text = sb.ToString();
}
private void OnBtnLoad(object sender, EventArgs e)
{
session?.Dispose();
if (txtPath.Text == "")
{
if (OD.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default["assembly_path"] = txtPath.Text = OD.FileName;
Properties.Settings.Default.Save();
}
else
{
return;
}
}
try
{
Properties.Settings.Default["assembly_path"] = txtPath.Text;
Properties.Settings.Default.Save();
session = new TestSession();
session.Load(txtPath.Text, cbEnableRegVM.Checked);
_isLoadAssembly = true;
LoadTest();
UpdateBtnState();
}
catch (Exception ex)
{
MessageBox.Show("[Error:]" + ex);
}
}
private void OnBtnRunSelect(object sender, EventArgs e)
{
if (_selectItemArgs == null)
return;
var testUnit = session.TestList[_selectItemArgs.ItemIndex];
testUnit.Run();
var res = testUnit.CheckResult();
_selectItemArgs.Item.SubItems[1].Text = res.Result == TestResults.Failed && res.HasTodo ? $"{res.Result}(Has TODO)" : res.Result.ToString();
switch (res.Result)
{
case TestResults.Pass:
case TestResults.Ignored:
_selectItemArgs.Item.BackColor = Color.Green;
break;
case TestResults.Failed:
if (res.HasTodo)
_selectItemArgs.Item.BackColor = Color.Yellow;
else
_selectItemArgs.Item.BackColor = Color.Red;
break;
}
StringBuilder sb = new StringBuilder();
sb.Append("Test:");
sb.AppendLine(res.TestName);
sb.Append("TestResult:");
sb.AppendLine(res.Result.ToString());
sb.AppendLine("Log:");
sb.AppendLine(res.Message);
sb.AppendLine("=======================");
tbLog.Text = sb.ToString();
}
private void OnFormLoaded(object sender, EventArgs e)
{
txtPath.Text = Properties.Settings.Default["assembly_path"] as string;
listView1.ItemSelectionChanged += OnItemSelectChanged;
btnRunSelect.Enabled = false;
btnRun.Enabled = false;
}
private void OnItemSelectChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (e.ItemIndex > session.TestList.Count - 1)
{
Console.WriteLine("select index out of range");
return;
}
_selectItemArgs = e;
UpdateBtnState();
}
private void LoadTest()
{
_resList.Clear();
listView1.Items.Clear();
foreach (var testUnit in session.TestList)
{
var item = new ListViewItem(testUnit.TestName);
item.SubItems.Add("--");
//item.BackColor = testUnit.Result ? Color.Green : Color.Red;
listView1.Items.Add(item);
}
}
private void UpdateBtnState()
{
btnRun.Enabled = _isLoadAssembly;
btnRunSelect.Enabled = _selectItemArgs != null;
}
private void button1_Click(object sender, EventArgs e)
{
var msg = ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(typeof(TestClass2), "ILRuntimeTest");
MessageBox.Show(msg);
msg = ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(typeof(IAsyncStateMachine), "ILRuntimeTest");
MessageBox.Show(msg);
}
private void btnGenerateBinding_Click(object sender, EventArgs e)
{
/*List<Type> types = new List<Type>();
types.Add(typeof(int));
types.Add(typeof(float));
types.Add(typeof(long));
types.Add(typeof(object));
types.Add(typeof(string));
types.Add(typeof(ValueType));
types.Add(typeof(Console));
types.Add(typeof(Array));
types.Add(typeof(Dictionary<string, int>));
types.Add(typeof(Dictionary<ILRuntime.Runtime.Intepreter.ILTypeInstance, int>));
types.Add(typeof(TestFramework.TestStruct));
ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(types, "..\\..\\AutoGenerate");*/
ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain();
using (FileStream fs = new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read))
{
domain.LoadAssembly(fs);
//Crossbind Adapter is needed to generate the correct binding code
ILRuntimeHelper.Init(domain);
string outputPath = ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "ILRuntimeTestBase/AutoGenerate"; // "..\\..\\AutoGenerate"
ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, outputPath);
}
}
}
}