[NUI] Update NUI.Devel to fix block and crash issues.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / Utility / TSFontClient.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/Utility/FontClient")]
15     class TSFontClient
16     {
17         private const string tag = "NUITEST";
18         private string ttf_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "TizenSansRegular.ttf";
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         internal class MySWIGTYPE_p_unsigned_int : SWIGTYPE_p_unsigned_int
33         {
34             public MySWIGTYPE_p_unsigned_int() : base()
35             { }
36         }
37
38         [Test]
39         [Category("P1")]
40         [Description("FontClient constructor.")]
41         [Property("SPEC", "Tizen.NUI.FontClient.FontClient C")]
42         [Property("SPEC_URL", "-")]
43         [Property("CRITERIA", "CONSTR")]
44         [Property("AUTHOR", "guowei.wang@samsung.com")]
45         public void FontClientConstructor()
46         {
47             tlog.Debug(tag, $"FontClientConstructor START");
48
49             var testingTarget = new FontClient();
50             Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
51             Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
52
53             testingTarget.Dispose();
54
55             tlog.Debug(tag, $"FontClientConstructor END (OK)");
56         }
57
58         [Test]
59         [Category("P1")]
60         [Description("FontClient constructor. With FontClient")]
61         [Property("SPEC", "Tizen.NUI.FontClient.FontClient C")]
62         [Property("SPEC_URL", "-")]
63         [Property("CRITERIA", "CONSTR")]
64         [Property("AUTHOR", "guowei.wang@samsung.com")]
65         public void FontClientConstructorWithFontClient()
66         {
67             tlog.Debug(tag, $"FontClientConstructorWithFontClient START");
68
69             var testingTarget = new FontClient(FontClient.Instance);
70             Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
71             Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
72
73             testingTarget.Dispose();
74
75             tlog.Debug(tag, $"FontClientConstructorWithFontClient END (OK)");
76         }
77
78         [Test]
79         [Category("P1")]
80         [Description("FontClient DefaultPointSize.")]
81         [Property("SPEC", "Tizen.NUI.FontClient.DefaultPointSize A")]
82         [Property("SPEC_URL", "-")]
83         [Property("CRITERIA", "PRO")]
84         [Property("AUTHOR", "guowei.wang@samsung.com")]
85         public void FontClientDefaultPointSize()
86         {
87             tlog.Debug(tag, $"FontClientDefaultPointSize START");
88
89             var testingTarget = FontClient.DefaultPointSize;
90             Assert.AreEqual(768, testingTarget, "Should be equal!");
91
92             tlog.Debug(tag, $"FontClientDefaultPointSize END (OK)");
93         }
94
95         [Test]
96         [Category("P1")]
97         [Description("FontClient Assign.")]
98         [Property("SPEC", "Tizen.NUI.FontClient.Assign M")]
99         [Property("SPEC_URL", "-")]
100         [Property("CRITERIA", "MR")]
101         [Property("AUTHOR", "guowei.wang@samsung.com")]
102         public void FontClientAssign()
103         {
104             tlog.Debug(tag, $"FontClientAssign START");
105
106             using (FontClient client = new FontClient())
107             {
108                 try
109                 {
110                     var testingTarget = client.Assign(FontClient.Instance);
111                     Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
112                     Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
113
114                     testingTarget.Dispose();
115                 }
116                 catch (Exception e)
117                 {
118                     tlog.Debug(tag, e.Message.ToString());
119                     Assert.Fail("Caught Exception: Failed!");
120                 }
121             }
122
123             tlog.Debug(tag, $"FontClientAssign END (OK)");
124         }
125
126         //[Test]
127         //[Category("P1")]
128         //[Description("FontClient GetDpi.")]
129         //[Property("SPEC", "Tizen.NUI.FontClient.GetDpi M")]
130         //[Property("SPEC_URL", "-")]
131         //[Property("CRITERIA", "MR")]
132         //[Property("AUTHOR", "guowei.wang@samsung.com")]
133         //public void FontClientGetDpi()
134         //{
135         //    tlog.Debug(tag, $"FontClientGetDpi START");
136
137         //    var testingTarget = new FontClient(FontClient.Instance);
138         //    Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
139         //    Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
140
141         //    testingTarget.SetDpi(50, 60);
142
143         //    try
144         //    {
145         //        var horizontalDpi = new SWIGTYPE_p_unsigned_int(testingTarget.GetBaseHandleCPtrHandleRef.Handle);
146         //        var verticalDpi = new SWIGTYPE_p_unsigned_int(new FontClient().GetBaseHandleCPtrHandleRef.Handle);
147         //        testingTarget.GetDpi(horizontalDpi, verticalDpi);
148         //    }
149         //    catch (Exception e)
150         //    {
151         //        tlog.Debug(tag, e.Message.ToString());
152         //        Assert.Fail("Caught Exception: Failed");
153         //    }
154
155         //    testingTarget.Dispose();
156         //    tlog.Debug(tag, $"FontClientGetDpi END (OK)");
157         //}
158
159         [Test]
160         [Category("P1")]
161         [Description("FontClient GetDefaultFontSize.")]
162         [Property("SPEC", "Tizen.NUI.FontClient.GetDefaultFontSize M")]
163         [Property("SPEC_URL", "-")]
164         [Property("CRITERIA", "MR")]
165         [Property("AUTHOR", "guowei.wang@samsung.com")]
166         public void FontClientGetDefaultFontSize()
167         {
168             tlog.Debug(tag, $"FontClientGetDefaultFontSize START");
169
170             var testingTarget = new FontClient(FontClient.Instance);
171             Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
172             Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
173
174             Assert.IsNotNull(testingTarget.GetDefaultFontSize());
175
176             testingTarget.Dispose();
177             tlog.Debug(tag, $"FontClientGetDefaultFontSize END (OK)");
178         }
179
180         [Test]
181         [Category("P1")]
182         [Description("FontClient GetDefaultPlatformFontDescription.")]
183         [Property("SPEC", "Tizen.NUI.FontClient.GetDefaultPlatformFontDescription M")]
184         [Property("SPEC_URL", "-")]
185         [Property("CRITERIA", "MR")]
186         [Property("AUTHOR", "guowei.wang@samsung.com")]
187         public void FontClientGetDefaultPlatformFontDescription()
188         {
189             tlog.Debug(tag, $"FontClientGetDefaultPlatformFontDescription START");
190
191             using (FontDescription description = new FontDescription())
192             {
193                 description.Path = ttf_path;
194
195                 var testingTarget = new FontClient(FontClient.Instance);
196                 Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
197                 Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
198
199                 try
200                 {
201                     testingTarget.GetDefaultPlatformFontDescription(description);
202                 }
203                 catch (Exception e)
204                 {
205                     tlog.Debug(tag, e.Message.ToString());
206                     Assert.Fail("Caught Exception: Failed");
207                 }
208
209                 testingTarget.Dispose();
210             }
211
212             tlog.Debug(tag, $"FontClientGetDefaultPlatformFontDescription END (OK)");
213         }
214
215         [Test]
216         [Category("P1")]
217         [Description("FontClient IsScalable.")]
218         [Property("SPEC", "Tizen.NUI.FontClient.IsScalable M")]
219         [Property("SPEC_URL", "-")]
220         [Property("CRITERIA", "MR")]
221         [Property("AUTHOR", "guowei.wang@samsung.com")]
222         public void FontClientIsScalable()
223         {
224             tlog.Debug(tag, $"FontClientIsScalable START");
225
226             using (FontDescription description = new FontDescription())
227             {
228                 description.Path = ttf_path;
229
230                 var testingTarget = new FontClient(FontClient.Instance);
231                 Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
232                 Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
233
234                 var result = testingTarget.IsScalable(description);
235                 Assert.IsNotNull(result);
236
237                 testingTarget.Dispose();
238             }
239
240             tlog.Debug(tag, $"FontClientIsScalable END (OK)");
241         }
242
243         [Test]
244         [Category("P1")]
245         [Description("FontClient CreateVectorBlob.")]
246         [Property("SPEC", "Tizen.NUI.FontClient.CreateVectorBlob M")]
247         [Property("SPEC_URL", "-")]
248         [Property("CRITERIA", "MR")]
249         [Property("AUTHOR", "guowei.wang@samsung.com")]
250         public void FontClientCreateVectorBlob()
251         {
252             tlog.Debug(tag, $"FontClientCreateVectorBlob START");
253
254             var testingTarget = new FontClient(FontClient.Instance);
255
256             using (Color color = new Color(0.4f, 1.0f, 0.3f, 0.0f))
257             {
258                 var blob = new SWIGTYPE_p_p_Dali__TextAbstraction__VectorBlob(color.SwigCPtr.Handle);
259                 var blobLegnth = new SWIGTYPE_p_unsigned_int(color.SwigCPtr.Handle);
260
261                 var nominalWidth = new SWIGTYPE_p_unsigned_int(FontClient.Instance.SwigCPtr.Handle);
262                 var nominalHeight = new SWIGTYPE_p_unsigned_int(testingTarget.SwigCPtr.Handle);
263
264                 try
265                 {
266                     testingTarget.CreateVectorBlob(0, 0, blob, blobLegnth, nominalWidth, nominalHeight);
267                 }
268                 catch (Exception e)
269                 {
270                     tlog.Debug(tag, e.Message.ToString());
271                     Assert.Fail("Caught Exception: Failed!");
272                 }
273
274                 testingTarget.Dispose();
275             }
276
277             tlog.Debug(tag, $"FontClientCreateVectorBlob END (OK)");
278         }
279
280         [Test]
281         [Category("P1")]
282         [Description("FontClient GetEllipsisGlyph.")]
283         [Property("SPEC", "Tizen.NUI.FontClient.GetEllipsisGlyph M")]
284         [Property("SPEC_URL", "-")]
285         [Property("CRITERIA", "MR")]
286         [Property("AUTHOR", "guowei.wang@samsung.com")]
287         public void FontClientGetEllipsisGlyph()
288         {
289             tlog.Debug(tag, $"FontClientGetEllipsisGlyph START");
290
291             var testingTarget = new FontClient(FontClient.Instance);
292             Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
293             Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
294
295             var result = testingTarget.GetEllipsisGlyph(10);
296             Assert.IsInstanceOf<GlyphInfo>(result, "Should be an instance of GlyphInfo type.");
297
298             testingTarget.Dispose();
299             tlog.Debug(tag, $"FontClientGetEllipsisGlyph END (OK)");
300         }
301
302         [Test]
303         [Category("P1")]
304         [Description("FontClient IsColorGlyph.")]
305         [Property("SPEC", "Tizen.NUI.FontClient.IsColorGlyph M")]
306         [Property("SPEC_URL", "-")]
307         [Property("CRITERIA", "MR")]
308         [Property("AUTHOR", "guowei.wang@samsung.com")]
309         public void FontClientIsColorGlyph()
310         {
311             tlog.Debug(tag, $"FontClientIsColorGlyph START");
312
313             var testingTarget = new FontClient(FontClient.Instance);
314             Assert.IsNotNull(testingTarget, "Return a null object of FontClient");
315             Assert.IsInstanceOf<FontClient>(testingTarget, "Should be an instance of FontClient type.");
316
317             try
318             {
319                 testingTarget.IsColorGlyph(testingTarget.GetFontId(ttf_path), testingTarget.GetGlyphIndex(0, 0x0041));
320             }
321             catch (Exception e)
322             {
323                 tlog.Debug(tag, e.Message.ToString());
324                 Assert.Fail("Caugth Exception: Failed!");
325             }
326
327             testingTarget.Dispose();
328             tlog.Debug(tag, $"FontClientIsColorGlyph END (OK)");
329         }
330
331         [Test]
332         [Category("P1")]
333         [Description("GlyphBufferData constructor.")]
334         [Property("SPEC", "Tizen.NUI.FontClient.GlyphBufferData.GlyphBufferData C")]
335         [Property("SPEC_URL", "-")]
336         [Property("CRITERIA", "MR")]
337         [Property("AUTHOR", "guowei.wang@samsung.com")]
338         public void FontClientGlyphBufferDataConstructor()
339         {
340             tlog.Debug(tag, $"FontClientGlyphBufferDataConstructor START");
341
342             using (FontClient.GlyphBufferData data = new FontClient.GlyphBufferData())
343             {
344                 var testingTarget = new FontClient.GlyphBufferData(FontClient.GlyphBufferData.getCPtr(data).Handle, true);
345                 Assert.IsNotNull(testingTarget, "Return a null object of GlyphBufferData");
346                 Assert.IsInstanceOf<FontClient.GlyphBufferData>(testingTarget, "Should be an instance of GlyphBufferData type.");
347
348                 testingTarget.Dispose();
349             }
350
351             tlog.Debug(tag, $"FontClientGlyphBufferDataConstructor END (OK)");
352         }
353
354         [Test]
355         [Category("P1")]
356         [Description("GlyphBufferData Width.")]
357         [Property("SPEC", "Tizen.NUI.FontClient.GlyphBufferData.Width A")]
358         [Property("SPEC_URL", "-")]
359         [Property("CRITERIA", "PRW")]
360         [Property("AUTHOR", "guowei.wang@samsung.com")]
361         public void FontClientGlyphBufferDataWidth()
362         {
363             tlog.Debug(tag, $"FontClientGlyphBufferDataWidth START");
364
365             var testingTarget = new FontClient.GlyphBufferData();
366             Assert.IsNotNull(testingTarget, "Return a null object of GlyphBufferData");
367             Assert.IsInstanceOf<FontClient.GlyphBufferData>(testingTarget, "Should be an instance of GlyphBufferData type.");
368
369             testingTarget.Width = 10;
370             Assert.AreEqual(10, testingTarget.Width, "Should be equal!");
371
372             testingTarget.Dispose();
373             tlog.Debug(tag, $"FontClientGlyphBufferDataWidth END (OK)");
374         }
375
376         [Test]
377         [Category("P1")]
378         [Description("GlyphBufferData Height.")]
379         [Property("SPEC", "Tizen.NUI.FontClient.GlyphBufferData.Height A")]
380         [Property("SPEC_URL", "-")]
381         [Property("CRITERIA", "PRW")]
382         [Property("AUTHOR", "guowei.wang@samsung.com")]
383         public void FontClientGlyphBufferDataHeight()
384         {
385             tlog.Debug(tag, $"FontClientGlyphBufferDataHeight START");
386
387             var testingTarget = new FontClient.GlyphBufferData(); ;
388             Assert.IsNotNull(testingTarget, "Return a null object of GlyphBufferData");
389             Assert.IsInstanceOf<FontClient.GlyphBufferData>(testingTarget, "Should be an instance of GlyphBufferData type.");
390
391             testingTarget.Height = 50;
392             Assert.AreEqual(50, testingTarget.Height, "Should be equal!");
393
394             testingTarget.Dispose();
395             tlog.Debug(tag, $"FontClientGlyphBufferDataHeight END (OK)");
396         }
397
398         [Test]
399         [Category("P1")]
400         [Description("GlyphBufferData Format.")]
401         [Property("SPEC", "Tizen.NUI.FontClient.GlyphBufferData.Format A")]
402         [Property("SPEC_URL", "-")]
403         [Property("CRITERIA", "PRW")]
404         [Property("AUTHOR", "guowei.wang@samsung.com")]
405         public void FontClientGlyphBufferDataFormat()
406         {
407             tlog.Debug(tag, $"FontClientGlyphBufferDataFormat START");
408
409             var testingTarget = new FontClient.GlyphBufferData();
410             Assert.IsNotNull(testingTarget, "Return a null object of GlyphBufferData");
411             Assert.IsInstanceOf<FontClient.GlyphBufferData>(testingTarget, "Should be an instance of GlyphBufferData type.");
412
413             testingTarget.Format = PixelFormat.BGR8888;
414             Assert.AreEqual(PixelFormat.BGR8888, testingTarget.Format, "Should be equal!");
415
416             testingTarget.Dispose();
417             tlog.Debug(tag, $"FontClientGlyphBufferDataFormat END (OK)");
418         }
419     }
420 }