Debian Codegraph @

bindings/cxx/tests/tests-chip-info.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 #include <sstream>
7
8 #include "gpiosim.hpp"
9 #include "helpers.hpp"
10
11 using ::gpiosim::make_sim;
12
13 namespace {
14
15 TEST_CASE("chip_info properties can be read", "[chip-info][chip]")
16 {
17 auto sim = make_sim()
18 .set_num_lines(8)
19 .set_label("foobar")
20 .build();
21
22 ::gpiod::chip chip(sim.dev_path());
23 auto info = chip.get_info();
24
25 SECTION("get chip name")
26 {
27 REQUIRE_THAT(info.name(), Catch::Matchers::Equals(sim.name()));
28 }
29
30 SECTION("get chip label")
31 {
32 REQUIRE_THAT(info.label(), Catch::Matchers::Equals("foobar"));
33 }
34
35 SECTION("get num_lines")
36 {
37 REQUIRE(info.num_lines() == 8);
38 }
39 }
40
41 TEST_CASE("chip_info can be copied and moved", "[chip-info]")
42 {
43 auto sim = make_sim()
44 .set_num_lines(4)
45 .set_label("foobar")
46 .build();
47
48 ::gpiod::chip chip(sim.dev_path());
49 auto info = chip.get_info();
50
51 SECTION("copy constructor works")
52 {
53 auto copy(info);
54
55 REQUIRE_THAT(copy.name(), Catch::Matchers::Equals(sim.name()));
56 REQUIRE_THAT(copy.label(), Catch::Matchers::Equals("foobar"));
57 REQUIRE(copy.num_lines() == 4);
58
59 REQUIRE_THAT(info.name(), Catch::Matchers::Equals(sim.name()));
60 REQUIRE_THAT(info.label(), Catch::Matchers::Equals("foobar"));
61 REQUIRE(info.num_lines() == 4);
62 }
63
64 SECTION("assignment operator works")
65 {
66 auto copy = chip.get_info();
67
68 copy = info;
69
70 REQUIRE_THAT(copy.name(), Catch::Matchers::Equals(sim.name()));
71 REQUIRE_THAT(copy.label(), Catch::Matchers::Equals("foobar"));
72 REQUIRE(copy.num_lines() == 4);
73
74 REQUIRE_THAT(info.name(), Catch::Matchers::Equals(sim.name()));
75 REQUIRE_THAT(info.label(), Catch::Matchers::Equals("foobar"));
76 REQUIRE(info.num_lines() == 4);
77 }
78
79 SECTION("move constructor works")
80 {
81 auto moved(std::move(info));
82
83 REQUIRE_THAT(moved.name(), Catch::Matchers::Equals(sim.name()));
84 REQUIRE_THAT(moved.label(), Catch::Matchers::Equals("foobar"));
85 REQUIRE(moved.num_lines() == 4);
86 }
87
88 SECTION("move assignment operator works")
89 {
90 auto moved = chip.get_info();
91
92 moved = ::std::move(info);
93
94 REQUIRE_THAT(moved.name(), Catch::Matchers::Equals(sim.name()));
95 REQUIRE_THAT(moved.label(), Catch::Matchers::Equals("foobar"));
96 REQUIRE(moved.num_lines() == 4);
97 }
98 }
99
100 TEST_CASE("stream insertion operator works for chip_info", "[chip-info]")
101 {
102 auto sim = make_sim()
103 .set_num_lines(4)
104 .set_label("foobar")
105 .build();
106
107 ::gpiod::chip chip(sim.dev_path());
108 auto info = chip.get_info();
109 ::std::stringstream expected;
110
111 expected << "gpiod::chip_info(name=\"" << sim.name() <<
112 "\", label=\"foobar\", num_lines=4)";
113
114 REQUIRE_THAT(info, stringify_matcher<::gpiod::chip_info>(expected.str()));
115 }
116
117 } /* namespace */