[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 / Template / TSDataTemplate.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Collections.Generic;
7 using System.Threading.Tasks;
8 using Tizen.NUI.Binding;
9
10 namespace Tizen.NUI.Devel.Tests
11 {
12     using tlog = Tizen.Log;
13
14     [TestFixture]
15     [Description("public/Template/DataTemplate")]
16     public class PublicDataTemplateTest
17     {
18         private const string tag = "NUITEST";
19         private static readonly Condition condition;
20         private string path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "index.xml";
21
22         private void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
23         {
24             if ((bool)oldValue == (bool)newValue) return;
25
26             condition.ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue);
27         }
28
29         internal class MyDataTemplateTest : DataTemplate
30         {
31             public MyDataTemplateTest() : base()
32             { }
33
34             public void OnSetupContent(object value)
35             {
36                 base.SetupContent(value);
37             }
38         }
39
40         [SetUp]
41         public void Init()
42         {
43             tlog.Info(tag, "Init() is called!");
44         }
45
46         [TearDown]
47         public void Destroy()
48         {
49             tlog.Info(tag, "Destroy() is called!");
50         }
51
52         [Test]
53         [Category("P1")]
54         [Description("DataTemplate constructor.")]
55         [Property("SPEC", "Tizen.NUI.DataTemplate.DataTemplate C")]
56         [Property("SPEC_URL", "-")]
57         [Property("CRITERIA", "CONSTR")]
58         [Property("AUTHOR", "guowei.wang@samsung.com")]
59         public void DataTemplateConstructor()
60         {
61             tlog.Debug(tag, $"DataTemplateConstructor START");
62
63             var testingTarget = new DataTemplate();
64             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
65             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
66
67             tlog.Debug(tag, $"DataTemplateConstructor END (OK)");
68         }
69
70         [Test]
71         [Category("P1")]
72         [Description("DataTemplate constructor. With Type.")]
73         [Property("SPEC", "Tizen.NUI.DataTemplate.DataTemplate C")]
74         [Property("SPEC_URL", "-")]
75         [Property("CRITERIA", "CONSTR")]
76         [Property("AUTHOR", "guowei.wang@samsung.com")]
77         public void DataTemplateConstructorWithType()
78         {
79             tlog.Debug(tag, $"DataTemplateConstructorWithType START");
80
81             string str = "myDataTemplate";
82             var testingTarget = new DataTemplate(str.GetType());
83             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
84             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
85
86             tlog.Debug(tag, $"DataTemplateConstructorWithType END (OK)");
87         }
88
89         [Test]
90         [Category("P1")]
91         [Description("DataTemplate constructor. With Func.")]
92         [Property("SPEC", "Tizen.NUI.DataTemplate.DataTemplate C")]
93         [Property("SPEC_URL", "-")]
94         [Property("CRITERIA", "CONSTR")]
95         [Property("AUTHOR", "guowei.wang@samsung.com")]
96         public void DataTemplateConstructorWithFunc()
97         {
98             tlog.Debug(tag, $"DataTemplateConstructorWithFunc START");
99
100             Func<object> LoadTemplate = () => new View();
101
102             var testingTarget = new DataTemplate(LoadTemplate);
103             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
104             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
105
106             tlog.Debug(tag, $"DataTemplateConstructorWithFunc END (OK)");
107         }
108
109         [Test]
110         [Category("P1")]
111         [Description("DataTemplate SetBinding.")]
112         [Property("SPEC", "Tizen.NUI.DataTemplate.SetBinding M")]
113         [Property("SPEC_URL", "-")]
114         [Property("CRITERIA", "MR")]
115         [Property("AUTHOR", "guowei.wang@samsung.com")]
116         public void DataTemplateSetBinding()
117         {
118             tlog.Debug(tag, $"DataTemplateSetBinding START");
119
120             BindingBase binding = new Tizen.NUI.Binding.Binding() as BindingBase;
121             BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
122  
123             var testingTarget = new DataTemplate();
124             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
125             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
126
127             try
128             {
129                 testingTarget.SetBinding(stateProperty, binding);
130             }
131             catch (Exception e)
132             {
133                 Assert.Fail("SetBinding Fail!");
134             }
135
136             tlog.Debug(tag, $"DataTemplateSetBinding END (OK)");
137         }
138
139         [Test]
140         [Category("P1")]
141         [Description("DataTemplate SetBinding. With null BindableProperty.")]
142         [Property("SPEC", "Tizen.NUI.DataTemplate.SetBinding M")]
143         [Property("SPEC_URL", "-")]
144         [Property("CRITERIA", "MR")]
145         [Property("AUTHOR", "guowei.wang@samsung.com")]
146         public void DataTemplateSetBindingWithNullBindableProperty()
147         {
148             tlog.Debug(tag, $"DataTemplateSetBindingWithNullBindableProperty START");
149
150             BindingBase binding = new Tizen.NUI.Binding.Binding() as BindingBase;
151
152             var testingTarget = new DataTemplate();
153             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
154             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
155
156             try
157             {
158                 testingTarget.SetBinding(null, binding);
159             }
160             catch (ArgumentNullException e)
161             {
162                 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty END (OK)");
163                 Assert.Pass("Caught ArgumentNullException: Pass!");
164             }
165         }
166
167         [Test]
168         [Category("P1")]
169         [Description("DataTemplate SetBinding. With null BindingBase.")]
170         [Property("SPEC", "Tizen.NUI.DataTemplate.SetBinding M")]
171         [Property("SPEC_URL", "-")]
172         [Property("CRITERIA", "MR")]
173         [Property("AUTHOR", "guowei.wang@samsung.com")]
174         public void DataTemplateSetBindingWithNullBindingBase()
175         {
176             tlog.Debug(tag, $"DataTemplateSetBindingWithNullBindingBase START");
177
178             BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
179
180             var testingTarget = new DataTemplate();
181             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
182             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
183
184             try
185             {
186                 testingTarget.SetBinding(stateProperty, null);
187             }
188             catch (ArgumentNullException e)
189             {
190                 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty END (OK)");
191                 Assert.Pass("Caught ArgumentNullException: Pass!");
192             }
193         }
194
195         [Test]
196         [Category("P1")]
197         [Description("DataTemplate SetValue.")]
198         [Property("SPEC", "Tizen.NUI.DataTemplate.SetValue M")]
199         [Property("SPEC_URL", "-")]
200         [Property("CRITERIA", "MR")]
201         [Property("AUTHOR", "guowei.wang@samsung.com")]
202         public void DataTemplateSetValue()
203         {
204             tlog.Debug(tag, $"DataTemplateSetValue START");
205
206             BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
207
208             var testingTarget = new DataTemplate();
209             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
210             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
211
212             try
213             {
214                 testingTarget.SetValue(stateProperty, true);
215             }
216             catch (Exception e)
217             {
218                 Assert.Fail("SetValue Fail!");
219             }
220
221             tlog.Debug(tag, $"DataTemplateSetValue END (OK)");
222         }
223
224         [Test]
225         [Category("P1")]
226         [Description("DataTemplate SetValue. With null BindableProperty.")]
227         [Property("SPEC", "Tizen.NUI.DataTemplate.SetValue M")]
228         [Property("SPEC_URL", "-")]
229         [Property("CRITERIA", "MR")]
230         [Property("AUTHOR", "guowei.wang@samsung.com")]
231         public void DataTemplateSetValueWithNullBindableProperty()
232         {
233             tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty START");
234
235             var testingTarget = new DataTemplate();
236             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
237             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
238
239             try
240             {
241                 testingTarget.SetValue(null, true);
242             }
243             catch (ArgumentNullException e)
244             {
245                 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty END (OK)");
246                 Assert.Pass("Caught ArgumentNullException: Pass!");
247             }
248         }
249
250         //[Test]
251         //[Category("P1")]
252         //[Description("DataTemplate SetupContent.")]
253         //[Property("SPEC", "Tizen.NUI.DataTemplate.SetupContent M")]
254         //[Property("SPEC_URL", "-")]
255         //[Property("CRITERIA", "MR")]
256         //[Property("AUTHOR", "guowei.wang@samsung.com")]
257         //public void DataTemplateSetupContent()
258         //{
259         //    tlog.Debug(tag, $"DataTemplateSetupContent START");
260
261         //    BindingBase binding = new Tizen.NUI.Binding.Binding(path) as BindingBase;
262         //    BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
263
264         //    var testingTarget = new MyDataTemplateTest();
265         //    Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
266         //    Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
267
268         //    testingTarget.SetBinding(stateProperty, binding);
269         //    testingTarget.SetValue(stateProperty, true);
270
271         //    try
272         //    {
273         //        ViewStyle style = new ViewStyle();
274         //        testingTarget.OnSetupContent(style);
275         //    }
276         //    catch (InvalidOperationException e)
277         //    {
278         //        tlog.Debug(tag, e.Message.ToString());
279         //        tlog.Debug(tag, $"DataTemplateSetupContent END (OK)");
280         //        Assert.Pass("Caught InvalidOperationException : Passed!");
281         //    }
282         //}
283
284         [Test]
285         [Category("P1")]
286         [Description("DataTemplate SetupContent. With null bandable.")]
287         [Property("SPEC", "Tizen.NUI.DataTemplate.SetupContent M")]
288         [Property("SPEC_URL", "-")]
289         [Property("CRITERIA", "MR")]
290         [Property("AUTHOR", "guowei.wang@samsung.com")]
291         public void DataTemplateSetupContentWithNullBindable()
292         {
293             tlog.Debug(tag, $"DataTemplateSetupContentWithNullBindable START");
294
295             BindingBase binding = new Tizen.NUI.Binding.Binding() as BindingBase;
296             BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
297
298             var testingTarget = new MyDataTemplateTest();
299             Assert.IsNotNull(testingTarget, "Can't create success object DataTemplate");
300             Assert.IsInstanceOf<DataTemplate>(testingTarget, "Should be an instance of DataTemplate type.");
301
302             testingTarget.SetBinding(stateProperty, binding);
303
304             try
305             {
306                 testingTarget.OnSetupContent(null);
307             }
308             catch (Exception e)
309             {
310                 Assert.Fail("Fail!");
311             }
312
313             tlog.Debug(tag, $"DataTemplateSetupContentWithNullBindable END (OK)");
314         }
315
316     }
317 }