<commit_before>/*
 * Iterator test cases for libgpiod.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 */

#include "gpiod-test.h"

static void chip_iter(void)
{
	TEST_CLEANUP(test_free_chip_iter) struct gpiod_chip_iter *iter = NULL;
	struct gpiod_chip *chip;
	bool A, B, C;

	A = B = C = false;

	iter = gpiod_chip_iter_new();
	TEST_ASSERT_NOT_NULL(iter);

	gpiod_foreach_chip(iter, chip) {
		TEST_ASSERT(!gpiod_chip_iter_err(iter));

		if (strcmp(gpiod_chip_label(chip), "gpio-mockup-A") == 0)
			A = true;
		else if (strcmp(gpiod_chip_label(chip), "gpio-mockup-B") == 0)
			B = true;
		else if (strcmp(gpiod_chip_label(chip), "gpio-mockup-C") == 0)
			C = true;
	}

	TEST_ASSERT(A);
	TEST_ASSERT(B);
	TEST_ASSERT(C);
}
TEST_DEFINE(chip_iter,
	    "gpiod_chip_iter - simple loop",
	    0, { 8, 8, 8 });

static void chip_iter_noclose(void)
{
	TEST_CLEANUP(test_free_chip_iter_noclose)
			struct gpiod_chip_iter *iter = NULL;
	TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipA;
	TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipB;
	TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipC;
	struct gpiod_chip *chip;
	bool A, B, C;

	A = B = C = false;

	iter = gpiod_chip_iter_new();
	TEST_ASSERT_NOT_NULL(iter);

	gpiod_foreach_chip_noclose(iter, chip) {<commit_msg>tests: iter: fix potential segfault<commit_after>/*
 * Iterator test cases for libgpiod.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 */

#include "gpiod-test.h"

static void chip_iter(void)
{
	TEST_CLEANUP(test_free_chip_iter) struct gpiod_chip_iter *iter = NULL;
	struct gpiod_chip *chip;
	bool A, B, C;

	A = B = C = false;

	iter = gpiod_chip_iter_new();
	TEST_ASSERT_NOT_NULL(iter);

	gpiod_foreach_chip(iter, chip) {
		TEST_ASSERT(!gpiod_chip_iter_err(iter));

		if (strcmp(gpiod_chip_label(chip), "gpio-mockup-A") == 0)
			A = true;
		else if (strcmp(gpiod_chip_label(chip), "gpio-mockup-B") == 0)
			B = true;
		else if (strcmp(gpiod_chip_label(chip), "gpio-mockup-C") == 0)
			C = true;
	}

	TEST_ASSERT(A);
	TEST_ASSERT(B);
	TEST_ASSERT(C);
}
TEST_DEFINE(chip_iter,
	    "gpiod_chip_iter - simple loop",
	    0, { 8, 8, 8 });

static void chip_iter_noclose(void)
{
	TEST_CLEANUP(test_free_chip_iter_noclose)
			struct gpiod_chip_iter *iter = NULL;
	TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipA = NULL;
	TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipB = NULL;
	TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipC = NULL;
	struct gpiod_chip *chip;
	bool A, B, C;

	A = B = C = false;

	iter = gpiod_chip_iter_new();
	TEST_ASSERT_NOT_NULL(iter);

	gpiod_foreach_chip_noclose(iter, chip) {
{'fraction_non_alphanumeric': 0.11884834281888182, 'fraction_numerical': 0.008704385671242048, 'mean_word_length': 4.757225433526012, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5352090', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1163, 'n_words': 281}