Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / Utility / TSColorCutQuantizer.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/ColorCutQuantizer")]
13     public class InternalColorCutQuantizerTest
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("ColorCutQuantizer FromBitmap .")]
32         [Property("SPEC", "Tizen.NUI.ColorCutQuantizer.FromBitmap M")]
33         [Property("SPEC_URL", "-")]
34         [Property("CRITERIA", "MR")]
35         [Property("AUTHOR", "guowei.wang@samsung.com")]
36         public void ColorCutQuantizerFromBitmap()
37         {
38             tlog.Debug(tag, $"ColorCutQuantizerFromBitmap START");
39
40             using (PixelBuffer pixelBuffer = new PixelBuffer(100, 200, PixelFormat.RGBA8888))
41             {
42                 using (Rectangle region = new Rectangle())
43                 {
44                     var testingTarget = ColorCutQuantizer.FromBitmap(pixelBuffer, region, 255);
45                     Assert.IsNotNull(testingTarget, "Should be not null!");
46                     Assert.IsInstanceOf<ColorCutQuantizer>(testingTarget, "Should be an Instance of ColorCutQuantizer!");
47                 }
48             }
49             
50             tlog.Debug(tag, $"ColorCutQuantizerFromBitmap END (OK)");
51         }
52
53         [Test]
54         [Category("P2")]
55         [Description("ColorCutQuantizer FromBitmap. MaxColor < 1.")]
56         [Property("SPEC", "Tizen.NUI.ColorCutQuantizer.FromBitmap M")]
57         [Property("SPEC_URL", "-")]
58         [Property("CRITERIA", "MR")]
59         [Property("AUTHOR", "guowei.wang@samsung.com")]
60         public void ColorCutQuantizerFromBitmapWithMaxColorLessThan1()
61         {
62             tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithMaxColorLessThan1 START");
63
64             using (PixelBuffer pixelBuffer = new PixelBuffer(100, 200, PixelFormat.RGBA8888))
65             {
66                 using (Rectangle region = new Rectangle())
67                 {
68                     try
69                     {
70                         ColorCutQuantizer.FromBitmap(pixelBuffer, region, 0);
71                     }
72                     catch (ArgumentNullException e)
73                     {
74                         tlog.Debug(tag, e.Message.ToString());
75                         tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithMaxColorLessThan1 END (OK)");
76                         Assert.Pass("Caught ArgumentNullException : Passed!");
77                     }
78                 }
79             }
80         }
81
82         [Test]
83         [Category("P2")]
84         [Description("ColorCutQuantizer FromBitmap. Region is null.")]
85         [Property("SPEC", "Tizen.NUI.ColorCutQuantizer.FromBitmap M")]
86         [Property("SPEC_URL", "-")]
87         [Property("CRITERIA", "MR")]
88         [Property("AUTHOR", "guowei.wang@samsung.com")]
89         public void ColorCutQuantizerFromBitmapWithNullRegion()
90         {
91             tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithNullRegion START");
92
93             using (PixelBuffer pixelBuffer = new PixelBuffer(1, 2, PixelFormat.A8))
94             {
95                 using (Rectangle region = null)
96                 {
97                     var testingTarget = ColorCutQuantizer.FromBitmap(pixelBuffer, region, 255);
98                     Assert.IsNotNull(testingTarget, "Should be not null!");
99                     Assert.IsInstanceOf<ColorCutQuantizer>(testingTarget, "Should be an Instance of ColorCutQuantizer!");
100                 }
101             }
102
103             tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithNullRegion END (OK)");
104         }
105
106         [Test]
107         [Category("P1")]
108         [Description("ColorCutQuantizer GetQuantizedColors .")]
109         [Property("SPEC", "Tizen.NUI.ColorCutQuantizer.GetQuantizedColors M")]
110         [Property("SPEC_URL", "-")]
111         [Property("CRITERIA", "MR")]
112         [Property("AUTHOR", "guowei.wang@samsung.com")]
113         public void ColorCutQuantizerGetQuantizedColors()
114         {
115             tlog.Debug(tag, $"ColorCutQuantizerGetQuantizedColors START");
116
117             using (PixelBuffer pixelBuffer = new PixelBuffer(100, 200, PixelFormat.A8))
118             {
119                 using (Rectangle region = new Rectangle())
120                 {
121                     var testingTarget = ColorCutQuantizer.FromBitmap(pixelBuffer, region, 255);
122                     Assert.IsNotNull(testingTarget, "Should be not null!");
123                     Assert.IsInstanceOf<ColorCutQuantizer>(testingTarget, "Should be an Instance of ColorCutQuantizer!");
124
125                     try
126                     {
127                         testingTarget.GetQuantizedColors();
128                         tlog.Debug(tag, "quantizedColors : " + testingTarget.GetQuantizedColors());
129                     }
130                     catch (Exception e)
131                     {
132                         tlog.Debug(tag, e.Message.ToString());
133                         Assert.Fail("Caught Exception: Failed!");
134                     }
135                 }
136             }
137
138             tlog.Debug(tag, $"ColorCutQuantizerGetQuantizedColors END (OK)");
139         }
140     }
141 }