File: flag.cpp

package info (click to toggle)
librepcb 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 58,484 kB
  • sloc: cpp: 267,986; python: 12,100; ansic: 6,899; xml: 234; sh: 215; makefile: 115; perl: 73
file content (81 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download | duplicates (2)
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
// Copyright (C) 2016-2020 Jonathan Müller <jonathanmueller.dev@gmail.com>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.

#include <type_safe/flag.hpp>

#include <catch.hpp>

using namespace type_safe;

TEST_CASE("flag")
{
    SECTION("constructor")
    {
        flag a(true);
        REQUIRE(a == true);

        flag b(false);
        REQUIRE(b == false);
    }
    SECTION("toggle")
    {
        flag a(true);
        REQUIRE(a.toggle());
        REQUIRE(a == false);

        flag b(false);
        REQUIRE(!b.toggle());
        REQUIRE(b == true);
    }
    SECTION("change")
    {
        flag a(true);
        a.change(false);
        REQUIRE(a == false);

        flag b(false);
        b.change(true);
        REQUIRE(b == true);
    }
    SECTION("set")
    {
        flag a(true);
        a.set();
        REQUIRE(a == true);

        flag b(false);
        b.set();
        REQUIRE(b == true);
    }
    SECTION("try_set")
    {
        flag a(true);
        REQUIRE(!a.try_set());
        REQUIRE(a == true);

        flag b(false);
        REQUIRE(b.try_set());
        REQUIRE(b == true);
    }
    SECTION("reset")
    {
        flag a(true);
        a.reset();
        REQUIRE(a == false);

        flag b(false);
        b.reset();
        REQUIRE(b == false);
    }
    SECTION("try_reset")
    {
        flag a(true);
        REQUIRE(a.try_reset());
        REQUIRE(a == false);

        flag b(false);
        REQUIRE(!b.try_reset());
        REQUIRE(b == false);
    }
}