[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: memcmp-tests module
From: |
Bruno Haible |
Subject: |
Re: memcmp-tests module |
Date: |
Tue, 20 May 2008 12:55:53 +0200 |
User-agent: |
KMail/1.5.4 |
Simon Josefsson wrote:
> The first part of this was adding a self-test for memcmp.
> I'm sure it can be improved to test more corner cases, but this is much
> better than nothing. Pushed.
It's good habit to include the tests from the autoconf macro also in the test
suite (to verify that the autoconf macro actually did its job). So I added this:
2008-05-20 Bruno Haible <address@hidden>
* tests/test-memcmp.c (main): Test also the sign of the result. Test
against two known bugs; code taken from autoconf's AC_FUNC_MEMCMP.
*** tests/test-memcmp.c.orig 2008-05-20 12:55:01.000000000 +0200
--- tests/test-memcmp.c 2008-05-20 12:53:53.000000000 +0200
***************
*** 37,52 ****
int
main (void)
{
! char foo[] = "foo";
! char foobar[] = "foobar";
! char bar[] = "bar";
!
ASSERT (memcmp (NULL, NULL, 0) == 0);
! ASSERT (memcmp (foo, foobar, 2) == 0);
! ASSERT (memcmp (foo, foobar, 3) == 0);
! ASSERT (memcmp (foo, foobar, 4) != 0);
! ASSERT (memcmp (foo, bar, 1) != 0);
! ASSERT (memcmp (foo, bar, 3) != 0);
return 0;
}
--- 37,80 ----
int
main (void)
{
! /* Test equal / not equal distinction. */
ASSERT (memcmp (NULL, NULL, 0) == 0);
! ASSERT (memcmp ("foo", "foobar", 2) == 0);
! ASSERT (memcmp ("foo", "foobar", 3) == 0);
! ASSERT (memcmp ("foo", "foobar", 4) != 0);
! ASSERT (memcmp ("foo", "bar", 1) != 0);
! ASSERT (memcmp ("foo", "bar", 3) != 0);
!
! /* Test less / equal / greater distinction. */
! ASSERT (memcmp ("foo", "moo", 4) < 0);
! ASSERT (memcmp ("moo", "foo", 4) > 0);
! ASSERT (memcmp ("oomph", "oops", 3) < 0);
! ASSERT (memcmp ("oops", "oomph", 3) > 0);
! ASSERT (memcmp ("foo", "foobar", 4) < 0);
! ASSERT (memcmp ("foobar", "foo", 4) > 0);
!
! /* Some old versions of memcmp were not 8-bit clean. */
! ASSERT (memcmp ("\100", "\201", 1) < 0);
! ASSERT (memcmp ("\201", "\100", 1) > 0);
! ASSERT (memcmp ("\200", "\201", 1) < 0);
! ASSERT (memcmp ("\201", "\200", 1) > 0);
!
! /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
! or more and with at least one buffer not starting on a 4-byte boundary.
! William Lewis provided this test program. */
! {
! char foo[21];
! char bar[21];
! int i;
! for (i = 0; i < 4; i++)
! {
! char *a = foo + i;
! char *b = bar + i;
! strcpy (a, "--------01111111");
! strcpy (b, "--------10000000");
! ASSERT (memcmp (a, b, 16) < 0);
! }
! }
return 0;
}
Re: rpl_memcmp on mingw with g++?, Bruno Haible, 2008/05/20