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;
10 namespace Tizen.NUI.Devel.Tests
12 using tlog = Tizen.Log;
15 [Description("public/Template/DataTemplate")]
16 public class PublicDataTemplateTest
18 private const string tag = "NUITEST";
19 private static readonly Condition condition;
20 private string path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "index.xml";
22 private void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
24 if ((bool)oldValue == (bool)newValue) return;
26 condition.ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue);
29 internal class MyDataTemplateTest : DataTemplate
31 public MyDataTemplateTest() : base()
34 public void OnSetupContent(object value)
36 base.SetupContent(value);
43 tlog.Info(tag, "Init() is called!");
49 tlog.Info(tag, "Destroy() is called!");
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()
61 tlog.Debug(tag, $"DataTemplateConstructor START");
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.");
67 tlog.Debug(tag, $"DataTemplateConstructor END (OK)");
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()
79 tlog.Debug(tag, $"DataTemplateConstructorWithType START");
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.");
86 tlog.Debug(tag, $"DataTemplateConstructorWithType END (OK)");
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()
98 tlog.Debug(tag, $"DataTemplateConstructorWithFunc START");
100 Func<object> LoadTemplate = () => new View();
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.");
106 tlog.Debug(tag, $"DataTemplateConstructorWithFunc END (OK)");
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()
118 tlog.Debug(tag, $"DataTemplateSetBinding START");
120 BindingBase binding = new Tizen.NUI.Binding.Binding() as BindingBase;
121 BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
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.");
129 testingTarget.SetBinding(stateProperty, binding);
133 Assert.Fail("SetBinding Fail!");
136 tlog.Debug(tag, $"DataTemplateSetBinding END (OK)");
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()
148 tlog.Debug(tag, $"DataTemplateSetBindingWithNullBindableProperty START");
150 BindingBase binding = new Tizen.NUI.Binding.Binding() as BindingBase;
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.");
158 testingTarget.SetBinding(null, binding);
160 catch (ArgumentNullException e)
162 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty END (OK)");
163 Assert.Pass("Caught ArgumentNullException: Pass!");
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()
176 tlog.Debug(tag, $"DataTemplateSetBindingWithNullBindingBase START");
178 BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
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.");
186 testingTarget.SetBinding(stateProperty, null);
188 catch (ArgumentNullException e)
190 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty END (OK)");
191 Assert.Pass("Caught ArgumentNullException: Pass!");
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()
204 tlog.Debug(tag, $"DataTemplateSetValue START");
206 BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
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.");
214 testingTarget.SetValue(stateProperty, true);
218 Assert.Fail("SetValue Fail!");
221 tlog.Debug(tag, $"DataTemplateSetValue END (OK)");
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()
233 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty START");
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.");
241 testingTarget.SetValue(null, true);
243 catch (ArgumentNullException e)
245 tlog.Debug(tag, $"DataTemplateSetValueWithNullBindableProperty END (OK)");
246 Assert.Pass("Caught ArgumentNullException: Pass!");
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()
259 // tlog.Debug(tag, $"DataTemplateSetupContent START");
261 // BindingBase binding = new Tizen.NUI.Binding.Binding(path) as BindingBase;
262 // BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
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.");
268 // testingTarget.SetBinding(stateProperty, binding);
269 // testingTarget.SetValue(stateProperty, true);
273 // ViewStyle style = new ViewStyle();
274 // testingTarget.OnSetupContent(style);
276 // catch (InvalidOperationException e)
278 // tlog.Debug(tag, e.Message.ToString());
279 // tlog.Debug(tag, $"DataTemplateSetupContent END (OK)");
280 // Assert.Pass("Caught InvalidOperationException : Passed!");
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()
293 tlog.Debug(tag, $"DataTemplateSetupContentWithNullBindable START");
295 BindingBase binding = new Tizen.NUI.Binding.Binding() as BindingBase;
296 BindableProperty stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged);
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.");
302 testingTarget.SetBinding(stateProperty, binding);
306 testingTarget.OnSetupContent(null);
310 Assert.Fail("Fail!");
313 tlog.Debug(tag, $"DataTemplateSetupContentWithNullBindable END (OK)");