<commit_before>/*
 * The RedFish distributed filesystem
 *
 * Copyright 2011, <NAME> <<EMAIL>>
 *
 * This is licensed under the Apache License, Version 2.0.  See file COPYING.
 */

#include "util/str_to_int.h"
#include "util/test.h"

#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

int test_str_to_int(void)
{
	int i;
	char err[512] = { 0 };

	err[0] = '\0';
	str_to_int("123", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 123);

	err[0] = '\0';
	str_to_int("0", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 0);

	err[0] = '\0';
	str_to_int("", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("10b", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("f", 16, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 15);

	err[0] = '\0';
	str_to_int("8589934592", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("2147483647", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 2147483647);

	err[0] = '\0';
	str_to_int("blah", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	return 0;
}

int main(void)
{
	EXPECT_ZERO(test_str_to_int());

	return EXIT_SUCCESS;
}
<commit_msg>str_to_int_unit: test more cases<commit_after>/*
 * The RedFish distributed filesystem
 *
 * Copyright 2011, <NAME> <<EMAIL>>
 *
 * This is licensed under the Apache License, Version 2.0.  See file COPYING.
 */

#include "util/str_to_int.h"
#include "util/test.h"

#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

int test_str_to_int(void)
{
	long long ll;
	int i;
	char err[512] = { 0 };

	err[0] = '\0';
	str_to_int("123", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 123);

	err[0] = '\0';
	str_to_int("0", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 0);

	err[0] = '\0';
	str_to_int("", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("10b", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("f", 16, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 15);

	err[0] = '\0';
	str_to_int("8589934592", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_int("2147483647", 10, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 2147483647);

	err[0] = '\0';
	str_to_int("blah", 10, &i, err, sizeof(err));
	EXPECT_NONZERO(err[0]);

	err[0] = '\0';
	str_to_long_long("281474976710656", 10, &ll, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(ll, 281474976710656LL);

	err[0] = '\0';
	str_to_long_long("0x1000000000000", 16, &ll, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(ll, 281474976710656LL);

	err[0] = '\0';
	str_to_int("0755", 8, &i, err, sizeof(err));
	EXPECT_ZERO(err[0]);
	EXPECT_EQUAL(i, 493);

	return 0;
}

int main(void)
{
	EXPECT_ZERO(test_str_to_int());

	return EXIT_SUCCESS;
}

{'fraction_non_alphanumeric': 0.21639344262295082, 'fraction_numerical': 0.08721311475409836, 'mean_word_length': 5.089820359281437, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '6576063', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1420, 'n_words': 282}