• R/O
  • SSH
  • HTTPS

c4ju: Commit


Commit MetaInfo

Revision3 (tree)
Time2011-10-22 16:03:59
Authorsrz_zumix

Log Message

高速化

Change Summary

Incremental Difference

--- trunk/src/Evaluation.cs (revision 2)
+++ trunk/src/Evaluation.cs (revision 3)
@@ -12,6 +12,7 @@
1212 #region フィールド
1313 CodeDomProvider m_cdp = null;
1414 CompilerParameters m_cps = null;
15+ Type m_type = null;
1516 #endregion
1617
1718 #region コンストラクタ
@@ -24,8 +25,8 @@
2425 }
2526 #endregion
2627
27- #region Evaluation
28- public string Eval(string expr)
28+ #region 初期化
29+ public bool Init(string expr)
2930 {
3031 try
3132 {
@@ -33,7 +34,7 @@
3334 @"
3435 public class MainClass
3536 {
36- public static string Eval()
37+ public static string Eval(float value)
3738 {
3839 return (expr).ToString();
3940 }
@@ -45,19 +46,26 @@
4546 cres = m_cdp.CompileAssemblyFromSource(m_cps, source);
4647 // コンパイルしたアセンブリを取得
4748 Assembly asm = cres.CompiledAssembly;
48- Type t = asm.GetType("MainClass");
49- string ret = (string)t.InvokeMember("Eval"
50- , BindingFlags.InvokeMethod
51- , null, null, null);
52- return ret;
49+ m_type = asm.GetType("MainClass");
5350 }
5451 catch (Exception e)
5552 {
5653 Console.WriteLine(e.Message);
57- return null;
54+ return false;
5855 }
56+ return true;
5957 }
6058 #endregion
59+
60+ #region Evaluation
61+ public string Eval(float value)
62+ {
63+ string ret = (string)m_type.InvokeMember("Eval"
64+ , BindingFlags.InvokeMethod
65+ , null, null, new object[] { value });
66+ return ret;
67+ }
68+ #endregion
6169 }
6270
6371 } // end of namespace crisp
--- trunk/src/Program.cs (revision 2)
+++ trunk/src/Program.cs (revision 3)
@@ -9,6 +9,21 @@
99
1010 namespace c4ju
1111 {
12+ #region フィルター
13+ class FilterAttribute
14+ {
15+ public string Name;
16+ public string Value;
17+ public CSharpEval Eval;
18+ };
19+ class Filter
20+ {
21+ public string TestName;
22+ public string strXPath;
23+ public List<FilterAttribute> list;
24+ };
25+ #endregion
26+
1227 class Program
1328 {
1429 static int Main(string[] args)
@@ -123,6 +138,29 @@
123138 Console.WriteLine("not found CCCC_Project node");
124139 return 1;
125140 }
141+ List<Filter> filter_list = new List<Filter>();
142+ foreach (string xpath in filter_xpaths)
143+ {
144+ Filter f = new Filter();
145+ XmlNode filter_node = doc_filter.SelectSingleNode(xpath);
146+ f.TestName = filter_node.ParentNode.Name + "/" + filter_node.Name + " : ";
147+ f.strXPath = xpath;
148+ f.list = new List<FilterAttribute>();
149+ foreach (XmlAttribute attr in filter_node.Attributes)
150+ {
151+ FilterAttribute a = new FilterAttribute();
152+ a.Name = attr.Name;
153+ a.Value = attr.Value;
154+ a.Eval = new CSharpEval();
155+ if (!a.Eval.Init(attr.Value))
156+ {
157+ Console.WriteLine("Evaluation of the filter expression is invalid xml.");
158+ return 1;
159+ }
160+ f.list.Add(a);
161+ }
162+ filter_list.Add(f);
163+ }
126164 #endregion
127165
128166 #region 標準入力からのファイルパス取得
@@ -141,8 +179,6 @@
141179 Stopwatch test_case_sw = new Stopwatch();
142180 Stopwatch test_sw = new Stopwatch();
143181
144- CSharpEval eval = new CSharpEval();
145-
146182 JunitXmlDocument junitDoc = new JunitXmlDocument();
147183 XmlNode TestSuites = junitDoc.AppendTestSuites("AllTest"
148184 , 0 // 仮
@@ -166,75 +202,77 @@
166202
167203 Console.WriteLine(f);
168204
169- foreach (string xpath in filter_xpaths)
205+ foreach (Filter filter in filter_list)
170206 {
171207 #region テストケース
172- XmlNode filter_node = doc_filter.SelectSingleNode(xpath);
173- if (filter_node != null)
208+ try
174209 {
175- try
210+ string test_case_name = filter.TestName + Path.GetFileNameWithoutExtension(f);
211+ XmlNodeList selectNodes = xml.SelectNodes(filter.strXPath);
212+ if (selectNodes != null && selectNodes.Count > 0)
176213 {
177- string test_case_name = filter_node.ParentNode.Name + "/" + filter_node.Name + " : " + Path.GetFileNameWithoutExtension(f);
178- XmlNodeList selectNodes = xml.SelectNodes(xpath);
179- if (selectNodes != null && selectNodes.Count > 0)
214+ XmlNode TestSuite = junitDoc.AppendTestSuite(test_case_name
215+ , selectNodes.Count
216+ , 0 // 仮
217+ , 0
218+ , test_case_sw.Elapsed // 仮
219+ );
220+ int failure_count = 0;
221+
222+ test_case_sw.Reset();
223+ test_case_sw.Start();
224+ foreach (XmlNode node in selectNodes)
180225 {
181- XmlNode TestSuite = junitDoc.AppendTestSuite(test_case_name
182- , selectNodes.Count
183- , 0 // 仮
184- , 0
185- , test_case_sw.Elapsed // 仮
186- );
187- int failure_count = 0;
226+ #region テスト
227+ List<JunitXmlDocument.FailureResult> fr_list = new List<JunitXmlDocument.FailureResult>();
228+ XmlNode sourceNode = null;
229+ string name = node.InnerText;
230+ string file = "";
231+ int line = -1;
232+ #region テスト名・ファイルパス情報の取得
233+ XmlNode parentNode = node.ParentNode;
234+ if (parentNode.Name == "member_function")
235+ {
236+ name = parentNode.SelectSingleNode("name").InnerText;
237+ sourceNode = parentNode.SelectSingleNode("extent/source_reference");
238+ }
239+ else if (parentNode.Name == "module_summary")
240+ {
241+ name = "module_summary";
242+ sourceNode = parentNode.ParentNode.SelectSingleNode("module_detail/source_reference");
243+ }
244+ if (sourceNode != null)
245+ {
246+ file = sourceNode.Attributes["file"].Value;
247+ line = int.Parse(sourceNode.Attributes["line"].Value);
248+ }
249+ #endregion
188250
189- test_case_sw.Reset();
190- test_case_sw.Start();
191- foreach (XmlNode node in selectNodes)
251+ test_sw.Reset();
252+ test_sw.Start();
253+ foreach (FilterAttribute filter_attr in filter.list)
192254 {
193- #region テスト
194- List<JunitXmlDocument.FailureResult> fr_list = new List<JunitXmlDocument.FailureResult>();
195- XmlNode sourceNode = null;
196- string name = node.InnerText;
197- string file = "";
198- int line = -1;
199- #region テスト名・ファイルパス情報の取得
200- XmlNode parentNode = node.ParentNode;
201- if (parentNode.Name == "member_function")
255+ #region 属性ごとにテスト
256+ try
202257 {
203- name = parentNode.SelectSingleNode("name").InnerText;
204- sourceNode = parentNode.SelectSingleNode("extent/source_reference");
205- }
206- else if (parentNode.Name == "module_summary")
207- {
208- name = "module_summary";
209- sourceNode = parentNode.ParentNode.SelectSingleNode("module_detail/source_reference");
210- }
211- if (sourceNode != null)
212- {
213- file = sourceNode.Attributes["file"].Value;
214- line = int.Parse(sourceNode.Attributes["line"].Value);
215- }
216- #endregion
258+ XmlAttribute attr = node.Attributes[filter_attr.Name];
259+ if (attr != null)
260+ {
261+ // フィルタリング用のxmlは式が記述されている
262+ // value は比較対象の属性valueに置換される。
263+ // 式評価がfalseを返した場合、テスト失敗とみなす。
217264
218- test_sw.Reset();
219- test_sw.Start();
220- foreach (XmlAttribute filter_attr in filter_node.Attributes)
221- {
222- #region 属性ごとにテスト
223- try
224- {
225- XmlAttribute attr = node.Attributes[filter_attr.Name];
226- if (attr != null)
265+ // parse 失敗はエラーとしない
266+ float lhs = float.Parse(attr.Value);
267+ try
227268 {
228- // フィルタリング用のxmlは式が記述されている
229- // value は比較対象の属性valueに置換される。
230- // 式評価がfalseを返した場合、テスト失敗とみなす。
231- string expr = filter_attr.Value;
232- expr = expr.Replace("value", attr.Value);
233- string result = eval.Eval(expr);
269+ string result = filter_attr.Eval.Eval(lhs);
234270 ++test_total_count;
235271
236272 if (!bool.Parse(result))
237273 {
274+ string expr = filter_attr.Value;
275+ expr = expr.Replace("value", attr.Value);
238276 JunitXmlDocument.FailureResult fr = new JunitXmlDocument.FailureResult();
239277 fr.Message = "Expected : " + filter_attr.Value + "\n actual : " + expr;
240278 fr.File = file;
@@ -242,39 +280,42 @@
242280 fr_list.Add(fr);
243281 }
244282 }
283+ catch (Exception e)
284+ {
285+ Console.WriteLine(e.Message);
286+ }
245287 }
246- catch (Exception e)
247- {
248- Console.WriteLine(e.Message);
249- }
250- #endregion
251288 }
252-
253- test_sw.Stop();
254- if (fr_list.Count > 0)
289+ catch
255290 {
256- ++failure_count;
257291 }
258- junitDoc.AppendTestCase(TestSuite
259- , name
260- , true
261- , test_sw.Elapsed
262- , fr_list
263- );
264292 #endregion
265293 }
266- test_case_sw.Stop();
267294
268- failure_total_count += failure_count;
269- TestSuite.Attributes["failures"].Value = failure_count.ToString();
270- TestSuite.Attributes["time"].Value = test_case_sw.Elapsed.TotalSeconds.ToString();
295+ test_sw.Stop();
296+ if (fr_list.Count > 0)
297+ {
298+ ++failure_count;
299+ }
300+ junitDoc.AppendTestCase(TestSuite
301+ , name
302+ , true
303+ , test_sw.Elapsed
304+ , fr_list
305+ );
306+ #endregion
271307 }
308+ test_case_sw.Stop();
309+
310+ failure_total_count += failure_count;
311+ TestSuite.Attributes["failures"].Value = failure_count.ToString();
312+ TestSuite.Attributes["time"].Value = test_case_sw.Elapsed.TotalSeconds.ToString();
272313 }
273- catch (Exception e)
274- {
275- Console.WriteLine(e.Message);
276- }
277314 }
315+ catch (Exception e)
316+ {
317+ Console.WriteLine(e.Message);
318+ }
278319 #endregion
279320 }
280321 }
Show on old repository browser