2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
19
#include "mir_toolkit/common.h"
20
#include "mir/graphics/pixel_format_utils.h"
21
#include <gmock/gmock.h>
22
#include <gtest/gtest.h>
24
using namespace mir::graphics;
25
TEST(MirPixelFormatUtils, contains_alpha)
27
EXPECT_FALSE(contains_alpha(mir_pixel_format_xbgr_8888));
28
EXPECT_FALSE(contains_alpha(mir_pixel_format_bgr_888));
29
EXPECT_FALSE(contains_alpha(mir_pixel_format_xrgb_8888));
30
EXPECT_FALSE(contains_alpha(mir_pixel_format_xbgr_8888));
31
EXPECT_TRUE(contains_alpha(mir_pixel_format_argb_8888));
32
EXPECT_TRUE(contains_alpha(mir_pixel_format_abgr_8888));
33
EXPECT_FALSE(contains_alpha(mir_pixel_format_invalid));
34
EXPECT_FALSE(contains_alpha(mir_pixel_formats));
37
TEST(MirPixelFormatUtils, red_channel_depths)
39
EXPECT_EQ(8, red_channel_depth(mir_pixel_format_xbgr_8888));
40
EXPECT_EQ(8, red_channel_depth(mir_pixel_format_bgr_888));
41
EXPECT_EQ(8, red_channel_depth(mir_pixel_format_xrgb_8888));
42
EXPECT_EQ(8, red_channel_depth(mir_pixel_format_xbgr_8888));
43
EXPECT_EQ(8, red_channel_depth(mir_pixel_format_argb_8888));
44
EXPECT_EQ(8, red_channel_depth(mir_pixel_format_abgr_8888));
45
EXPECT_EQ(0, red_channel_depth(mir_pixel_format_invalid));
46
EXPECT_EQ(0, red_channel_depth(mir_pixel_formats));
49
TEST(MirPixelFormatUtils, blue_channel_depths)
51
EXPECT_EQ(8, blue_channel_depth(mir_pixel_format_xbgr_8888));
52
EXPECT_EQ(8, blue_channel_depth(mir_pixel_format_bgr_888));
53
EXPECT_EQ(8, blue_channel_depth(mir_pixel_format_xrgb_8888));
54
EXPECT_EQ(8, blue_channel_depth(mir_pixel_format_xbgr_8888));
55
EXPECT_EQ(8, blue_channel_depth(mir_pixel_format_argb_8888));
56
EXPECT_EQ(8, blue_channel_depth(mir_pixel_format_abgr_8888));
57
EXPECT_EQ(0, blue_channel_depth(mir_pixel_format_invalid));
58
EXPECT_EQ(0, blue_channel_depth(mir_pixel_formats));
61
TEST(MirPixelFormatUtils, green_channel_depths)
63
EXPECT_EQ(8, green_channel_depth(mir_pixel_format_xbgr_8888));
64
EXPECT_EQ(8, green_channel_depth(mir_pixel_format_bgr_888));
65
EXPECT_EQ(8, green_channel_depth(mir_pixel_format_xrgb_8888));
66
EXPECT_EQ(8, green_channel_depth(mir_pixel_format_xbgr_8888));
67
EXPECT_EQ(8, green_channel_depth(mir_pixel_format_argb_8888));
68
EXPECT_EQ(8, green_channel_depth(mir_pixel_format_abgr_8888));
69
EXPECT_EQ(0, green_channel_depth(mir_pixel_format_invalid));
70
EXPECT_EQ(0, green_channel_depth(mir_pixel_formats));
74
TEST(MirPixelFormatUtils, alpha_channel_depths)
76
EXPECT_EQ(0, alpha_channel_depth(mir_pixel_format_xbgr_8888));
77
EXPECT_EQ(0, alpha_channel_depth(mir_pixel_format_bgr_888));
78
EXPECT_EQ(0, alpha_channel_depth(mir_pixel_format_xrgb_8888));
79
EXPECT_EQ(0, alpha_channel_depth(mir_pixel_format_xbgr_8888));
80
EXPECT_EQ(8, alpha_channel_depth(mir_pixel_format_argb_8888));
81
EXPECT_EQ(8, alpha_channel_depth(mir_pixel_format_abgr_8888));
82
EXPECT_EQ(0, alpha_channel_depth(mir_pixel_format_invalid));
83
EXPECT_EQ(0, alpha_channel_depth(mir_pixel_formats));
86
TEST(MirPixelFormatUtils, valid_mir_pixel_format)
88
EXPECT_TRUE(valid_pixel_format(mir_pixel_format_xbgr_8888));
89
EXPECT_TRUE(valid_pixel_format(mir_pixel_format_bgr_888));
90
EXPECT_TRUE(valid_pixel_format(mir_pixel_format_xrgb_8888));
91
EXPECT_TRUE(valid_pixel_format(mir_pixel_format_xbgr_8888));
92
EXPECT_TRUE(valid_pixel_format(mir_pixel_format_argb_8888));
93
EXPECT_TRUE(valid_pixel_format(mir_pixel_format_abgr_8888));
94
EXPECT_FALSE(valid_pixel_format(mir_pixel_format_invalid));
95
EXPECT_FALSE(valid_pixel_format(mir_pixel_formats));