1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-04-28 06:33:36 +00:00

tests: Use memeq, part 3.

* tests/**/*.[hc]: Use memeq instead of memcmp.
* modules/*-tests (Dependencies): Add memeq.
This commit is contained in:
Bruno Haible
2026-03-01 12:37:49 +01:00
parent 0e0dc90965
commit 6003a49f09
36 changed files with 61 additions and 57 deletions

View File

@@ -1,5 +1,9 @@
2026-03-01 Bruno Haible <bruno@clisp.org>
tests: Use memeq, part 3.
* tests/**/*.[hc]: Use memeq instead of memcmp.
* modules/*-tests (Dependencies): Add memeq.
tests: Use memeq, part 2.
Done through
sed -e 's/memcmp \([(][^()]*[)]\) != 0/!memeq \1/g' \

View File

@@ -2,6 +2,7 @@ Files:
tests/test-arcfour.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-arctwo.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-des.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-gc-arcfour.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-gc-arctwo.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-gc-des.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-md2-buffer.c
Depends-on:
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-md4-buffer.c
Depends-on:
memeq
configure.ac:

View File

@@ -8,6 +8,7 @@ Depends-on:
c99
getrusage
gettimeofday
memeq
configure.ac:

View File

@@ -8,6 +8,7 @@ Depends-on:
c99
getrusage
gettimeofday
memeq
configure.ac:

View File

@@ -10,6 +10,7 @@ Depends-on:
c99
getrusage
gettimeofday
memeq
configure.ac:

View File

@@ -10,6 +10,7 @@ Depends-on:
c99
getrusage
gettimeofday
memeq
configure.ac:

View File

@@ -2,6 +2,7 @@ Files:
tests/test-sm3-buffer.c
Depends-on:
memeq
configure.ac:

View File

@@ -3,6 +3,7 @@ tests/test-pthread-thread.c
tests/macros.h
Depends-on:
memeq
configure.ac:

View File

@@ -5,6 +5,7 @@ tests/test-thrd_exit.c
tests/macros.h
Depends-on:
memeq
configure.ac:

View File

@@ -4,6 +4,7 @@ tests/test-thread_create.c
tests/macros.h
Depends-on:
memeq
configure.ac:

View File

@@ -35,7 +35,7 @@ main (int argc, char *argv[])
arcfour_setkey (&ctx, key_1, sizeof (key_1));
arcfour_stream (&ctx, plaintext_1, scratch, sizeof (plaintext_1));
if (memcmp (scratch, ciphertext_1, sizeof (ciphertext_1)))
if (!memeq (scratch, ciphertext_1, sizeof (ciphertext_1)))
{
printf ("expected:\n");
for (size_t i = 0; i < 5; i++)
@@ -51,7 +51,7 @@ main (int argc, char *argv[])
arcfour_setkey (&ctx, key_1, sizeof (key_1));
arcfour_stream (&ctx, scratch, scratch, sizeof (plaintext_1));
if (memcmp (scratch, plaintext_1, sizeof (plaintext_1)))
if (!memeq (scratch, plaintext_1, sizeof (plaintext_1)))
{
printf ("expected:\n");
for (size_t i = 0; i < 5; i++)

View File

@@ -77,42 +77,42 @@ main (int argc, char *argv[])
arctwo_setkey_ekb (&ctx, sizeof (key_1), key_1, 0);
arctwo_encrypt (&ctx, plaintext_1, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, ciphertext_1, sizeof (ciphertext_1)))
if (!memeq (scratch, ciphertext_1, sizeof (ciphertext_1)))
return 1;
arctwo_setkey_ekb (&ctx, sizeof (key_1), key_1, 0);
arctwo_decrypt (&ctx, scratch, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, plaintext_1, sizeof (plaintext_1)))
if (!memeq (scratch, plaintext_1, sizeof (plaintext_1)))
return 1;
/* Second test. */
arctwo_setkey_ekb (&ctx, sizeof (key_2), key_2, 0);
arctwo_encrypt (&ctx, plaintext_2, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, ciphertext_2, sizeof (ciphertext_2)))
if (!memeq (scratch, ciphertext_2, sizeof (ciphertext_2)))
return 1;
arctwo_setkey_ekb (&ctx, sizeof (key_2), key_2, 0);
arctwo_decrypt (&ctx, scratch, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, plaintext_2, sizeof (plaintext_2)))
if (!memeq (scratch, plaintext_2, sizeof (plaintext_2)))
return 1;
/* Third test. */
arctwo_setkey_ekb (&ctx, sizeof (key_3), key_3, 0);
arctwo_encrypt (&ctx, plaintext_3, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, ciphertext_3, sizeof (ciphertext_3)))
if (!memeq (scratch, ciphertext_3, sizeof (ciphertext_3)))
return 1;
arctwo_setkey_ekb (&ctx, sizeof (key_3), key_3, 0);
arctwo_decrypt (&ctx, scratch, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, plaintext_3, sizeof (plaintext_3)))
if (!memeq (scratch, plaintext_3, sizeof (plaintext_3)))
return 1;
/* Fourth test. */
arctwo_setkey_ekb (&ctx, sizeof (key_4), key_4, 63);
arctwo_encrypt (&ctx, plaintext_4, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, ciphertext_4, sizeof (ciphertext_4)))
if (!memeq (scratch, ciphertext_4, sizeof (ciphertext_4)))
{
printf ("expected:\n");
for (size_t i = 0; i < sizeof (ciphertext_4); i++)
@@ -126,14 +126,14 @@ main (int argc, char *argv[])
arctwo_setkey_ekb (&ctx, sizeof (key_4), key_4, 63);
arctwo_decrypt (&ctx, scratch, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, plaintext_4, sizeof (plaintext_4)))
if (!memeq (scratch, plaintext_4, sizeof (plaintext_4)))
return 1;
/* Fifth test. */
arctwo_setkey_ekb (&ctx, sizeof (key_5), key_5, 64);
arctwo_encrypt (&ctx, plaintext_5, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, ciphertext_5, sizeof (ciphertext_5)))
if (!memeq (scratch, ciphertext_5, sizeof (ciphertext_5)))
{
printf ("expected:\n");
for (size_t i = 0; i < sizeof (ciphertext_5); i++)
@@ -147,14 +147,14 @@ main (int argc, char *argv[])
arctwo_setkey_ekb (&ctx, sizeof (key_5), key_5, 64);
arctwo_decrypt (&ctx, scratch, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, plaintext_5, sizeof (plaintext_5)))
if (!memeq (scratch, plaintext_5, sizeof (plaintext_5)))
return 1;
/* Sixth test. */
arctwo_setkey_ekb (&ctx, 8, key_6, 64);
arctwo_encrypt (&ctx, plaintext_6, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, ciphertext_6, sizeof (ciphertext_6)))
if (!memeq (scratch, ciphertext_6, sizeof (ciphertext_6)))
{
printf ("expected:\n");
for (size_t i = 0; i < sizeof (ciphertext_6); i++)
@@ -168,7 +168,7 @@ main (int argc, char *argv[])
arctwo_setkey_ekb (&ctx, sizeof (key_6), key_6, 64);
arctwo_decrypt (&ctx, scratch, scratch, ARCTWO_BLOCK_SIZE);
if (memcmp (scratch, plaintext_6, sizeof (plaintext_6)))
if (!memeq (scratch, plaintext_6, sizeof (plaintext_6)))
return 1;
return 0;

View File

@@ -47,7 +47,7 @@ main (int argc, char *argv[])
memcpy (key, temp3, 8);
memcpy (input, temp1, 8);
}
if (memcmp (temp3, result, 8))
if (!memeq (temp3, result, 8))
return 1;
}
@@ -71,7 +71,7 @@ main (int argc, char *argv[])
gl_3des_set3keys (&des3, key1, input, key2);
gl_3des_ecb_encrypt (&des3, input, input);
}
if (memcmp (input, result, 8))
if (!memeq (input, result, 8))
return 1;
}
@@ -197,13 +197,13 @@ main (int argc, char *argv[])
testdata[i].key + 8, testdata[i].key + 16);
gl_3des_ecb_encrypt (&des3, testdata[i].plain, result);
if (memcmp (testdata[i].cipher, result, 8))
if (!memeq (testdata[i].cipher, result, 8))
{
return 1;
}
gl_3des_ecb_decrypt (&des3, testdata[i].cipher, result);
if (memcmp (testdata[i].plain, result, 8))
if (!memeq (testdata[i].plain, result, 8))
{
return 1;
}

