dcavalca / rpms / grub2

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