xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/rgba_color_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "modules/desktop_capture/rgba_color.h"
12 
13 #include <cstdint>
14 #include <vector>
15 
16 #include "test/gtest.h"
17 
18 namespace webrtc {
19 
TEST(RgbaColorTest,ConvertFromAndToUInt32)20 TEST(RgbaColorTest, ConvertFromAndToUInt32) {
21   static const std::vector<uint32_t> cases{
22       0,         1000,       2693,       3725,       4097,      12532,
23       19902,     27002,      27723,      30944,      65535,     65536,
24       231194,    255985,     322871,     883798,     9585200,   12410056,
25       12641940,  30496970,   105735668,  110117847,  482769275, 542368468,
26       798173396, 2678656711, 3231043200, UINT32_MAX,
27   };
28 
29   for (uint32_t value : cases) {
30     RgbaColor left(value);
31     ASSERT_EQ(left.ToUInt32(), value);
32     RgbaColor right(left);
33     ASSERT_EQ(left.ToUInt32(), right.ToUInt32());
34   }
35 }
36 
TEST(RgbaColorTest,AlphaChannelEquality)37 TEST(RgbaColorTest, AlphaChannelEquality) {
38   RgbaColor left(10, 10, 10, 0);
39   RgbaColor right(10, 10, 10, 255);
40   ASSERT_EQ(left, right);
41   right.alpha = 128;
42   ASSERT_NE(left, right);
43 }
44 
45 }  // namespace webrtc
46