Merge branch 'bit-test-improvements' into 'main'

tests: Test the function forms of g_bit_*() APIs too

See merge request GNOME/glib!2381
This commit is contained in:
Sebastian Dröge 2021-12-02 10:21:59 +00:00
commit 5ab008a50c

View File

@ -310,28 +310,45 @@ test_basic_bits (void)
/* we loop like this: 0, -1, 1, -2, 2, -3, 3, ... */
for (i = 0; (glong) i < 1500; i = -(i + ((glong) i >= 0)))
{
guint naive_bit_storage_i = naive_bit_storage (i);
/* Test the g_bit_*() implementations against the compiler builtins (if
* available), and against a slow-but-correct naive implementation.
* They should all agree.
*
* The macro and function versions of the g_bit_*() functions are tested,
* hence one call with the function name in brackets (to avoid it being
* expanded as a macro). */
#if TEST_BUILTINS
g_assert_cmpint (naive_bit_storage (i), ==, builtin_bit_storage (i));
g_assert_cmpint (naive_bit_storage_i, ==, builtin_bit_storage (i));
#endif
g_assert_cmpint (naive_bit_storage (i), ==, g_bit_storage (i));
g_assert_cmpint (naive_bit_storage_i, ==, g_bit_storage (i));
g_assert_cmpint (naive_bit_storage_i, ==, (g_bit_storage) (i));
for (nth_bit = -3; nth_bit <= 2 + GLIB_SIZEOF_LONG * 8; nth_bit++)
{
#if TEST_BUILTINS
g_assert_cmpint (naive_bit_nth_lsf (i, nth_bit), ==,
builtin_bit_nth_lsf1 (i, nth_bit));
g_assert_cmpint (naive_bit_nth_lsf (i, nth_bit), ==,
builtin_bit_nth_lsf2 (i, nth_bit));
#endif
g_assert_cmpint (naive_bit_nth_lsf (i, nth_bit), ==,
g_bit_nth_lsf (i, nth_bit));
gint naive_bit_nth_lsf_i_nth_bit = naive_bit_nth_lsf (i, nth_bit);
gint naive_bit_nth_msf_i_nth_bit = naive_bit_nth_msf (i, nth_bit);
#if TEST_BUILTINS
g_assert_cmpint (naive_bit_nth_msf (i, nth_bit), ==,
g_assert_cmpint (naive_bit_nth_lsf_i_nth_bit, ==,
builtin_bit_nth_lsf1 (i, nth_bit));
g_assert_cmpint (naive_bit_nth_lsf_i_nth_bit, ==,
builtin_bit_nth_lsf2 (i, nth_bit));
#endif
g_assert_cmpint (naive_bit_nth_lsf_i_nth_bit, ==,
g_bit_nth_lsf (i, nth_bit));
g_assert_cmpint (naive_bit_nth_lsf_i_nth_bit, ==,
(g_bit_nth_lsf) (i, nth_bit));
#if TEST_BUILTINS
g_assert_cmpint (naive_bit_nth_msf_i_nth_bit, ==,
builtin_bit_nth_msf (i, nth_bit));
#endif
g_assert_cmpint (naive_bit_nth_msf (i, nth_bit), ==,
g_assert_cmpint (naive_bit_nth_msf_i_nth_bit, ==,
g_bit_nth_msf (i, nth_bit));
g_assert_cmpint (naive_bit_nth_msf_i_nth_bit, ==,
(g_bit_nth_msf) (i, nth_bit));
}
}
}