File: tests-request-config.cpp

package info (click to toggle)
libgpiod 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,108 kB
  • sloc: ansic: 26,612; sh: 7,554; cpp: 4,944; python: 2,426; makefile: 811; xml: 49
file content (83 lines) | stat: -rw-r--r-- 1,810 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
82
83
// SPDX-License-Identifier: GPL-2.0-or-later
// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <brgl@bgdev.pl>

#include <catch2/catch_all.hpp>
#include <cstddef>
#include <gpiod.hpp>
#include <string>
#include <sstream>

#include "helpers.hpp"

using offsets = ::gpiod::line::offsets;

namespace {

TEST_CASE("request_config constructor works", "[request-config]")
{
	SECTION("no arguments")
	{
		::gpiod::request_config cfg;

		REQUIRE(cfg.consumer().empty());
		REQUIRE(cfg.event_buffer_size() == 0);
	}
}

TEST_CASE("request_config can be moved", "[request-config]")
{
	::gpiod::request_config cfg;

	cfg.set_consumer("foobar").set_event_buffer_size(64);

	SECTION("move constructor works")
	{
		auto moved(::std::move(cfg));
		REQUIRE_THAT(moved.consumer(), Catch::Matchers::Equals("foobar"));
		REQUIRE(moved.event_buffer_size() == 64);
	}

	SECTION("move assignment operator works")
	{
		::gpiod::request_config moved;

		moved = ::std::move(cfg);

		REQUIRE_THAT(moved.consumer(), Catch::Matchers::Equals("foobar"));
		REQUIRE(moved.event_buffer_size() == 64);
	}
}

TEST_CASE("request_config mutators work", "[request-config]")
{
	::gpiod::request_config cfg;

	SECTION("set consumer")
	{
		cfg.set_consumer("foobar");
		REQUIRE_THAT(cfg.consumer(), Catch::Matchers::Equals("foobar"));
	}

	SECTION("set event_buffer_size")
	{
		cfg.set_event_buffer_size(128);
		REQUIRE(cfg.event_buffer_size() == 128);
	}
}

TEST_CASE("request_config stream insertion operator works", "[request-config]")
{
	::gpiod::request_config cfg;

	cfg.set_consumer("foobar").set_event_buffer_size(32);

	::std::stringstream buf;

	buf << cfg;

	::std::string expected("gpiod::request_config(consumer='foobar', event_buffer_size=32)");

	REQUIRE_THAT(buf.str(), Catch::Matchers::Equals(expected));
}

} /* namespace */