[NUI][TEST] Update TCs of NUI.Components.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Components.Devel.Tests / testcase / Controls / TSScrollableBase.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI;
5 using Tizen.NUI.Components;
6 using Tizen.NUI.BaseComponents;
7 using Tizen.NUI.Binding;
8
9 namespace Tizen.NUI.Components.Devel.Tests
10 {
11     using static Tizen.NUI.Components.ScrollOutOfBoundEventArgs;
12     using tlog = Tizen.Log;
13
14     [TestFixture]
15     [Description("Controls/ScrollableBase")]
16     public class ScrollableBaseTest
17     {
18         private const string tag = "NUITEST";
19
20         internal class MyScrollableBase : ScrollableBase
21         {
22             public MyScrollableBase() : base()
23             { }
24
25             public void MyAccessibilityIsScrollable()
26             {
27                 base.AccessibilityIsScrollable();
28             }
29
30             public void OnGetNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
31             {
32                 base.GetNextFocusableView(currentFocusedView, direction, loopEnabled);
33             }
34
35             public void MyDecelerating(float velocity, Animation animation)
36             {
37                 base.Decelerating(velocity, animation);
38             }
39
40             public bool MyAccessibilityScrollToChild(View child)
41             {
42                 return base.AccessibilityScrollToChild(child);
43             }
44         }
45
46         [SetUp]
47         public void Init()
48         {
49             tlog.Info(tag, "Init() is called!");
50         }
51
52         [TearDown]
53         public void Destroy()
54         {
55             tlog.Info(tag, "Destroy() is called!");
56         }
57
58         [Test]
59         [Category("P1")]
60         [Description("ScrollableBase constructor.")]
61         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.ScrollableBase C")]
62         [Property("SPEC_URL", "-")]
63         [Property("CRITERIA", "CONSTR")]
64         [Property("COVPARAM", "")]
65         [Property("AUTHOR", "guowei.wang@samsung.com")]
66         public void ScrollableBaseConstructor()
67         {
68             tlog.Debug(tag, $"ScrollableBaseConstructor START");
69
70             var testingTarget = new ScrollableBase();
71             Assert.IsNotNull(testingTarget, "null handle");
72             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
73
74             tlog.Debug(tag, "ScrollPosition : " + testingTarget.ScrollPosition);
75
76             testingTarget.ScrollingEventThreshold = 0.3f;
77             tlog.Debug(tag, "ScrollingEventThreshold : " + testingTarget.ScrollingEventThreshold);
78
79             testingTarget.NoticeAnimationEndBeforePosition = 0.5f;
80             tlog.Debug(tag, "NoticeAnimationEndBeforePosition : " + testingTarget.NoticeAnimationEndBeforePosition);
81
82             testingTarget.Padding = new Extents(2, 2, 2, 2);
83             tlog.Debug(tag, "Padding : " + testingTarget.Padding);
84
85             testingTarget.Dispose();
86             tlog.Debug(tag, $"ScrollableBaseConstructor END (OK)");
87         }
88
89         [Test]
90         [Category("P1")]
91         [Description("ScrollEventArgs ScrollPosition")]
92         [Property("SPEC", "Tizen.NUI.Components.ScrollEventArgs.ScrollPosition A")]
93         [Property("SPEC_URL", "-")]
94         [Property("CRITERIA", "PRW")]
95         [Property("COVPARAM", "")]
96         [Property("AUTHOR", "guowei.wang@samsung.com")]
97         public void ScrollEventArgsScrollPosition()
98         {
99             tlog.Debug(tag, $"ScrollEventArgsScrollPosition START");
100
101             using (Position position = new Position(10, 20))
102             {
103                 var testingTarget = new ScrollEventArgs(position);
104                 Assert.IsNotNull(testingTarget, "null handle");
105                 Assert.IsInstanceOf<ScrollEventArgs>(testingTarget, "Should return ScrollEventArgs instance.");
106
107                 tlog.Debug(tag, "ScrollPosition : " + testingTarget.ScrollPosition);
108             }
109
110             tlog.Debug(tag, $"ScrollEventArgsScrollPosition END (OK)");
111         }
112
113         [Test]
114         [Category("P1")]
115         [Description("ScrollOutOfBoundEventArgs constructor")]
116         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.ScrollOutOfBoundEventArgs C")]
117         [Property("SPEC_URL", "-")]
118         [Property("CRITERIA", "MR")]
119         [Property("COVPARAM", "")]
120         [Property("AUTHOR", "guowei.wang@samsung.com")]
121         public void ScrollOutOfBoundEventArgsConstructor()
122         {
123             tlog.Debug(tag, $"ScrollOutOfBoundEventArgsConstructor START");
124
125             var testingTarget = new ScrollOutOfBoundEventArgs(ScrollOutOfBoundEventArgs.Direction.Up, 0.3f);
126             Assert.IsNotNull(testingTarget, "null handle");
127             Assert.IsInstanceOf<ScrollOutOfBoundEventArgs>(testingTarget, "Should return ScrollOutOfBoundEventArgs instance.");
128
129             tlog.Debug(tag, "PanDirection : " + testingTarget.PanDirection);
130             tlog.Debug(tag, "Displacement : " + testingTarget.Displacement);
131
132             tlog.Debug(tag, $"ScrollOutOfBoundEventArgsConstructor END (OK)");
133         }
134
135         [Test]
136         [Category("P1")]
137         [Description("ScrollableBase ScrollEnabled")]
138         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.ScrollEnabled A")]
139         [Property("SPEC_URL", "-")]
140         [Property("CRITERIA", "PRW")]
141         [Property("COVPARAM", "")]
142         [Property("AUTHOR", "guowei.wang@samsung.com")]
143         public void ScrollableBaseScrollEnabled()
144         {
145             tlog.Debug(tag, $"ScrollableBaseScrollEnabled START");
146
147             var testingTarget = new ScrollableBase();
148             Assert.IsNotNull(testingTarget, "null handle");
149             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
150
151             testingTarget.ScrollEnabled = true;
152             tlog.Debug(tag, "ScrollEnabled : " + testingTarget.ScrollEnabled);
153
154             testingTarget.ScrollEnabled = false;
155             tlog.Debug(tag, "ScrollEnabled : " + testingTarget.ScrollEnabled);
156
157             testingTarget.ScrollEnabled = true;
158             tlog.Debug(tag, "ScrollEnabled : " + testingTarget.ScrollEnabled);
159
160             testingTarget.Dispose();
161             tlog.Debug(tag, $"ScrollableBaseScrollEnabled END (OK)");
162         }
163
164         [Test]
165         [Category("P1")]
166         [Description("ScrollableBase Scrollbar")]
167         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.Scrollbar A")]
168         [Property("SPEC_URL", "-")]
169         [Property("CRITERIA", "PRW")]
170         [Property("COVPARAM", "")]
171         [Property("AUTHOR", "guowei.wang@samsung.com")]
172         public void ScrollableBaseScrollbar()
173         {
174             tlog.Debug(tag, $"ScrollableBaseScrollbar START");
175
176             var testingTarget = new ScrollableBase();
177             Assert.IsNotNull(testingTarget, "null handle");
178             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
179
180             testingTarget.ScrollEnabled = true;
181             tlog.Debug(tag, "ScrollEnabled : " + testingTarget.ScrollEnabled);
182
183             testingTarget.HideScrollbar = false;
184
185             Scrollbar bar = new Scrollbar()
186             {
187                 Size = new Size(50, 2),
188             };
189             testingTarget.Scrollbar = bar;
190
191             testingTarget.Dispose();
192             tlog.Debug(tag, $"ScrollableBaseScrollbar END (OK)");
193         }
194
195         [Test]
196         [Category("P1")]
197         [Description("ScrollableBase ScrollableBaseAccessibilityIsScrollable")]
198         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.ScrollableBaseAccessibilityIsScrollable M")]
199         [Property("SPEC_URL", "-")]
200         [Property("CRITERIA", "PRW")]
201         [Property("COVPARAM", "")]
202         [Property("AUTHOR", "guowei.wang@samsung.com")]
203         public void ScrollableBaseAccessibilityIsScrollable()
204         {
205             tlog.Debug(tag, $"ScrollableBaseAccessibilityIsScrollable START");
206
207             var testingTarget = new MyScrollableBase();
208             Assert.IsNotNull(testingTarget, "null handle");
209             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
210
211             try
212             {
213                 testingTarget.MyAccessibilityIsScrollable();
214             }
215             catch (Exception e)
216             {
217                 tlog.Debug(tag, e.Message.ToString());
218                 Assert.Fail("Caught Exception : Failed!");
219             }
220
221             testingTarget.Dispose();
222             tlog.Debug(tag, $"ScrollableBaseAccessibilityIsScrollable END (OK)");
223         }
224
225         [Test]
226         [Category("P1")]
227         [Description("ScrollableBase GetNextFocusableView")]
228         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.GetNextFocusableView M")]
229         [Property("SPEC_URL", "-")]
230         [Property("CRITERIA", "PRW")]
231         [Property("COVPARAM", "")]
232         [Property("AUTHOR", "guowei.wang@samsung.com")]
233         public void ScrollableBaseGetNextFocusableView()
234         {
235             tlog.Debug(tag, $"ScrollableBaseGetNextFocusableView START");
236
237             var testingTarget = new MyScrollableBase();
238             Assert.IsNotNull(testingTarget, "null handle");
239             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
240
241             View view1 = new View()
242             { 
243                 Size = new Size(100, 200),
244                 Position = new Position(0, 0),
245                 BackgroundColor = Color.Cyan
246             };
247
248             View view2 = new View()
249             {
250                 Size = new Size(100, 200),
251                 Position = new Position(150, 0),
252                 BackgroundColor = Color.Green
253             };
254
255             View view3 = new View()
256             {
257                 Size = new Size(100, 200),
258                 Position = new Position(300, 200),
259                 BackgroundColor = Color.Green
260             };
261
262             FocusManager.Instance.SetCurrentFocusView(view1);
263
264             try
265             {
266                 testingTarget.OnGetNextFocusableView(view1, View.FocusDirection.Right, true);
267                 testingTarget.OnGetNextFocusableView(view2, View.FocusDirection.Right, true);
268                 testingTarget.OnGetNextFocusableView(view3, View.FocusDirection.Left, true);
269             }
270             catch (Exception e)
271             {
272                 tlog.Debug(tag, e.Message.ToString());
273                 Assert.Fail("Caught Exception : Failed!");
274             }
275
276             FocusManager.Instance.ClearFocus();
277
278             testingTarget.Dispose();
279             tlog.Debug(tag, $"ScrollableBaseGetNextFocusableView END (OK)");
280         }
281
282         [Test]
283         [Category("P1")]
284         [Description("ScrollableBase ScrollTo")]
285         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.ScrollTo M")]
286         [Property("SPEC_URL", "-")]
287         [Property("CRITERIA", "PRW")]
288         [Property("COVPARAM", "")]
289         [Property("AUTHOR", "guowei.wang@samsung.com")]
290         public void ScrollableBaseScrollTo()
291         {
292             tlog.Debug(tag, $"ScrollableBaseScrollTo START");
293
294             var testingTarget = new ScrollableBase()
295             {
296                 Size = new Size(100, 2),
297                 BackgroundColor = Color.Cyan,
298                 ScrollingDirection = ScrollableBase.Direction.Horizontal,
299             };
300             Assert.IsNotNull(testingTarget, "null handle");
301             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
302
303             try
304             {
305                 testingTarget.ScrollTo(0.3f, true);
306             }
307             catch (Exception e)
308             {
309                 tlog.Debug(tag, e.Message.ToString());
310                 Assert.Fail("Caught Exception : Failed!");
311             }
312
313             testingTarget.Dispose();
314             tlog.Debug(tag, $"ScrollableBaseScrollTo END (OK)");
315         }
316
317         [Test]
318         [Category("P1")]
319         [Description("ScrollableBase OnAccessibilityPan")]
320         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.OnAccessibilityPan M")]
321         [Property("SPEC_URL", "-")]
322         [Property("CRITERIA", "PRW")]
323         [Property("COVPARAM", "")]
324         [Property("AUTHOR", "guowei.wang@samsung.com")]
325         public void ScrollableBaseOnAccessibilityPan()
326         {
327             tlog.Debug(tag, $"ScrollableBaseOnAccessibilityPan START");
328
329             var testingTarget = new ScrollableBase()
330             {
331                 Size = new Size(100, 2),
332                 BackgroundColor = Color.Cyan,
333                 ScrollingDirection = ScrollableBase.Direction.Vertical,
334             };
335             Assert.IsNotNull(testingTarget, "null handle");
336             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
337
338             using (PanGesture gesture = new PanGesture())
339             {
340                 try
341                 {
342                     testingTarget.OnAccessibilityPan(gesture);
343                 }
344                 catch (Exception e)
345                 {
346                     tlog.Debug(tag, e.Message.ToString());
347                     Assert.Fail("Caught Exception : Failed!");
348                 }
349             }
350
351             testingTarget.Dispose();
352             tlog.Debug(tag, $"ScrollableBaseOnAccessibilityPan END (OK)");
353         }
354
355         [Test]
356         [Category("P1")]
357         [Description("ScrollableBase Decelerating")]
358         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.Decelerating M")]
359         [Property("SPEC_URL", "-")]
360         [Property("CRITERIA", "PRW")]
361         [Property("COVPARAM", "")]
362         [Property("AUTHOR", "guowei.wang@samsung.com")]
363         public void ScrollableBaseDecelerating()
364         {
365             tlog.Debug(tag, $"ScrollableBaseDecelerating START");
366
367             var testingTarget = new MyScrollableBase()
368             {
369                 Size = new Size(100, 2),
370                 BackgroundColor = Color.Cyan,
371                 ScrollingDirection = ScrollableBase.Direction.Vertical,
372             };
373             Assert.IsNotNull(testingTarget, "null handle");
374             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
375
376             try
377             {
378                 using (Animation ani = new Animation(300))
379                 {
380                     ani.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Bounce);
381                     testingTarget.MyDecelerating(0.3f, ani);
382                 }
383             }
384             catch (Exception e)
385             {
386                 tlog.Debug(tag, e.Message.ToString());
387                 Assert.Fail("Caught Exception : Failed!");
388             }
389
390             testingTarget.Dispose();
391             tlog.Debug(tag, $"ScrollableBaseDecelerating END (OK)");
392         }
393
394         [Test]
395         [Category("P1")]
396         [Description("ScrollableBase DecelerationThreshold")]
397         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.DecelerationThreshold A")]
398         [Property("SPEC_URL", "-")]
399         [Property("CRITERIA", "PRW")]
400         [Property("COVPARAM", "")]
401         [Property("AUTHOR", "guowei.wang@samsung.com")]
402         public void ScrollableBaseDecelerationThreshold()
403         {
404             tlog.Debug(tag, $"ScrollableBaseDecelerationThreshold START");
405
406             var testingTarget = new MyScrollableBase()
407             {
408                 Size = new Size(100, 2),
409                 BackgroundColor = Color.Cyan,
410                 ScrollingDirection = ScrollableBase.Direction.Vertical,
411             };
412             Assert.IsNotNull(testingTarget, "null handle");
413             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
414
415             testingTarget.DecelerationThreshold = 0.8f;
416             tlog.Debug(tag, "DecelerationThreshold : " + testingTarget.DecelerationThreshold);
417
418             testingTarget.Dispose();
419             tlog.Debug(tag, $"ScrollableBaseDecelerationThreshold END (OK)");
420         }
421
422         [Test]
423         [Category("P1")]
424         [Description("ScrollableBase ScrollAlphaFunction")]
425         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.ScrollAlphaFunction A")]
426         [Property("SPEC_URL", "-")]
427         [Property("CRITERIA", "PRW")]
428         [Property("COVPARAM", "")]
429         [Property("AUTHOR", "guowei.wang@samsung.com")]
430         public void ScrollableBaseScrollAlphaFunction()
431         {
432             tlog.Debug(tag, $"ScrollableBaseScrollAlphaFunction START");
433
434             var testingTarget = new MyScrollableBase()
435             {
436                 Size = new Size(100, 2),
437                 BackgroundColor = Color.Cyan,
438                 ScrollingDirection = ScrollableBase.Direction.Vertical,
439             };
440             Assert.IsNotNull(testingTarget, "null handle");
441             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
442
443             testingTarget.ScrollAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseIn);
444             tlog.Debug(tag, "ScrollAlphaFunction : " + testingTarget.ScrollAlphaFunction);
445
446             testingTarget.Dispose();
447             tlog.Debug(tag, $"ScrollableBaseScrollAlphaFunction END (OK)");
448         }
449
450         [Test]
451         [Category("P1")]
452         [Description("ScrollableBase AccessibilityScrollToChild")]
453         [Property("SPEC", "Tizen.NUI.Components.ScrollableBase.AccessibilityScrollToChild M")]
454         [Property("SPEC_URL", "-")]
455         [Property("CRITERIA", "MR")]
456         [Property("COVPARAM", "")]
457         [Property("AUTHOR", "guowei.wang@samsung.com")]
458         public void ScrollableBaseAccessibilityScrollToChild()
459         {
460             tlog.Debug(tag, $"ScrollableBaseAccessibilityScrollToChild START");
461
462             var testingTarget = new MyScrollableBase()
463             {
464                 Size = new Size(2000, 200),
465                 BackgroundColor = Color.Cyan,
466                 ScrollingDirection = ScrollableBase.Direction.Horizontal,
467             };
468             Assert.IsNotNull(testingTarget, "null handle");
469             Assert.IsInstanceOf<ScrollableBase>(testingTarget, "Should return ScrollableBase instance.");
470
471             testingTarget.ScrollAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseIn);
472             tlog.Debug(tag, "ScrollAlphaFunction : " + testingTarget.ScrollAlphaFunction);
473
474             View[] views = new View[10];
475             for (int i = 0; i < 10; i++)
476             {
477                 views[i] = new View();
478                 views[i].Size = new Size(200, 200);
479                 testingTarget.Add(views[i]);
480             }
481
482             var result = testingTarget.MyAccessibilityScrollToChild(views[9]);
483             tlog.Debug(tag, "AccessibilityScrollToChild : " + result);
484
485             try
486             {
487                 testingTarget.RemoveAllChildren(true);
488             }
489             catch (Exception e)
490             {
491                 tlog.Debug(tag, e.Message.ToString());
492                 Assert.Fail("Caught Exception : Failed!");
493             }
494
495             testingTarget.Dispose();
496             tlog.Debug(tag, $"ScrollableBaseAccessibilityScrollToChild END (OK)");
497         }
498     }
499 }