3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
7 namespace Tizen.NUI.Devel.Tests
9 using tlog = Tizen.Log;
12 [Description("Internal/Utility/ColorUtils")]
13 public class InternalColorUtilsTest
15 private const string tag = "NUITEST";
20 tlog.Info(tag, "Init() is called!");
26 tlog.Info(tag, "Destroy() is called!");
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()
38 tlog.Debug(tag, $"ColorUtilsRgbToXyz START");
42 double[] outXyz = new double[3];
43 ColorUtils.RgbToXyz(10, 8, 133, outXyz);
47 tlog.Debug(tag, e.Message.ToString());
48 Assert.Pass("Caught Exception: Passed!");
51 tlog.Debug(tag, $"ColorUtilsRgbToXyz END (OK)");
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()
63 tlog.Debug(tag, $"ColorUtilsRgbToXyzWithArgumentException START");
67 double[] outXyz = new double[2];
68 ColorUtils.RgbToXyz(10, 8, 133, outXyz);
70 catch (ArgumentException e)
72 tlog.Debug(tag, e.Message.ToString());
73 tlog.Debug(tag, $"ColorUtilsRgbToXyzWithArgumentException END (OK)");
74 Assert.Pass("Caught ArgumentException: Passed!");
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()
87 tlog.Debug(tag, $"ColorUtilsCalculateLuminance START");
91 ColorUtils.CalculateLuminance(115);
95 tlog.Debug(tag, e.Message.ToString());
96 Assert.Pass("Caught Exception: Passed!");
99 tlog.Debug(tag, $"ColorUtilsCalculateLuminance END (OK)");
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()
111 tlog.Debug(tag, $"ColorUtilsCalculateContrast START");
115 ColorUtils.CalculateContrast(30, -2);
119 tlog.Debug(tag, e.Message.ToString());
120 Assert.Pass("Caught ArgumentException: Passed!");
123 tlog.Debug(tag, $"ColorUtilsCalculateContrast END (OK)");
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()
135 tlog.Debug(tag, $"ColorUtilsCalculateContrastArgumentException START");
139 ColorUtils.CalculateContrast(25, 0);
141 catch (ArgumentException e)
143 tlog.Debug(tag, e.Message.ToString());
144 tlog.Debug(tag, $"ColorUtilsCalculateContrastArgumentException END (OK)");
145 Assert.Pass("Caught ArgumentException: Passed!");
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()
158 tlog.Debug(tag, $"ColorUtilsSetAlphaComponent START");
162 ColorUtils.SetAlphaComponent(25, 111);
166 tlog.Debug(tag, e.Message.ToString());
167 Assert.Pass("Caught Exception: Passed!");
170 tlog.Debug(tag, $"ColorUtilsSetAlphaComponent END (OK)");
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()
182 tlog.Debug(tag, $"ColorUtilsSetAlphaComponentArgumentException START");
186 ColorUtils.SetAlphaComponent(25, -1);
188 catch (ArgumentException e)
190 tlog.Debug(tag, e.Message.ToString());
191 tlog.Debug(tag, $"ColorUtilsSetAlphaComponentArgumentException END (OK)");
192 Assert.Pass("Caught ArgumentException: Passed!");
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()
205 tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlpha START");
209 ColorUtils.CalculateMinimumAlpha(25, -2, 0.3f);
213 tlog.Debug(tag, e.Message.ToString());
214 Assert.Pass("Caught Exception: Passed!");
217 tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlpha END (OK)");
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()
229 tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlphaArgumentException START");
233 ColorUtils.CalculateMinimumAlpha(25, 0, 0.3f);
235 catch (ArgumentException e)
237 tlog.Debug(tag, e.Message.ToString());
238 tlog.Debug(tag, $"ColorUtilsCalculateMinimumAlphaArgumentException END (OK)");
239 Assert.Pass("Caught ArgumentException: Passed!");
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()
252 tlog.Debug(tag, $"ColorUtilsHslToRgb START");
256 float[] hsl0 = { 10.0f, 200.0f, 500.0f };
257 ColorUtils.HslToRgb(hsl0);
261 tlog.Debug(tag, e.Message.ToString());
262 Assert.Fail("Caugth Exception: Failed!");
267 float[] hsl1 = { 60.0f, 210.0f, 510.0f };
268 ColorUtils.HslToRgb(hsl1);
272 tlog.Debug(tag, e.Message.ToString());
273 Assert.Fail("Caugth Exception: Failed!");
278 float[] hsl2 = { 120.0f, 220.0f, 520.0f };
279 ColorUtils.HslToRgb(hsl2);
283 tlog.Debug(tag, e.Message.ToString());
284 Assert.Fail("Caugth Exception: Failed!");
289 float[] hsl3 = { 180.0f, 230.0f, 530.0f };
290 ColorUtils.HslToRgb(hsl3);
294 tlog.Debug(tag, e.Message.ToString());
295 Assert.Fail("Caugth Exception: Failed!");
300 float[] hsl4 = { 240.0f, 240.0f, 540.0f };
301 ColorUtils.HslToRgb(hsl4);
305 tlog.Debug(tag, e.Message.ToString());
306 Assert.Fail("Caugth Exception: Failed!");
311 float[] hsl5 = { 300.0f, 250.0f, 550.0f };
312 ColorUtils.HslToRgb(hsl5);
316 tlog.Debug(tag, e.Message.ToString());
317 Assert.Fail("Caugth Exception: Failed!");
322 float[] hsl6 = { 360.0f, 260.0f, 560.0f };
323 ColorUtils.HslToRgb(hsl6);
327 tlog.Debug(tag, e.Message.ToString());
328 Assert.Fail("Caugth Exception: Failed!");
331 tlog.Debug(tag, $"ColorUtilsHslToRgb END (OK)");
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()
343 tlog.Debug(tag, $"ColorUtilsGetBytesPerPixel START");
345 var result = ColorUtils.GetBytesPerPixel(PixelFormat.RGBA4444);
346 Assert.AreEqual(2, result, "Should be equal!");
348 result = ColorUtils.GetBytesPerPixel(PixelFormat.RGB888);
349 Assert.AreEqual(3, result, "Should be equal!");
351 result = ColorUtils.GetBytesPerPixel(PixelFormat.BGR8888);
352 Assert.AreEqual(4, result, "Should be equal!");
354 result = ColorUtils.GetBytesPerPixel(0);
355 Assert.AreEqual(0, result, "Should be equal!");
357 tlog.Debug(tag, $"ColorUtilsGetBytesPerPixel END (OK)");