View File

@@ -54,7 +54,7 @@ main (int argc, char *argv[])
if (rc != GC_OK)
return 1;
if (memcmp (scratch, ciphertext_1, sizeof (ciphertext_1)))
if (!memeq (scratch, ciphertext_1, sizeof (ciphertext_1)))
{
printf ("expected:\n");
for (size_t i = 0; i < 5; i++)
@@ -76,7 +76,7 @@ main (int argc, char *argv[])
if (rc != GC_OK)
return 1;
if (memcmp (scratch, plaintext_1, sizeof (plaintext_1)))
if (!memeq (scratch, plaintext_1, sizeof (plaintext_1)))
{
printf ("expected:\n");
for (size_t i = 0; i < 5; i++)

View File

@@ -56,7 +56,7 @@ main (int argc, char *argv[])
if (rc != GC_OK)
return 1;
if (memcmp (scratch, ciphertext, sizeof (ciphertext)))
if (!memeq (scratch, ciphertext, sizeof (ciphertext)))
{
printf ("expected:\n");
for (size_t i = 0; i < 5; i++)
@@ -78,7 +78,7 @@ main (int argc, char *argv[])
if (rc != GC_OK)
return 1;
if (memcmp (scratch, plaintext, sizeof (plaintext)))
if (!memeq (scratch, plaintext, sizeof (plaintext)))
{
printf ("expected:\n");
for (size_t i = 0; i < 5; i++)

View File

@@ -80,7 +80,7 @@ main (int argc, char *argv[])
ctx_array[i] = ctx;
}
if (memcmp (temp3, result, 8))
if (!memeq (temp3, result, 8))
return 1;
for (int i = 0; i < 64; ++i)

View File

@@ -34,8 +34,7 @@ main (int argc, char *argv[])
"\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b";
char buf[MD2_DIGEST_SIZE];
if (memcmp (md2_buffer (in1, strlen (in1), buf), out1, MD2_DIGEST_SIZE) !=
0)
if (!memeq (md2_buffer (in1, strlen (in1), buf), out1, MD2_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < MD2_DIGEST_SIZE; i++)
@@ -47,8 +46,7 @@ main (int argc, char *argv[])
return 1;
}
if (memcmp (md2_buffer (in2, strlen (in2), buf), out2, MD2_DIGEST_SIZE) !=
0)
if (!memeq (md2_buffer (in2, strlen (in2), buf), out2, MD2_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < MD2_DIGEST_SIZE; i++)

View File

@@ -35,8 +35,7 @@ main (int argc, char *argv[])
"\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d\xa9";
char buf[MD4_DIGEST_SIZE];
if (memcmp (md4_buffer (in1, strlen (in1), buf), out1, MD4_DIGEST_SIZE) !=
0)
if (!memeq (md4_buffer (in1, strlen (in1), buf), out1, MD4_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < MD4_DIGEST_SIZE; i++)
@@ -48,8 +47,7 @@ main (int argc, char *argv[])
return 1;
}
if (memcmp (md4_buffer (in2, strlen (in2), buf), out2, MD4_DIGEST_SIZE) !=
0)
if (!memeq (md4_buffer (in2, strlen (in2), buf), out2, MD4_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < MD4_DIGEST_SIZE; i++)

View File

@@ -37,7 +37,7 @@ main (void)
"\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0";
char buf[MD5_DIGEST_SIZE];
if (memcmp (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE) != 0)
if (!memeq (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < MD5_DIGEST_SIZE; i++)
@@ -49,7 +49,7 @@ main (void)
return 1;
}
if (memcmp (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE) != 0)
if (!memeq (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < MD5_DIGEST_SIZE; i++)

View File

@@ -51,9 +51,8 @@ main ()
/* Check that pthread_self () has the same value before than after the
first call to pthread_create (). */
main_thread_after = pthread_self ();
ASSERT (memcmp (&main_thread_before, &main_thread_after,
sizeof (pthread_t))
== 0);
ASSERT (memeq (&main_thread_before, &main_thread_after,
sizeof (pthread_t)));
ASSERT (pthread_join (worker_thread, &ret) == 0);

View File

@@ -30,8 +30,7 @@ main (void)
"\x32\x2e\x93\xa0\x15\xbc\xf8\x68\xe3\x24\xd5\x6a";
char buf[SHA1_DIGEST_SIZE];
if (memcmp (sha1_buffer (in1, strlen (in1), buf),
out1, SHA1_DIGEST_SIZE) != 0)
if (!memeq (sha1_buffer (in1, strlen (in1), buf), out1, SHA1_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < SHA1_DIGEST_SIZE; i++)

View File

@@ -33,8 +33,7 @@ main (void)
"\x5b\xdf\x7e\x27\xa1\xb7\x00\xf4\x62\x89\x41\x84";
char buf[SHA224_DIGEST_SIZE];
if (memcmp (sha224_buffer (in1, strlen (in1), buf),
out1, SHA224_DIGEST_SIZE) != 0)
if (!memeq (sha224_buffer (in1, strlen (in1), buf), out1, SHA224_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < SHA224_DIGEST_SIZE; i++)

View File

@@ -33,8 +33,7 @@ main (void)
"\x89\xaf\xfa\x91\x9c\x8a\x85\xb7\x19\x8d\x8b\x15\xaf\xa3\x4b\x2c";
char buf[SHA256_DIGEST_SIZE];
if (memcmp (sha256_buffer (in1, strlen (in1), buf),
out1, SHA256_DIGEST_SIZE) != 0)
if (!memeq (sha256_buffer (in1, strlen (in1), buf), out1, SHA256_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < SHA256_DIGEST_SIZE; i++)

View File

@@ -34,8 +34,7 @@ main (void)
"\x74\x8d\x80\x99\xfb\x05\xb5\x22\xa3\x8f\x29\x1c\xea\xdd\x7a\x82";
char buf[SHA384_DIGEST_SIZE];
if (memcmp (sha384_buffer (in1, strlen (in1), buf),
out1, SHA384_DIGEST_SIZE) != 0)
if (!memeq (sha384_buffer (in1, strlen (in1), buf), out1, SHA384_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < SHA384_DIGEST_SIZE; i++)

View File

@@ -35,8 +35,7 @@ main (void)
"\xac\x8a\xf9\x83\x9c\x35\x92\x94\x2d\xb7\xb4\xb4\x08\x2e\x7f\xe2";
char buf[SHA512_DIGEST_SIZE];
if (memcmp (sha512_buffer (in1, strlen (in1), buf),
out1, SHA512_DIGEST_SIZE) != 0)
if (!memeq (sha512_buffer (in1, strlen (in1), buf), out1, SHA512_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < SHA512_DIGEST_SIZE; i++)

View File

@@ -27,8 +27,7 @@ test (const char *in, const char *out)
{
char buf[SM3_DIGEST_SIZE];
if (memcmp (sm3_buffer (in, strlen (in), buf),
out, SM3_DIGEST_SIZE) != 0)
if (!memeq (sm3_buffer (in, strlen (in), buf), out, SM3_DIGEST_SIZE))
{
printf ("expected:\n");
for (size_t i = 0; i < SM3_DIGEST_SIZE; i++)

View File

@@ -51,9 +51,7 @@ main ()
/* Check that thrd_current () has the same value before than after the
first call to thrd_create (). */
main_thread_after = thrd_current ();
ASSERT (memcmp (&main_thread_before, &main_thread_after,
sizeof (thrd_t))
== 0);
ASSERT (memeq (&main_thread_before, &main_thread_after, sizeof (thrd_t)));
ASSERT (thrd_join (worker_thread, &ret) == thrd_success);

View File

@@ -55,9 +55,7 @@ main ()
/* Check that thrd_current () has the same value before than after the
first call to thrd_create (). */
main_thread_after = thrd_current ();
ASSERT (memcmp (&main_thread_before, &main_thread_after,
sizeof (thrd_t))
== 0);
ASSERT (memeq (&main_thread_before, &main_thread_after, sizeof (thrd_t)));
ASSERT (thrd_join (worker_thread, &ret) == thrd_success);

View File

@@ -51,9 +51,8 @@ main ()
/* Check that gl_thread_self () has the same value before than after the
first call to gl_thread_create (). */
main_thread_after = gl_thread_self ();
ASSERT (memcmp (&main_thread_before, &main_thread_after,
sizeof (gl_thread_t))
== 0);
ASSERT (memeq (&main_thread_before, &main_thread_after,
sizeof (gl_thread_t)));
gl_thread_join (worker_thread, &ret);