<commit_before>/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * This file is part of libgpiod.
 *
 * Copyright (C) 2019 <NAME> <<EMAIL>>
 */

#include <catch.hpp>
#include <gpiod.hpp>

#include "gpio-mockup.hpp"

using ::gpiod::test::mockup;

namespace {

const ::std::string consumer = "line-test";

} /* namespace */

TEST_CASE("Global find_line() function works", "[line]")
{
	mockup::probe_guard mockup_chips({ 8, 8, 8, 8, 8 }, mockup::FLAG_NAMED_LINES);

	auto line = ::gpiod::find_line("gpio-mockup-C-5");
	REQUIRE(line.offset() == 5);
	REQUIRE(line.name() == "gpio-mockup-C-5");
	REQUIRE(line.get_chip().label() == "gpio-mockup-C");
}

TEST_CASE("Line information can be correctly retrieved", "[line]")
{
	mockup::probe_guard mockup_chips({ 8 }, mockup::FLAG_NAMED_LINES);
	::gpiod::chip chip(mockup::instance().chip_name(0));
	auto line = chip.get_line(4);

	SECTION("unexported line")
	{<commit_msg>bindings: cxx: tests: extend the test case for global find_line()<commit_after>/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * This file is part of libgpiod.
 *
 * Copyright (C) 2019 <NAME> <<EMAIL>>
 */

#include <catch.hpp>
#include <gpiod.hpp>

#include "gpio-mockup.hpp"

using ::gpiod::test::mockup;

namespace {

const ::std::string consumer = "line-test";

} /* namespace */

TEST_CASE("Global find_line() function works", "[line]")
{
	mockup::probe_guard mockup_chips({ 8, 8, 8, 8, 8 }, mockup::FLAG_NAMED_LINES);

	SECTION("line found")
	{
		auto line = ::gpiod::find_line("gpio-mockup-C-5");
		REQUIRE(line.offset() == 5);
		REQUIRE(line.name() == "gpio-mockup-C-5");
		REQUIRE(line.get_chip().label() == "gpio-mockup-C");
	}

	SECTION("line not found")
	{
		auto line = ::gpiod::find_line("nonexistent-line");
		REQUIRE_FALSE(line);
	}
}

TEST_CASE("Line information can be correctly retrieved", "[line]")
{
	mockup::probe_guard mockup_chips({ 8 }, mockup::FLAG_NAMED_LINES);
	::gpiod::chip chip(mockup::instance().chip_name(0));
	auto line = chip.get_line(4);

	SECTION("unexported line")
	{
{'fraction_non_alphanumeric': 0.19812252964426877, 'fraction_numerical': 0.016798418972332016, 'mean_word_length': 5.136363636363637, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '105913', 'n_tokens_mistral': 821, 'n_tokens_neox': 779, 'n_words': 154}