[NUI] Update TCs of NUI.Devel.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / BaseComponents / Style / TSSelector.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
8 namespace Tizen.NUI.Devel.Tests.testcase
9 {
10     using tlog = Tizen.Log;
11
12     [TestFixture]
13     [Description("public/BaseComponents/Style/Selector")]
14     public class PublicSelectorTest
15     {
16         private const string tag = "NUITEST";
17
18         [SetUp]
19         public void Init()
20         {
21             tlog.Info(tag, "Init() is called!");
22         }
23
24         [TearDown]
25         public void Destroy()
26         {
27             tlog.Info(tag, "Destroy() is called!");
28         }
29
30         [Test]
31         [Category("P1")]
32         [Description("Selector Add.")]
33         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.Add M")]
34         [Property("SPEC_URL", "-")]
35         [Property("CRITERIA", "PRW")]
36         [Property("AUTHOR", "guowei.wang@samsung.com")]
37         public void SelectorAddSelectorItem()
38         {
39             tlog.Debug(tag, $"SelectorAddSelectorItem START");
40
41             Selector<Color> colors = new Selector<Color>();
42
43             SelectorItem<Color> item = new SelectorItem<Color>();
44             item.Value = Color.White;
45             item.State = ControlState.All;
46
47             colors.Add(item);
48             // if item be added, remove if first
49             colors.Add(item);
50
51             colors.GetValue(ControlState.All, out Color color);
52             tlog.Debug(tag, "color : " + color);
53
54             tlog.Debug(tag, "Count :" + colors.Count);
55             tlog.Debug(tag, "IsReadOnly :" + colors.IsReadOnly);
56
57             var result = colors.Contains(item);
58             Assert.AreEqual(true, result, "Should be equal!");
59
60             try
61             {
62                 colors.GetEnumerator();
63             }
64             catch (Exception e)
65             {
66                 tlog.Debug(tag, e.Message.ToString());
67                 Assert.Fail("Caught Exception : Failed!");
68             }
69
70             result = colors.Remove(item);
71             Assert.AreEqual(true, result, "Should be equal!");
72
73             tlog.Debug(tag, $"SelectorAddSelectorItem END (OK)");
74         }
75
76         [Test]
77         [Category("P2")]
78         [Description("Selector Add.")]
79         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.Add M")]
80         [Property("SPEC_URL", "-")]
81         [Property("CRITERIA", "PRW")]
82         [Property("AUTHOR", "guowei.wang@samsung.com")]
83         public void SelectorAddNullSelectorItem()
84         {
85             tlog.Debug(tag, $"SelectorAddNullSelectorItem START");
86
87             Selector<Color> colors = new Selector<Color>();
88
89             SelectorItem<Color> item = null;
90
91             try
92             {
93                 colors.Add(item);
94             }
95             catch (ArgumentNullException)
96             {
97                 tlog.Debug(tag, $"SelectorAddNullSelectorItem END (OK)");
98                 Assert.Pass("Caught ArgumentNullException :  Passed!");
99             }
100         }
101
102         [Test]
103         [Category("P2")]
104         [Description("Selector Contains.")]
105         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.Contains M")]
106         [Property("SPEC_URL", "-")]
107         [Property("CRITERIA", "PRW")]
108         [Property("AUTHOR", "guowei.wang@samsung.com")]
109         public void SelectorContainsNullSelectorItem()
110         {
111             tlog.Debug(tag, $"SelectorContainsNullSelectorItem START");
112
113             Selector<Color> colors = new Selector<Color>();
114
115             SelectorItem<Color> item = null;
116
117             try
118             {
119                 colors.Contains(item);
120             }
121             catch (ArgumentNullException)
122             {
123                 tlog.Debug(tag, $"SelectorContainsNullSelectorItem END (OK)");
124                 Assert.Pass("Caught ArgumentNullException :  Passed!");
125             }
126         }
127
128         [Test]
129         [Category("P1")]
130         [Description("SelectorExtensions Add.")]
131         [Property("SPEC", "Tizen.NUI.BaseComponents.SelectorExtensions.Add M")]
132         [Property("SPEC_URL", "-")]
133         [Property("CRITERIA", "PRW")]
134         [Property("AUTHOR", "guowei.wang@samsung.com")]
135         public void SelectorExtensionsAdd()
136         {
137             tlog.Debug(tag, $"SelectorExtensionsAdd START");
138
139             Selector<Color> colors = new Selector<Color>();
140
141             IList<SelectorItem<Color>> list = new List<SelectorItem<Color>>();
142
143             var item = new SelectorItem<Color>()
144             {
145                 Value = Color.Cyan,
146                 State = ControlState.All
147             };
148             item.ToString();
149             list.Add(item);
150
151             try
152             {
153                 SelectorExtensions.Add(list, ControlState.All, Color.White);
154             }
155             catch (Exception e)
156             {
157                 tlog.Debug(tag, e.Message.ToString());
158                 Assert.Fail("Caught Exception : Failed!");
159             }
160
161             tlog.Debug(tag, $"SelectorExtensionsAdd END (OK)");
162         }
163
164         [Test]
165         [Category("P2")]
166         [Description("SelectorExtensions Add.")]
167         [Property("SPEC", "Tizen.NUI.BaseComponents.SelectorExtensions.Add M")]
168         [Property("SPEC_URL", "-")]
169         [Property("CRITERIA", "PRW")]
170         [Property("AUTHOR", "guowei.wang@samsung.com")]
171         public void SelectorExtensionsAddWithNullList()
172         {
173             tlog.Debug(tag, $"SelectorExtensionsAddWithNullList START");
174
175             Selector<Color> colors = new Selector<Color>();
176
177             IList<SelectorItem<Color>> list = null;
178
179             try
180             {
181                 SelectorExtensions.Add(list, ControlState.All, Color.White);
182             }
183             catch (ArgumentNullException)
184             {
185                 tlog.Debug(tag, $"SelectorExtensionsAddWithNullList END (OK)");
186                 Assert.Pass("Caught ArgumentNullException : Passed!");
187             }
188         }
189
190         [Test]
191         [Category("P1")]
192         [Description("Selector GetHashCode.")]
193         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.GetHashCode M")]
194         [Property("SPEC_URL", "-")]
195         [Property("CRITERIA", "PRW")]
196         [Property("AUTHOR", "guowei.wang@samsung.com")]
197         public void SelectorGetHashCode()
198         {
199             tlog.Debug(tag, $"SelectorGetHashCode START");
200
201             Selector<Color> colors = new Selector<Color>();
202
203             SelectorItem<Color> item = new SelectorItem<Color>();
204             item.Value = Color.White;
205             item.State = ControlState.All;
206
207             colors.Add(item);
208             var result = colors.GetHashCode();
209             tlog.Debug(tag, "HashCode : " + result);
210
211             tlog.Debug(tag, $"SelectorGetHashCode END (OK)");
212         }
213
214         [Test]
215         [Category("P1")]
216         [Description("Selector Equals.")]
217         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.Equals M")]
218         [Property("SPEC_URL", "-")]
219         [Property("CRITERIA", "PRW")]
220         [Property("AUTHOR", "guowei.wang@samsung.com")]
221         public void SelectorEquals()
222         {
223             tlog.Debug(tag, $"SelectorEquals START");
224
225             Selector<Color> colors = new Selector<Color>();
226
227             SelectorItem<Color> item = new SelectorItem<Color>();
228             item.Value = Color.White;
229             item.State = ControlState.All;
230
231             colors.Add(item);
232             Selector<Color> dummy1 = new Selector<Color>(Color.Cyan);
233             Selector<string> dummy2 = new Selector<string>("mytest");
234
235             var result = colors.Equals(dummy1);
236             tlog.Debug(tag, "Equals : " + result);
237
238             result = colors.Equals(dummy2);
239             tlog.Debug(tag, "Equals : " + result);
240
241             tlog.Debug(tag, $"SelectorEquals END (OK)");
242         }
243
244         [Test]
245         [Category("P1")]
246         [Description("Selector ToString.")]
247         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.ToString M")]
248         [Property("SPEC_URL", "-")]
249         [Property("CRITERIA", "PRW")]
250         [Property("AUTHOR", "guowei.wang@samsung.com")]
251         public void SelectorToString()
252         {
253             tlog.Debug(tag, $"SelectorToString START");
254
255             var testingTarget = new Selector<Color>(Color.Cyan);
256             Assert.IsNotNull(testingTarget, "Can't create success object RenderTask.");
257             Assert.IsInstanceOf<Selector<Color>>(testingTarget, "Should return Selector<Color> instance.");
258
259             var result = testingTarget.ToString();
260             tlog.Debug(tag, "ToString : " + result);
261
262             tlog.Debug(tag, $"SelectorToString END (OK)");
263         }
264
265         [Test]
266         [Category("P1")]
267         [Description("Selector CopyTo.")]
268         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.CopyTo M")]
269         [Property("SPEC_URL", "-")]
270         [Property("CRITERIA", "PRW")]
271         [Property("AUTHOR", "guowei.wang@samsung.com")]
272         public void SelectorCopyTo()
273         {
274             tlog.Debug(tag, $"SelectorCopyTo START");
275
276             var testingTarget = new Selector<Color>(Color.Cyan);
277             Assert.IsNotNull(testingTarget, "Can't create success object RenderTask.");
278             Assert.IsInstanceOf<Selector<Color>>(testingTarget, "Should return Selector<Color> instance.");
279
280             SelectorItem<Color>[] item = new SelectorItem<Color>[2];
281             item[0] = new SelectorItem<Color>();
282             item[0].Value = Color.Cyan;
283             item[0].State = ControlState.All;
284
285             item[1] = new SelectorItem<Color>();
286             item[1].Value = Color.Yellow;
287             item[1].State = ControlState.Normal;
288
289             try
290             {
291                 testingTarget.CopyTo(item, 0);
292             }
293             catch (Exception e)
294             {
295                 tlog.Debug(tag, e.Message.ToString());
296                 Assert.Fail("Caught Exception : Failed!" );
297             }
298
299             tlog.Debug(tag, $"SelectorCopyTo END (OK)");
300         }
301
302         [Test]
303         [Category("P1")]
304         [Description("Selector GetValue.")]
305         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.GetValue M")]
306         [Property("SPEC_URL", "-")]
307         [Property("CRITERIA", "PRW")]
308         [Property("AUTHOR", "guowei.wang@samsung.com")]
309         public void SelectorGetValue()
310         {
311             tlog.Debug(tag, $"SelectorGetValue START");
312
313             var testingTarget = new Selector<Color>();
314             Assert.IsNotNull(testingTarget, "Can't create success object RenderTask.");
315             Assert.IsInstanceOf<Selector<Color>>(testingTarget, "Should return Selector<Color> instance.");
316
317             SelectorItem<Color>[] item = new SelectorItem<Color>[2];
318             item[0] = new SelectorItem<Color>();
319             item[0].Value = Color.Cyan;
320             item[0].State = ControlState.All;
321
322             item[1] = new SelectorItem<Color>();
323             item[1].Value = Color.Yellow;
324             item[1].State = ControlState.Normal;
325
326             testingTarget.CopyTo(item, 0);
327             testingTarget.GetValue(ControlState.Normal, out Color color);
328             tlog.Debug(tag, "color : " + color);
329
330             tlog.Debug(tag, $"SelectorGetValue END (OK)");
331         }
332     }
333 }