3
using System.Collections;
11
public class TestConditions: TestBase
13
ParameterInfoCondition pinfo;
19
public override void Setup ()
23
pinfo = new ParameterInfoCondition ();
25
GlobalInfoCondition.Value = "res";
27
ctx = AddinManager.CreateExtensionContext ();
28
ctx.RegisterCondition ("InputParameter", pinfo);
31
void StartListenerCheck (string tid)
33
// Get the current writers
35
added = new Hashtable ();
36
removed = new Hashtable ();
38
ctx.AddExtensionNodeHandler ("/SimpleApp/ExtraWriters", OnExtensionAddRemove);
39
Assert.AreEqual (0, removed.Count, tid + ": RegisterExtensionListener should not remove");
42
added = new Hashtable ();
45
void EndListenerCheck (string tid)
47
IWriter[] writers = (IWriter[]) ctx.GetExtensionObjects ("/SimpleApp/ExtraWriters", typeof(IWriter));
49
Hashtable newwriters = new Hashtable ();
50
for (int n=0; n<writers.Length; n++) {
51
string nwrit = writers[n].Id;
54
if (oldwriters.Contains (nwrit)) {
55
Assert.IsFalse (added.Contains (nwrit), tid + ": incorrect Add event for node: " + writers[n].Write ());
56
Assert.IsFalse (removed.Contains (nwrit), tid + ": incorrect Remove event for node: " + writers[n].Write ());
58
Assert.IsTrue (added.Contains (nwrit), tid + ": Add event not sent for node: " + writers[n].Write ());
60
newwriters [nwrit] = nwrit;
63
// Check remove events
64
foreach (string old in oldwriters.Keys) {
65
if (!newwriters.Contains (old))
66
Assert.IsTrue (removed.Contains (old), tid + ": Remove event not sent for node: " + old);
69
ctx.RemoveExtensionNodeHandler ("/SimpleApp/ExtraWriters", OnExtensionAddRemove);
72
void CheckWriters (string tid, string gval, string pval, params string[] result)
76
StartListenerCheck (tid + " set InputParameter");
78
EndListenerCheck (tid + " set InputParameter");
80
StartListenerCheck (tid + " set GlobalInfo");
81
GlobalInfoCondition.Value = gval;
82
EndListenerCheck (tid + " set GlobalInfo");
84
// Get the new writers
86
IWriter[] writers = (IWriter[]) ctx.GetExtensionObjects ("/SimpleApp/ExtraWriters", typeof(IWriter));
87
Assert.AreEqual (result.Length, writers.Length, tid + ": result count");
89
for (int n=0; n<result.Length; n++) {
90
string nwrit = writers[n].Write ();
91
Assert.AreEqual (result[n], nwrit, tid + ": result #" + n);
95
void OnExtensionAddRemove (object s, ExtensionNodeEventArgs args)
97
IWriter w = (IWriter) ((TypeExtensionNode)args.ExtensionNode).CreateInstance ();
98
if (args.Change == ExtensionChange.Add)
105
public void TestAllFalse ()
107
// All conditions evaluate to false
117
public void TestSimpleCondition ()
119
// Simple condition is true
133
public void TestOr ()
135
string[] istrue = new string [] { "cmd:ca1", "cmd:ca2", "cmd:c1 x or y or yes", "cmd:c2 x or y or yes" };
137
CheckWriters ("t1", "", "x", istrue);
139
CheckWriters ("t2", "", "y", istrue);
141
CheckWriters ("t3", "yes", "", istrue);
143
CheckWriters ("t3", "yes", "x", istrue);
145
CheckWriters ("t3", "yes", "y", istrue);
149
public void TestAnd ()
151
string[] isfalse = new string [] { "cmd:ca1", "cmd:ca2" };
152
string[] istrue = new string [] { "cmd:ca1", "cmd:ca2", "cmd:c3 x1 and yes1", "cmd:c4 x1 and yes1" };
154
CheckWriters ("t1", "", "x1", isfalse);
156
CheckWriters ("t2", "yes1", "", isfalse);
158
CheckWriters ("t3", "yes1", "x1", istrue);
162
public void NestedTestOrAnd ()
164
string[] isfalse = new string [] { "cmd:ca1", "cmd:ca2" };
165
string[] istrue = new string [] { "cmd:ca1", "cmd:ca2", "cmd:cc5", "cmd:cc6" };
169
CheckWriters ("t1", "", "nx", isfalse);
171
CheckWriters ("t2", "nx1", "nx", istrue);
173
CheckWriters ("t3", "nx2", "nx", istrue);
175
CheckWriters ("t4", "nx1", "", isfalse);
177
CheckWriters ("t5", "nx2", "", isfalse);
181
CheckWriters ("t6", "", "ny", isfalse);
183
CheckWriters ("t7", "ny1", "ny", istrue);
185
CheckWriters ("t8", "ny2", "ny", istrue);
187
CheckWriters ("t9", "ny1", "", isfalse);
189
CheckWriters ("t10", "ny2", "", isfalse);
193
public void InnerCondition ()
195
CheckWriters ("t1", "", "ines1", "cmd:ca1", "cmd:ca2");
197
CheckWriters ("t2", "cnes", "", "cmd:ca1", "cmd:ca2", "cmd:cnes1", "cmd:cnes2");
199
CheckWriters ("t3", "cnes", "ines1", "cmd:ca1", "cmd:ca2", "cmd:cnes1", "cmd:cnes2", "cmd:ines1", "cmd:ines2");
203
public void InnerOrCondition ()
205
CheckWriters ("t1", "", "inesOr", "cmd:ca1", "cmd:ca2");
207
CheckWriters ("t2", "cnesOr", "", "cmd:ca1", "cmd:ca2", "cmd:cnesOr1", "cmd:cnesOr2");
209
CheckWriters ("t3", "cnesOr", "inesOr", "cmd:ca1", "cmd:ca2", "cmd:cnesOr1", "cmd:cnesOr2", "cmd:inesOr1", "cmd:inesOr2");
213
public void InnerAndCondition ()
215
CheckWriters ("t1", "", "inesAnd", "cmd:ca1", "cmd:ca2");
217
CheckWriters ("t2", "cnesAnd", "", "cmd:ca1", "cmd:ca2", "cmd:cnesAnd1", "cmd:cnesAnd2");
219
CheckWriters ("t3", "cnesAnd", "inesAnd", "cmd:ca1", "cmd:ca2", "cmd:cnesAnd1", "cmd:cnesAnd2", "cmd:inesAnd1", "cmd:inesAnd2");
223
public void ChildNodeConditions ()
225
CheckWriters ("t1", "testChildren", "tc1", "cmd:ca1", "cmd:ca2", "file:someFile1[child1][child2]");
228
GlobalInfoCondition.Value = "testChildren";
230
string[] result = new string [] {"cmd:ca1", "cmd:ca2", "file:someFile1[child1][child3]"};
232
IWriter[] writers = (IWriter[]) ctx.GetExtensionObjects ("/SimpleApp/ExtraWriters", typeof(IWriter));
233
Assert.AreEqual (result.Length, writers.Length, "t2: result count");
234
for (int n=0; n<result.Length; n++) {
235
string nwrit = writers[n].Write ();
236
Assert.AreEqual (result[n], nwrit, "t2: result #" + n);