[NUI] Components function coverage test
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Components.Devel.Tests / testcase / Controls / Navigation / TSNavigator.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
8 namespace Tizen.NUI.Components.Devel.Tests
9 {
10     using tlog = Tizen.Log;
11
12     [TestFixture]
13     [Description("Controls/Navigation/Navigator")]
14     public class NavigationNavigatorTest
15     {
16         private const string tag = "NUITEST";
17
18         internal class MyPage : Page { }
19
20         [SetUp]
21         public void Init()
22         {
23             tlog.Info(tag, "Init() is called!");
24         }
25
26         [TearDown]
27         public void Destroy()
28         {
29             tlog.Info(tag, "Destroy() is called!");
30         }
31
32         [Test]
33         [Category("P1")]
34         [Description("PoppedEventArgs Page.")]
35         [Property("SPEC", "Tizen.NUI.Components.PoppedEventArgs.Page A")]
36         [Property("SPEC_URL", "-")]
37         [Property("CRITERIA", "PRW")]
38         [Property("COVPARAM", "")]
39         [Property("AUTHOR", "guowei.wang@samsung.com")]
40         public void PoppedEventArgsPage()
41         {
42             tlog.Debug(tag, $"PoppedEventArgsPage START");
43
44             var testingTarget = new PoppedEventArgs();
45             Assert.IsNotNull(testingTarget, "null handle");
46             Assert.IsInstanceOf<PoppedEventArgs>(testingTarget, "Should return PoppedEventArgs instance.");
47
48             tlog.Debug(tag, "Page : " + testingTarget.Page);
49
50             tlog.Debug(tag, $"PoppedEventArgsPage END (OK)");
51         }
52
53         [Test]
54         [Category("P1")]
55         [Description("Navigator Transition.")]
56         [Property("SPEC", "Tizen.NUI.Components.Navigator.Transition A")]
57         [Property("SPEC_URL", "-")]
58         [Property("CRITERIA", "PRW")]
59         [Property("COVPARAM", "")]
60         [Property("AUTHOR", "guowei.wang@samsung.com")]
61         public void NavigatorTransition()
62         {
63             tlog.Debug(tag, $"NavigatorTransition START");
64
65             var testingTarget = NUIApplication.GetDefaultWindow().GetDefaultNavigator();
66             Assert.IsNotNull(testingTarget, "null handle");
67             Assert.IsInstanceOf<Navigator>(testingTarget, "Should return Navigator instance.");
68
69             Transition ts = new Transition()
70             {
71                 AlphaFunction = new AlphaFunction(Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn),
72                 TimePeriod = new TimePeriod(300)
73             };
74
75             testingTarget.Transition = ts;
76             tlog.Debug(tag, "AppearingTransition : " + testingTarget.Transition);
77
78             tlog.Debug(tag, $"NavigatorTransition END (OK)");
79         }
80
81         [Test]
82         [Category("P1")]
83         [Description("Navigator PushWithTransition.")]
84         [Property("SPEC", "Tizen.NUI.Components.Navigator.PushWithTransition M")]
85         [Property("SPEC_URL", "-")]
86         [Property("CRITERIA", "MR")]
87         [Property("COVPARAM", "")]
88         [Property("AUTHOR", "guowei.wang@samsung.com")]
89         public void NavigatorPushWithTransition()
90         {
91             tlog.Debug(tag, $"NavigatorPushWithTransition START");
92
93             var testingTarget = NUIApplication.GetDefaultWindow().GetDefaultNavigator();
94             Assert.IsNotNull(testingTarget, "null handle");
95             Assert.IsInstanceOf<Navigator>(testingTarget, "Should return Navigator instance.");
96
97             Window.Instance.Add(testingTarget);
98
99             var page1 = CreateFirstPage(testingTarget);
100             var page2 = CreateSecondPage(testingTarget);
101             var page3 = CreateThirdPage(testingTarget);
102             var page4 = CreateFourthPage(testingTarget);
103
104             Transition ts = new Transition()
105             {
106                 AlphaFunction = new AlphaFunction(Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn),
107                 TimePeriod = new TimePeriod(300)
108             };
109
110             testingTarget.Transition = ts;
111             tlog.Debug(tag, "Transition : " + testingTarget.Transition);
112
113             try
114             {
115                 testingTarget.PushWithTransition(page1);
116                 testingTarget.PopWithTransition();
117
118                 testingTarget.PushWithTransition(page2);
119                 testingTarget.PopWithTransition();
120
121                 testingTarget.PushWithTransition(page3);
122                 testingTarget.PopWithTransition();
123
124                 testingTarget.PushWithTransition(page4);
125                 testingTarget.PopWithTransition();
126             }
127             catch (Exception e)
128             {
129                 tlog.Debug(tag, e.Message.ToString());
130                 Assert.Fail("Caught Exception : Failed!");
131             }
132
133             tlog.Debug(tag, $"NavigatorPushWithTransition END (OK)");
134         }
135
136         [Test]
137         [Category("P2")]
138         [Description("Navigator PushWithTransition.")]
139         [Property("SPEC", "Tizen.NUI.Components.Navigator.PushWithTransition M")]
140         [Property("SPEC_URL", "-")]
141         [Property("CRITERIA", "MR")]
142         [Property("COVPARAM", "")]
143         [Property("AUTHOR", "guowei.wang@samsung.com")]
144         public void NavigatorPushWithTransitionWithNullPage()
145         {
146             tlog.Debug(tag, $"NavigatorPushWithTransitionWithNullPage START");
147
148             var testingTarget = NUIApplication.GetDefaultWindow().GetDefaultNavigator();
149
150             Assert.IsNotNull(testingTarget, "null handle");
151             Assert.IsInstanceOf<Navigator>(testingTarget, "Should return Navigator instance.");
152
153             Transition ts = new Transition()
154             {
155                 AlphaFunction = new AlphaFunction(Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn),
156                 TimePeriod = new TimePeriod(300)
157             };
158
159             testingTarget.Transition = ts;
160
161             MyPage page = null;
162
163             try
164             {
165                 testingTarget.PushWithTransition(page);
166             }
167             catch (ArgumentNullException)
168             {
169                 tlog.Debug(tag, $"NavigatorPushWithTransitionWithNullPage END (OK)");
170                 Assert.Pass("Caught ArgumentNullException : Passed!");
171             }
172         }
173
174         private Page CreateFirstPage(Navigator navigator)
175         {
176             var button = new Button()
177             {
178                 Text = "First Page",
179                 WidthResizePolicy = ResizePolicyType.FillToParent,
180                 HeightResizePolicy = ResizePolicyType.FillToParent,
181             };
182
183             var page = new MyPage();
184             page.Add(button);
185             page.Appearing += (object sender, PageAppearingEventArgs e) =>
186             {
187                 global::System.Console.WriteLine("First Page is appearing!");
188             };
189             page.Disappearing += (object sender, PageDisappearingEventArgs e) =>
190             {
191                 global::System.Console.WriteLine("First Page is disappearing!");
192             };
193
194             navigator.Push(page);
195
196             return page;
197         }
198
199         private Page CreateSecondPage(Navigator navigator)
200         {
201             var button = new Button()
202             {
203                 Text = "Second Page",
204                 WidthResizePolicy = ResizePolicyType.FillToParent,
205                 HeightResizePolicy = ResizePolicyType.FillToParent,
206             };
207
208             var page = new MyPage();
209             page.Add(button);
210             page.Appearing += (object sender, PageAppearingEventArgs e) =>
211             {
212                 global::System.Console.WriteLine("Second Page is appearing!");
213             };
214             page.Disappearing += (object sender, PageDisappearingEventArgs e) =>
215             {
216                 global::System.Console.WriteLine("Second Page is disappearing!");
217             };
218
219             navigator.Push(page);
220
221             return page;
222         }
223
224         private Page CreateThirdPage(Navigator navigator)
225         {
226             var button = new Button()
227             {
228                 Text = "Third Page",
229                 WidthResizePolicy = ResizePolicyType.FillToParent,
230                 HeightResizePolicy = ResizePolicyType.FillToParent,
231             };
232
233             var page = new DialogPage();
234             page.Add(button);
235             page.Appearing += (object sender, PageAppearingEventArgs e) =>
236             {
237                 global::System.Console.WriteLine("Third Page is appearing!");
238             };
239             page.Disappearing += (object sender, PageDisappearingEventArgs e) =>
240             {
241                 global::System.Console.WriteLine("Third Page is disappearing!");
242             };
243
244             navigator.Push(page);
245
246             return page;
247         }
248
249         private Page CreateFourthPage(Navigator navigator)
250         {
251             var button = new Button()
252             {
253                 Text = "Fourth Page",
254                 WidthResizePolicy = ResizePolicyType.FillToParent,
255                 HeightResizePolicy = ResizePolicyType.FillToParent,
256             };
257
258             var page = new DialogPage();
259             page.Add(button);
260             page.Appearing += (object sender, PageAppearingEventArgs e) =>
261             {
262                 global::System.Console.WriteLine("Third Page is appearing!");
263             };
264             page.Disappearing += (object sender, PageDisappearingEventArgs e) =>
265             {
266                 global::System.Console.WriteLine("Third Page is disappearing!");
267             };
268
269             navigator.Push(page);
270
271             return page;
272         }
273     }
274 }