Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / Utility / TSColorUtils.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
7 namespace Tizen.NUI.Devel.Tests
8 {
9     using tlog = Tizen.Log;
10
11     [TestFixture]
12     [Description("Internal/Utility/ColorUtils")]
13     public class InternalColorUtilsTest
14     {
15         private const string tag = "NUITEST";
16
17         [SetUp]
18         public void Init()
19         {
20             tlog.Info(tag, "Init() is called!");
21         }
22
23         [TearDown]
24         public void Destroy()
25         {
26             tlog.Info(tag, "Destroy() is called!");
27         }
28
29         [Test]
30         [Category("P1")]
31         [Description("ColorUtils RgbToXyz.")]
32         [Property("SPEC", "Tizen.NUI.ColorUtils.RgbToXyz M")]
33         [Property("SPEC_URL", "-")]
34         [Property("CRITERIA", "MR")]
35         [Property("AUTHOR", "guowei.wang@samsung.com")]
36         public void ColorUtilsRgbToXyz()
37         {
38             tlog.Debug(tag, $"ColorUtilsRgbToXyz START");
39
40             try
41             {
42                 double[] outXyz = new double[3];
43                 ColorUtils.RgbToXyz(10, 8, 133, outXyz);
44             }
45             catch (Exception e)
46             {
47                 tlog.Debug(tag, e.Message.ToString());
48                 Assert.Pass("Caught Exception: Passed!");
49             }
50
51             tlog.Debug(tag, $"ColorUtilsRgbToXyz END (OK)");
52         }
53
54         [Test]
55         [Category("P2")]
56         [Description("ColorUtils RgbToXyz.")]
57         [Property("SPEC", "Tizen.NUI.ColorUtils.RgbToXyz M")]
58         [Property("SPEC_URL", "-")]
59         [Property("CRITERIA", "MR")]
60         [Property("AUTHOR", "guowei.wang@samsung.com")]
61         public void ColorUtilsRgbToXyzWithArgumentException()
62         {
63             tlog.Debug(tag, $"ColorUtilsRgbToXyzWithArgumentException START");
64
65             try
66             {
67                 double[] outXyz = new double[2];
68                 ColorUtils.RgbToXyz(10, 8, 133, outXyz);
69             }
70             catch (ArgumentException e)
71             {
72                 tlog.Debug(tag, e.Message.ToString());
73                 tlog.Debug(tag, $"ColorUtilsRgbToXyzWithArgumentException END (OK)");
74                 Assert.Pass("Caught ArgumentException: Passed!");
75             }
76         }
77
78         [Test]
79         [Category("P1")]
80         [Description("ColorUtils CalculateLuminance.")]
81         [Property("SPEC", "Tizen.NUI.ColorUtils.CalculateLuminance M")]
82         [Property("SPEC_URL", "-")]
83         [Property("CRITERIA", "MR")]
84         [Property("AUTHOR", "guowei.wang@samsung.com")]
85         public void ColorUtilsCalculateLuminance()
86         {
87             tlog.Debug(tag, $"ColorUtilsCalculateLuminance START");
88
89             try
90             {
91                 ColorUtils.CalculateLuminance(115);
92             }
93             catch (Exception e)
94             {
95                 tlog.Debug(tag, e.Message.ToString());
96                 Assert.Pass("Caught Exception: Passed!");
97             }
98
99             tlog.Debug(tag, $"ColorUtilsCalculateLuminance END (OK)");
100         }
101
102         [Test]
103         [Category("P1")]
104         [Description("ColorUtils CalculateContrast.")]
105         [Property("SPEC", "Tizen.NUI.ColorUtils.CalculateContrast M")]
106         [Property("SPEC_URL", "-")]
107         [Property("CRITERIA", "MR")]
108         [Property("AUTHOR", "guowei.wang@samsung.com")]
109         public void ColorUtilsCalculateContrast()
110         {
111             tlog.Debug(tag, $"ColorUtilsCalculateContrast START");
112
113             try
114             {
115                 ColorUtils.CalculateContrast(30, -2);
116             }
117             catch (Exception e)
118             {
119                 tlog.Debug(tag, e.Message.ToString());
120                 Assert.Pass("Caught ArgumentException: Passed!");
121             }
122
123             tlog.Debug(tag, $"ColorUtilsCalculateContrast END (OK)");
124         }
125
126         [Test]
127         [Category("P2")]
128         [Description("ColorUtils CalculateContrast. ArgumentException.")]
129         [Property("SPEC", "Tizen.NUI.ColorUtils.CalculateContrast M")]
130         [Property("SPEC_URL", "-")]
131         [Property("CRITERIA", "MR")]
132         [Property("AUTHOR", "guowei.wang@samsung.com")]
133         public void ColorUtilsCalculateContrastArgumentException()
134         {
135             tlog.Debug(tag, $"ColorUtilsCalculateContrastArgumentException START");
136
137             try
138             {
139                 ColorUtils.CalculateContrast(25, 0);
140             }
141             catch (ArgumentException e)
142             {
143                 tlog.Debug(tag, e.Message.ToString());
144                 tlog.Debug(tag, $"ColorUtilsCalculateContrastArgumentException END (OK)");
145                 Assert.Pass("Caught ArgumentException: Passed!");
146             }
147         }
148
149         [Test]
150         [Category("P1")]
151         [Description("ColorUtils SetAlphaComponent.")]
152         [Property("SPEC", "Tizen.NUI.ColorUtils.SetAlphaComponent M")]
153         [Property("SPEC_URL", "-")]
154         [Property("CRITERIA", "MR")]
155         [Property("AUTHOR", "guowei.wang@samsung.com")]
156         public void ColorUtilsSetAlphaComponent()
157         {
158             tlog.Debug(tag, $"ColorUtilsSetAlphaComponent START");
159
160             try
161             {
162                 ColorUtils.SetAlphaComponent(25, 111);
163             }
164             catch (Exception e)
165             {
166                 tlog.Debug(tag, e.Message.ToString());
167                 Assert.Pass("Caught Exception: Passed!");
168             }
169
170             tlog.Debug(tag, $"ColorUtilsSetAlphaComponent END (OK)");
171         }
172
173         [Test]
174         [Category("P2")]
175         [Description("ColorUtils SetAlphaComponent. ArgumentException")]
176         [Property("SPEC", "Tizen.NUI.ColorUtils.SetAlphaComponent M")]
177         [Property("SPEC_URL", "-")]
178         [Property("CRITERIA", "MR")]
179         [Property("AUTHOR", "guowei.wang@samsung.com")]
180         public void ColorUtilsSetAlphaComponentArgumentException()
181         {
182             tlog.Debug(tag, $"ColorUtilsSetAlphaComponentArgumentException START");
183
184             try
185             {
186                 ColorUtils.SetAlphaComponent(25, -1);
187             }
188             catch (ArgumentException e)
189             {
190                 tlog.Debug(tag, e.Message.ToString());
191                 tlog.Debug(tag, $"ColorUtilsSetAlphaComponentArgumentException END (OK)");
192                 Assert.Pass("Caught ArgumentException: Passed!");
193             }            
194         }
195
196         [Test]
197         [Category("P1")]
198         [Description("ColorUtils CalculateMinimumAlpha.")]
199         [Property("SPEC", "Tizen.NUI.ColorUtils.CalculateMinimumAlpha M")]
200         [Property("SPEC_URL", "-")]
201         [Property("CRITERIA", "MR")]
202         [Property("AUTHOR", "guowei.wang@samsung.com")]
203         public void ColorUtilsCalculateMinimumAlpha()
204         {
205             tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlpha START");
206
207             try
208             {
209                 ColorUtils.CalculateMinimumAlpha(25, -2, 0.3f);
210             }
211             catch (Exception e)
212             {
213                 tlog.Debug(tag, e.Message.ToString());
214                 Assert.Pass("Caught Exception: Passed!");
215             }
216
217             tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlpha END (OK)");
218         }
219
220         [Test]
221         [Category("P2")]
222         [Description("ColorUtils CalculateMinimumAlpha. ArgumentException")]
223         [Property("SPEC", "Tizen.NUI.ColorUtils.CalculateMinimumAlpha M")]
224         [Property("SPEC_URL", "-")]
225         [Property("CRITERIA", "MR")]
226         [Property("AUTHOR", "guowei.wang@samsung.com")]
227         public void ColorUtilsCalculateMinimumAlphaArgumentException()
228         {
229             tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlphaArgumentException START");
230
231             try
232             {
233                 ColorUtils.CalculateMinimumAlpha(25, 0, 0.3f);
234             }
235             catch (ArgumentException e)
236             {
237                 tlog.Debug(tag, e.Message.ToString());
238                 tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlphaArgumentException END (OK)");
239                 Assert.Pass("Caught ArgumentException: Passed!");
240             }
241         }
242
243         [Test]
244         [Category("P1")]
245         [Description("ColorUtils HslToRgb.")]
246         [Property("SPEC", "Tizen.NUI.ColorUtils.HslToRgb M")]
247         [Property("SPEC_URL", "-")]
248         [Property("CRITERIA", "MR")]
249         [Property("AUTHOR", "guowei.wang@samsung.com")]
250         public void ColorUtilsHslToRgb()
251         {
252             tlog.Debug(tag, $"ColorUtilsHslToRgb START");
253
254             try
255             {
256                 float[] hsl0 = { 10.0f, 200.0f, 500.0f };
257                 ColorUtils.HslToRgb(hsl0);
258             }
259             catch (Exception e)
260             {
261                 tlog.Debug(tag, e.Message.ToString());
262                 Assert.Fail("Caugth Exception: Failed!");
263             }
264
265             try
266             {
267                 float[] hsl1 = { 60.0f, 210.0f, 510.0f };
268                 ColorUtils.HslToRgb(hsl1);
269             }
270             catch (Exception e)
271             {
272                 tlog.Debug(tag, e.Message.ToString());
273                 Assert.Fail("Caugth Exception: Failed!");
274             }
275
276             try
277             {
278                 float[] hsl2 = { 120.0f, 220.0f, 520.0f };
279                 ColorUtils.HslToRgb(hsl2);
280             }
281             catch (Exception e)
282             {
283                 tlog.Debug(tag, e.Message.ToString());
284                 Assert.Fail("Caugth Exception: Failed!");
285             }
286
287             try
288             {
289                 float[] hsl3 = { 180.0f, 230.0f, 530.0f };
290                 ColorUtils.HslToRgb(hsl3);
291             }
292             catch (Exception e)
293             {
294                 tlog.Debug(tag, e.Message.ToString());
295                 Assert.Fail("Caugth Exception: Failed!");
296             }
297
298             try
299             {
300                 float[] hsl4 = { 240.0f, 240.0f, 540.0f };
301                 ColorUtils.HslToRgb(hsl4);
302             }
303             catch (Exception e)
304             {
305                 tlog.Debug(tag, e.Message.ToString());
306                 Assert.Fail("Caugth Exception: Failed!");
307             }
308
309             try
310             {
311                 float[] hsl5 = { 300.0f, 250.0f, 550.0f };
312                 ColorUtils.HslToRgb(hsl5);
313             }
314             catch (Exception e)
315             {
316                 tlog.Debug(tag, e.Message.ToString());
317                 Assert.Fail("Caugth Exception: Failed!");
318             }
319
320             try
321             {
322                 float[] hsl6 = { 360.0f, 260.0f, 560.0f };
323                 ColorUtils.HslToRgb(hsl6);
324             }
325             catch (Exception e)
326             {
327                 tlog.Debug(tag, e.Message.ToString());
328                 Assert.Fail("Caugth Exception: Failed!");
329             }
330
331             tlog.Debug(tag, $"ColorUtilsHslToRgb END (OK)");
332         }
333
334         [Test]
335         [Category("P1")]
336         [Description("ColorUtils GetBytesPerPixel.")]
337         [Property("SPEC", "Tizen.NUI.ColorUtils.GetBytesPerPixel M")]
338         [Property("SPEC_URL", "-")]
339         [Property("CRITERIA", "MR")]
340         [Property("AUTHOR", "guowei.wang@samsung.com")]
341         public void ColorUtilsGetBytesPerPixel()
342         {
343             tlog.Debug(tag, $"ColorUtilsGetBytesPerPixel START");
344
345             var result = ColorUtils.GetBytesPerPixel(PixelFormat.RGBA4444);
346             Assert.AreEqual(2, result, "Should be equal!");
347
348             result = ColorUtils.GetBytesPerPixel(PixelFormat.RGB888);
349             Assert.AreEqual(3, result, "Should be equal!");
350
351             result = ColorUtils.GetBytesPerPixel(PixelFormat.BGR8888);
352             Assert.AreEqual(4, result, "Should be equal!");
353
354             result = ColorUtils.GetBytesPerPixel(0);
355             Assert.AreEqual(0, result, "Should be equal!");
356
357             tlog.Debug(tag, $"ColorUtilsGetBytesPerPixel END (OK)");
358         }
359     }
360 }