ParamsReaderの修正、テストコード
@@ -1,4 +1,5 @@ | ||
1 | -・前景と背景に分かれた3Dオブジェクト(線路など用) | |
1 | +・プラグイン関連ファイルをParamReaderで抽象化、最終的にStreamで読み込むように | |
2 | +・前景と背景に分かれた3Dオブジェクト(線路など用) | |
2 | 3 | ・選択UIの基本、ステータス表示の基本 |
3 | 4 | ・MRT昼夜同時描画/HitTest用マップ |
4 | 5 |
@@ -44,10 +44,14 @@ | ||
44 | 44 | get { return monitor; } |
45 | 45 | } |
46 | 46 | |
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)); | |
51 | 55 | return true; |
52 | 56 | } |
53 | 57 | } |
@@ -6,11 +6,11 @@ | ||
6 | 6 | |
7 | 7 | namespace nft.framework.loader |
8 | 8 | { |
9 | - class XmlParamParser : IParamsParser | |
9 | + public class XmlParamParser : IParamsParser | |
10 | 10 | { |
11 | 11 | protected XmlNode node; |
12 | 12 | public XmlParamParser(XmlNode xnode) { |
13 | - | |
13 | + this.node = xnode; | |
14 | 14 | } |
15 | 15 | |
16 | 16 | public string InnerText { |
@@ -33,9 +33,11 @@ | ||
33 | 33 | } |
34 | 34 | |
35 | 35 | 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 | + } | |
39 | 41 | } |
40 | 42 | foreach (XmlNode n in node.SelectNodes(key)) { |
41 | 43 | yield return new XmlParamParser(n); |
@@ -10,11 +10,11 @@ | ||
10 | 10 | private IParamsParser[] loader; |
11 | 11 | |
12 | 12 | public ParamsReader(IParamsParser ploader) { |
13 | - PrimaryLoader = ploader != null ? ploader : NullParam.TheInstance; | |
13 | + Loaders = ploader != null ? new IParamsParser[] { ploader } : null; | |
14 | 14 | } |
15 | 15 | |
16 | 16 | protected ParamsReader(IParamsParser[] ploaders) { |
17 | - loader = ploaders != null ? ploaders : new IParamsParser[0]; | |
17 | + Loaders = ploaders; | |
18 | 18 | } |
19 | 19 | |
20 | 20 | public string InnerText { |
@@ -23,6 +23,9 @@ | ||
23 | 23 | |
24 | 24 | public ParamsReader this[string key] { |
25 | 25 | get { |
26 | + if (key == null || key.Length == 0) { | |
27 | + return new ParamsReader(NullParam.TheInstance); | |
28 | + } | |
26 | 29 | String[] keys = key.Split('|'); |
27 | 30 | if (keys.Length == 1) { |
28 | 31 | IParamsParser[] parr = FindForKey(PrimaryLoader, keys[0]); |
@@ -35,8 +38,12 @@ | ||
35 | 38 | } |
36 | 39 | |
37 | 40 | 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 | + } | |
40 | 47 | } |
41 | 48 | } |
42 | 49 |
@@ -56,21 +63,21 @@ | ||
56 | 63 | get { return loader.Length; } |
57 | 64 | } |
58 | 65 | |
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 | + } | |
61 | 71 | } |
62 | 72 | |
73 | + public IEnumerable<ParamsReader> EnumChildren(string key) { | |
74 | + return new KeyedParamsReaderEnumerator(loader, key); | |
75 | + } | |
76 | + | |
63 | 77 | protected IParamsParser PrimaryLoader { |
64 | 78 | get { |
65 | - return loader[0]; | |
79 | + return loader.Length>0 ? loader[0]:NullParam.TheInstance; | |
66 | 80 | } |
67 | - set { | |
68 | - if (value != null) { | |
69 | - loader = new IParamsParser[] { value }; | |
70 | - } else { | |
71 | - loader = new IParamsParser[0]; | |
72 | - } | |
73 | - } | |
74 | 81 | } |
75 | 82 | |
76 | 83 | protected IParamsParser[] Loaders { |
@@ -100,8 +107,9 @@ | ||
100 | 107 | IEnumerator<KeyValuePair<String, IParamsParser>> en = p.EnumChildren(); |
101 | 108 | while (en.MoveNext()) { |
102 | 109 | 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); | |
105 | 113 | break; |
106 | 114 | } |
107 | 115 | } |
@@ -108,5 +116,66 @@ | ||
108 | 116 | } |
109 | 117 | return arr.ToArray(); |
110 | 118 | } |
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 | + } | |
111 | 180 | } |
112 | 181 | } |
@@ -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 | +} |
@@ -31,7 +31,7 @@ | ||
31 | 31 | if (!init) { |
32 | 32 | init = true; |
33 | 33 | // TODO: カスタム属性をつけたメソッドを集められないか? |
34 | - Assembly[] a = new Assembly[] { typeof(TestUtil).Assembly }; | |
34 | + Assembly[] a = new Assembly[] { Assembly.GetExecutingAssembly(), typeof(TestUtil).Assembly }; | |
35 | 35 | LoadAssemblies(a); |
36 | 36 | listEntryView.AdjustColumns(); |
37 | 37 | } |
@@ -3,6 +3,9 @@ | ||
3 | 3 | using System.Linq; |
4 | 4 | using System.Windows.Forms; |
5 | 5 | using System.Diagnostics; |
6 | +using nft.framework; | |
7 | +using System.Collections; | |
8 | +using System.IO; | |
6 | 9 | |
7 | 10 | namespace nft.test |
8 | 11 | { |
@@ -16,6 +19,9 @@ | ||
16 | 19 | static void Main() { |
17 | 20 | Application.EnableVisualStyles(); |
18 | 21 | Application.SetCompatibleTextRenderingDefault(false); |
22 | + Hashtable h = new Hashtable(); | |
23 | + h.Add("-B",Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,@"..\..\..")); | |
24 | + Directories.Initialize(h); | |
19 | 25 | window = new TestLauncher(); |
20 | 26 | Debug.Listeners.Add(window.TraceListener); |
21 | 27 | Application.Run(window); |
@@ -18,9 +18,9 @@ | ||
18 | 18 | protected int stateColumn; |
19 | 19 | public ToolStripLabel statusLabel = null; |
20 | 20 | protected bool ignoreStatusUpdate = false; |
21 | - private static readonly string EntryStartLogText = "<<<<<<<- Start of {0} <<<<<<<-"; | |
21 | + private static readonly string EntryStartLogText = "vvvvvv Start of {0} vvvvvv"; | |
22 | 22 | private ImageList iconList; |
23 | - private static readonly string EntryEndLogText = "->>>>>>> End of {0} ->>>>>>>"; | |
23 | + private static readonly string EntryEndLogText = "^^^^^^ End of {0} ^^^^^^"; | |
24 | 24 | |
25 | 25 | public TestEntryListView() { |
26 | 26 | InitListView(); |
@@ -200,8 +200,15 @@ | ||
200 | 200 | TestInfo info = (TestInfo)item.Tag; |
201 | 201 | info.Run(); |
202 | 202 | item.SubItems[stateColumn].Text = GetStatusText(info); |
203 | + Debug.WriteLineIf(info.TestState != TestState.Success,"### ERROR ###"); | |
203 | 204 | 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 | + } | |
204 | 210 | Debug.WriteLine(EndLogText(item)); |
211 | + Debug.WriteLine(""); | |
205 | 212 | if (!ignoreStatusUpdate) { |
206 | 213 | UpdateStatusLabel(); |
207 | 214 | } |