forked from daedric/commonpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.cpp
71 lines (60 loc) · 1.54 KB
/
options.cpp
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
/*
* File: tests/core/options.cpp
* Part of commonpp.
*
* Distributed under the 2-clause BSD licence (See LICENCE.TXT file at the
* project root).
*
* Copyright (c) 2016 Thomas Sanchez. All rights reserved.
*
*/
#include <commonpp/core/Options.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
using namespace commonpp;
enum class Test : unsigned int
{
O1 = (1 << 0),
O2 = (1 << 1),
O3 = (1 << 2),
O4 = (1 << 3),
O5 = (1 << 4),
O6 = (1 << 5),
};
using TestOS = Options<Test>;
COMMONPP_GENERATE_OPTIONS_OSTREAM_OP(
TestOS, Test::O1, Test::O2, Test::O3, Test::O4, Test::O5, Test::O6)
BOOST_AUTO_TEST_CASE(basic)
{
using Opt1 = Options<Test, Test::O1, Test::O2, Test::O3>;
{
Opt1 o(Test::O4);
BOOST_CHECK(o & Test::O1);
BOOST_CHECK(o & Test::O2);
BOOST_CHECK(o & Test::O3);
BOOST_CHECK(o & Test::O4);
BOOST_CHECK(!(o & Test::O5));
BOOST_CHECK(!(o & Test::O6));
}
using Opt2 = Options<Test>;
{
Opt2 o;
BOOST_CHECK(!(o & Test::O1));
BOOST_CHECK(!(o & Test::O2));
BOOST_CHECK(!(o & Test::O3));
BOOST_CHECK(!(o & Test::O4));
BOOST_CHECK(!(o & Test::O5));
BOOST_CHECK(!(o & Test::O6));
}
{
Opt2 o;
o |= Test::O1;
BOOST_CHECK(o & Test::O1);
o += Test::O2;
BOOST_CHECK(o & Test::O2);
o -= Test::O2;
BOOST_CHECK(o & Test::O1);
BOOST_CHECK(!(o & Test::O2));
}
std::cout << TestOS(Test::O1, Test::O6) << std::endl;
}