[NUI] Make PrimaryCursorPosition property public
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / BaseComponents / TSControlState.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/ControlState")]
14     public class PublicControlStateTest
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("P2")]
32         [Description("ControlState Create. Parameter is null.")]
33         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
34         [Property("SPEC_URL", "-")]
35         [Property("CRITERIA", "MR")]
36         [Property("AUTHOR", "guowei.wang@samsung.com")]
37         public void ControlStateCreateWithNullString()
38         {
39             tlog.Debug(tag, $"ControlStateCreateWithNullString START");
40
41             try
42             {
43                 string str = null;
44                 ControlState.Create(str);
45             }
46             catch (ArgumentNullException e)
47             {
48                 tlog.Debug(tag, e.Message.ToString());
49                 tlog.Debug(tag, $"ControlStateCreateWithNullString END (OK)");
50                 Assert.Pass("Caught ArgumentNullException: Passed!");
51             }
52         }
53
54         [Test]
55         [Category("P2")]
56         [Description("ControlState Create. Parameter is empty.")]
57         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
58         [Property("SPEC_URL", "-")]
59         [Property("CRITERIA", "MR")]
60         [Property("AUTHOR", "guowei.wang@samsung.com")]
61         public void ControlStateCreateWithEmptyString()
62         {
63             tlog.Debug(tag, $"ControlStateCreateWithEmptyString START");
64
65             try
66             {
67                 string str = " ";
68                 ControlState.Create(str);
69             }
70             catch (ArgumentException e)
71             {
72                 tlog.Debug(tag, e.Message.ToString());
73                 tlog.Debug(tag, $"ControlStateCreateWithEmptyString END (OK)");
74                 Assert.Pass("Caught ArgumentException: Passed!");
75             }
76         }
77
78         [Test]
79         [Category("P2")]
80         [Description("ControlState Create. State is added.")]
81         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
82         [Property("SPEC_URL", "-")]
83         [Property("CRITERIA", "MR")]
84         [Property("AUTHOR", "guowei.wang@samsung.com")]
85         public void ControlStateCreateWithAddedState()
86         {
87             tlog.Debug(tag, $"ControlStateCreateWithAddedState START");
88
89             var testingTarget = ControlState.Create("Focused");
90             Assert.IsNotNull(testingTarget);
91             Assert.AreEqual(ControlState.Focused, testingTarget, "Should be equal!");
92
93             tlog.Debug(tag, $"ControlStateCreateWithAddedState END (OK)");
94         }
95
96         [Test]
97         [Category("P1")]
98         [Description("ControlState Create. StateList length is 0.")]
99         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
100         [Property("SPEC_URL", "-")]
101         [Property("CRITERIA", "MR")]
102         [Property("AUTHOR", "guowei.wang@samsung.com")]
103         public void ControlStateCreateStateListLengthEqualZero()
104         {
105             tlog.Debug(tag, $"ControlStateCreateStateListLengthEqualZero START");
106
107             ControlState[] states = new ControlState[0];
108             var testingTarget = ControlState.Create(states);
109             Assert.IsNotNull(testingTarget);
110             Assert.AreEqual("Normal", testingTarget.ToString(), "Should be equal!");
111
112             tlog.Debug(tag, $"ControlStateCreateStateListLengthEqualZero END (OK)");
113         }
114
115         [Test]
116         [Category("P1")]
117         [Description("ControlState Create. StateList length is 1.")]
118         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
119         [Property("SPEC_URL", "-")]
120         [Property("CRITERIA", "MR")]
121         [Property("AUTHOR", "guowei.wang@samsung.com")]
122         public void ControlStateCreateStateListLengthEqualOne()
123         {
124             tlog.Debug(tag, $"ControlStateCreateStateListLengthEqualOne START");
125
126             ControlState[] states = new ControlState[1];
127             states[0] = ControlState.Other;
128             var testingTarget = ControlState.Create(states);
129             Assert.IsNotNull(testingTarget);
130             Assert.AreEqual("Other", testingTarget.ToString(), "Should be equal!");
131
132             tlog.Debug(tag, $"ControlStateCreateStateListLengthEqualOne END (OK)");
133         }
134
135         [Test]
136         [Category("P1")]
137         [Description("ControlState Create. StateList length greater than 1.")]
138         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
139         [Property("SPEC_URL", "-")]
140         [Property("CRITERIA", "MR")]
141         [Property("AUTHOR", "guowei.wang@samsung.com")]
142         public void ControlStateCreateStateListLengthGreaterThanOne()
143         {
144             tlog.Debug(tag, $"ControlStateCreateStateListLengthGreaterThanOne START");
145
146             ControlState[] states = new ControlState[5];
147             states[0] = ControlState.Normal;
148             states[1] = ControlState.Selected;
149             states[2] = ControlState.Focused;
150             states[3] = ControlState.Pressed;
151             states[4] = ControlState.Disabled;
152             var testingTarget = ControlState.Create(states);
153             Assert.IsNotNull(testingTarget);
154             Assert.AreEqual("Selected, Focused, Pressed, Disabled", testingTarget.ToString(), "Should be equal!");
155
156             tlog.Debug(tag, $"ControlStateCreateStateListLengthGreaterThanOne END (OK)");
157         }
158
159         [Test]
160         [Category("P1")]
161         [Description("ControlState Create. StateList contain All.")]
162         [Property("SPEC", "Tizen.NUI.ControlState.Create M")]
163         [Property("SPEC_URL", "-")]
164         [Property("CRITERIA", "MR")]
165         [Property("AUTHOR", "guowei.wang@samsung.com")]
166         public void ControlStateCreateStateListContainAll()
167         {
168             tlog.Debug(tag, $"ControlStateCreateStateListContainAll START");
169
170             ControlState[] states = new ControlState[5];
171             states[0] = ControlState.Normal;
172             states[1] = ControlState.Selected;
173             states[2] = ControlState.All;
174             states[3] = ControlState.Pressed;
175             states[4] = ControlState.Disabled;
176             var testingTarget = ControlState.Create(states);
177             Assert.IsNotNull(testingTarget);
178             Assert.AreEqual("All", testingTarget.ToString(), "Should be equal!");
179
180             tlog.Debug(tag, $"ControlStateCreateStateListContainAll END (OK)");
181         }
182
183         [Test]
184         [Category("P1")]
185         [Description("ControlState Contains.")]
186         [Property("SPEC", "Tizen.NUI.ControlState.Contains M")]
187         [Property("SPEC_URL", "-")]
188         [Property("CRITERIA", "MR")]
189         [Property("AUTHOR", "guowei.wang@samsung.com")]
190         public void ControlStateContains()
191         {
192             tlog.Debug(tag, $"ControlStateContains START");
193
194             ControlState[] states = new ControlState[5];
195             states[0] = ControlState.Normal;
196             states[1] = ControlState.Selected;
197             states[2] = ControlState.Focused;
198             states[3] = ControlState.Pressed;
199             states[4] = ControlState.Disabled;
200             var testingTarget = ControlState.Create(states);
201
202             Assert.AreEqual(false, testingTarget.Contains(ControlState.All), "Should be equal!");
203             Assert.AreEqual(true, testingTarget.Contains(ControlState.Selected), "Should be equal!");
204
205             tlog.Debug(tag, $"ControlStateContains END (OK)");
206         }
207
208         [Test]
209         [Category("P1")]
210         [Description("ControlState Contains. IsCombined is false.")]
211         [Property("SPEC", "Tizen.NUI.ControlState.Contains M")]
212         [Property("SPEC_URL", "-")]
213         [Property("CRITERIA", "MR")]
214         [Property("AUTHOR", "guowei.wang@samsung.com")]
215         public void ControlStateContainsWithFalseIsCombined()
216         {
217             tlog.Debug(tag, $"ControlStateContainsWithFalseIsCombined START");
218
219             ControlState[] states = new ControlState[1];
220             states[0] = ControlState.Normal;
221             var testingTarget = ControlState.Create(states);
222
223             Assert.AreEqual(true, testingTarget.Contains(ControlState.Normal), "Should be equal!");
224             
225             tlog.Debug(tag, $"ControlStateContainsWithFalseIsCombined END (OK)");
226         }
227
228         [Test]
229         [Category("P2")]
230         [Description("ControlState Contains. State is null.")]
231         [Property("SPEC", "Tizen.NUI.ControlState.Contains M")]
232         [Property("SPEC_URL", "-")]
233         [Property("CRITERIA", "MR")]
234         [Property("AUTHOR", "guowei.wang@samsung.com")]
235         public void ControlStateContainsWithNullState()
236         {
237             tlog.Debug(tag, $"ControlStateContainsWithNullState START");
238
239             ControlState state = ControlState.Create("Focused");
240
241             try
242             {
243                 state.Contains(null);
244             }
245             catch (ArgumentNullException e)
246             {
247                 tlog.Debug(tag, e.Message.ToString());
248                 tlog.Debug(tag, $"ControlStateContainsWithNullState END (OK)");
249                 Assert.Pass("Caught ArgumentNullException: Passed!");
250             }
251         }
252
253         [Test]
254         [Category("P2")]
255         [Description("ControlState ==. Both null.")]
256         [Property("SPEC", "Tizen.NUI.ControlState.== M")]
257         [Property("SPEC_URL", "-")]
258         [Property("CRITERIA", "MR")]
259         [Property("AUTHOR", "guowei.wang@samsung.com")]
260         public void ControlStateEquivalentWithBothNullVaule()
261         {
262             tlog.Debug(tag, $"ControlStateEquivalentWithBothNullVaule START");
263
264             Assert.True(null == null);
265
266             tlog.Debug(tag, $"ControlStateEquivalentWithBothNullVaule END (OK)");
267         }
268
269         [Test]
270         [Category("P2")]
271         [Description("ControlState ==. Right null.")]
272         [Property("SPEC", "Tizen.NUI.ControlState.== M")]
273         [Property("SPEC_URL", "-")]
274         [Property("CRITERIA", "MR")]
275         [Property("AUTHOR", "guowei.wang@samsung.com")]
276         public void ControlStateEquivalentWithOneNullValue()
277         {
278             tlog.Debug(tag, $"ControlStateEquivalentWithOneNullValue START");
279
280             Assert.False(null == ControlState.Focused);
281             Assert.True(null != ControlState.Focused);
282
283             tlog.Debug(tag, $"ControlStateEquivalentWithOneNullValue END (OK)");
284         }
285
286         [Test]
287         [Category("P1")]
288         [Description("ControlState subtraction.")]
289         [Property("SPEC", "Tizen.NUI.ControlState.- M")]
290         [Property("SPEC_URL", "-")]
291         [Property("CRITERIA", "MR")]
292         [Property("AUTHOR", "guowei.wang@samsung.com")]
293         public void ControlStateSubtraction()
294         {
295             tlog.Debug(tag, $"ControlStateSubtraction START");
296
297             var result = ControlState.Focused - ControlState.Focused;
298             Assert.AreEqual("Normal", result.ToString(), "Should be equal!");
299
300             result = ControlState.Focused - ControlState.Pressed;
301             Assert.AreEqual("Focused", result.ToString(), "Should be equal!");
302
303             tlog.Debug(tag, $"ControlStateSubtraction END (OK)");
304         }
305
306         [Test]
307         [Category("P1")]
308         [Description("ControlState subtraction. IsCombined")]
309         [Property("SPEC", "Tizen.NUI.ControlState.- M")]
310         [Property("SPEC_URL", "-")]
311         [Property("CRITERIA", "MR")]
312         [Property("AUTHOR", "guowei.wang@samsung.com")]
313         public void ControlStateSubtractionWithTrueIsCombined()
314         {
315             tlog.Debug(tag, $"ControlStateSubtractionWithTrueIsCombined START");
316
317             ControlState[] states1 = new ControlState[2];
318             states1[0] = ControlState.Selected;
319             states1[1] = ControlState.Focused;
320             var testingTarget1 = ControlState.Create(states1);
321
322             ControlState[] states2 = new ControlState[2];
323             states2[0] = ControlState.Pressed;
324             states2[1] = ControlState.Focused;
325             var testingTarget2 = ControlState.Create(states2);
326
327             var result = testingTarget1 - testingTarget2;
328             Assert.AreEqual("Selected", result.ToString(), "Should be equal!");
329
330             ControlState[] states3 = new ControlState[2];
331             states3[0] = ControlState.Selected;
332             states3[1] = ControlState.Focused;
333             var testingTarget3 = ControlState.Create(states3);
334
335             ControlState[] states4 = new ControlState[2];
336             states4[0] = ControlState.Pressed;
337             states4[1] = ControlState.Disabled;
338             var testingTarget4 = ControlState.Create(states4);
339
340             result = testingTarget3 - testingTarget4;
341             Assert.AreEqual("Selected, Focused", result.ToString(), "Should be equal!");
342
343             tlog.Debug(tag, $"ControlStateSubtractionWithTrueIsCombined END (OK)");
344         }
345
346         [Test]
347         [Category("P2")]
348         [Description("ControlState subtraction. lhs is null.")]
349         [Property("SPEC", "Tizen.NUI.ControlState.- M")]
350         [Property("SPEC_URL", "-")]
351         [Property("CRITERIA", "MR")]
352         [Property("AUTHOR", "guowei.wang@samsung.com")]
353         public void ControlStateSubtractionWithNullFirstParameter()
354         {
355             tlog.Debug(tag, $"ControlStateSubtractionWithNullFirstParameter START");
356
357             try
358             {
359                 var result = null - ControlState.Normal;
360             }
361             catch (ArgumentNullException e)
362             {
363                 tlog.Debug(tag, e.Message.ToString());
364                 tlog.Debug(tag, $"ControlStateSubtractionWithNullFirstParameter END (OK)");
365                 Assert.Pass("Caught ArgumentNullException: Passed!");
366             }
367         }
368
369         [Test]
370         [Category("P2")]
371         [Description("ControlState subtraction. rhs is null.")]
372         [Property("SPEC", "Tizen.NUI.ControlState.- M")]
373         [Property("SPEC_URL", "-")]
374         [Property("CRITERIA", "MR")]
375         [Property("AUTHOR", "guowei.wang@samsung.com")]
376         public void ControlStateSubtractionWithNullSecondParameter()
377         {
378             tlog.Debug(tag, $"ControlStateSubtractionWithNullSecondParameter START");
379
380             try
381             {
382                 var result = ControlState.Normal - null;
383             }
384             catch (ArgumentNullException e)
385             {
386                 tlog.Debug(tag, e.Message.ToString());
387                 tlog.Debug(tag, $"ControlStateSubtractionWithNullSecondParameter END (OK)");
388                 Assert.Pass("Caught ArgumentNullException: Passed!");
389             }
390         }
391     }
392 }