Debian Codegraph @

bindings/cxx/tests/tests-request-config.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 <cstddef>
6 #include <gpiod.hpp>
7 #include <string>
8 #include <sstream>
9
10 #include "helpers.hpp"
11
12 using offsets = ::gpiod::line::offsets;
13
14 namespace {
15
16 TEST_CASE("request_config constructor works", "[request-config]")
17 {
18 SECTION("no arguments")
19 {
20 ::gpiod::request_config cfg;
21
22 REQUIRE(cfg.consumer().empty());
23 REQUIRE(cfg.event_buffer_size() == 0);
24 }
25 }
26
27 TEST_CASE("request_config can be moved", "[request-config]")
28 {
29 ::gpiod::request_config cfg;
30
31 cfg.set_consumer("foobar").set_event_buffer_size(64);
32
33 SECTION("move constructor works")
34 {
35 auto moved(::std::move(cfg));
36 REQUIRE_THAT(moved.consumer(), Catch::Matchers::Equals("foobar"));
37 REQUIRE(moved.event_buffer_size() == 64);
38 }
39
40 SECTION("move assignment operator works")
41 {
42 ::gpiod::request_config moved;
43
44 moved = ::std::move(cfg);
45
46 REQUIRE_THAT(moved.consumer(), Catch::Matchers::Equals("foobar"));
47 REQUIRE(moved.event_buffer_size() == 64);
48 }
49 }
50
51 TEST_CASE("request_config mutators work", "[request-config]")
52 {
53 ::gpiod::request_config cfg;
54
55 SECTION("set consumer")
56 {
57 cfg.set_consumer("foobar");
58 REQUIRE_THAT(cfg.consumer(), Catch::Matchers::Equals("foobar"));
59 }
60
61 SECTION("set event_buffer_size")
62 {
63 cfg.set_event_buffer_size(128);
64 REQUIRE(cfg.event_buffer_size() == 128);
65 }
66 }
67
68 TEST_CASE("request_config stream insertion operator works", "[request-config]")
69 {
70 ::gpiod::request_config cfg;
71
72 cfg.set_consumer("foobar").set_event_buffer_size(32);
73
74 ::std::stringstream buf;
75
76 buf << cfg;
77
78 ::std::string expected("gpiod::request_config(consumer='foobar', event_buffer_size=32)");
79
80 REQUIRE_THAT(buf.str(), Catch::Matchers::Equals(expected));
81 }
82
83 } /* namespace */