Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / Widget / TSWidgetApplication.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("Internal/Widget/WidgetApplication")]
14     public class InternalWidgetApplicationTest
15     {
16         private const string tag = "NUITEST";
17
18         internal class MyWidgetApplication : WidgetApplication
19         {
20             public MyWidgetApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
21             { }
22
23             public void OnReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
24             {
25                 base.ReleaseSwigCPtr(swigCPtr);
26             }
27         }
28
29         [SetUp]
30         public void Init()
31         {
32             tlog.Info(tag, "Init() is called!");
33         }
34
35         [TearDown]
36         public void Destroy()
37         {
38             tlog.Info(tag, "Destroy() is called!");
39         }
40
41         [Test]
42         [Category("P1")]
43         [Description("WidgetApplication Constructor.")]
44         [Property("SPEC", "Tizen.NUI.WidgetApplication.WidgetApplication C")]
45         [Property("SPEC_URL", "-")]
46         [Property("CRITERIA", "CONSTR")]
47         [Property("AUTHOR", "guowei.wang@samsung.com")]
48         public void WidgetApplicationConstructor()
49         {
50             tlog.Debug(tag, $"WidgetApplicationConstructor START");
51
52             Widget widget = new Widget();
53
54             var testingTarget = new WidgetApplication(widget.GetIntPtr(), false);
55             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
56             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
57
58             widget.Dispose();
59             widget = null;
60
61             testingTarget.Dispose();
62             testingTarget = null;
63             tlog.Debug(tag, $"WidgetApplicationConstructor END (OK)");
64         }
65
66         [Test]
67         [Category("P1")]
68         [Description("WidgetApplication Constructor. With WidgetApplication.")]
69         [Property("SPEC", "Tizen.NUI.WidgetApplication.WidgetApplication C")]
70         [Property("SPEC_URL", "-")]
71         [Property("CRITERIA", "CONSTR")]
72         [Property("AUTHOR", "guowei.wang@samsung.com")]
73         public void WidgetApplicationConstructorWithWidgetApplication()
74         {
75             tlog.Debug(tag, $"WidgetApplicationConstructorWithWidgetApplication START");
76
77             Widget widget = new Widget();
78
79             WidgetApplication widgetApplication = new WidgetApplication(widget.GetIntPtr(), false);
80             Assert.IsNotNull(widgetApplication, "Can't create success object WidgetApplication");
81             Assert.IsInstanceOf<WidgetApplication>(widgetApplication, "Should be an instance of WidgetApplication type.");
82
83             var testingTarget = new WidgetApplication(widgetApplication);
84             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
85             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
86
87             widget.Dispose();
88             widget = null;
89
90             widgetApplication.Dispose();
91             widgetApplication = null;
92
93             testingTarget.Dispose();
94             testingTarget = null;
95             tlog.Debug(tag, $"WidgetApplicationConstructorWithWidgetApplication END (OK)");
96         }
97
98         [Test]
99         [Category("P1")]
100         [Description("WidgetApplication Assign.")]
101         [Property("SPEC", "Tizen.NUI.WidgetApplication.Assign M")]
102         [Property("SPEC_URL", "-")]
103         [Property("CRITERIA", "MR")]
104         [Property("AUTHOR", "guowei.wang@samsung.com")]
105         public void WidgetApplicationAssign()
106         {
107             tlog.Debug(tag, $"WidgetApplicationAssign START");
108
109             Widget widget = new Widget();
110
111             WidgetApplication widgetApplication = new WidgetApplication(widget.GetIntPtr(), false);
112             Assert.IsNotNull(widgetApplication, "Can't create success object WidgetApplication");
113             Assert.IsInstanceOf<WidgetApplication>(widgetApplication, "Should be an instance of WidgetApplication type.");
114
115             var testingTarget = widgetApplication.Assign(widgetApplication);
116             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
117             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
118
119             widget.Dispose();
120             widget = null;
121
122             widgetApplication.Dispose();
123             widgetApplication = null;
124
125             testingTarget.Dispose();
126             testingTarget = null;
127             tlog.Debug(tag, $"WidgetApplicationAssign END (OK)");
128         }
129
130         [Test]
131         [Category("P1")]
132         [Description("WidgetApplication getCPtr.")]
133         [Property("SPEC", "Tizen.NUI.WidgetApplication.getCPtr M")]
134         [Property("SPEC_URL", "-")]
135         [Property("CRITERIA", "MR")]
136         [Property("AUTHOR", "guowei.wang@samsung.com")]
137         public void WidgetApplicationgetCPtr()
138         {
139             tlog.Debug(tag, $"WidgetApplicationgetCPtr START");
140
141             Widget widget = new Widget();
142
143             var testingTarget = new WidgetApplication(widget.GetIntPtr(), false);
144             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
145             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
146
147             try
148             {
149                 WidgetApplication.getCPtr(testingTarget);
150             }
151             catch (Exception e)
152             {
153                 tlog.Debug(tag, e.Message.ToString());
154                 Assert.Fail("Caught Exception: Failed!");
155             }
156
157             widget.Dispose();
158             widget = null;
159
160             testingTarget.Dispose();
161             testingTarget = null;
162             tlog.Debug(tag, $"WidgetApplicationgetCPtr END (OK)");
163         }
164
165         [Test]
166         [Category("P1")]
167         [Description("WidgetApplication ReleaseSwigCPtr.")]
168         [Property("SPEC", "Tizen.NUI.WidgetApplication.ReleaseSwigCPtr M")]
169         [Property("SPEC_URL", "-")]
170         [Property("CRITERIA", "MR")]
171         [Property("AUTHOR", "guowei.wang@samsung.com")]
172         public void WidgetApplicationReleaseSwigCPtr()
173         {
174             tlog.Debug(tag, $"WidgetApplicationReleaseSwigCPtr START");
175
176             Widget widget = new Widget();
177
178             var testingTarget = new MyWidgetApplication(widget.GetIntPtr(), false);
179             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
180             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
181
182             try
183             {
184                 testingTarget.OnReleaseSwigCPtr(widget.SwigCPtr);
185             }
186             catch (Exception e)
187             {
188                 tlog.Debug(tag, e.Message.ToString());
189                 Assert.Fail("Caught Exception: Failed!");
190             }
191
192             testingTarget.Dispose();
193             testingTarget = null;
194             tlog.Debug(tag, $"WidgetApplicationReleaseSwigCPtr END (OK)");
195         }
196
197         [Test]
198         [Category("P1")]
199         [Description("WidgetApplication RegisterWidgetCreatingFunction.")]
200         [Property("SPEC", "Tizen.NUI.WidgetApplication.RegisterWidgetCreatingFunction M")]
201         [Property("SPEC_URL", "-")]
202         [Property("CRITERIA", "MR")]
203         [Property("AUTHOR", "guowei.wang@samsung.com")]
204         public void WidgetApplicationRegisterWidgetCreatingFunction()
205         {
206             tlog.Debug(tag, $"WidgetApplicationRegisterWidgetCreatingFunction START");
207
208             Widget widget = new Widget();
209
210             var testingTarget = new MyWidgetApplication(widget.GetIntPtr(), false);
211             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
212             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
213
214             global::System.Collections.Generic.Dictionary<Type, string> widgetInfo = new global::System.Collections.Generic.Dictionary<Type, string>(){
215                 { typeof(Widget), "w1@org.tizen.WidgetApp"} };
216
217             testingTarget.RegisterWidgetInfo(widgetInfo);
218
219             try
220             {
221                 testingTarget.RegisterWidgetCreatingFunction();
222             }
223             catch (Exception e)
224             {
225                 tlog.Debug(tag, e.Message.ToString());
226                 Assert.Fail("Caught Exception: Failed!");
227             }
228
229             widget.Dispose();
230             widget = null;
231
232             testingTarget.Dispose();
233             testingTarget = null;
234             tlog.Debug(tag, $"WidgetApplicationRegisterWidgetCreatingFunction END (OK)");
235         }
236
237         [Test]
238         [Category("P1")]
239         [Description("WidgetApplication AddWidgetInstance.")]
240         [Property("SPEC", "Tizen.NUI.WidgetApplication.AddWidgetInstance M")]
241         [Property("SPEC_URL", "-")]
242         [Property("CRITERIA", "MR")]
243         [Property("AUTHOR", "guowei.wang@samsung.com")]
244         public void WidgetApplicationAddWidgetInstance()
245         {
246             tlog.Debug(tag, $"WidgetApplicationAddWidgetInstance START");
247
248             Widget widget = new Widget();
249
250             var testingTarget = new WidgetApplication(widget.GetIntPtr(), false);
251             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
252             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
253
254             try
255             {
256                 testingTarget.AddWidgetInstance(widget);
257             }
258             catch (Exception e)
259             {
260                 tlog.Debug(tag, e.Message.ToString());
261                 Assert.Fail("Caught Exception: Failed!");
262             }
263
264             widget.Dispose();
265             widget = null;
266
267             testingTarget.Dispose();
268             testingTarget = null;
269             tlog.Debug(tag, $"WidgetApplicationAddWidgetInstance END (OK)");
270         }
271
272         [Test]
273         [Category("P1")]
274         [Description("WidgetApplication RegisterWidgetInfo.")]
275         [Property("SPEC", "Tizen.Applications.WidgetApplication.RegisterWidgetInfo M")]
276         [Property("SPEC_URL", "-")]
277         [Property("CRITERIA", "MR")]
278         [Property("AUTHOR", "guowei.wang@samsung.com")]
279         public void WidgetApplicationRegisterWidgetInfo()
280         {
281             tlog.Debug(tag, $"WidgetApplicationRegisterWidgetInfo START");
282
283             Widget widget = new Widget();
284
285             var testingTarget = new WidgetApplication(widget.GetIntPtr(), false);
286             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
287             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
288
289             global::System.Collections.Generic.Dictionary<Type, string> widgetInfo = new global::System.Collections.Generic.Dictionary<Type, string>(){
290                 { typeof(Widget), "w1@org.tizen.WidgetApp"} };
291
292             try
293             {
294                 testingTarget.RegisterWidgetInfo(widgetInfo);
295             }
296             catch (Exception e)
297             {
298                 tlog.Debug(tag, e.Message.ToString());
299                 Assert.Fail("Caught Exception: Failed!");
300             }
301
302             widget.Dispose();
303             widget = null;
304
305             testingTarget.Dispose();
306             testingTarget = null;
307             tlog.Debug(tag, $"WidgetApplicationRegisterWidgetInfo END (OK)");
308         }
309
310         [Test]
311         [Category("P1")]
312         [Description("WidgetApplication AddWidgetInfo.")]
313         [Property("SPEC", "Tizen.Applications.WidgetApplication.AddWidgetInfo M")]
314         [Property("SPEC_URL", "-")]
315         [Property("CRITERIA", "MR")]
316         [Property("AUTHOR", "guowei.wang@samsung.com")]
317         public void WidgetApplicationAddWidgetInfo()
318         {
319             tlog.Debug(tag, $"WidgetApplicationAddWidgetInfo START");
320
321             Widget widget = new Widget();
322
323             var testingTarget = new WidgetApplication(widget.GetIntPtr(), false);
324             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
325             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
326
327             global::System.Collections.Generic.Dictionary<Type, string> widgetInfo = new global::System.Collections.Generic.Dictionary<Type, string>(){
328                 { typeof(Widget), "w1@org.tizen.WidgetApp"} };
329             testingTarget.RegisterWidgetInfo(widgetInfo);
330             
331             try
332             {
333                 testingTarget.AddWidgetInfo(new global::System.Collections.Generic.Dictionary<Type, string>(){
334                 { typeof(WidgetApplication), "w2@org.tizen.WidgetApp"} });
335             }
336             catch (Exception e)
337             {
338                 tlog.Debug(tag, e.Message.ToString());
339                 Assert.Fail("Caught Exception: Failed!");
340             }
341
342             widget.Dispose();
343             widget = null;
344
345             testingTarget.Dispose();
346             testingTarget = null;
347             tlog.Debug(tag, $"WidgetApplicationAddWidgetInfo END (OK)");
348         }
349
350         [Test]
351         [Category("P1")]
352         [Description("WidgetApplication WidgetCreateFunction.")]
353         [Property("SPEC", "Tizen.Applications.WidgetApplication.WidgetCreateFunction M")]
354         [Property("SPEC_URL", "-")]
355         [Property("CRITERIA", "MR")]
356         [Property("AUTHOR", "guowei.wang@samsung.com")]
357         public void WidgetApplicationWidgetCreateFunction()
358         {
359             tlog.Debug(tag, $"WidgetApplicationWidgetCreateFunction START");
360
361             tlog.Debug(tag, "WidgetApplication.Instance : " + WidgetApplication.Instance);
362
363             try
364             {
365                 string widgetName = null;
366                 WidgetApplication.WidgetCreateFunction(ref widgetName);
367             }
368             catch (Exception e)
369             {
370                 tlog.Debug(tag, e.Message.ToString());
371                 Assert.Fail("Caught Exception: Failed!");
372             }
373
374             tlog.Debug(tag, $"WidgetApplicationWidgetCreateFunction END (OK)");
375         }
376
377         [Test]
378         [Category("P1")]
379         [Description("WidgetApplication WidgetInfo.")]
380         [Property("SPEC", "Tizen.Applications.WidgetApplication.WidgetInfo M")]
381         [Property("SPEC_URL", "-")]
382         [Property("CRITERIA", "MR")]
383         [Property("AUTHOR", "guowei.wang@samsung.com")]
384         public void WidgetApplicationWidgetInfo()
385         {
386             tlog.Debug(tag, $"WidgetApplicationWidgetInfo START");
387
388             Widget widget = new Widget();
389
390             var testingTarget = new WidgetApplication(widget.GetIntPtr(), false);
391             Assert.IsNotNull(testingTarget, "Can't create success object WidgetApplication");
392             Assert.IsInstanceOf<WidgetApplication>(testingTarget, "Should be an instance of WidgetApplication type.");
393
394             global::System.Collections.Generic.Dictionary<Type, string> widgetInfo = new global::System.Collections.Generic.Dictionary<Type, string>(){
395                 { typeof(Widget), "w1@org.tizen.WidgetApp"} };
396             testingTarget.RegisterWidgetInfo(widgetInfo);
397
398             tlog.Debug(tag, "testingTarget.WidgetInfo : " + testingTarget.WidgetInfo);
399
400             widget.Dispose();
401             widget = null;
402
403             testingTarget.Dispose();
404             testingTarget = null;
405
406             tlog.Debug(tag, $"WidgetApplicationWidgetInfo END (OK)");
407         }
408     }
409 }