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