• R/O
  • SSH
  • HTTPS

freetrain: Commit


Commit MetaInfo

Revisión104 (tree)
Tiempo2013-10-14 20:05:33
Autorc477

Log Message

ParamsReaderの修正、テストコード

Cambiar Resumen

Diferencia incremental

--- NeoFT/framework/TODO.txt (revision 103)
+++ NeoFT/framework/TODO.txt (revision 104)
@@ -1,4 +1,5 @@
1-・前景と背景に分かれた3Dオブジェクト(線路など用)
1+・プラグイン関連ファイルをParamReaderで抽象化、最終的にStreamで読み込むように
2+・前景と背景に分かれた3Dオブジェクト(線路など用)
23 ・選択UIの基本、ステータス表示の基本
34 ・MRT昼夜同時描画/HitTest用マップ
45
--- NeoFT/framework/framework/TestUtil.cs (revision 103)
+++ NeoFT/framework/framework/TestUtil.cs (revision 104)
@@ -44,10 +44,14 @@
4444 get { return monitor; }
4545 }
4646
47- [TestEntry(new object[]{"あああ",123})]
48- [TestEntry("Test2", new object[] { "ううう", 10101.01 })]
49- private static bool TestOfTestUtil(string arg1, int arg2) {
50- Debug.WriteLine(String.Format("Test called: arg text={0} arg int2={1}",arg1,arg2*2));
47+ [TestEntry(new object[]{"あああ", 123, 2.0f})]
48+ //[TestEntry(new object[] { "いいい", 1 })] // Argument Count Mismatch
49+ //[TestEntry("Test2", new object[] { "ううう", "x", 0.1f })] // Argument Type Mismatch
50+ //[TestEntry(new object[] { "えええ", 123, float.NaN })] // Cause TargetInvocationException
51+ private static bool TestOfTestUtil(string arg1, int arg2, float arg3) {
52+ float r = arg3 * arg2;
53+ if (float.IsNaN(r)) throw new Exception("Wrong result!");
54+ Debug.WriteLine(String.Format("Test called: arg text={0} arg arg2 x arg3={1}",arg1,r));
5155 return true;
5256 }
5357 }
--- NeoFT/framework/framework/loader/XmlParamParser.cs (revision 103)
+++ NeoFT/framework/framework/loader/XmlParamParser.cs (revision 104)
@@ -6,11 +6,11 @@
66
77 namespace nft.framework.loader
88 {
9- class XmlParamParser : IParamsParser
9+ public class XmlParamParser : IParamsParser
1010 {
1111 protected XmlNode node;
1212 public XmlParamParser(XmlNode xnode) {
13-
13+ this.node = xnode;
1414 }
1515
1616 public string InnerText {
@@ -33,9 +33,11 @@
3333 }
3434
3535 public IEnumerator<IParamsParser> EnumChildren(string key) {
36- XmlAttribute a = node.Attributes[key];
37- if (a != null) {
38- yield return new PlainStringParam(a.Value);
36+ if (node.Attributes != null) {
37+ XmlAttribute a = node.Attributes[key];
38+ if (a != null) {
39+ yield return new PlainStringParam(a.Value);
40+ }
3941 }
4042 foreach (XmlNode n in node.SelectNodes(key)) {
4143 yield return new XmlParamParser(n);
--- NeoFT/framework/framework/ParamsReader.cs (revision 103)
+++ NeoFT/framework/framework/ParamsReader.cs (revision 104)
@@ -10,11 +10,11 @@
1010 private IParamsParser[] loader;
1111
1212 public ParamsReader(IParamsParser ploader) {
13- PrimaryLoader = ploader != null ? ploader : NullParam.TheInstance;
13+ Loaders = ploader != null ? new IParamsParser[] { ploader } : null;
1414 }
1515
1616 protected ParamsReader(IParamsParser[] ploaders) {
17- loader = ploaders != null ? ploaders : new IParamsParser[0];
17+ Loaders = ploaders;
1818 }
1919
2020 public string InnerText {
@@ -23,6 +23,9 @@
2323
2424 public ParamsReader this[string key] {
2525 get {
26+ if (key == null || key.Length == 0) {
27+ return new ParamsReader(NullParam.TheInstance);
28+ }
2629 String[] keys = key.Split('|');
2730 if (keys.Length == 1) {
2831 IParamsParser[] parr = FindForKey(PrimaryLoader, keys[0]);
@@ -35,8 +38,12 @@
3538 }
3639
3740 public ParamsReader this[int index] {
38- get {
39- return new ParamsReader(loader[index]);
41+ get {
42+ if (index < 0 || index >= loader.Length) {
43+ return new ParamsReader(NullParam.TheInstance);
44+ } else {
45+ return new ParamsReader(loader[index]);
46+ }
4047 }
4148 }
4249
@@ -56,21 +63,21 @@
5663 get { return loader.Length; }
5764 }
5865
59- public IEnumerator<IParamsParser> EnumChildren(string key) {
60- throw new NotImplementedException();
66+
67+ public IEnumerable<ParamsReader> Enum {
68+ get {
69+ return new ParamsReaderEnumerator(loader);
70+ }
6171 }
6272
73+ public IEnumerable<ParamsReader> EnumChildren(string key) {
74+ return new KeyedParamsReaderEnumerator(loader, key);
75+ }
76+
6377 protected IParamsParser PrimaryLoader {
6478 get {
65- return loader[0];
79+ return loader.Length>0 ? loader[0]:NullParam.TheInstance;
6680 }
67- set {
68- if (value != null) {
69- loader = new IParamsParser[] { value };
70- } else {
71- loader = new IParamsParser[0];
72- }
73- }
7481 }
7582
7683 protected IParamsParser[] Loaders {
@@ -100,8 +107,9 @@
100107 IEnumerator<KeyValuePair<String, IParamsParser>> en = p.EnumChildren();
101108 while (en.MoveNext()) {
102109 foreach (String k in keys) {
103- if (en.Current.Key.Equals(keys)) {
104- arr.Add(en.Current.Value);
110+ KeyValuePair<String, IParamsParser> pair = en.Current;
111+ if (pair.Key.Equals(k)) {
112+ arr.Add(pair.Value);
105113 break;
106114 }
107115 }
@@ -108,5 +116,66 @@
108116 }
109117 return arr.ToArray();
110118 }
119+
120+ internal protected class ParamsReaderEnumerator : IEnumerable<ParamsReader>
121+ {
122+ protected readonly IParamsParser[] array;
123+
124+ public ParamsReaderEnumerator(IParamsParser[] arr) {
125+ if (arr == null) arr = new IParamsParser[0];
126+ this.array = arr;
127+ }
128+
129+ public IEnumerator<ParamsReader> GetEnumerator() {
130+ foreach (IParamsParser pp in array) {
131+ yield return new ParamsReader(pp);
132+ }
133+ }
134+
135+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
136+ return GetEnumerator();
137+ }
138+ }
139+
140+ internal protected class KeyedParamsReaderEnumerator : IEnumerable<ParamsReader>
141+ {
142+ protected readonly IParamsParser[] array;
143+ protected readonly string key;
144+
145+ public KeyedParamsReaderEnumerator(IParamsParser[] arr, string key) {
146+ if (arr == null) arr = new IParamsParser[0];
147+ this.array = arr;
148+ this.key = key;
149+ }
150+
151+ public IEnumerator<ParamsReader> GetEnumerator() {
152+ if(key==null) yield break;
153+ String[] keys = key.Split('|');
154+ if (keys.Length == 1) {
155+ foreach (IParamsParser pp in array) {
156+ IEnumerator<IParamsParser> en = pp.EnumChildren(key);
157+ while (en.MoveNext()) {
158+ yield return new ParamsReader(en.Current);
159+ }
160+ }
161+ } else {
162+ foreach (IParamsParser pp in array) {
163+ IEnumerator<KeyValuePair<String, IParamsParser>> en = pp.EnumChildren();
164+ while (en.MoveNext()) {
165+ foreach (String k in keys) {
166+ if (en.Current.Key.Equals(keys)) {
167+ yield return new ParamsReader(en.Current.Value);
168+ break;
169+ }
170+ }
171+ }
172+ }
173+ }
174+ }
175+
176+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
177+ return GetEnumerator();
178+ }
179+ }
111180 }
112181 }
--- NeoFT/TestLauncher/test/ParamsReaderTest.cs (nonexistent)
+++ NeoFT/TestLauncher/test/ParamsReaderTest.cs (revision 104)
@@ -0,0 +1,41 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using nft.framework;
6+using System.Xml;
7+using nft.util;
8+using nft.framework.loader;
9+using System.Diagnostics;
10+
11+namespace nft.test.test
12+{
13+ class ParamsReaderTest
14+ {
15+ static readonly string xmlPath = @"\system\plugin.xml";
16+ static XmlDocument doc;
17+
18+ static ParamsReaderTest() {
19+ string path = Directories.PluginDir + xmlPath;
20+ doc = XmlUtil.LoadFile(path);
21+ }
22+
23+ [TestEntry]
24+ static private void TestXmlParser(){
25+ XmlParamParser parser = new XmlParamParser(doc);
26+ ParamsReader reader = new ParamsReader(parser);
27+ ParamsReader r2 = reader["plug-in "];
28+ Debug.WriteLine("title = " + r2["title"].InnerText);
29+ foreach (ParamsReader r3 in r2.EnumChildren("contribution")) {
30+ Debug.Write("name = " + r3["name"].InnerText);
31+ Debug.WriteLine(", ID = " + r3["id"].InnerText);
32+ Debug.WriteLine("impl or class = " + r3["class|implementation"]["name"].InnerText);
33+ ParamsReader r4 = r3["command"];
34+ if (!r4.IsNull) {
35+ Debug.WriteLine("command = " + r4["menupath"].InnerText);
36+ }
37+ }
38+ }
39+
40+ }
41+}
--- NeoFT/TestLauncher/TestLauncher.cs (revision 103)
+++ NeoFT/TestLauncher/TestLauncher.cs (revision 104)
@@ -31,7 +31,7 @@
3131 if (!init) {
3232 init = true;
3333 // TODO: カスタム属性をつけたメソッドを集められないか?
34- Assembly[] a = new Assembly[] { typeof(TestUtil).Assembly };
34+ Assembly[] a = new Assembly[] { Assembly.GetExecutingAssembly(), typeof(TestUtil).Assembly };
3535 LoadAssemblies(a);
3636 listEntryView.AdjustColumns();
3737 }
--- NeoFT/TestLauncher/Program.cs (revision 103)
+++ NeoFT/TestLauncher/Program.cs (revision 104)
@@ -3,6 +3,9 @@
33 using System.Linq;
44 using System.Windows.Forms;
55 using System.Diagnostics;
6+using nft.framework;
7+using System.Collections;
8+using System.IO;
69
710 namespace nft.test
811 {
@@ -16,6 +19,9 @@
1619 static void Main() {
1720 Application.EnableVisualStyles();
1821 Application.SetCompatibleTextRenderingDefault(false);
22+ Hashtable h = new Hashtable();
23+ h.Add("-B",Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,@"..\..\.."));
24+ Directories.Initialize(h);
1925 window = new TestLauncher();
2026 Debug.Listeners.Add(window.TraceListener);
2127 Application.Run(window);
--- NeoFT/TestLauncher/TestEntryListView.cs (revision 103)
+++ NeoFT/TestLauncher/TestEntryListView.cs (revision 104)
@@ -18,9 +18,9 @@
1818 protected int stateColumn;
1919 public ToolStripLabel statusLabel = null;
2020 protected bool ignoreStatusUpdate = false;
21- private static readonly string EntryStartLogText = "<<<<<<<- Start of {0} <<<<<<<-";
21+ private static readonly string EntryStartLogText = "vvvvvv Start of {0} vvvvvv";
2222 private ImageList iconList;
23- private static readonly string EntryEndLogText = "->>>>>>> End of {0} ->>>>>>>";
23+ private static readonly string EntryEndLogText = "^^^^^^ End of {0} ^^^^^^";
2424
2525 public TestEntryListView() {
2626 InitListView();
@@ -200,8 +200,15 @@
200200 TestInfo info = (TestInfo)item.Tag;
201201 info.Run();
202202 item.SubItems[stateColumn].Text = GetStatusText(info);
203+ Debug.WriteLineIf(info.TestState != TestState.Success,"### ERROR ###");
203204 item.SubItems[resultColumn].Text = "" + info.LastResult;
205+ if (info.LastResult is Exception) {
206+ Exception ex = (Exception)info.LastResult;
207+ Debug.WriteLine(ex.GetType().Name +":"+ ex.Message);
208+ Debug.WriteLine(ex.StackTrace);
209+ }
204210 Debug.WriteLine(EndLogText(item));
211+ Debug.WriteLine("");
205212 if (!ignoreStatusUpdate) {
206213 UpdateStatusLabel();
207214 }
Show on old repository browser