5e8bfde07496c8ce8bc3fceffdcc8d8e4a8b75c8
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / Application / TSNUIApplication.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.Globalization;
7 using System.Resources;
8 using Tizen.Applications;
9
10 namespace Tizen.NUI.Devel.Tests
11 {
12     using tlog = Tizen.Log;
13
14     [TestFixture]
15     [Description("public/Application/NUIApplication")]
16     class PublicNUIApplicationTest
17     {
18         private const string tag = "NUITEST";
19         private delegate bool dummyCallback(IntPtr NUIApplication);
20         private bool OnDummyCallback(IntPtr data)
21         {
22             return false;
23         }
24
25         internal class MyNUIApplication : NUIApplication
26         {
27             public MyNUIApplication() : base()
28             { }
29
30             public void MyOnTerminate()
31             {
32                 base.OnTerminate();
33             }
34
35             public void MyOnLocaleChanged(LocaleChangedEventArgs e)
36             {
37                 base.OnLocaleChanged(e);
38             }
39         }
40
41         [SetUp]
42         public void Init()
43         {
44             tlog.Info(tag, "Init() is called!");
45         }
46
47         [TearDown]
48         public void Destroy()
49         {
50             tlog.Info(tag, "Destroy() is called!");
51         }
52
53         [Test]
54         [Category("P1")]
55         [Description("NUIApplication constructor.")]
56         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
57         [Property("SPEC_URL", "-")]
58         [Property("CRITERIA", "CONSTR")]
59         [Property("AUTHOR", "guowei.wang@samsung.com")]
60         public void NUIApplicationConstructor()
61         {
62             tlog.Debug(tag, $"NUIApplicationConstructor START");
63
64             var testingTarget = new NUIApplication();
65             Assert.IsNotNull(testingTarget, "Should be not null.");
66             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
67
68             testingTarget.Dispose();
69             tlog.Debug(tag, $"NUIApplicationConstructor END (OK)");
70         }
71
72         [Test]
73         [Category("P1")]
74         [Description("NUIApplication constructor. With window size and position")]
75         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
76         [Property("SPEC_URL", "-")]
77         [Property("CRITERIA", "CONSTR")]
78         [Property("AUTHOR", "guowei.wang@samsung.com")]
79         public void NUIApplicationConstructorWithWindowSizeAndPosition()
80         {
81             tlog.Debug(tag, $"NUIApplicationConstructorWithWindowSizeAndPosition START");
82
83             Size size = new Size(100, 200);
84             Position pos = new Position(200, 300);
85             var testingTarget = new NUIApplication(size, pos);
86             Assert.IsNotNull(testingTarget, "Should be not null.");
87             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
88
89             pos.Dispose();
90             size.Dispose();
91             testingTarget.Dispose();
92             tlog.Debug(tag, $"NUIApplicationConstructorWithWindowSizeAndPosition END (OK)");
93         }
94
95         [Test]
96         [Category("P1")]
97         [Description("NUIApplication constructor. With stylesheet.")]
98         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
99         [Property("SPEC_URL", "-")]
100         [Property("CRITERIA", "CONSTR")]
101         [Property("AUTHOR", "guowei.wang@samsung.com")]
102         public void NUIApplicationConstructorWithStyleSheet()
103         {
104             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheet START");
105
106             var testingTarget = new NUIApplication("stylesheet");
107             Assert.IsNotNull(testingTarget, "Should be not null.");
108             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
109
110             testingTarget.Dispose();
111             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheet END (OK)");
112         }
113
114         [Test]
115         [Category("P1")]
116         [Description("NUIApplication constructor. With stylesheet, window size, position.")]
117         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
118         [Property("SPEC_URL", "-")]
119         [Property("CRITERIA", "CONSTR")]
120         [Property("AUTHOR", "guowei.wang@samsung.com")]
121         public void NUIApplicationConstructorWithStyleSheetAndWindowSizeAndPostion()
122         {
123             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheetAndWindowSizeAndPostion START");
124
125             var testingTarget = new NUIApplication("stylesheet", new Size(100, 200), new Position(200, 300));
126             Assert.IsNotNull(testingTarget, "Should be not null.");
127             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
128
129             testingTarget.Dispose();
130             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheetAndWindowSizeAndPostion END (OK)");
131         }
132
133         [Test]
134         [Category("P1")]
135         [Description("NUIApplication constructor. With stylesheet and WindowMode.")]
136         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
137         [Property("SPEC_URL", "-")]
138         [Property("CRITERIA", "CONSTR")]
139         [Property("AUTHOR", "guowei.wang@samsung.com")]
140         public void NUIApplicationConstructorWithStringAndWindowMode()
141         {
142             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowMode START");
143
144             var testingTarget = new NUIApplication("stylesheet", NUIApplication.WindowMode.Opaque);
145             Assert.IsNotNull(testingTarget, "Should be not null.");
146             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
147
148             testingTarget.Dispose();
149             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowMode END (OK)");
150         }
151
152         [Test]
153         [Category("P1")]
154         [Description("NUIApplication constructor. With stylesheet, WindowMode, window size and position")]
155         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
156         [Property("SPEC_URL", "-")]
157         [Property("CRITERIA", "CONSTR")]
158         [Property("AUTHOR", "guowei.wang@samsung.com")]
159         public void NUIApplicationConstructorWithStringAndWindowModeAndWindowSizeAndPosition()
160         {
161             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowModeAndWindowSizeAndPosition START");
162
163             var testingTarget = new NUIApplication("stylesheet", NUIApplication.WindowMode.Opaque, new Size(100, 200), new Position(200, 300));
164             Assert.IsNotNull(testingTarget, "Should be not null.");
165             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
166
167             testingTarget.Dispose();
168             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowModeAndWindowSizeAndPosition END (OK)");
169         }
170
171         [Test]
172         [Category("P1")]
173         [Description("NUIApplication constructor. With BackendType.")]
174         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
175         [Property("SPEC_URL", "-")]
176         [Property("CRITERIA", "CONSTR")]
177         [Property("AUTHOR", "guowei.wang@samsung.com")]
178         public void NUIApplicationConstructorWithBackendType()
179         {
180             tlog.Debug(tag, $"NUIApplicationConstructorWithBackendType START");
181
182             var testingTarget = new NUIApplication(Graphics.BackendType.Vulkan);
183             Assert.IsNotNull(testingTarget, "Should be not null.");
184             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
185
186             testingTarget.Dispose();
187             tlog.Debug(tag, $"NUIApplicationConstructorWithBackendType END (OK)");
188         }
189
190         [Test]
191         [Category("P1")]
192         [Description("NUIApplication constructor. With ThemeOptions.")]
193         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
194         [Property("SPEC_URL", "-")]
195         [Property("CRITERIA", "CONSTR")]
196         [Property("AUTHOR", "guowei.wang@samsung.com")]
197         public void NUIApplicationConstructorWithThemeOptions()
198         {
199             tlog.Debug(tag, $"NUIApplicationConstructorWithThemeOptions START");
200
201             var testingTarget = new NUIApplication(NUIApplication.ThemeOptions.PlatformThemeEnabled);
202             Assert.IsNotNull(testingTarget, "Should be not null.");
203             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
204
205             testingTarget.Dispose();
206             tlog.Debug(tag, $"NUIApplicationConstructorWithThemeOptions END (OK)");
207         }
208
209         [Test]
210         [Category("P1")]
211         [Description("NUIApplication constructor. With windowSize, windowPosition and options.")]
212         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
213         [Property("SPEC_URL", "-")]
214         [Property("CRITERIA", "CONSTR")]
215         [Property("AUTHOR", "guowei.wang@samsung.com")]
216         public void NUIApplicationConstructorWithSizePositionAndThemeOptions()
217         {
218             tlog.Debug(tag, $"NUIApplicationConstructorWithSizePositionAndThemeOptions START");
219
220             Size2D windowSize = new Size2D(100, 50);
221             Position2D windowPosition = new Position2D(20, 30);
222             var testingTarget = new NUIApplication(windowSize, windowPosition, NUIApplication.ThemeOptions.PlatformThemeEnabled);
223             Assert.IsNotNull(testingTarget, "Should be not null.");
224             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
225
226             windowSize.Dispose();
227             windowPosition.Dispose();
228             testingTarget.Dispose();
229             tlog.Debug(tag, $"NUIApplicationConstructorWithSizePositionAndThemeOptions END (OK)");
230         }
231
232         [Test]
233         [Category("P1")]
234         [Description("NUIApplication constructor. Support IME window.")]
235         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
236         [Property("SPEC_URL", "-")]
237         [Property("CRITERIA", "CONSTR")]
238         [Property("AUTHOR", "guowei.wang@samsung.com")]
239         public void NUIApplicationConstructorForImeWindow()
240         {
241             tlog.Debug(tag, $"NUIApplicationConstructorForImeWindow START");
242
243             var application = new NUIApplication("stylesheet", NUIApplication.WindowMode.Opaque, WindowType.Ime);
244             Assert.IsNotNull(application, "NUIApplication Should return NUIApplication instance.");
245             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
246
247             windowSize.Dispose();
248             windowPosition.Dispose();
249             testingTarget.Dispose();
250             tlog.Debug(tag, $"NUIApplicationConstructorForImeWindow END (OK)");
251         }
252
253         [Test]
254         [Category("P1")]
255         [Description("NUIApplication RegisterAssembly.")]
256         [Property("SPEC", "Tizen.NUI.NUIApplication.RegisterAssembly M")]
257         [Property("SPEC_URL", "-")]
258         [Property("CRITERIA", "MR")]
259         [Property("AUTHOR", "guowei.wang@samsung.com")]
260         public void NUIApplicationRegisterAssembly()
261         {
262             tlog.Debug(tag, $"NUIApplicationRegisterAssembly START");
263
264             try
265             {
266                 NUIApplication.RegisterAssembly(typeof(NUIApplication).Assembly);
267             }
268             catch (Exception e)
269             {
270                 tlog.Error(tag, "Caught Exception" + e.ToString());
271                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
272                 Assert.Fail("Caught Exception" + e.ToString());
273             }
274
275             tlog.Debug(tag, $"NUIApplicationRegisterAssembly END (OK)");
276         }
277
278         [Test]
279         [Category("P1")]
280         [Description("NUIApplication MultilingualResourceManager.")]
281         [Property("SPEC", "Tizen.NUI.NUIApplication.MultilingualResourceManager A")]
282         [Property("SPEC_URL", "-")]
283         [Property("CRITERIA", "PRW")]
284         [Property("AUTHOR", "guowei.wang@samsung.com")]
285         public void NUIApplicationMultilingualResourceManager()
286         {
287             tlog.Debug(tag, $"NUIApplicationMultilingualResourceManager START");
288
289             NUIApplication.MultilingualResourceManager = Resource.ResourceManager;
290             Assert.IsNotNull(NUIApplication.MultilingualResourceManager, "Should be not null!");
291
292             string str = null;
293             str = NUIApplication.MultilingualResourceManager?.GetString("Test");
294             Assert.AreEqual("Test", str, "Picture should be Beeld in Dutch");
295
296             tlog.Debug(tag, $"NUIApplicationMultilingualResourceManager END (OK)");
297         }
298
299         [Test]
300         [Category("P1")]
301         [Description("NUIApplication AppId")]
302         [Property("SPEC", "Tizen.NUI.NUIApplication.AppId A")]
303         [Property("SPEC_URL", "-")]
304         [Property("CRITERIA", "PRO")]
305         [Property("AUTHOR", "guowei.wang@samsung.com")]
306         public void NUIApplicationAppId()
307         {
308             tlog.Debug(tag, $"NUIApplicationAppId START");
309
310             var testingTarget = new NUIApplication();
311             Assert.IsNotNull(testingTarget, "Should be not null.");
312             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
313
314             var result = testingTarget.AppId;
315             Assert.IsNotNull(result, "Should be not null.");
316
317             tlog.Debug(tag, $"NUIApplicationAppId END (OK)");
318         }
319
320         [Test]
321         [Category("P1")]
322         [Description("NUIApplication GetDefaultWindow")]
323         [Property("SPEC", "Tizen.NUI.NUIApplication.GetDefaultWindow M")]
324         [Property("SPEC_URL", "-")]
325         [Property("CRITERIA", "MR")]
326         [Property("AUTHOR", "guowei.wang@samsung.com")]
327         public void NUIApplicationGetDefaultWindow()
328         {
329             tlog.Debug(tag, $"NUIApplicationGetDefaultWindow START");
330
331             var testingTarget = NUIApplication.GetDefaultWindow();
332             Assert.IsNotNull(testingTarget, "Should be not null.");
333             Assert.IsInstanceOf<Window>(testingTarget, "Should be an instance of Window type.");
334
335             testingTarget.Dispose();
336             tlog.Debug(tag, $"NUIApplicationGetDefaultWindow END (OK)");
337         }
338
339         [Test]
340         [Category("P1")]
341         [Description("NUIApplication AddIdle")]
342         [Property("SPEC", "Tizen.NUI.NUIApplication.AddIdle M")]
343         [Property("SPEC_URL", "-")]
344         [Property("CRITERIA", "MR")]
345         [Property("AUTHOR", "guowei.wang@samsung.com")]
346         public void NUIApplicationAddIdle()
347         {
348             tlog.Debug(tag, $"NUIApplicationAddIdle START");
349
350             dummyCallback callback = OnDummyCallback;
351             var result = Application.Instance.AddIdle(callback);
352             Assert.IsTrue(result);
353
354             tlog.Debug(tag, $"NUIApplicationAddIdle END (OK)");
355         }
356
357         [Test]
358         [Category("P1")]
359         [Description("NUIApplication SetRenderRefreshRate")]
360         [Property("SPEC", "Tizen.NUI.NUIApplication.SetRenderRefreshRate M")]
361         [Property("SPEC_URL", "-")]
362         [Property("CRITERIA", "MR")]
363         [Property("AUTHOR", "guowei.wang@samsung.com")]
364         public void NUIApplicationSetRenderRefreshRate()
365         {
366             tlog.Debug(tag, $"NUIApplicationSetRenderRefreshRate START");
367
368             try
369             {
370                 NUIApplication.SetRenderRefreshRate(2);
371             }
372             catch (Exception e)
373             {
374                 tlog.Error(tag, "Caught Exception" + e.ToString());
375                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
376                 Assert.Fail("Caught Exception" + e.ToString());
377             }
378
379             tlog.Debug(tag, $"NUIApplicationSetRenderRefreshRate END (OK)");
380         }
381
382         [Test]
383         [Category("P1")]
384         [Description("NUIApplication TransitionOptions")]
385         [Property("SPEC", "Tizen.NUI.NUIApplication.TransitionOptions A")]
386         [Property("SPEC_URL", "-")]
387         [Property("CRITERIA", "PRW")]
388         [Property("AUTHOR", "guowei.wang@samsung.com")]
389         public void NUIApplicationTransitionOptions()
390         {
391             tlog.Debug(tag, $"NUIApplicationTransitionOptions START");
392
393             var testingTarget = new NUIApplication();
394             Assert.IsNotNull(testingTarget, "Should be not null.");
395             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of Window type.");
396
397             TransitionOptions transitionOption = new TransitionOptions(Window.Instance);
398             testingTarget.TransitionOptions = transitionOption;
399
400             var result = testingTarget.TransitionOptions;
401             Assert.IsNotNull(result);
402             Assert.IsInstanceOf<TransitionOptions>(result, "Should be an instance of TransitionOptions type.");
403
404             result.Dispose();
405             transitionOption.Dispose();
406             testingTarget.Dispose();
407             tlog.Debug(tag, $"NUIApplicationTransitionOptions END (OK)");
408         }
409
410         [Test]
411         [Category("P1")]
412         [Description("NUIApplication OnTerminate")]
413         [Property("SPEC", "Tizen.NUI.NUIApplication.OnTerminate M")]
414         [Property("SPEC_URL", "-")]
415         [Property("CRITERIA", "MR")]
416         [Property("AUTHOR", "guowei.wang@samsung.com")]
417         public void NUIApplicationOnTerminate()
418         {
419             tlog.Debug(tag, $"NUIApplicationOnTerminate START");
420
421             var testingTarget = new MyNUIApplication();
422             Assert.IsNotNull(testingTarget, "Should be not null.");
423             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of Window type.");
424
425             try
426             {
427                 testingTarget.MyOnTerminate();
428             }
429             catch (Exception e)
430             {
431                 tlog.Debug(tag, e.Message.ToString());
432                 Assert.Fail("Caught Exception : Failed!");
433             }
434
435             tlog.Debug(tag, $"NUIApplicationOnTerminate END (OK)");
436         }
437
438         [Test]
439         [Category("P1")]
440         [Description("NUIApplication OnLocaleChanged")]
441         [Property("SPEC", "Tizen.NUI.NUIApplication.OnLocaleChanged M")]
442         [Property("SPEC_URL", "-")]
443         [Property("CRITERIA", "MR")]
444         [Property("AUTHOR", "guowei.wang@samsung.com")]
445         public void NUIApplicationOnLocaleChanged()
446         {
447             tlog.Debug(tag, $"NUIApplicationOnLocaleChanged START");
448
449             var testingTarget = new MyNUIApplication();
450             Assert.IsNotNull(testingTarget, "Should be not null.");
451             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of Window type.");
452
453             try
454             {
455                 testingTarget.MyOnLocaleChanged(new LocaleChangedEventArgs("Shanghai"));
456             }
457             catch (Exception e)
458             {
459                 tlog.Debug(tag, e.Message.ToString());
460                 Assert.Fail("Caught Exception : Failed!");
461             }
462
463             tlog.Debug(tag, $"NUIApplicationOnTerminate END (OK)");
464         }
465     }
466 }