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