tests: replace NMTST_SWAP() by new NM_SWAP() macro

NMTST_SWAP() used memcpy() for copying the value, while NM_SWAP() uses
a temporary variable with typeof(). I think the latter is preferable.

Also, the macro is essentially doing the same thing.

(cherry picked from commit 6f9a478b7d)
This commit is contained in:
Thomas Haller 2020-03-23 08:04:33 +01:00 committed by Beniamino Galvani
parent a5c465848a
commit 743377595d
6 changed files with 10 additions and 19 deletions

View file

@ -3494,7 +3494,7 @@ test_setting_compare_addresses (void)
nm_ip_address_unref (a);
if (nmtst_get_rand_uint32 () % 2)
NMTST_SWAP (s1, s2);
NM_SWAP (s1, s2);
success = nm_setting_compare (s1, s2, NM_SETTING_COMPARE_FLAG_EXACT);
g_assert (!success);
@ -3526,7 +3526,7 @@ test_setting_compare_routes (void)
nm_ip_route_unref (r);
if (nmtst_get_rand_uint32 () % 2)
NMTST_SWAP (s1, s2);
NM_SWAP (s1, s2);
success = nm_setting_compare (s1, s2, NM_SETTING_COMPARE_FLAG_EXACT);
g_assert (!success);
@ -6820,7 +6820,7 @@ _team_config_equal_check (const char *conf1,
gboolean is_same;
if (nmtst_get_rand_bool ())
NMTST_SWAP (conf1, conf2);
NM_SWAP (conf1, conf2);
if (!nm_streq0 (conf1, conf2)) {
_team_config_equal_check (conf1, conf1, port_config, TRUE);

View file

@ -1156,15 +1156,6 @@ nmtst_uuid_generate (void)
#endif
#define NMTST_SWAP(x, y) \
G_STMT_START { \
char __nmtst_swap_temp[sizeof((x)) == sizeof((y)) ? (signed) sizeof((x)) : -1]; \
\
memcpy(__nmtst_swap_temp, &(y), sizeof (__nmtst_swap_temp)); \
memcpy(&(y), &(x), sizeof (__nmtst_swap_temp)); \
memcpy(&(x), __nmtst_swap_temp, sizeof (__nmtst_swap_temp)); \
} G_STMT_END
#define nmtst_assert_str_has_substr(str, substr) \
G_STMT_START { \
const char *__str = (str); \
@ -1959,14 +1950,14 @@ nmtst_assert_setting_is_equal (gconstpointer /* const NMSetting * */ a,
g_assert (NM_IS_SETTING (b));
if (NM_FLAGS_HAS (r, 0x4))
NMTST_SWAP (a, b);
NM_SWAP (a, b);
g_assert (nm_setting_compare ((NMSetting *) a,
(NMSetting *) b,
flags));
if (NM_FLAGS_HAS (r, 0x8))
NMTST_SWAP (a, b);
NM_SWAP (a, b);
g_assert (nm_setting_diff ((NMSetting *) a,
(NMSetting *) b,

View file

@ -296,7 +296,7 @@ _strv_cmp_fuzz_input (const char *const*in,
if (nmtst_get_rand_bool ()) {
/* randomly swap the original and the clone. That means, out_s1 is either
* the input argument (as-is) or the sementically equal clone. */
NMTST_SWAP (*out_s1, *out_s2);
NM_SWAP (*out_s1, *out_s2);
}
if (nmtst_get_rand_bool ()) {
/* randomly make s1 and s2 the same. This is for testing that

View file

@ -1238,7 +1238,7 @@ again_uid_range:
rr->uid_range.end = nmtst_rand_select (0u, uids.uid, uids.euid);
if (rr->uid_range_has) {
if (rr->uid_range.end < rr->uid_range.start)
NMTST_SWAP (rr->uid_range.start, rr->uid_range.end);
NM_SWAP (rr->uid_range.start, rr->uid_range.end);
if ( rr->uid_range.start == ((guint32) -1)
|| rr->uid_range.end == ((guint32) -1))
goto again_uid_range;
@ -1258,7 +1258,7 @@ again_uid_range:
range->start = nmtst_rand_select (1u, 0xFFFEu, ((p ) % 0xFFFEu) + 1);
range->end = nmtst_rand_select (1u, 0xFFFEu, ((p >> 16) % 0xFFFEu) + 1, range->start);
if (range->end < range->start)
NMTST_SWAP (range->start, range->end);
NM_SWAP (range->start, range->end);
}
}
}

View file

@ -1019,7 +1019,7 @@ _test_connection_sort_autoconnect_priority_one (NMConnection **list, gboolean sh
if (shuffle) {
for (i = count - 1; i > 0; i--) {
j = g_rand_int (nmtst_get_rand ()) % (i + 1);
NMTST_SWAP (connections->pdata[i], connections->pdata[j]);
NM_SWAP (connections->pdata[i], connections->pdata[j]);
}
}

View file

@ -246,7 +246,7 @@ test_nm_ip6_config_addresses_sort_check (NMIP6Config *config, NMSettingIP6Config
for (i = 0; i < addr_count; i++) {
int j = g_rand_int_range (nmtst_get_rand (), i, addr_count);
NMTST_SWAP (idx[i], idx[j]);
NM_SWAP (idx[i], idx[j]);
nm_ip6_config_add_address (copy, _nmtst_ip6_config_get_address (config, idx[i]));
}