Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / Application / TSNUIWidgetApplication.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/Application/NUIWidgetApplication")]
14
15     internal class MyWidget : Widget
16     {
17         protected override void OnCreate(string contentInfo, Window window)
18         {
19             window.BackgroundColor = Color.White;
20             TextLabel textLabel = new TextLabel("Widget Works");
21
22             window.GetDefaultLayer().Add(textLabel);
23             base.OnCreate(contentInfo, window);
24         }
25     }
26
27     internal class MyNUIWidgetApplication : NUIWidgetApplication
28     {
29         public MyNUIWidgetApplication(global::System.Type widgetType) : base(widgetType)
30         { }
31
32         public void MyOnCreate()
33         {
34             base.OnCreate();
35         }
36
37         public void MyOnTerminate()
38         {
39             base.OnTerminate();
40         }
41
42         public void MyOnLocaleChanged(Applications.LocaleChangedEventArgs e)
43         {
44             base.OnLocaleChanged(e);
45         }
46
47         public void MyOnLowBattery(Applications.LowBatteryEventArgs e)
48         {
49             base.OnLowBattery(e);
50         }
51
52         public void MyOnLowMemory(Applications.LowMemoryEventArgs e)
53         {
54             base.OnLowMemory(e);
55         }
56
57         public void MyOnRegionFormatChanged(Applications.RegionFormatChangedEventArgs e)
58         {
59             base.OnRegionFormatChanged(e);
60         }
61     }
62
63     public class PublicNUIWidgetApplicationTest
64     {
65         private const string tag = "NUITEST";
66
67         [SetUp]
68         public void Init()
69         {
70             tlog.Info(tag, "Init() is called!");
71         }
72
73         [TearDown]
74         public void Destroy()
75         {
76             tlog.Info(tag, "Destroy() is called!");
77         }
78
79         [Test]
80         [Category("P1")]
81         [Description("NUIWidgetApplication constructor.")]
82         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.NUIWidgetApplication C")]
83         [Property("SPEC_URL", "-")]
84         [Property("CRITERIA", "CONSTR")]
85         [Property("AUTHOR", "guowei.wang@samsung.com")]
86         public void NUIWidgetApplicationConstructor()
87         {
88             tlog.Debug(tag, $"NUIWidgetApplicationConstructor START");
89
90             var testingTarget = new NUIWidgetApplication(typeof(MyWidget));
91             Assert.IsNotNull(testingTarget, "should be not null.");
92             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
93
94             testingTarget.Dispose();
95             tlog.Debug(tag, $"NUIWidgetApplicationConstructor END (OK)");
96         }
97
98         [Test]
99         [Category("P1")]
100         [Description("NUIWidgetApplication constructor. With stylesheet.")]
101         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.NUIWidgetApplication C")]
102         [Property("SPEC_URL", "-")]
103         [Property("CRITERIA", "CONSTR")]
104         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
105         public void NUIWidgetApplicationConstructorWithStylesheet()
106         {
107             tlog.Debug(tag, $"NUIWidgetApplicationConstructorWithStylesheet START");
108
109             var testingTarget = new NUIWidgetApplication(typeof(MyWidget), "stylesheet");
110             Assert.IsNotNull(testingTarget, "should be not null.");
111             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
112
113             testingTarget.Dispose();
114             tlog.Debug(tag, $"NUIWidgetApplicationConstructorWithStylesheet END (OK)");
115         }
116
117         [Test]
118         [Category("P1")]
119         [Description("NUIWidgetApplication constructor. With multi class.")]
120         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.NUIWidgetApplication C")]
121         [Property("SPEC_URL", "-")]
122         [Property("CRITERIA", "CONSTR")]
123         [Property("AUTHOR", "guowei.wang@samsung.com")]
124         public void NUIWidgetApplicationConstructorWithMultiClass()
125         {
126             tlog.Debug(tag, $"NUIWidgetApplicationConstructorWithMultiClass START");
127
128             Dictionary<Type, string> widgetSet = new Dictionary<Type, string>();
129             widgetSet.Add(typeof(MyWidget), "Tizen.NUI.Tests");
130
131             var testingTarget = new NUIWidgetApplication(widgetSet);
132             Assert.IsNotNull(testingTarget, "should be not null.");
133             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
134
135             testingTarget.Dispose();
136             tlog.Debug(tag, $"NUIWidgetApplicationConstructorWithMultiClass END (OK)");
137         }
138
139         [Test]
140         [Category("P2")]
141         [Description("NUIWidgetApplication constructor. With invalid value.")]
142         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.NUIWidgetApplication C")]
143         [Property("SPEC_URL", "-")]
144         [Property("CRITERIA", "CONSTR")]
145         [Property("AUTHOR", "guowei.wang@samsung.com")]
146         public void NUIWidgetApplicationConstructorWithNullValue()
147         {
148             tlog.Debug(tag, $"NUIWidgetApplicationConstructorWithNullValue START");
149
150             try
151             {
152                 Dictionary<Type, string> widgetSet = null;
153                 var testingTarget = new NUIWidgetApplication(widgetSet);
154             }
155             catch (InvalidOperationException e)
156             {
157                 tlog.Debug(tag, e.Message.ToString());
158                 tlog.Debug(tag, $"NUIWidgetApplicationConstructorWithNullValue END (OK)");
159                 Assert.Pass("Create a NUIWidgetApplication with invalid Dictionary");
160             }
161         }
162
163         [Test]
164         [Category("P1")]
165         [Description("NUIWidgetApplication Dispose.")]
166         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.Dispose M")]
167         [Property("SPEC_URL", "-")]
168         [Property("CRITERIA", "MR")]
169         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
170         public void NUIWidgetApplicationDispose()
171         {
172             tlog.Debug(tag, $"NUIWidgetApplicationDispose START");
173
174             try
175             {
176                 var testingTarget = new NUIWidgetApplication(typeof(MyWidget));
177                 Assert.IsNotNull(testingTarget, "should be not null.");
178                 Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
179
180                 testingTarget.Dispose();
181             }
182             catch (Exception e)
183             {
184                 tlog.Error(tag, "Caught Exception" + e.ToString());
185                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
186                 Assert.Fail("Caught Exception" + e.ToString());
187             }
188
189             tlog.Debug(tag, $"NUIWidgetApplicationDispose END (OK)");
190         }
191
192         [Test]
193         [Category("P1")]
194         [Description("NUIWidgetApplication AddWidgetType.")]
195         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.AddWidgetType M")]
196         [Property("SPEC_URL", "-")]
197         [Property("CRITERIA", "MR")]
198         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
199         public void NUIWidgetApplicationAddWidgetType()
200         {
201             tlog.Debug(tag, $"NUIWidgetApplicationAddWidgetType START");
202
203             var testingTarget = new NUIWidgetApplication(typeof(MyWidget));
204             Assert.IsNotNull(testingTarget, "should be not null.");
205             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
206             
207             try
208             {
209                 testingTarget.AddWidgetType(typeof(MyWidget));
210             }
211             catch (Exception e)
212             {
213                 tlog.Error(tag, "Caught Exception" + e.ToString());
214                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
215                 Assert.Fail("Caught Exception" + e.ToString());
216             }
217
218             testingTarget.Dispose();
219             tlog.Debug(tag, $"NUIWidgetApplicationAddWidgetType END (OK)");
220         }
221
222         [Test]
223         [Category("P1")]
224         [Description("NUIWidgetApplication AddWidgetType. With Dictionary.")]
225         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.AddWidgetType M")]
226         [Property("SPEC_URL", "-")]
227         [Property("CRITERIA", "MR")]
228         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
229         public void NUIWidgetApplicationAddWidgetTypeWithDictionary()
230         {
231             tlog.Debug(tag, $"NUIWidgetApplicationAddWidgetTypeWithDictionary START");
232
233             var testingTarget = new NUIWidgetApplication(typeof(MyWidget));
234             Assert.IsNotNull(testingTarget, "should be not null.");
235             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
236
237             try
238             {
239                 Dictionary<global::System.Type, string> widgetTypes = new Dictionary<Type, string>();
240                 widgetTypes.Add(typeof(MyWidget), "MyWidget");
241                 testingTarget.AddWidgetType(widgetTypes);
242             }
243             catch (Exception e)
244             {
245                 tlog.Error(tag, "Caught Exception" + e.ToString());
246                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
247                 Assert.Fail("Caught Exception" + e.ToString());
248             }
249
250             testingTarget.Dispose();
251             tlog.Debug(tag, $"NUIWidgetApplicationAddWidgetTypeWithDictionary END (OK)");
252         }
253
254         [Test]
255         [Category("P1")]
256         [Description("NUIWidgetApplication ApplicationHandle.")]
257         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.ApplicationHandle M")]
258         [Property("SPEC_URL", "-")]
259         [Property("CRITERIA", "MR")]
260         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
261         public void NUIWidgetApplicationApplicationHandle()
262         {
263             tlog.Debug(tag, $"NUIWidgetApplicationApplicationHandle START");
264
265             var testingTarget = new NUIWidgetApplication(typeof(MyWidget));
266             Assert.IsNotNull(testingTarget, "should be not null.");
267             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
268
269             try
270             {
271                 var result =  testingTarget.ApplicationHandle;
272             }
273             catch (Exception e)
274             {
275                 tlog.Error(tag, "Caught Exception" + e.ToString());
276                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
277                 Assert.Fail("Caught Exception" + e.ToString());
278             }
279
280             testingTarget.Dispose();
281             tlog.Debug(tag, $"NUIWidgetApplicationApplicationHandle END (OK)");
282         }
283
284         [Test]
285         [Category("P1")]
286         [Description("NUIWidgetApplication OnCreate.")]
287         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.OnCreate M")]
288         [Property("SPEC_URL", "-")]
289         [Property("CRITERIA", "MR")]
290         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
291         public void NUIWidgetApplicationOnCreate()
292         {
293             tlog.Debug(tag, $"NUIWidgetApplicationOnCreate START");
294
295             var testingTarget = new MyNUIWidgetApplication(typeof(MyWidget));
296             Assert.IsNotNull(testingTarget, "should be not null.");
297             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
298
299             try
300             {
301                 testingTarget.MyOnCreate();
302             }
303             catch (Exception e)
304             {
305                 tlog.Error(tag, "Caught Exception" + e.ToString());
306                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
307                 Assert.Fail("Caught Exception" + e.ToString());
308             }
309
310             testingTarget.Dispose();
311             tlog.Debug(tag, $"NUIWidgetApplicationOnCreate END (OK)");
312         }
313
314         [Test]
315         [Category("P1")]
316         [Description("NUIWidgetApplication OnLocaleChanged.")]
317         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.OnLocaleChanged M")]
318         [Property("SPEC_URL", "-")]
319         [Property("CRITERIA", "MR")]
320         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
321         public void NUIWidgetApplicationOnLocaleChanged()
322         {
323             tlog.Debug(tag, $"NUIWidgetApplicationOnLocaleChanged START");
324
325             var testingTarget = new MyNUIWidgetApplication(typeof(MyWidget));
326             Assert.IsNotNull(testingTarget, "should be not null.");
327             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
328
329             try
330             {
331                 testingTarget.MyOnLocaleChanged(new Applications.LocaleChangedEventArgs("BeiJing"));
332             }
333             catch (Exception e)
334             {
335                 tlog.Error(tag, "Caught Exception" + e.ToString());
336                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
337                 Assert.Fail("Caught Exception" + e.ToString());
338             }
339
340             testingTarget.Dispose();
341             tlog.Debug(tag, $"NUIWidgetApplicationOnLocaleChanged END (OK)");
342         }
343
344         [Test]
345         [Category("P1")]
346         [Description("NUIWidgetApplication OnLowBattery.")]
347         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.OnLowBattery M")]
348         [Property("SPEC_URL", "-")]
349         [Property("CRITERIA", "MR")]
350         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
351         public void NUIWidgetApplicationOnLowBattery()
352         {
353             tlog.Debug(tag, $"NUIWidgetApplicationOnLowBattery START");
354
355             var testingTarget = new MyNUIWidgetApplication(typeof(MyWidget));
356             Assert.IsNotNull(testingTarget, "should be not null.");
357             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
358
359             try
360             {
361                 testingTarget.MyOnLowBattery(new Applications.LowBatteryEventArgs(Applications.LowBatteryStatus.PowerOff));
362             }
363             catch (Exception e)
364             {
365                 tlog.Error(tag, "Caught Exception" + e.ToString());
366                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
367                 Assert.Fail("Caught Exception" + e.ToString());
368             }
369
370             testingTarget.Dispose();
371             tlog.Debug(tag, $"NUIWidgetApplicationOnLowBattery END (OK)");
372         }
373
374         [Test]
375         [Category("P1")]
376         [Description("NUIWidgetApplication OnLowMemory.")]
377         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.OnLowMemory M")]
378         [Property("SPEC_URL", "-")]
379         [Property("CRITERIA", "MR")]
380         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
381         public void NUIWidgetApplicationOnLowMemory()
382         {
383             tlog.Debug(tag, $"NUIWidgetApplicationOnLowMemory START");
384
385             var testingTarget = new MyNUIWidgetApplication(typeof(MyWidget));
386             Assert.IsNotNull(testingTarget, "should be not null.");
387             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
388
389             try
390             {
391                 testingTarget.MyOnLowMemory(new Applications.LowMemoryEventArgs(Applications.LowMemoryStatus.Normal));
392             }
393             catch (Exception e)
394             {
395                 tlog.Error(tag, "Caught Exception" + e.ToString());
396                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
397                 Assert.Fail("Caught Exception" + e.ToString());
398             }
399
400             testingTarget.Dispose();
401             tlog.Debug(tag, $"NUIWidgetApplicationOnLowMemory END (OK)");
402         }
403
404         [Test]
405         [Category("P1")]
406         [Description("NUIWidgetApplication OnTerminate.")]
407         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.OnTerminate M")]
408         [Property("SPEC_URL", "-")]
409         [Property("CRITERIA", "MR")]
410         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
411         public void NUIWidgetApplicationOnTerminate()
412         {
413             tlog.Debug(tag, $"NUIWidgetApplicationOnTerminate START");
414
415             var testingTarget = new MyNUIWidgetApplication(typeof(MyWidget));
416             Assert.IsNotNull(testingTarget, "should be not null.");
417             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
418
419             try
420             {
421                 testingTarget.MyOnTerminate();
422             }
423             catch (Exception e)
424             {
425                 tlog.Error(tag, "Caught Exception" + e.ToString());
426                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
427                 Assert.Fail("Caught Exception" + e.ToString());
428             }
429
430             testingTarget.Dispose();
431             tlog.Debug(tag, $"NUIWidgetApplicationOnTerminate END (OK)");
432         }
433
434         [Test]
435         [Category("P1")]
436         [Description("NUIWidgetApplication OnRegionFormatChanged.")]
437         [Property("SPEC", "Tizen.NUI.NUIWidgetApplication.OnRegionFormatChanged M")]
438         [Property("SPEC_URL", "-")]
439         [Property("CRITERIA", "MR")]
440         [Property("AUTHOR", "guowei.wang@partner.samsung.com")]
441         public void NUIWidgetApplicationOnRegionFormatChanged()
442         {
443             tlog.Debug(tag, $"NUIWidgetApplicationOnRegionFormatChanged START");
444
445             var testingTarget = new MyNUIWidgetApplication(typeof(MyWidget));
446             Assert.IsNotNull(testingTarget, "should be not null.");
447             Assert.IsInstanceOf<NUIWidgetApplication>(testingTarget, "Should be an instance of NUIWidgetApplication type.");
448
449             try
450             {
451                 testingTarget.MyOnRegionFormatChanged(new Applications.RegionFormatChangedEventArgs("China"));
452             }
453             catch (Exception e)
454             {
455                 tlog.Error(tag, "Caught Exception" + e.ToString());
456                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
457                 Assert.Fail("Caught Exception" + e.ToString());
458             }
459
460             testingTarget.Dispose();
461             tlog.Debug(tag, $"NUIWidgetApplicationOnRegionFormatChanged END (OK)");
462         }
463     }
464 }