|
|
8e15ce |
/*
|
|
|
8e15ce |
* GRUB -- GRand Unified Bootloader
|
|
|
8e15ce |
* Copyright (C) 2016 Free Software Foundation, Inc.
|
|
|
8e15ce |
*
|
|
|
8e15ce |
* GRUB is free software: you can redistribute it and/or modify
|
|
|
8e15ce |
* it under the terms of the GNU General Public License as published by
|
|
|
8e15ce |
* the Free Software Foundation, either version 3 of the License, or
|
|
|
8e15ce |
* (at your option) any later version.
|
|
|
8e15ce |
*
|
|
|
8e15ce |
* GRUB is distributed in the hope that it will be useful,
|
|
|
8e15ce |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
8e15ce |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
8e15ce |
* GNU General Public License for more details.
|
|
|
8e15ce |
*
|
|
|
8e15ce |
* You should have received a copy of the GNU General Public License
|
|
|
8e15ce |
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
8e15ce |
*/
|
|
|
8e15ce |
|
|
|
8e15ce |
#include <grub/test.h>
|
|
|
8e15ce |
#include <grub/dl.h>
|
|
|
8e15ce |
|
|
|
8e15ce |
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
8e15ce |
|
|
|
8e15ce |
static void
|
|
|
8e15ce |
strtoull_testcase (const char *input, int base, unsigned long long expected,
|
|
|
8e15ce |
int num_digits, grub_err_t error)
|
|
|
8e15ce |
{
|
|
|
8e15ce |
char *output;
|
|
|
8e15ce |
unsigned long long value;
|
|
|
8e15ce |
grub_errno = 0;
|
|
|
8e15ce |
value = grub_strtoull(input, &output, base);
|
|
|
8e15ce |
grub_test_assert (grub_errno == error,
|
|
|
8e15ce |
"unexpected error. Expected %d, got %d. Input \"%s\"",
|
|
|
8e15ce |
error, grub_errno, input);
|
|
|
8e15ce |
if (grub_errno)
|
|
|
8e15ce |
{
|
|
|
8e15ce |
grub_errno = 0;
|
|
|
8e15ce |
return;
|
|
|
8e15ce |
}
|
|
|
8e15ce |
grub_test_assert (input + num_digits == output,
|
|
|
8e15ce |
"unexpected number of digits. Expected %d, got %d, input \"%s\"",
|
|
|
8e15ce |
num_digits, (int) (output - input), input);
|
|
|
8e15ce |
grub_test_assert (value == expected,
|
|
|
8e15ce |
"unexpected return value. Expected %llu, got %llu, input \"\%s\"",
|
|
|
8e15ce |
expected, value, input);
|
|
|
8e15ce |
}
|
|
|
8e15ce |
|
|
|
8e15ce |
static void
|
|
|
8e15ce |
strtoull_test (void)
|
|
|
8e15ce |
{
|
|
|
8e15ce |
strtoull_testcase ("9", 0, 9, 1, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("0xaa", 0, 0xaa, 4, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("0xff", 0, 0xff, 4, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("0", 10, 0, 1, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("8", 8, 0, 0, GRUB_ERR_BAD_NUMBER);
|
|
|
8e15ce |
strtoull_testcase ("38", 8, 3, 1, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("7", 8, 7, 1, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("1]", 16, 1, 1, GRUB_ERR_NONE);
|
|
|
8e15ce |
strtoull_testcase ("18446744073709551616", 10, 0, 0, GRUB_ERR_OUT_OF_RANGE);
|
|
|
8e15ce |
}
|
|
|
8e15ce |
|
|
|
8e15ce |
|
|
|
8e15ce |
GRUB_FUNCTIONAL_TEST (strtoull_test, strtoull_test);
|