[NUI][NUI.Devel] Update nui line coverage TCs.
[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
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         [Test]
333         [Category("P1")]
334         [Description("Selector Get.")]
335         [Property("SPEC", "Tizen.NUI.BaseComponents.Selector.Get M")]
336         [Property("SPEC_URL", "-")]
337         [Property("CRITERIA", "PRW")]
338         [Property("AUTHOR", "guowei.wang@samsung.com")]
339         public void SelectorGet()
340         {
341             tlog.Debug(tag, $"SelectorGet START");
342
343             Color result = null;
344             var testingTarget = new Selector<Color>();
345             Assert.IsNotNull(testingTarget, "Can't create success object RenderTask.");
346             Assert.IsInstanceOf<Selector<Color>>(testingTarget, "Should return Selector<Color> instance.");
347
348                         try
349                         {
350                 testingTarget.Normal = Color.Blue;  // 1100
351                 result = testingTarget.Normal;      
352                 Assert.AreEqual(1, result.A, "Should be equal!");
353                 Assert.AreEqual(1, result.B, "Should be equal!");
354                 Assert.AreEqual(0, result.G, "Should be equal!");
355                 Assert.AreEqual(0, result.R, "Should be equal!");
356
357                 testingTarget.Pressed = Color.Green;    // 1010
358                 result = testingTarget.Pressed;
359                 Assert.AreEqual(1, result.A, "Should be equal!");
360                 Assert.AreEqual(0, result.B, "Should be equal!");
361                 Assert.AreEqual(1, result.G, "Should be equal!");
362                 Assert.AreEqual(0, result.R, "Should be equal!");
363
364                 testingTarget.Focused = Color.Red;      // 1001
365                 result = testingTarget.Focused;
366                 Assert.AreEqual(1, result.A, "Should be equal!");
367                 Assert.AreEqual(0, result.B, "Should be equal!");
368                 Assert.AreEqual(0, result.G, "Should be equal!");
369                 Assert.AreEqual(1, result.R, "Should be equal!");
370
371                 testingTarget.Selected = Color.Cyan;    // 1110
372                 result = testingTarget.Selected;
373                 Assert.AreEqual(1, result.A, "Should be equal!");
374                 Assert.AreEqual(1, result.B, "Should be equal!");
375                 Assert.AreEqual(1, result.G, "Should be equal!");
376                 Assert.AreEqual(0, result.R, "Should be equal!");
377
378                 testingTarget.Disabled = Color.Gray;    // 1 0.74509805 0.74509805 0.74509805
379                 result = testingTarget.Disabled;
380                 Assert.AreEqual(1, result.A, "Should be equal!");
381
382                 testingTarget.DisabledFocused = Color.Orange;       // 1 0 0.64705884 1
383                 result = testingTarget.DisabledFocused;
384                 Assert.AreEqual(1, result.A, "Should be equal!");
385                 Assert.AreEqual(0, result.B, "Should be equal!");
386                 Assert.AreEqual(1, result.R, "Should be equal!");
387
388                 testingTarget.SelectedFocused = Color.Magenta;      // 1101
389                 result = testingTarget.SelectedFocused;
390                 Assert.AreEqual(1, result.A, "Should be equal!");
391                 Assert.AreEqual(1, result.B, "Should be equal!");
392                 Assert.AreEqual(0, result.G, "Should be equal!");
393                 Assert.AreEqual(1, result.R, "Should be equal!");
394
395                 testingTarget.DisabledSelected = Color.Black;   // 1000 
396                 result = testingTarget.DisabledSelected;
397                 Assert.AreEqual(1, result.A, "Should be equal!");
398                 Assert.AreEqual(0, result.B, "Should be equal!");
399                 Assert.AreEqual(0, result.G, "Should be equal!");
400                 Assert.AreEqual(0, result.R, "Should be equal!");
401
402                 testingTarget.SelectedPressed = Color.Yellow;   //1011
403                 result = testingTarget.SelectedPressed;
404                 Assert.AreEqual(1, result.A, "Should be equal!");
405                 Assert.AreEqual(0, result.B, "Should be equal!");
406                 Assert.AreEqual(1, result.G, "Should be equal!");
407                 Assert.AreEqual(1, result.R, "Should be equal!");
408
409                 testingTarget.Other = Color.White;      // 1111
410                 result = testingTarget.Other;
411                 Assert.AreEqual(1, result.A, "Should be equal!");
412                 Assert.AreEqual(1, result.B, "Should be equal!");
413                 Assert.AreEqual(1, result.G, "Should be equal!");
414                 Assert.AreEqual(1, result.R, "Should be equal!");
415             }
416             catch (Exception e)
417             {
418                 tlog.Debug(tag, e.Message.ToString());
419                 Assert.Fail("Caught Exception : Failed!" );
420             }
421
422             tlog.Debug(tag, $"SelectorGet END (OK)");
423         }
424     }
425 }