[NUI] Fix build errors of NUI.Devel based on API10.
[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             tlog.Debug(tag, "Window : " + testingTarget.Window);
69
70             tlog.Debug(tag, $"NUIApplicationConstructor END (OK)");
71         }
72
73         [Test]
74         [Category("P1")]
75         [Description("NUIApplication constructor. With window size and position")]
76         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
77         [Property("SPEC_URL", "-")]
78         [Property("CRITERIA", "CONSTR")]
79         [Property("AUTHOR", "guowei.wang@samsung.com")]
80         public void NUIApplicationConstructorWithWindowSizeAndPosition()
81         {
82             tlog.Debug(tag, $"NUIApplicationConstructorWithWindowSizeAndPosition START");
83
84             Size size = new Size(100, 200);
85             Position pos = new Position(200, 300);
86             var testingTarget = new NUIApplication(size, pos);
87             Assert.IsNotNull(testingTarget, "Should be not null.");
88             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
89
90             tlog.Debug(tag, "ApplicationHandle : " + testingTarget.ApplicationHandle);
91
92             pos.Dispose();
93             size.Dispose();
94             tlog.Debug(tag, $"NUIApplicationConstructorWithWindowSizeAndPosition END (OK)");
95         }
96
97         [Test]
98         [Category("P1")]
99         [Description("NUIApplication constructor. With stylesheet.")]
100         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
101         [Property("SPEC_URL", "-")]
102         [Property("CRITERIA", "CONSTR")]
103         [Property("AUTHOR", "guowei.wang@samsung.com")]
104         public void NUIApplicationConstructorWithStyleSheet()
105         {
106             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheet START");
107
108             var testingTarget = new NUIApplication("stylesheet");
109             Assert.IsNotNull(testingTarget, "Should be not null.");
110             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
111
112             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheet END (OK)");
113         }
114
115         [Test]
116         [Category("P1")]
117         [Description("NUIApplication constructor. With stylesheet, window size, position.")]
118         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
119         [Property("SPEC_URL", "-")]
120         [Property("CRITERIA", "CONSTR")]
121         [Property("AUTHOR", "guowei.wang@samsung.com")]
122         public void NUIApplicationConstructorWithStyleSheetAndWindowSizeAndPostion()
123         {
124             tlog.Debug(tag, $"NUIApplicationConstructorWithStyleSheetAndWindowSizeAndPostion START");
125
126             var testingTarget = new NUIApplication("stylesheet", new Size(100, 200), new Position(200, 300));
127             Assert.IsNotNull(testingTarget, "Should be not null.");
128             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
129
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             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowMode END (OK)");
149         }
150
151         [Test]
152         [Category("P1")]
153         [Description("NUIApplication constructor. With stylesheet, WindowMode, window size and position")]
154         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
155         [Property("SPEC_URL", "-")]
156         [Property("CRITERIA", "CONSTR")]
157         [Property("AUTHOR", "guowei.wang@samsung.com")]
158         public void NUIApplicationConstructorWithStringAndWindowModeAndWindowSizeAndPosition()
159         {
160             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowModeAndWindowSizeAndPosition START");
161
162             var testingTarget = new NUIApplication("stylesheet", NUIApplication.WindowMode.Opaque, new Size(100, 200), new Position(200, 300));
163             Assert.IsNotNull(testingTarget, "Should be not null.");
164             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
165
166             tlog.Debug(tag, $"NUIApplicationConstructorWithStringAndWindowModeAndWindowSizeAndPosition END (OK)");
167         }
168
169         [Test]
170         [Category("P1")]
171         [Description("NUIApplication constructor. With BackendType.")]
172         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
173         [Property("SPEC_URL", "-")]
174         [Property("CRITERIA", "CONSTR")]
175         [Property("AUTHOR", "guowei.wang@samsung.com")]
176         public void NUIApplicationConstructorWithBackendType()
177         {
178             tlog.Debug(tag, $"NUIApplicationConstructorWithBackendType START");
179
180             var testingTarget = new NUIApplication(Graphics.BackendType.Vulkan);
181             Assert.IsNotNull(testingTarget, "Should be not null.");
182             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
183
184             tlog.Debug(tag, $"NUIApplicationConstructorWithBackendType END (OK)");
185         }
186
187         [Test]
188         [Category("P1")]
189         [Description("NUIApplication constructor. With ThemeOptions.")]
190         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
191         [Property("SPEC_URL", "-")]
192         [Property("CRITERIA", "CONSTR")]
193         [Property("AUTHOR", "guowei.wang@samsung.com")]
194         public void NUIApplicationConstructorWithThemeOptions()
195         {
196             tlog.Debug(tag, $"NUIApplicationConstructorWithThemeOptions START");
197
198             var testingTarget = new NUIApplication(NUIApplication.ThemeOptions.PlatformThemeEnabled);
199             Assert.IsNotNull(testingTarget, "Should be not null.");
200             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
201
202             tlog.Debug(tag, $"NUIApplicationConstructorWithThemeOptions END (OK)");
203         }
204
205         [Test]
206         [Category("P1")]
207         [Description("NUIApplication constructor. With windowSize, windowPosition and options.")]
208         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
209         [Property("SPEC_URL", "-")]
210         [Property("CRITERIA", "CONSTR")]
211         [Property("AUTHOR", "guowei.wang@samsung.com")]
212         public void NUIApplicationConstructorWithSizePositionAndThemeOptions()
213         {
214             tlog.Debug(tag, $"NUIApplicationConstructorWithSizePositionAndThemeOptions START");
215
216             Size2D windowSize = new Size2D(100, 50);
217             Position2D windowPosition = new Position2D(20, 30);
218             var testingTarget = new NUIApplication(windowSize, windowPosition, NUIApplication.ThemeOptions.PlatformThemeEnabled);
219             Assert.IsNotNull(testingTarget, "Should be not null.");
220             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
221
222             windowSize.Dispose();
223             windowPosition.Dispose();
224             tlog.Debug(tag, $"NUIApplicationConstructorWithSizePositionAndThemeOptions END (OK)");
225         }
226
227         [Test]
228         [Category("P1")]
229         [Description("NUIApplication constructor. Support IME window.")]
230         [Property("SPEC", "Tizen.NUI.NUIApplication.NUIApplication C")]
231         [Property("SPEC_URL", "-")]
232         [Property("CRITERIA", "CONSTR")]
233         [Property("AUTHOR", "guowei.wang@samsung.com")]
234         public void NUIApplicationConstructorForImeWindow()
235         {
236             tlog.Debug(tag, $"NUIApplicationConstructorForImeWindow START");
237
238             var testingTarget = new NUIApplication("", NUIApplication.WindowMode.Opaque, WindowType.Dialog);
239             Assert.IsNotNull(testingTarget, "Should be not null.");
240             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
241
242             tlog.Debug(tag, $"NUIApplicationConstructorForImeWindow END (OK)");
243         }
244
245         [Test]
246         [Category("P1")]
247         [Description("NUIApplication RegisterAssembly.")]
248         [Property("SPEC", "Tizen.NUI.NUIApplication.RegisterAssembly M")]
249         [Property("SPEC_URL", "-")]
250         [Property("CRITERIA", "MR")]
251         [Property("AUTHOR", "guowei.wang@samsung.com")]
252         public void NUIApplicationRegisterAssembly()
253         {
254             tlog.Debug(tag, $"NUIApplicationRegisterAssembly START");
255
256             try
257             {
258                 NUIApplication.RegisterAssembly(typeof(NUIApplication).Assembly);
259             }
260             catch (Exception e)
261             {
262                 tlog.Error(tag, "Caught Exception" + e.ToString());
263                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
264                 Assert.Fail("Caught Exception" + e.ToString());
265             }
266
267             tlog.Debug(tag, $"NUIApplicationRegisterAssembly END (OK)");
268         }
269
270         [Test]
271         [Category("P1")]
272         [Description("NUIApplication MultilingualResourceManager.")]
273         [Property("SPEC", "Tizen.NUI.NUIApplication.MultilingualResourceManager A")]
274         [Property("SPEC_URL", "-")]
275         [Property("CRITERIA", "PRW")]
276         [Property("AUTHOR", "guowei.wang@samsung.com")]
277         public void NUIApplicationMultilingualResourceManager()
278         {
279             tlog.Debug(tag, $"NUIApplicationMultilingualResourceManager START");
280
281             NUIApplication.MultilingualResourceManager = Resource.ResourceManager;
282             Assert.IsNotNull(NUIApplication.MultilingualResourceManager, "Should be not null!");
283
284             string str = null;
285             str = NUIApplication.MultilingualResourceManager?.GetString("Test");
286             Assert.AreEqual("Test", str, "Picture should be Beeld in Dutch");
287
288             tlog.Debug(tag, $"NUIApplicationMultilingualResourceManager END (OK)");
289         }
290
291         [Test]
292         [Category("P1")]
293         [Description("NUIApplication AppId")]
294         [Property("SPEC", "Tizen.NUI.NUIApplication.AppId A")]
295         [Property("SPEC_URL", "-")]
296         [Property("CRITERIA", "PRO")]
297         [Property("AUTHOR", "guowei.wang@samsung.com")]
298         public void NUIApplicationAppId()
299         {
300             tlog.Debug(tag, $"NUIApplicationAppId START");
301
302             var testingTarget = new NUIApplication();
303             Assert.IsNotNull(testingTarget, "Should be not null.");
304             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of NUIApplication type.");
305
306             var result = testingTarget.AppId;
307             Assert.IsNotNull(result, "Should be not null.");
308
309             tlog.Debug(tag, $"NUIApplicationAppId END (OK)");
310         }
311
312         [Test]
313         [Category("P1")]
314         [Description("NUIApplication GetDefaultWindow")]
315         [Property("SPEC", "Tizen.NUI.NUIApplication.GetDefaultWindow M")]
316         [Property("SPEC_URL", "-")]
317         [Property("CRITERIA", "MR")]
318         [Property("AUTHOR", "guowei.wang@samsung.com")]
319         public void NUIApplicationGetDefaultWindow()
320         {
321             tlog.Debug(tag, $"NUIApplicationGetDefaultWindow START");
322
323             var testingTarget = NUIApplication.GetDefaultWindow();
324             Assert.IsNotNull(testingTarget, "Should be not null.");
325             Assert.IsInstanceOf<Window>(testingTarget, "Should be an instance of Window type.");
326
327             tlog.Debug(tag, $"NUIApplicationGetDefaultWindow END (OK)");
328         }
329
330         [Test]
331         [Category("P1")]
332         [Description("NUIApplication AddIdle")]
333         [Property("SPEC", "Tizen.NUI.NUIApplication.AddIdle M")]
334         [Property("SPEC_URL", "-")]
335         [Property("CRITERIA", "MR")]
336         [Property("AUTHOR", "guowei.wang@samsung.com")]
337         public void NUIApplicationAddIdle()
338         {
339             tlog.Debug(tag, $"NUIApplicationAddIdle START");
340
341             dummyCallback callback = OnDummyCallback;
342             var result = Application.Instance.AddIdle(callback);
343             Assert.IsTrue(result);
344
345             tlog.Debug(tag, $"NUIApplicationAddIdle END (OK)");
346         }
347
348         [Test]
349         [Category("P1")]
350         [Description("NUIApplication SetRenderRefreshRate")]
351         [Property("SPEC", "Tizen.NUI.NUIApplication.SetRenderRefreshRate M")]
352         [Property("SPEC_URL", "-")]
353         [Property("CRITERIA", "MR")]
354         [Property("AUTHOR", "guowei.wang@samsung.com")]
355         public void NUIApplicationSetRenderRefreshRate()
356         {
357             tlog.Debug(tag, $"NUIApplicationSetRenderRefreshRate START");
358
359             try
360             {
361                 NUIApplication.SetRenderRefreshRate(2);
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             tlog.Debug(tag, $"NUIApplicationSetRenderRefreshRate END (OK)");
371         }
372
373         [Test]
374         [Category("P1")]
375         [Description("NUIApplication OnTerminate")]
376         [Property("SPEC", "Tizen.NUI.NUIApplication.OnTerminate M")]
377         [Property("SPEC_URL", "-")]
378         [Property("CRITERIA", "MR")]
379         [Property("AUTHOR", "guowei.wang@samsung.com")]
380         public void NUIApplicationOnTerminate()
381         {
382             tlog.Debug(tag, $"NUIApplicationOnTerminate START");
383
384             var testingTarget = new MyNUIApplication();
385             Assert.IsNotNull(testingTarget, "Should be not null.");
386             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of Window type.");
387
388             try
389             {
390                 testingTarget.MyOnTerminate();
391             }
392             catch (Exception e)
393             {
394                 tlog.Debug(tag, e.Message.ToString());
395                 Assert.Fail("Caught Exception : Failed!");
396             }
397
398             tlog.Debug(tag, $"NUIApplicationOnTerminate END (OK)");
399         }
400
401         [Test]
402         [Category("P1")]
403         [Description("NUIApplication OnLocaleChanged")]
404         [Property("SPEC", "Tizen.NUI.NUIApplication.OnLocaleChanged M")]
405         [Property("SPEC_URL", "-")]
406         [Property("CRITERIA", "MR")]
407         [Property("AUTHOR", "guowei.wang@samsung.com")]
408         public void NUIApplicationOnLocaleChanged()
409         {
410             tlog.Debug(tag, $"NUIApplicationOnLocaleChanged START");
411
412             var testingTarget = new MyNUIApplication();
413             Assert.IsNotNull(testingTarget, "Should be not null.");
414             Assert.IsInstanceOf<NUIApplication>(testingTarget, "Should be an instance of Window type.");
415
416             try
417             {
418                 testingTarget.MyOnLocaleChanged(new LocaleChangedEventArgs("Shanghai"));
419             }
420             catch (Exception e)
421             {
422                 tlog.Debug(tag, e.Message.ToString());
423                 Assert.Fail("Caught Exception : Failed!");
424             }
425
426             tlog.Debug(tag, $"NUIApplicationOnTerminate END (OK)");
427         }
428     }
429 }