[NUI] Add Common(public) TCs.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.TCT / testcase / public / Common / TSBaseHandle.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 using System.Threading.Tasks;
8
9 namespace Tizen.NUI.Devel.Tests
10 {
11     using tlog = Tizen.Log;
12
13     [TestFixture]
14     [Description("public/Common/BaseHandle")]
15     public class PublicBaseHandleTest
16     {
17         private const string tag = "NUITEST";
18         private bool flag = false;
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         private void baseHandleEventCallback(object sender, EventArgs e)
33         {
34             flag = true;
35         }
36
37         [Test]
38         [Category("P1")]
39         [Description("BaseHandle constructor.")]
40         [Property("SPEC", "Tizen.NUI.BaseHandle.BaseHandle C")]
41         [Property("SPEC_URL", "-")]
42         [Property("CRITERIA", "CONSTR")]
43         [Property("COVPARAM", "")]
44         [Property("AUTHOR", "guowei.wang@samsung.com")]
45         public void BaseHandleConstructor()
46         {
47             tlog.Debug(tag, $"BaseHandleConstructor START");
48
49             var testingTarget = new BaseHandle();
50             Assert.IsNotNull(testingTarget, "null handle");
51             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
52
53             var swigCMemOwn = testingTarget.SwigCMemOwn;
54             Assert.IsTrue(swigCMemOwn);
55
56             testingTarget.Dispose();
57             tlog.Debug(tag, $"BaseHandleConstructor END (OK)");
58         }
59
60         [Test]
61         [Category("P1")]
62         [Description("BaseHandle constructor. With BaseHandle")]
63         [Property("SPEC", "Tizen.NUI.BaseHandle.BaseHandle C")]
64         [Property("SPEC_URL", "-")]
65         [Property("CRITERIA", "CONSTR")]
66         [Property("COVPARAM", "BaseHandle")]
67         [Property("AUTHOR", "guowei.wang@samsung.com")]
68         public void BaseHandleConstructorWithBaseHandle()
69         {
70             tlog.Debug(tag, $"BaseHandleConstructorWithBaseHandle START");
71
72             BaseHandle testingTarget = null;
73             using (BaseHandle view = new View())
74             {
75                 testingTarget = new BaseHandle(view);
76                 Assert.IsNotNull(testingTarget, "null handle");
77                 Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
78             }
79
80             testingTarget.Dispose();
81             tlog.Debug(tag, $"BaseHandleConstructorWithBaseHandle END (OK)");
82         }
83         [Test]
84         [Category("P1")]
85         [Description("BaseHandle EqualTo.")]
86         [Property("SPEC", "Tizen.NUI.BaseHandle.EqualTo M")]
87         [Property("SPEC_URL", "-")]
88         [Property("CRITERIA", "MR")]
89         [Property("AUTHOR", "guowei.wang@samsung.com")]
90         public void BaseHandleEqualTo()
91         {
92             tlog.Debug(tag, $"BaseHandleEqualTo START");
93
94             var testingTarget = new View();
95             Assert.IsNotNull(testingTarget, "null handle");
96             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
97
98             View view = new View();
99             view = testingTarget;
100             Assert.IsTrue(testingTarget.EqualTo(view), "Should be true!");
101
102             view.Dispose();
103             testingTarget.Dispose();
104             tlog.Debug(tag, $"BaseHandleEqualTo END (OK)");
105         }
106
107         [Test]
108         [Category("P1")]
109         [Description("BaseHandle NotEqualTo.")]
110         [Property("SPEC", "Tizen.NUI.BaseHandle.NotEqualTo M")]
111         [Property("SPEC_URL", "-")]
112         [Property("CRITERIA", "MR")]
113         [Property("AUTHOR", "guowei.wang@samsung.com")]
114         public void BaseHandleNotEqualTo()
115         {
116             tlog.Debug(tag, $"BaseHandleNotEqualTo START");
117
118             var testingTarget = new View();
119             Assert.IsNotNull(testingTarget, "null handle");
120             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
121
122             using (View view = new View())
123             {
124                 Assert.IsTrue(testingTarget.NotEqualTo(view), "Should be true!");
125             }
126
127             testingTarget.Dispose();
128             tlog.Debug(tag, $"BaseHandleNotEqualTo END (OK)");
129         }
130
131         [Test]
132         [Category("P1")]
133         [Description("BaseHandle IsEqual.")]
134         [Property("SPEC", "Tizen.NUI.BaseHandle.IsEqual M")]
135         [Property("SPEC_URL", "-")]
136         [Property("CRITERIA", "MR")]
137         [Property("AUTHOR", "guowei.wang@samsung.com")]
138         public void BaseHandleIsEqual()
139         {
140             tlog.Debug(tag, $"BaseHandleIsEqual START");
141
142             var testingTarget = new View();
143             Assert.IsNotNull(testingTarget, "null handle");
144             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
145
146             View view = new View();
147             view = testingTarget;
148             Assert.IsTrue(testingTarget.IsEqual(view), "Should be true!");
149
150             testingTarget.Dispose();
151             Assert.IsFalse(testingTarget.IsEqual(view), "Should be true!");
152
153             view.Dispose();           
154             tlog.Debug(tag, $"BaseHandleIsEqual END (OK)");
155         }
156
157         [Test]
158         [Category("P1")]
159         [Description("BaseHandle GetTypeName.")]
160         [Property("SPEC", "Tizen.NUI.BaseHandle.GetTypeName M")]
161         [Property("SPEC_URL", "-")]
162         [Property("CRITERIA", "MR")]
163         [Property("AUTHOR", "guowei.wang@samsung.com")]
164         public void BaseHandleGetTypeName()
165         {
166             tlog.Debug(tag, $"BaseHandleGetTypeName START");
167
168             var testingTarget = new TextLabel();
169             Assert.IsNotNull(testingTarget, "null handle");
170             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
171
172             Assert.AreEqual("TextLabel", testingTarget.GetTypeName(), "Should be equal!");
173
174             testingTarget.Dispose();
175             tlog.Debug(tag, $"BaseHandleGetTypeName END (OK)");
176         }
177         [Test]
178         [Category("P2")]
179         [Description("BaseHandle. Logical Not !.")]
180         [Property("SPEC", "Tizen.NUI.BaseHandle.! M")]
181         [Property("SPEC_URL", "-")]
182         [Property("CRITERIA", "MR")]
183         [Property("AUTHOR", "guowei.wang@samsung.com")]
184         public void BaseHandleLogicalNotWithNullObject()
185         {
186             tlog.Debug(tag, $"BaseHandleLogicalNotWithNullObject START");
187
188             View testingTarget = null;
189             Assert.IsTrue(!testingTarget, "view should be true!");
190
191             tlog.Debug(tag, $"BaseHandleLogicalNotWithNullObject END (OK)");
192         }
193
194         [Test]
195         [Category("P1")]
196         [Description("BaseHandle bool.")]
197         [Property("SPEC", "Tizen.NUI.BaseHandle.bool M")]
198         [Property("SPEC_URL", "-")]
199         [Property("CRITERIA", "MR")]
200         [Property("AUTHOR", "guowei.wang@samsung.com")]
201         public void BaseHandleBool()
202         {
203             tlog.Debug(tag, $"BaseHandleBool START");
204
205             View testingTarget = null;
206             Assert.IsFalse((bool)testingTarget);
207
208             testingTarget = new View();
209             Assert.IsTrue((bool)testingTarget);
210
211             testingTarget.Dispose();
212             tlog.Debug(tag, $"BaseHandleBool END (OK)");
213         }
214         [Test]
215         [Category("P1")]
216         [Description("BaseHandle Dispose.")]
217         [Property("SPEC", "Tizen.NUI.BaseHandle.Dispose M")]
218         [Property("SPEC_URL", "-")]
219         [Property("CRITERIA", "MR MCST")]
220         [Property("AUTHOR", "guowei.wang@samsung.com")]
221         public void BaseHandleDispose()
222         {
223             tlog.Debug(tag, $"BaseHandleDispose START");
224
225             var testingTarget = new BaseHandle();
226             Assert.IsNotNull(testingTarget, "null handle");
227             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
228
229             try
230             {
231
232                 testingTarget.Dispose();
233             }
234             catch (Exception e)
235             {
236                 tlog.Error(tag, "Caught Exception" + e.ToString());
237                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
238                 Assert.Fail("Caught Exception" + e.ToString());
239             }
240
241             tlog.Debug(tag, $"BaseHandleDispose END (OK)");
242         }
243
244         [Test]
245         [Category("P1")]
246         [Description("BaseHandle GetTypeInfo.")]
247         [Property("SPEC", "Tizen.NUI.BaseHandle.GetTypeInfo M")]
248         [Property("SPEC_URL", "-")]
249         [Property("CRITERIA", "MR")]
250         [Property("AUTHOR", "guowei.wang@samsung.com")]
251         public void BaseHandleGetTypeInfo()
252         {
253             tlog.Debug(tag, $"BaseHandleGetTypeInfo START");
254
255             var testingTarget = new TextLabel();
256             Assert.IsNotNull(testingTarget, "null handle");
257             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
258
259             TypeInfo typeInfo = TypeRegistry.Get().GetTypeInfo("TextLabel");
260
261             try
262             {
263                 Assert.True(testingTarget.GetTypeInfo(typeInfo), "Should be true");
264             }
265             catch (Exception e)
266             {
267                 tlog.Error(tag, "Caught Exception" + e.ToString());
268                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
269                 Assert.Fail("Caught Exception" + e.ToString());
270             }
271
272             typeInfo.Dispose();
273             testingTarget.Dispose();
274             tlog.Debug(tag, $"BaseHandleGetTypeInfo END (OK)");
275         }
276
277         [Test]
278         [Category("P1")]
279         [Description("BaseHandle Equals.")]
280         [Property("SPEC", "Tizen.NUI.BaseHandle.Equals M")]
281         [Property("SPEC_URL", "-")]
282         [Property("CRITERIA", "MR")]
283         [Property("AUTHOR", "guowei.wang@samsung.com")]
284         public void BaseHandleEquals()
285         {
286             tlog.Debug(tag, $"BaseHandleEquals START");
287
288             var testingTarget = new View();
289             Assert.IsNotNull(testingTarget, "null handle");
290             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
291             
292             try
293             {
294                 using (View view = testingTarget as View)
295                 {
296                     Assert.True(testingTarget.Equals(view), "Should be true");
297                 }
298
299                 using (View view = new View())
300                 {
301                     Assert.False(testingTarget.Equals(view), "Should be false");
302                 }
303             }
304             catch (Exception e)
305             {
306                 tlog.Error(tag, "Caught Exception" + e.ToString());
307                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
308                 Assert.Fail("Caught Exception" + e.ToString());
309             }
310
311             testingTarget.Dispose();
312             tlog.Debug(tag, $"BaseHandleEquals END (OK)");
313         }
314
315         [Test]
316         [Category("P1")]
317         [Description("BaseHandle GetHashCode.")]
318         [Property("SPEC", "Tizen.NUI.BaseHandle.GetHashCode M")]
319         [Property("SPEC_URL", "-")]
320         [Property("CRITERIA", "MR")]
321         [Property("AUTHOR", "guowei.wang@samsung.com")]
322         public void BaseHandleGetHashCode()
323         {
324             tlog.Debug(tag, $"BaseHandleGetHashCode START");
325
326             var testingTarget = new View();
327             Assert.IsNotNull(testingTarget, "null handle");
328             Assert.IsInstanceOf<BaseHandle>(testingTarget, "Should return BaseHandle instance.");
329
330             try
331             {
332                 Assert.GreaterOrEqual(testingTarget.GetHashCode(), 0, "Should be true");
333             }
334             catch (Exception e)
335             {
336                 tlog.Error(tag, "Caught Exception" + e.ToString());
337                 LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
338                 Assert.Fail("Caught Exception" + e.ToString());
339             }
340
341             testingTarget.Dispose();
342             tlog.Debug(tag, $"BaseHandleGetHashCode END (OK)");
343         }
344     }
345 }