2
* Copyright © 2015 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/flags.h"
20
#include "mir_toolkit/common.h"
22
#include <gtest/gtest.h>
23
#include <gmock/gmock.h>
25
namespace arbitrary_namespace
27
enum class Character : uint32_t
37
Positive = (1<<4) - 1,
41
Character mir_enable_enum_bit_operators(Character);
42
using Profile = mir::Flags<Character>;
47
namespace ns_inside_mir
49
enum class Capability : uint8_t { Pointer = 1<<4, Touchpad = 1<<3};
50
Capability mir_enable_enum_bit_operators(Capability);
51
using Capabilities = mir::Flags<Capability>;
55
namespace nested = mir::ns_inside_mir;
56
namespace arb = arbitrary_namespace;
58
TEST(MirFlags,lookup_rules_work_in_mir_nested_namespace)
60
using namespace testing;
61
nested::Capabilities cap = nested::Capability::Pointer | nested::Capability::Touchpad;
63
EXPECT_THAT(cap.value(), (1<<3) | (1<<4));
66
TEST(MirFlags,lookup_rules_work_in_arbitrary_namespace)
68
using namespace testing;
69
arb::Profile empty = arb::Character::Curious & arb::Character::Reckless;
71
EXPECT_THAT(empty.value(),Eq(0));
74
TEST(MirFlags,contains_check_works_for_masks)
76
using namespace testing;
77
arb::Profile mostly_positive;
78
mostly_positive |= arb::Character::Curious | arb::Character::Logical;
80
EXPECT_THAT(contains(mostly_positive,arb::Character::Positive),Eq(false));
81
mostly_positive = mostly_positive | arb::Character::Idealistic | arb::Character::Englihtened;
83
EXPECT_THAT(contains(mostly_positive,arb::Character::Positive),Eq(true));
86
TEST(MirFlags, toggling_bits)
88
using namespace testing;
89
arb::Profile negative{arb::Character::Negative};
91
EXPECT_THAT(contains(negative,arb::Character::Paranoid),Eq(true));
92
EXPECT_THAT(contains(negative^arb::Character::Paranoid,arb::Character::Paranoid),Eq(false));