Ejemplo n.º 1
0
/* Functional test main method.  */
static void
example_test (void)
{
    /* Check if 1st argument is true and report with default error message.  */
    grub_test_assert (1 == 1);

    /* Check if 1st argument is true and report with custom error message.  */
    grub_test_assert (2 == 2, "2 equal 2 expected");
    grub_test_assert (2 != 3, "2 matches %d", 3);
}
Ejemplo n.º 2
0
static void
test32s (grub_int32_t a, grub_int32_t b)
{
  grub_test_assert ((a < b) == is_less32s(a, b), "comparison result mismatch: %lld, %lld",
		    (long long) a, (long long) b);
  grub_test_assert ((a > b) == is_less32s(b, a), "comparison result mismatch: %lld, %lld",
		    (long long) a, (long long) b);
  grub_test_assert ((b < a) == is_less32s(b, a), "comparison result mismatch: %lld, %lld",
		    (long long) a, (long long) b);
  grub_test_assert ((b > a) == is_less32s(a, b), "comparison result mismatch: %lld, %lld",
		    (long long) a, (long long) b);
  grub_test_assert (!(is_less32s(a, b) && is_less32s(b, a)), "comparison inconsistent: %lld, %lld",
		    (long long) a, (long long) b);
}
Ejemplo n.º 3
0
static void
printf_test (void)
{
  char real[512];
  char expected[512];
  grub_snprintf (real, sizeof (real), "%d %d %d", 1, 2, 3);
  snprintf (expected, sizeof (expected), "%d %d %d", 1, 2, 3);
  grub_test_assert (strcmp (real, expected) == 0);
  grub_snprintf (real, sizeof (real), "%3$d %2$d %1$d", 1, 2, 3);
  snprintf (expected, sizeof (expected), "%3$d %2$d %1$d", 1, 2, 3);
  grub_test_assert (strcmp (real, expected) == 0);
  grub_snprintf (real, sizeof (real), "%d %lld %d", 1, 2LL, 3);
  snprintf (expected, sizeof (expected), "%d %lld %d", 1, 2LL, 3);
  grub_test_assert (strcmp (real, expected) == 0);
  grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3);
  snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3);
  grub_test_assert (strcmp (real, expected) == 0);
}
Ejemplo n.º 4
0
static void
test64 (grub_uint64_t a)
{
  grub_uint64_t b, c;
  grub_uint8_t *ap, *bp;
  int i;
  b = grub_swap_bytes64 (a);
  c = grub_swap_bytes64 (b);
  grub_test_assert (a == c, "bswap not idempotent: 0x%llx, 0x%llx, 0x%llx",
		    (long long) a, (long long) b, (long long) c);
  ap = (grub_uint8_t *) &a;
  bp = (grub_uint8_t *) &b;
  for (i = 0; i < 4; i++)
    {
      grub_test_assert (ap[i] == bp[7 - i],
			"bswap bytes wrong: 0x%llx, 0x%llx",
			(long long) a, (long long) b);
    }
}
Ejemplo n.º 5
0
static void
printf_test (void)
{
  char real[512];
  char expected[512];
  char *null = NULL;

  grub_snprintf (real, sizeof (real), "%s", null);
  snprintf (expected, sizeof (expected), "%s", null);
  grub_test_assert (strcmp (real, expected) == 0, MSG);

  grub_snprintf (real, sizeof (real), "%10s", null);
  snprintf (expected, sizeof (expected), "%10s", null);
  grub_test_assert (strcmp (real, expected) == 0, MSG);

  grub_snprintf (real, sizeof (real), "%-10s", null);
  snprintf (expected, sizeof (expected), "%-10s", null);
  grub_test_assert (strcmp (real, expected) == 0, MSG);

  grub_snprintf (real, sizeof (real), "%d%%", 10);
  snprintf (expected, sizeof (expected), "%d%%", 10);
  grub_test_assert (strcmp (real, expected) == 0, MSG);

  grub_snprintf (real, sizeof (real), "%d %%", 10);
  snprintf (expected, sizeof (expected), "%d %%", 10);
  grub_test_assert (strcmp (real, expected) == 0, MSG);

  grub_snprintf (real, sizeof (real), "%%");
  snprintf (expected, sizeof (expected), "%%");
  grub_test_assert (strcmp (real, expected) == 0, MSG);

  grub_snprintf (real, sizeof (real), "%d %d %d", 1, 2, 3);
  snprintf (expected, sizeof (expected), "%d %d %d", 1, 2, 3);
  grub_test_assert (strcmp (real, expected) == 0, MSG);
  grub_snprintf (real, sizeof (real), "%3$d %2$d %1$d", 1, 2, 3);
  snprintf (expected, sizeof (expected), "%3$d %2$d %1$d", 1, 2, 3);
  grub_test_assert (strcmp (real, expected) == 0, MSG);
  grub_snprintf (real, sizeof (real), "%d %lld %d", 1, 2LL, 3);
  snprintf (expected, sizeof (expected), "%d %lld %d", 1, 2LL, 3);
  grub_test_assert (strcmp (real, expected) == 0, MSG);
  grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3);
  snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3);
  grub_test_assert (strcmp (real, expected) == 0, MSG);
  grub_snprintf (real, sizeof (real), "%%0%dd ", 1);
  snprintf (expected, sizeof (expected), "%%0%dd ", 1);
  grub_test_assert (strcmp (real, expected) == 0, MSG);
}