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