1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "color_picker_unittest.h"
17 #include "color_picker.h"
18 #include "color.h"
19 #include "image_source.h"
20 #include "pixel_map.h"
21 #include "effect_errors.h"
22 #include "hilog/log.h"
23 #include "test_picture_files.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 using namespace OHOS::Media;
28 using namespace OHOS::HiviewDFX;
29 
30 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
31     LOG_CORE, LOG_DOMAIN, "ColorPickerTest"
32 };
33 
34 namespace OHOS {
35 namespace Rosen {
36 /**
37  * @tc.name: CreateColorPickerFromPixelmapTest001
38  * @tc.desc: Ensure the ability of creating color picker from pixelmap.
39  * @tc.type: FUNC
40  * @tc.require:
41  * @tc.author:
42  */
43 HWTEST_F(ColorPickerUnittest, CreateColorPickerFromPixelmapTest001, TestSize.Level1)
44 {
45     GTEST_LOG_(INFO) << "ColorPickerUnittest CreateColorPickerFromPixelmapTest001 start";
46     /**
47      * @tc.steps: step1. Create a pixelmap
48      */
49     Media::InitializationOptions opts;
50     opts.size.width = 200;
51     opts.size.height = 150;
52     opts.editable = true;
53     std::unique_ptr<Media::PixelMap> pixmap = Media::PixelMap::Create(opts);
54 
55     /**
56      * @tc.steps: step2. Call create From pixelMap
57      */
58     uint32_t errorCode = SUCCESS;
59     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
60     ASSERT_EQ(errorCode, SUCCESS);
61     EXPECT_NE(pColorPicker, nullptr);
62 }
63 
64 /**
65  * @tc.name: CreateColorPickerFromPixelmapTest002
66  * @tc.desc: Ensure the ability of creating color picker from pixelmap.
67  * @tc.type: FUNC
68  * @tc.require:
69  * @tc.author:
70  */
71 HWTEST_F(ColorPickerUnittest, CreateColorPickerFromPixelmapTest002, TestSize.Level1)
72 {
73     GTEST_LOG_(INFO) << "ColorPickerUnittest CreateColorPickerFromPixelmapTest002 start";
74     size_t bufferSize = 0;
75     uint8_t *buffer = GetPngBuffer(bufferSize);
76     ASSERT_NE(buffer, nullptr);
77 
78     /**
79      * @tc.steps: step1. Create a ImageSource
80      */
81     uint32_t errorCode = 0;
82     SourceOptions opts;
83     opts.formatHint = "image/png";
84     std::unique_ptr<ImageSource> imageSource =
85         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
86     ASSERT_EQ(errorCode, SUCCESS);
87 
88     /**
89      * @tc.steps: step2. decode image source to pixel map by default decode options
90      * @tc.expected: step2. decode image source to pixel map success.
91      */
92     DecodeOptions decodeOpts;
93     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
94     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
95     ASSERT_EQ(errorCode, SUCCESS);
96     ASSERT_NE(pixmap.get(), nullptr);
97 
98     /**
99      * @tc.steps: step3. Call create From pixelMap
100      */
101     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
102     EXPECT_NE(pColorPicker, nullptr);
103 }
104 
105 /**
106  * @tc.name: CreateColorPickerFromPixelmapTest003
107  * @tc.desc: Ensure the ability of creating effect chain from config file.
108  * @tc.type: FUNC
109  * @tc.require:
110  * @tc.author:
111  */
112 HWTEST_F(ColorPickerUnittest, CreateColorPickerFromPixelmapTest003, TestSize.Level1)
113 {
114     GTEST_LOG_(INFO) << "ColorPickerUnittest CreateColorPickerFromPixelmapTest003 start";
115     /**
116      * @tc.steps: step1. Create a pixelMap
117      */
118     std::unique_ptr<Media::PixelMap> pixmap = nullptr;
119 
120     /**
121      * @tc.steps: step2. Call create From pixelMap
122      */
123     uint32_t errorCode = SUCCESS;
124     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
125     ASSERT_EQ(errorCode, ERR_EFFECT_INVALID_VALUE);
126     EXPECT_EQ(pColorPicker, nullptr);
127 }
128 
129 /**
130  * @tc.name: CreateColorPickerFromPixelmapTest004
131  * @tc.desc: Ensure the ability of creating color picker from pixelmap.
132  * @tc.type: FUNC
133  * @tc.require:
134  * @tc.author:
135  */
136 HWTEST_F(ColorPickerUnittest, CreateColorPickerFromPixelmapTest004, TestSize.Level1)
137 {
138     GTEST_LOG_(INFO) << "ColorPickerUnittest CreateColorPickerFromPixelmapTest004 start";
139     /**
140      * @tc.steps: step1. Create a pixelmap
141      */
142     Media::InitializationOptions opts;
143     opts.size.width = 200;
144     opts.size.height = 150;
145     opts.editable = true;
146     std::unique_ptr<Media::PixelMap> pixmap = Media::PixelMap::Create(opts);
147 
148     /**
149      * @tc.steps: step2. Call create From pixelMap
150      */
151     uint32_t errorCode = SUCCESS;
152     double region[4] = {0, 0, 0.5, 0.5};
153     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), region, errorCode);
154     ASSERT_EQ(errorCode, SUCCESS);
155     EXPECT_NE(pColorPicker, nullptr);
156 }
157 
158 /**
159  * @tc.name: CreateColorPickerFromPixelmapTest005
160  * @tc.desc: Ensure the ability of creating color picker from pixelmap.
161  * @tc.type: FUNC
162  * @tc.require:
163  * @tc.author:
164  */
165 HWTEST_F(ColorPickerUnittest, CreateColorPickerFromPixelmapTest005, TestSize.Level1)
166 {
167     GTEST_LOG_(INFO) << "ColorPickerUnittest CreateColorPickerFromPixelmapTest005 start";
168     /**
169      * @tc.steps: step1. Create a pixelmap
170      */
171     Media::InitializationOptions opts;
172     opts.size.width = 200;
173     opts.size.height = 150;
174     opts.editable = true;
175     std::unique_ptr<Media::PixelMap> pixmap = Media::PixelMap::Create(opts);
176 
177     /**
178      * @tc.steps: step2. Call create From pixelMap
179      */
180     uint32_t errorCode = SUCCESS;
181     double region[4] = {0, 0.5, 0.5, 0.5};
182     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), region, errorCode);
183     ASSERT_EQ(pColorPicker->colorValLen_, 0);
184     EXPECT_NE(pColorPicker, nullptr);
185 }
186 
187 /**
188  * @tc.name: GetMainColorTest001
189  * @tc.desc: Ensure the ability of creating effect chain from config file.
190  * @tc.type: FUNC
191  * @tc.require:
192  * @tc.author:
193  */
194 HWTEST_F(ColorPickerUnittest, GetMainColorTest001, TestSize.Level1)
195 {
196     GTEST_LOG_(INFO) << "ColorPickerUnittest GetMainColorTest001 start";
197     size_t bufferSize = 0;
198     uint8_t *buffer = GetJpgBuffer(bufferSize);
199     ASSERT_NE(buffer, nullptr);
200 
201     /**
202      * @tc.steps: step1. create image source by correct jpeg file path and jpeg format hit.
203      * @tc.expected: step1. create image source success.
204      */
205     uint32_t errorCode = 0;
206     SourceOptions opts;
207     opts.formatHint = "image/jpeg";
208     std::unique_ptr<ImageSource> imageSource =
209         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
210     ASSERT_EQ(errorCode, SUCCESS);
211     ASSERT_NE(imageSource.get(), nullptr);
212 
213     /**
214      * @tc.steps: step2. decode image source to pixel map by default decode options
215      * @tc.expected: step2. decode image source to pixel map success.
216      */
217     DecodeOptions decodeOpts;
218     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
219     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
220     ASSERT_EQ(errorCode, SUCCESS);
221     ASSERT_NE(pixmap.get(), nullptr);
222 
223     /**
224      * @tc.steps: step2. Call create From pixelMap
225      */
226     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
227     ASSERT_EQ(errorCode, SUCCESS);
228     EXPECT_NE(pColorPicker, nullptr);
229 
230     /**
231      * @tc.steps: step3. Get main color from pixmap
232      */
233     ColorManager::Color color;
234     errorCode = pColorPicker->GetMainColor(color);
235     HiLog::Info(LABEL_TEST, "get main color t1[rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
236                 color.r, color.g, color.b, color.a);
237     ASSERT_EQ(errorCode, SUCCESS);
238     bool ret = color.ColorEqual(ColorManager::Color(1.f, 0.788235f, 0.050980f, 1.f));
239     EXPECT_EQ(true, ret);
240 }
241 
242 /**
243  * @tc.name: GetMainColorTest002
244  * @tc.desc: Ensure the ability of creating effect chain from config file.
245  * @tc.type: FUNC
246  * @tc.require:
247  * @tc.author:
248  */
249 HWTEST_F(ColorPickerUnittest, GetMainColorTest002, TestSize.Level1)
250 {
251     GTEST_LOG_(INFO) << "ColorPickerUnittest GetMainColorTest002 start";
252     size_t bufferSize = 0;
253     uint8_t *buffer = GetPngBuffer(bufferSize);
254     ASSERT_NE(buffer, nullptr);
255 
256     /**
257      * @tc.steps: step1. Create a ImageSource
258      */
259     uint32_t errorCode = 0;
260     SourceOptions opts;
261     opts.formatHint = "image/png";
262     std::unique_ptr<ImageSource> imageSource =
263         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
264     ASSERT_EQ(errorCode, SUCCESS);
265     ASSERT_NE(imageSource.get(), nullptr);
266 
267     /**
268      * @tc.steps: step2. decode image source to pixel map by default decode options
269      * @tc.expected: step2. decode image source to pixel map success.
270      */
271     DecodeOptions decodeOpts;
272     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
273     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
274     ASSERT_EQ(errorCode, SUCCESS);
275     ASSERT_NE(pixmap.get(), nullptr);
276 
277     /**
278      * @tc.steps: step3. Call create From pixelMap
279      */
280     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
281     ASSERT_EQ(errorCode, SUCCESS);
282     ASSERT_NE(pColorPicker, nullptr);
283 
284     /**
285      * @tc.steps: step4. Get main color from pixmap
286      */
287     ColorManager::Color color;
288     errorCode = pColorPicker->GetMainColor(color);
289     HiLog::Info(LABEL_TEST, "get main color t2[rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
290                 color.r, color.g, color.b, color.a);
291     ASSERT_EQ(errorCode, SUCCESS);
292     bool ret = color.ColorEqual(ColorManager::Color(1.f, 1.f, 1.f, 1.f));
293     EXPECT_EQ(true, ret);
294 }
295 
296 /**
297  * @tc.name: GetMainColorTest003
298  * @tc.desc: Ensure the ability of creating effect chain from config file.
299  * @tc.type: FUNC
300  * @tc.require:
301  * @tc.author:
302  */
303 HWTEST_F(ColorPickerUnittest, GetMainColorTest003, TestSize.Level1)
304 {
305     GTEST_LOG_(INFO) << "ColorPickerUnittest GetMainColorTest003 start";
306     /**
307      * @tc.steps: step1. Create a pixelMap
308      */
309     Media::InitializationOptions opts;
310     opts.size.width = 200;
311     opts.size.height = 100;
312     opts.editable = true;
313     std::unique_ptr<Media::PixelMap> pixmap = Media::PixelMap::Create(opts);
314 
315     /**
316      * @tc.steps: step2. Call create From pixelMap
317      */
318     uint32_t errorCode = SUCCESS;
319     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
320     ASSERT_EQ(errorCode, SUCCESS);
321     ASSERT_NE(pColorPicker, nullptr);
322 
323     /**
324      * @tc.steps: step3. Get main color from pixmap
325      */
326     ColorManager::Color color;
327     errorCode = pColorPicker->GetMainColor(color);
328     HiLog::Info(LABEL_TEST, "get main color t3[rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
329                 color.r, color.g, color.b, color.a);
330     ASSERT_EQ(errorCode, SUCCESS);
331     bool ret = color.ColorEqual(ColorManager::Color(0x00000000U));
332     EXPECT_EQ(true, ret);
333 }
334 
335 /**
336  * @tc.name: GetLargestProportionColor
337  * @tc.desc: Ensure the ability of creating effect chain from config file.
338  * @tc.type: FUNC
339  * @tc.require:
340  * @tc.author:
341  */
342 HWTEST_F(ColorPickerUnittest, GetLargestProportionColor, TestSize.Level1)
343 {
344     GTEST_LOG_(INFO) << "ColorPickerUnittest GetLargestProportionColor start";
345     size_t bufferSize = 0;
346     uint8_t *buffer = GetJpgBuffer(bufferSize);
347     ASSERT_NE(buffer, nullptr);
348 
349     uint32_t errorCode = 0;
350     SourceOptions opts;
351     opts.formatHint = "image/jpeg";
352     std::unique_ptr<ImageSource> imageSource =
353         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
354     ASSERT_EQ(errorCode, SUCCESS);
355     ASSERT_NE(imageSource.get(), nullptr);
356 
357     DecodeOptions decodeOpts;
358     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
359     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
360     ASSERT_EQ(errorCode, SUCCESS);
361     ASSERT_NE(pixmap.get(), nullptr);
362 
363     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
364     ASSERT_EQ(errorCode, SUCCESS);
365     EXPECT_NE(pColorPicker, nullptr);
366 
367     ColorManager::Color color;
368     errorCode = pColorPicker->GetLargestProportionColor(color);
369     HiLog::Info(LABEL_TEST, "get largest proportion color [rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
370                 color.r, color.g, color.b, color.a);
371     ASSERT_EQ(errorCode, SUCCESS);
372     bool ret = color.ColorEqual(ColorManager::Color(0.972549f, 0.784314f, 0.0313726f, 1.f));
373     EXPECT_EQ(true, ret);
374 }
375 
376 /**
377  * @tc.name: GetHighestSaturationColor
378  * @tc.desc: Ensure the ability of creating effect chain from config file.
379  * @tc.type: FUNC
380  * @tc.require:
381  * @tc.author:
382  */
383 HWTEST_F(ColorPickerUnittest, GetHighestSaturationColor, TestSize.Level1)
384 {
385     GTEST_LOG_(INFO) << "ColorPickerUnittest GetHighestSaturationColor start";
386     size_t bufferSize = 0;
387     uint8_t *buffer = GetJpgBuffer(bufferSize);
388     ASSERT_NE(buffer, nullptr);
389 
390     uint32_t errorCode = 0;
391     SourceOptions opts;
392     opts.formatHint = "image/jpeg";
393     std::unique_ptr<ImageSource> imageSource =
394         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
395     ASSERT_EQ(errorCode, SUCCESS);
396     ASSERT_NE(imageSource.get(), nullptr);
397 
398     DecodeOptions decodeOpts;
399     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
400     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
401     ASSERT_EQ(errorCode, SUCCESS);
402     ASSERT_NE(pixmap.get(), nullptr);
403 
404     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
405     ASSERT_EQ(errorCode, SUCCESS);
406     EXPECT_NE(pColorPicker, nullptr);
407 
408     ColorManager::Color color;
409     errorCode = pColorPicker->GetHighestSaturationColor(color);
410     HiLog::Info(LABEL_TEST, "get highest saturation color [rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
411                 color.r, color.g, color.b, color.a);
412     ASSERT_EQ(errorCode, SUCCESS);
413     bool ret = color.ColorEqual(ColorManager::Color(0.972549f, 0.784314f, 0.0313726f, 1.f));
414     EXPECT_EQ(true, ret);
415 }
416 
417 /**
418  * @tc.name: GetAverageColor
419  * @tc.desc: Ensure the ability of creating effect chain from config file.
420  * @tc.type: FUNC
421  * @tc.require:
422  * @tc.author:
423  */
424 HWTEST_F(ColorPickerUnittest, GetAverageColor, TestSize.Level1)
425 {
426     GTEST_LOG_(INFO) << "ColorPickerUnittest GetAverageColor start";
427     size_t bufferSize = 0;
428     uint8_t *buffer = GetJpgBuffer(bufferSize);
429     ASSERT_NE(buffer, nullptr);
430 
431     uint32_t errorCode = 0;
432     SourceOptions opts;
433     opts.formatHint = "image/jpeg";
434     std::unique_ptr<ImageSource> imageSource =
435         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
436     ASSERT_EQ(errorCode, SUCCESS);
437     ASSERT_NE(imageSource.get(), nullptr);
438 
439     DecodeOptions decodeOpts;
440     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
441     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
442     ASSERT_EQ(errorCode, SUCCESS);
443     ASSERT_NE(pixmap.get(), nullptr);
444 
445     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
446     ASSERT_EQ(errorCode, SUCCESS);
447     EXPECT_NE(pColorPicker, nullptr);
448 
449     ColorManager::Color color;
450     errorCode = pColorPicker->GetAverageColor(color);
451     HiLog::Info(LABEL_TEST, "get average color [rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
452                 color.r, color.g, color.b, color.a);
453     ASSERT_EQ(errorCode, SUCCESS);
454     bool ret = color.ColorEqual(ColorManager::Color(0.972549f, 0.784314f, 0.0313726f, 1.f));
455     EXPECT_EQ(true, ret);
456 }
457 
458 /**
459  * @tc.name: IsBlackOrWhiteOrGrayColor
460  * @tc.desc: Ensure the ability of creating effect chain from config file.
461  * @tc.type: FUNC
462  * @tc.require:
463  * @tc.author:
464  */
465 HWTEST_F(ColorPickerUnittest, IsBlackOrWhiteOrGrayColor, TestSize.Level1)
466 {
467     GTEST_LOG_(INFO) << "ColorPickerUnittest IsBlackOrWhiteOrGrayColor start";
468     size_t bufferSize = 0;
469     uint8_t *buffer = GetJpgBuffer(bufferSize);
470     ASSERT_NE(buffer, nullptr);
471 
472     uint32_t errorCode = 0;
473     SourceOptions opts;
474     opts.formatHint = "image/jpeg";
475     std::unique_ptr<ImageSource> imageSource =
476         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
477     ASSERT_EQ(errorCode, SUCCESS);
478     ASSERT_NE(imageSource.get(), nullptr);
479 
480     DecodeOptions decodeOpts;
481     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
482     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
483     ASSERT_EQ(errorCode, SUCCESS);
484     ASSERT_NE(pixmap.get(), nullptr);
485 
486     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
487     ASSERT_EQ(errorCode, SUCCESS);
488     EXPECT_NE(pColorPicker, nullptr);
489 
490     bool judgeRst = pColorPicker->IsBlackOrWhiteOrGrayColor(0xFFFFFFFF);
491     HiLog::Info(LABEL_TEST, "get largest proportion color result=%{public}d", judgeRst);
492     ASSERT_EQ(judgeRst, true);
493 }
494 
495 /**
496  * @tc.name: GetTopProportionColors
497  * @tc.desc: Ensure the ability of creating effect chain from config file.
498  * @tc.type: FUNC
499  * @tc.require:
500  * @tc.author:
501  */
502 HWTEST_F(ColorPickerUnittest, GetTopProportionColors, TestSize.Level1)
503 {
504     GTEST_LOG_(INFO) << "ColorPickerUnittest GetTopProportionColors start";
505     size_t bufferSize = 0;
506     uint8_t *buffer = GetJpgBuffer(bufferSize);
507     ASSERT_NE(buffer, nullptr);
508 
509     uint32_t errorCode = 0;
510     SourceOptions opts;
511     opts.formatHint = "image/jpeg";
512     std::unique_ptr<ImageSource> imageSource =
513         ImageSource::CreateImageSource(buffer, bufferSize, opts, errorCode);
514     ASSERT_EQ(errorCode, SUCCESS);
515     ASSERT_NE(imageSource.get(), nullptr);
516 
517     DecodeOptions decodeOpts;
518     std::unique_ptr<PixelMap> pixmap = imageSource->CreatePixelMap(decodeOpts, errorCode);
519     HiLog::Debug(LABEL_TEST, "create pixel map error code=%{public}u.", errorCode);
520     ASSERT_EQ(errorCode, SUCCESS);
521     ASSERT_NE(pixmap.get(), nullptr);
522 
523     std::shared_ptr<ColorPicker> pColorPicker = ColorPicker::CreateColorPicker(std::move(pixmap), errorCode);
524     ASSERT_EQ(errorCode, SUCCESS);
525     EXPECT_NE(pColorPicker, nullptr);
526 
527     std::vector<ColorManager::Color> colors = pColorPicker->GetTopProportionColors(10); // the color num limit is 10
528     HiLog::Info(LABEL_TEST, "get top proportion colors[0][rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
529                 colors[0].r, colors[0].g, colors[0].b, colors[0].a);
530     ASSERT_EQ(colors.size(), 1);
531     bool ret = colors[0].ColorEqual(
532         ColorManager::Color(0.972549f, 0.784314f, 0.0313726f, 1.f)); // the top 1 proportion color
533     EXPECT_EQ(true, ret);
534 
535     std::vector<ColorManager::Color> colors1 = pColorPicker->GetTopProportionColors(1);
536     HiLog::Info(LABEL_TEST, "get top proportion colors[0][rgba]=%{public}f,%{public}f,%{public}f,%{public}f",
537                 colors1[0].r, colors1[0].g, colors1[0].b, colors1[0].a);
538     ASSERT_EQ(colors1.size(), 1);
539     ret = colors1[0].ColorEqual(
540         ColorManager::Color(0.972549f, 0.784314f, 0.0313726f, 1.f)); // the top 1 proportion color
541     EXPECT_EQ(true, ret);
542 
543     std::vector<ColorManager::Color> colors2 = pColorPicker->GetTopProportionColors(0);
544     ASSERT_EQ(colors2.size(), 0);
545 }
546 } // namespace Rosen
547 } // namespace OHOS
548