Debian Codegraph @

bindings/cxx/tests/tests-line.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]>
3
4 #include <catch2/catch_all.hpp>
5 #include <gpiod.hpp>
6
7 #include "helpers.hpp"
8
9 using offset = ::gpiod::line::offset;
10 using value = ::gpiod::line::value;
11 using direction = ::gpiod::line::direction;
12 using edge = ::gpiod::line::edge;
13 using bias = ::gpiod::line::bias;
14 using drive = ::gpiod::line::drive;
15 using clock_type = ::gpiod::line::clock;
16 using offsets = ::gpiod::line::offsets;
17 using values = ::gpiod::line::values;
18 using value_mapping = ::gpiod::line::value_mapping;
19 using value_mappings = ::gpiod::line::value_mappings;
20
21 namespace {
22
23 TEST_CASE("stream insertion operators for types in gpiod::line work", "[line]")
24 {
25 SECTION("offset")
26 {
27 offset off = 4;
28
29 REQUIRE_THAT(off, stringify_matcher<offset>("4"));
30 }
31
32 SECTION("value")
33 {
34 auto active = value::ACTIVE;
35 auto inactive = value::INACTIVE;
36
37 REQUIRE_THAT(active, stringify_matcher<value>("ACTIVE"));
38 REQUIRE_THAT(inactive, stringify_matcher<value>("INACTIVE"));
39 }
40
41 SECTION("direction")
42 {
43 auto input = direction::INPUT;
44 auto output = direction::OUTPUT;
45 auto as_is = direction::AS_IS;
46
47 REQUIRE_THAT(input, stringify_matcher<direction>("INPUT"));
48 REQUIRE_THAT(output, stringify_matcher<direction>("OUTPUT"));
49 REQUIRE_THAT(as_is, stringify_matcher<direction>("AS_IS"));
50 }
51
52 SECTION("edge")
53 {
54 auto rising = edge::RISING;
55 auto falling = edge::FALLING;
56 auto both = edge::BOTH;
57 auto none = edge::NONE;
58
59 REQUIRE_THAT(rising, stringify_matcher<edge>("RISING_EDGE"));
60 REQUIRE_THAT(falling, stringify_matcher<edge>("FALLING_EDGE"));
61 REQUIRE_THAT(both, stringify_matcher<edge>("BOTH_EDGES"));
62 REQUIRE_THAT(none, stringify_matcher<edge>("NONE"));
63 }
64
65 SECTION("bias")
66 {
67 auto pull_up = bias::PULL_UP;
68 auto pull_down = bias::PULL_DOWN;
69 auto disabled = bias::DISABLED;
70 auto as_is = bias::AS_IS;
71 auto unknown = bias::UNKNOWN;
72
73 REQUIRE_THAT(pull_up, stringify_matcher<bias>("PULL_UP"));
74 REQUIRE_THAT(pull_down, stringify_matcher<bias>("PULL_DOWN"));
75 REQUIRE_THAT(disabled, stringify_matcher<bias>("DISABLED"));
76 REQUIRE_THAT(as_is, stringify_matcher<bias>("AS_IS"));
77 REQUIRE_THAT(unknown, stringify_matcher<bias>("UNKNOWN"));
78 }
79
80 SECTION("drive")
81 {
82 auto push_pull = drive::PUSH_PULL;
83 auto open_drain = drive::OPEN_DRAIN;
84 auto open_source = drive::OPEN_SOURCE;
85
86 REQUIRE_THAT(push_pull, stringify_matcher<drive>("PUSH_PULL"));
87 REQUIRE_THAT(open_drain, stringify_matcher<drive>("OPEN_DRAIN"));
88 REQUIRE_THAT(open_source, stringify_matcher<drive>("OPEN_SOURCE"));
89 }
90
91 SECTION("clock")
92 {
93 auto monotonic = clock_type::MONOTONIC;
94 auto realtime = clock_type::REALTIME;
95 auto hte = clock_type::HTE;
96
97 REQUIRE_THAT(monotonic, stringify_matcher<clock_type>("MONOTONIC"));
98 REQUIRE_THAT(realtime, stringify_matcher<clock_type>("REALTIME"));
99 REQUIRE_THAT(hte, stringify_matcher<clock_type>("HTE"));
100 }
101
102 SECTION("offsets")
103 {
104 offsets offs = { 2, 5, 3, 9, 8, 7 };
105
106 REQUIRE_THAT(offs, stringify_matcher<offsets>("gpiod::offsets(2, 5, 3, 9, 8, 7)"));
107 }
108
109 SECTION("values")
110 {
111 values vals = {
112 value::ACTIVE,
113 value::INACTIVE,
114 value::ACTIVE,
115 value::ACTIVE,
116 value::INACTIVE
117 };
118
119 REQUIRE_THAT(vals,
120 stringify_matcher<values>("gpiod::values(ACTIVE, INACTIVE, ACTIVE, ACTIVE, INACTIVE)"));
121 }
122
123 SECTION("value_mapping")
124 {
125 value_mapping val = { 4, value::ACTIVE };
126
127 REQUIRE_THAT(val, stringify_matcher<value_mapping>("gpiod::value_mapping(4: ACTIVE)"));
128 }
129
130 SECTION("value_mappings")
131 {
132 value_mappings vals = { { 0, value::ACTIVE }, { 4, value::INACTIVE }, { 8, value::ACTIVE } };
133
134 REQUIRE_THAT(vals, stringify_matcher<value_mappings>(
135 "gpiod::value_mappings(gpiod::value_mapping(0: ACTIVE), gpiod::value_mapping(4: INACTIVE), gpiod::value_mapping(8: ACTIVE))"));
136 }
137 }
138
139 } /* namespace */