[NUI] Update NUI.Devel to fix block and crash issues.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / Xaml / TSStaticResourceExtension.cs
1 using NUnit.Framework;
2 using System;
3 using System.Xml;
4 using Tizen.NUI.Xaml;
5
6 namespace Tizen.NUI.Devel.Tests
7 {
8     using tlog = Tizen.Log;
9
10     [TestFixture]
11     [Description("public/xaml/StaticResourceExtension")]
12     public class PublicStaticResourceExtensionTest
13     {
14         private const string tag = "NUITEST";
15         private static StaticResourceExtension resourceExtension;
16
17         internal class XmlLineInfoImplent : IXmlLineInfo
18         {
19             public int LineNumber => 16;
20
21             public int LinePosition => 8;
22
23             public bool HasLineInfo()
24             {
25                 return true;
26             }
27         }
28
29         internal class ServiceProviderImplemente : IServiceProvider
30         {
31             private static readonly object service = new object();
32
33             public object GetService(Type type)
34             {
35                 return service;
36             }
37         }
38
39         [SetUp]
40         public void Init()
41         {
42             tlog.Info(tag, "Init() is called!");
43             resourceExtension = new StaticResourceExtension();
44         }
45
46         [TearDown]
47         public void Destroy()
48         {
49             resourceExtension = null;
50             tlog.Info(tag, "Destroy() is called!");
51         }
52
53         [Test]
54         [Category("P1")]
55         [Description("StaticResourceExtension Key")]
56         [Property("SPEC", "Tizen.NUI.StaticResourceExtension.Key A")]
57         [Property("SPEC_URL", "-")]
58         [Property("CRITERIA", "PRW")]
59         [Property("AUTHOR", "guowei.wang@samsung.com")]
60         public void StaticResourceExtensionKey()
61         {
62             tlog.Debug(tag, $"StaticResourceExtensionKey START");
63             try
64             {
65                 var result = resourceExtension.Key;
66                 tlog.Debug(tag, "Key : " + result);
67                 resourceExtension.Key = "size";
68                 tlog.Debug(tag, "Key : " + result);
69             }
70             catch (Exception e)
71             {
72                 tlog.Debug(tag, "Caught Exception" + e.ToString());
73                 Assert.Fail("Caught Exception : Failed!");
74             }
75             tlog.Debug(tag, $"StaticResourceExtensionKey END (OK)");
76             Assert.Pass("StaticResourceExtensionKey");
77         }
78
79         [Test]
80         [Category("P1")]
81         [Description("StaticResourceExtension ProvideValue")]
82         [Property("SPEC", "Tizen.NUI.StaticResourceExtension.ProvideValue M")]
83         [Property("SPEC_URL", "-")]
84         [Property("CRITERIA", "MR")]
85         public void StaticResourceExtensionProvideValue()
86         {
87             tlog.Debug(tag, $"StaticResourceExtensionProvideValue START");
88
89             try
90             {
91                 ServiceProviderImplemente ss = new ServiceProviderImplemente();
92
93                 resourceExtension.Key = "myKey";
94                 resourceExtension.ProvideValue(ss);
95             }
96             catch (Exception e)
97             {
98                 tlog.Debug(tag, e.Message.ToString());
99                 tlog.Debug(tag, $"StaticResourceExtensionProvideValue END (OK)");
100                 Assert.Pass("Caught Exception : passed!");
101             }
102         }
103
104         [Test]
105         [Category("P2")]
106         [Description("StaticResourceExtension ProvideValue. Null serviceProvider.")]
107         [Property("SPEC", "Tizen.NUI.StaticResourceExtension.ProvideValue M")]
108         [Property("SPEC_URL", "-")]
109         [Property("CRITERIA", "MR")]
110         [Property("AUTHOR", "guowei.wang@samsung.com")]
111         public void StaticResourceExtensionProvideValueWithNullServiceProvder()
112         {
113             tlog.Debug(tag, $"StaticResourceExtensionProvideValueWithNullServiceProvder START");
114             try
115             {
116                 resourceExtension.ProvideValue(null);
117             }
118             catch (ArgumentNullException e)
119             {
120                 tlog.Debug(tag, e.Message.ToString());
121                 tlog.Debug(tag, $"StaticResourceExtensionProvideValueWithNullServiceProvder END (OK)");
122                 Assert.Pass("Caught ArgumentNullException : passed!");
123             }
124         }
125
126         [Test]
127         [Category("P2")]
128         [Description("StaticResourceExtension ProvideValue. Null Key.")]
129         [Property("SPEC", "Tizen.NUI.StaticResourceExtension.ProvideValue M")]
130         [Property("SPEC_URL", "-")]
131         [Property("CRITERIA", "MR")]
132         [Property("AUTHOR", "guowei.wang@samsung.com")]
133         public void StaticResourceExtensionProvideValueWithNullKey()
134         {
135             tlog.Debug(tag, $"StaticResourceExtensionProvideValueWithNullKey START");
136
137             var serviceProvider = new ServiceProviderImplemente();
138             Assert.IsNotNull(serviceProvider, "Can't create success object IServiceProvider");
139             Assert.IsInstanceOf<IServiceProvider>(serviceProvider, "Should be an instance of IServiceProvider type.");
140
141             resourceExtension.Key = null;
142
143             try
144             {
145                 resourceExtension.ProvideValue(serviceProvider);
146             }
147             catch (XamlParseException e)
148             {
149                 tlog.Debug(tag, $"StaticResourceExtensionProvideValueWithNullKey END (OK)");
150                 Assert.Pass("Caught XamlParseException : passed!");
151             }
152         }
153
154         [Test]
155         [Category("P1")]
156         [Description("StaticResourceExtension GetApplicationLevelResource")]
157         [Property("SPEC", "Tizen.NUI.StaticResourceExtension.GetApplicationLevelResource M")]
158         [Property("SPEC_URL", "-")]
159         [Property("CRITERIA", "MR")]
160         public void StaticResourceExtensionGetApplicationLevelResource()
161         {
162             tlog.Debug(tag, $"StaticResourceExtensionGetApplicationLevelResource START");
163
164             try
165             {
166                 XmlLineInfoImplent xx = new XmlLineInfoImplent();
167                 resourceExtension.GetApplicationLevelResource("mykey", xx);
168             }
169             catch (Exception e)
170             {
171                 tlog.Debug(tag, $"StaticResourceExtensionGetApplicationLevelResource END (OK)");
172                 Assert.Pass("StaticResource not found for key mykey : Passed!");
173             }
174         }
175     }
176 }