1 using NUnit.Framework;
3 using System.Collections;
4 using System.Collections.Generic;
6 using Tizen.NUI.Binding;
9 namespace Tizen.NUI.Devel.Tests
11 using tlog = Tizen.Log;
13 internal class MockNameSpaceResolver : IXmlNamespaceResolver
15 public global::System.Collections.Generic.IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
17 throw new NotImplementedException();
20 public string LookupNamespace(string prefix)
25 public string LookupPrefix(string namespaceName)
32 [Description("internal/Xaml/ApplyPropertiesVisitor")]
33 public class InternalApplyPropertiesVisitorTest
35 private const string tag = "NUITEST";
36 private ApplyPropertiesVisitor visitor;
38 public class MarkupExtension : IMarkupExtension
40 public object ProvideValue(global::System.IServiceProvider serviceProvider)
42 return "provided value";
46 public class ArrayListOwner
48 public ArrayList ArrayList { get; } = new ArrayList();
51 internal class INodeImpl : INode
53 public global::System.Collections.Generic.List<string> IgnorablePrefixes { get; set; }
54 public global::System.Xml.IXmlNamespaceResolver NamespaceResolver => new INodeImpl().NamespaceResolver;
55 public INode Parent { get; set; }
56 public void Accept(IXamlNodeVisitor visitor, INode parentNode) { }
57 public INode Clone() { return new INodeImpl(); }
63 tlog.Info(tag, "Init() is called!");
64 visitor = new ApplyPropertiesVisitor(new HydrationContext(), false);
71 tlog.Info(tag, "Destroy() is called!");
75 [Description("ApplyPropertiesVisitor ApplyPropertiesVisitor")]
76 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.ApplyPropertiesVisitor C")]
77 [Property("SPEC_URL", "-")]
78 [Property("CRITERIA", "CONSTR")]
79 public void ApplyPropertiesVisitorConstructor()
81 tlog.Debug(tag, $"ApplyPropertiesVisitorConstructor START");
83 HydrationContext context = new HydrationContext();
84 Assert.IsNotNull(context, "null HydrationContext");
86 ApplyPropertiesVisitor applyPropertiesVisitor = new ApplyPropertiesVisitor(context, false);
87 Assert.IsNotNull(applyPropertiesVisitor, "null ApplyPropertiesVisitor");
88 Assert.IsInstanceOf<ApplyPropertiesVisitor>(applyPropertiesVisitor, "Should return ApplyPropertiesVisitor instance.");
90 tlog.Debug(tag, $"ApplyPropertiesVisitorConstructor END");
95 [Description("ApplyPropertiesVisitor VisitingMode")]
96 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.VisitingMode A")]
97 [Property("SPEC_URL", "-")]
98 [Property("CRITERIA", "PRW")]
99 public void ApplyPropertiesVisitorVisitingMode()
101 tlog.Debug(tag, $"ApplyPropertiesVisitorVisitingMode START");
105 var result = visitor.VisitingMode;
106 tlog.Debug(tag, "VisitingMode : " + result);
110 tlog.Debug(tag, e.Message.ToString());
111 Assert.Fail("Caught Exception : Failed!");
114 tlog.Debug(tag, $"ApplyPropertiesVisitorVisitingMode END");
119 [Description("ApplyPropertiesVisitor StopOnDataTemplate")]
120 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.StopOnDataTemplate A")]
121 [Property("SPEC_URL", "-")]
122 [Property("CRITERIA", "PRW")]
123 public void ApplyPropertiesVisitorStopOnDataTemplate()
125 tlog.Debug(tag, $"ApplyPropertiesVisitorStopOnDataTemplate START");
129 var result = visitor.StopOnDataTemplate;
130 tlog.Debug(tag, "StopOnDataTemplate : " + result);
134 tlog.Debug(tag, e.Message.ToString());
135 Assert.Fail("Caught Exception : Failed!");
138 tlog.Debug(tag, $"ApplyPropertiesVisitorStopOnDataTemplate END");
143 [Description("ApplyPropertiesVisitor StopOnResourceDictionary ")]
144 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.StopOnResourceDictionary A")]
145 [Property("SPEC_URL", "-")]
146 [Property("CRITERIA", "PRW")]
147 public void ApplyPropertiesVisitorStopOnResourceDictionary()
149 tlog.Debug(tag, $"ApplyPropertiesVisitorStopOnResourceDictionary START");
153 var result = visitor.StopOnResourceDictionary;
154 tlog.Debug(tag, "StopOnResourceDictionary : " + result);
158 tlog.Debug(tag, e.Message.ToString());
159 Assert.Fail("Caught Exception : Failed!");
162 tlog.Debug(tag, $"ApplyPropertiesVisitorStopOnResourceDictionary END");
167 [Description("ApplyPropertiesVisitor VisitNodeOnDataTemplate ")]
168 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.VisitNodeOnDataTemplate A")]
169 [Property("SPEC_URL", "-")]
170 [Property("CRITERIA", "PRW")]
171 public void ApplyPropertiesVisitorVisitNodeOnDataTemplate()
173 tlog.Debug(tag, $"ApplyPropertiesVisitorVisitNodeOnDataTemplate START");
177 var result = visitor.VisitNodeOnDataTemplate;
178 tlog.Debug(tag, "VisitNodeOnDataTemplate : " + result);
182 tlog.Debug(tag, e.Message.ToString());
183 Assert.Fail("Caught Exception : Failed!");
186 tlog.Debug(tag, $"ApplyPropertiesVisitorVisitNodeOnDataTemplate END");
191 [Description("ApplyPropertiesVisitor SkipChildren")]
192 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.SkipChildren M")]
193 [Property("SPEC_URL", "-")]
194 [Property("CRITERIA", "MR")]
195 public void ApplyPropertiesVisitorSkipChildren()
197 tlog.Debug(tag, $"ApplyPropertiesVisitorSkipChildren START");
201 var child = new INodeImpl();
202 Assert.IsNotNull(child, "null INodeImpl object.");
204 var parent = new INodeImpl();
205 Assert.IsNotNull(parent, "null INodeImpl object.");
207 var result = visitor.SkipChildren(child, parent);
208 tlog.Debug(tag, "SkipChildren : " + result);
212 tlog.Debug(tag, e.Message.ToString());
213 Assert.Fail("Caught Exception : Failed!");
216 tlog.Debug(tag, $"ApplyPropertiesVisitorSkipChildren END");
219 public class IXmlNamespaceResolverImplement : IXmlNamespaceResolver
221 public IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
223 throw new NotImplementedException();
226 public string LookupNamespace(string prefix)
228 throw new NotImplementedException();
231 public string LookupPrefix(string namespaceName)
233 throw new NotImplementedException();
239 [Description("ApplyPropertiesVisitor IsResourceDictionary")]
240 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.IsResourceDictionary M")]
241 [Property("SPEC_URL", "-")]
242 [Property("CRITERIA", "MR")]
243 public void ApplyPropertiesVisitorIsResourceDictionary()
245 tlog.Debug(tag, $"ApplyPropertiesVisitorIsResourceDictionary START");
249 HydrationContext context = new HydrationContext();
250 IList<XmlType> list = new List<XmlType>();
251 XmlType xmlType = new XmlType("myNameSpace", "myName", list);
252 Assert.IsNotNull(xmlType, "null XmlType");
253 IXmlNamespaceResolverImplement i1 = new IXmlNamespaceResolverImplement();
254 Assert.IsNotNull(i1, "null IXmlNamespaceResolverImplement");
255 ElementNode n1 = new ElementNode(xmlType, "myNameSpace", i1);
256 Assert.IsNotNull(n1, "null ElementNode");
257 context.Types[n1] = typeof(ResourceDictionary);
258 ApplyPropertiesVisitor a2 = new ApplyPropertiesVisitor(context, false);
259 Assert.IsNotNull(a2, "null ApplyPropertiesVisitor");
260 bool b1 = a2.IsResourceDictionary(n1);
261 Assert.True(b1, "Should be true");
265 tlog.Debug(tag, e.Message.ToString());
266 Assert.Fail("Caught Exception" + e.ToString());
268 tlog.Debug(tag, $"ApplyPropertiesVisitorIsResourceDictionary END");
274 [Description("ApplyPropertiesVisitor Visit")]
275 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.Visit M")]
276 [Property("SPEC_URL", "-")]
277 [Property("CRITERIA", "MR")]
278 public void ApplyPropertiesVisitorVisit1()
280 tlog.Debug(tag, $"ApplyPropertiesVisitorVisit1 START");
284 HydrationContext context = new HydrationContext();
285 object o1 = new object();
286 IXmlNamespaceResolverImplement i1 = new IXmlNamespaceResolverImplement();
287 Assert.IsNotNull(i1, "null IXmlNamespaceResolverImplement");
288 ValueNode valueNode = new ValueNode(o1, i1);
289 Assert.IsNotNull(valueNode, "null ValueNode");
291 INodeImpl nodeImplement = new INodeImpl();
292 Assert.IsNotNull(nodeImplement, "null INodeImplement");
293 context.Values[valueNode] = o1;
294 context.Values[nodeImplement] = o1;
295 ApplyPropertiesVisitor a2 = new ApplyPropertiesVisitor(context, false);
296 Assert.IsNotNull(a2, "null ApplyPropertiesVisitor");
297 a2.Visit(valueNode, nodeImplement);
301 tlog.Debug(tag, e.Message.ToString());
302 Assert.Fail("Caught Exception" + e.ToString());
304 tlog.Debug(tag, $"ApplyPropertiesVisitorVisit1 END");
309 [Description("ApplyPropertiesVisitor Visit")]
310 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.Visit M")]
311 [Property("SPEC_URL", "-")]
312 [Property("CRITERIA", "MR")]
313 public void ApplyPropertiesVisitorVisit2()
315 tlog.Debug(tag, $"ApplyPropertiesVisitorVisit2 START");
319 HydrationContext context = new HydrationContext();
320 object o1 = new object();
321 INodeImpl nodeImplement = new INodeImpl();
322 Assert.IsNotNull(nodeImplement, "null INodeImplement");
324 IList<XmlType> list = null;
325 XmlType xmlType = new XmlType("myNameSpace", "myName", list);
326 Assert.IsNotNull(xmlType, "null XmlType");
327 IXmlNamespaceResolverImplement ix1 = new IXmlNamespaceResolverImplement();
328 Assert.IsNotNull(ix1, "null IXmlNamespaceResolverImplement");
329 ElementNode n1 = new ElementNode(xmlType, "myNameSpace", ix1);
330 Assert.IsNotNull(n1, "null ElementNode");
331 context.Values[n1] = o1;
332 context.Values[nodeImplement] = o1;
333 ApplyPropertiesVisitor a2 = new ApplyPropertiesVisitor(context, false);
334 Assert.IsNotNull(a2, "null ApplyPropertiesVisitor");
335 a2.Visit(n1, nodeImplement);
339 tlog.Debug(tag, e.Message.ToString());
340 Assert.Fail("Caught Exception" + e.ToString());
342 tlog.Debug(tag, $"ApplyPropertiesVisitorVisit2 END");
348 [Description("ApplyPropertiesVisitor TryGetPropertyName")]
349 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.TryGetPropertyName M")]
350 [Property("SPEC_URL", "-")]
351 [Property("CRITERIA", "MR")]
352 public void ApplyPropertiesVisitorTryGetPropertyName()
354 tlog.Debug(tag, $"ApplyPropertiesVisitorTryGetPropertyName START");
358 INodeImpl n1 = new INodeImpl();
359 Assert.IsNotNull(n1, "null INodeImplement");
360 INodeImpl n2 = new INodeImpl();
361 Assert.IsNotNull(n2, "null INodeImplement");
362 XmlName xmlName = new XmlName();
363 Assert.IsNotNull(xmlName, "null XmlName");
364 ApplyPropertiesVisitor.TryGetPropertyName(n1, n2, out xmlName);
368 Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
369 Assert.Fail("Caught Exception" + e.ToString());
372 tlog.Debug(tag, $"ApplyPropertiesVisitorTryGetPropertyName END");
377 [Description("ApplyPropertiesVisitor IsCollectionItem")]
378 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.IsCollectionItem M")]
379 [Property("SPEC_URL", "-")]
380 [Property("CRITERIA", "MR")]
381 public void ApplyPropertiesVisitorIsCollectionItem()
383 tlog.Debug(tag, $"ApplyPropertiesVisitorIsCollectionItem START");
387 INodeImpl n1 = new INodeImpl();
388 Assert.IsNotNull(n1, "null INodeImplement");
389 INodeImpl n2 = new INodeImpl();
390 Assert.IsNotNull(n2, "null INodeImplement");
392 ApplyPropertiesVisitor.IsCollectionItem(n1, n2);
396 Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
397 Assert.Fail("Caught Exception" + e.ToString());
400 tlog.Debug(tag, $"ApplyPropertiesVisitorIsCollectionItem END");
405 //[Description("ApplyPropertiesVisitor GetContentPropertyName")]
406 //[Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.GetContentPropertyName M")]
407 //[Property("SPEC_URL", "-")]
408 //[Property("CRITERIA", "MR")]
409 //public void ApplyPropertiesVisitorGetContentPropertyName()
411 // tlog.Debug(tag, $"ApplyPropertiesVisitorGetContentPropertyName START");
415 // System.Reflection.TypeInfo typeInfo = new System.Reflection.TypeInfo();
416 // ApplyPropertiesVisitor.GetContentPropertyName(typeInfo);
418 // catch (Exception e)
420 // Tizen.Log.Error(tag, "Caught Exception" + e.ToString());
421 // Assert.Fail("Caught Exception" + e.ToString());
424 // tlog.Debug(tag, $"ApplyPropertiesVisitorGetContentPropertyName END");
425 // Assert.Pass("ApplyPropertiesVisitorGetContentPropertyName");
428 public class IXmlLineInfoImplement : IXmlLineInfo
430 public int LineNumber => throw new NotImplementedException();
432 public int LinePosition => throw new NotImplementedException();
434 public bool HasLineInfo()
436 throw new NotImplementedException();
442 //[Description("ApplyPropertiesVisitor SetPropertyValue")]
443 //[Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.SetPropertyValue M")]
444 //[Property("SPEC_URL", "-")]
445 //[Property("CRITERIA", "MR")]
446 //public void ApplyPropertiesVisitorSetPropertyValue()
448 // tlog.Debug(tag, $"ApplyPropertiesVisitorSetPropertyValue START");
452 // object o1 = new object();
453 // XmlName xmlName = new XmlName();
454 // Assert.IsNotNull(xmlName, "null XmlName");
455 // object value = new object();
456 // object rootElement = new object();
457 // INodeImplement nodeImplement = new INodeImplement();
458 // Assert.IsNotNull(nodeImplement, "null INodeImplement");
459 // HydrationContext context = new HydrationContext();
460 // Assert.IsNotNull(context, "null HydrationContext");
461 // IXmlLineInfoImplement xmlLineInfoImplement = new IXmlLineInfoImplement();
462 // Assert.IsNotNull(xmlLineInfoImplement, "null IXmlLineInfoImplement");
464 // ApplyPropertiesVisitor.SetPropertyValue(o1, xmlName, value, rootElement, nodeImplement, context, xmlLineInfoImplement);
466 // catch (Exception e)
468 // tlog.Debug(tag, e.Message.ToString());
469 // Assert.Fail("Caught Exception" + e.ToString());
471 // tlog.Debug(tag, $"ApplyPropertiesVisitorSetPropertyValue END");
476 [Description("ApplyPropertiesVisitor GetPropertyValue")]
477 [Property("SPEC", "Tizen.NUI.ApplyPropertiesVisitor.GetPropertyValue M")]
478 [Property("SPEC_URL", "-")]
479 [Property("CRITERIA", "MR")]
480 public void ApplyPropertiesVisitorGetPropertyValue()
482 tlog.Debug(tag, $"ApplyPropertiesVisitorGetPropertyValue START");
486 const string NAMESPACE = "clr-namespace:Tizen.NUI.Devel.Tests;assembly=Tizen.NUI.Devel.Tests";
487 var resolver = new MockNameSpaceResolver();
488 var type = new XmlType(NAMESPACE, "InternalApplyPropertiesVisitorTest+MarkupExtension", null);
489 var listNode = new ListNode(new[]
491 new ElementNode(type, NAMESPACE, resolver),
492 new ElementNode(type, NAMESPACE, resolver)
494 var rootElement = new ArrayListOwner();
495 var rootType = new XmlType(NAMESPACE, "InternalApplyPropertiesVisitorTest+ArrayListOwner", null);
496 var rootNode = new XamlLoader.RuntimeRootNode(rootType, rootElement, null);
497 var context = new HydrationContext { RootElement = rootElement };
499 rootNode.Properties.Add(new XmlName(null, "ArrayList"), listNode);
500 rootNode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null);
501 rootNode.Accept(new CreateValuesVisitor(context), null);
502 rootNode.Accept(new ApplyPropertiesVisitor(context), null);
504 Assert.AreEqual("provided value", rootElement.ArrayList[0]);
505 Assert.AreEqual("provided value", rootElement.ArrayList[1]);
509 tlog.Debug(tag, e.Message.ToString());
510 Assert.Fail("Caught Exception" + e.ToString());
512 tlog.Debug(tag, $"ApplyPropertiesVisitorGetPropertyValue END");