1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored By: Andreas Pokorny <andreas.pokorny@canonical.com>
*/
#include "mir/flags.h"
#include "mir_toolkit/common.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
namespace arbitrary_namespace
{
enum class Character : uint32_t
{
Empty = 0,
Logical = 1<<0,
Idealistic = 1<<1,
Englihtened = 1<<2,
Curious = 1<<3,
Paranoid = 1<<16,
Unstable = 1<<17,
Reckless = 1<<18,
Positive = (1<<4) - 1,
Negative = 0xFFFF0000
};
Character mir_enable_enum_bit_operators(Character);
using Profile = mir::Flags<Character>;
}
namespace mir
{
namespace ns_inside_mir
{
enum class Capability : uint8_t { Pointer = 1<<4, Touchpad = 1<<3};
Capability mir_enable_enum_bit_operators(Capability);
using Capabilities = mir::Flags<Capability>;
}
}
namespace nested = mir::ns_inside_mir;
namespace arb = arbitrary_namespace;
TEST(MirFlags,lookup_rules_work_in_mir_nested_namespace)
{
using namespace testing;
nested::Capabilities cap = nested::Capability::Pointer | nested::Capability::Touchpad;
EXPECT_THAT(cap.value(), (1<<3) | (1<<4));
}
TEST(MirFlags,lookup_rules_work_in_arbitrary_namespace)
{
using namespace testing;
arb::Profile empty = arb::Character::Curious & arb::Character::Reckless;
EXPECT_THAT(empty.value(),Eq(0));
}
TEST(MirFlags,contains_check_works_for_masks)
{
using namespace testing;
arb::Profile mostly_positive;
mostly_positive |= arb::Character::Curious | arb::Character::Logical;
EXPECT_THAT(contains(mostly_positive,arb::Character::Positive),Eq(false));
mostly_positive = mostly_positive | arb::Character::Idealistic | arb::Character::Englihtened;
EXPECT_THAT(contains(mostly_positive,arb::Character::Positive),Eq(true));
}
TEST(MirFlags, toggling_bits)
{
using namespace testing;
arb::Profile negative{arb::Character::Negative};
EXPECT_THAT(contains(negative,arb::Character::Paranoid),Eq(true));
EXPECT_THAT(contains(negative^arb::Character::Paranoid,arb::Character::Paranoid),Eq(false));
}
|