mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 06:30:33 +01:00
platform: use g_assert_cmpint() and g_assert_cmpstr() in tests
"g_assert_cmpint (x, ==, y)" is nicer than "g_assert (x == y)", because if it fails, it shows you the values of x and y in the assert message. Likewise g_assert_cmpstr(). The "ifindex > 0" checks still just use g_assert(), since we don't need to distinguish specific negative values there.
This commit is contained in:
parent
4d32618264
commit
bb9b276278
3 changed files with 17 additions and 17 deletions
|
|
@ -75,7 +75,7 @@ test_ip4_address (void)
|
|||
addrs[0].ifindex = ifindex;
|
||||
addrs[0].address = addr;
|
||||
addrs[0].plen = IP4_PLEN;
|
||||
g_assert (addresses->len == 1);
|
||||
g_assert_cmpint (addresses->len, ==, 1);
|
||||
g_assert (!memcmp (addresses->data, addrs, sizeof (addrs)));
|
||||
g_array_unref (addresses);
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ test_ip6_address (void)
|
|||
addrs[0].ifindex = ifindex;
|
||||
addrs[0].address = addr;
|
||||
addrs[0].plen = IP6_PLEN;
|
||||
g_assert (addresses->len == 1);
|
||||
g_assert_cmpint (addresses->len, ==, 1);
|
||||
g_assert (!memcmp (addresses->data, addrs, sizeof (addrs)));
|
||||
g_array_unref (addresses);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,9 +91,9 @@ static void
|
|||
test_loopback (void)
|
||||
{
|
||||
g_assert (nm_platform_link_exists (LO_NAME));
|
||||
g_assert (nm_platform_link_get_type (LO_INDEX) == NM_LINK_TYPE_LOOPBACK);
|
||||
g_assert (nm_platform_link_get_ifindex (LO_NAME) == LO_INDEX);
|
||||
g_assert (!g_strcmp0 (nm_platform_link_get_name (LO_INDEX), LO_NAME));
|
||||
g_assert_cmpint (nm_platform_link_get_type (LO_INDEX), ==, NM_LINK_TYPE_LOOPBACK);
|
||||
g_assert_cmpint (nm_platform_link_get_ifindex (LO_NAME), ==, LO_INDEX);
|
||||
g_assert_cmpstr (nm_platform_link_get_name (LO_INDEX), ==, LO_NAME);
|
||||
|
||||
g_assert (nm_platform_link_supports_carrier_detect (LO_INDEX));
|
||||
g_assert (!nm_platform_link_supports_vlans (LO_INDEX));
|
||||
|
|
@ -150,7 +150,7 @@ test_slave (int master, int type, SignalData *link_added, SignalData *master_cha
|
|||
/* Enslave */
|
||||
link_changed->ifindex = ifindex;
|
||||
g_assert (nm_platform_link_enslave (master, ifindex)); no_error ();
|
||||
g_assert (nm_platform_link_get_master (ifindex) == master); no_error ();
|
||||
g_assert_cmpint (nm_platform_link_get_master (ifindex), ==, master); no_error ();
|
||||
accept_signal (link_changed);
|
||||
accept_signal (master_changed);
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ test_slave (int master, int type, SignalData *link_added, SignalData *master_cha
|
|||
no_error ();
|
||||
value = nm_platform_slave_get_option (ifindex, "priority");
|
||||
no_error ();
|
||||
g_assert (!g_strcmp0 (value, "789"));
|
||||
g_assert_cmpstr (value, ==, "789");
|
||||
g_free (value);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -208,7 +208,7 @@ test_slave (int master, int type, SignalData *link_added, SignalData *master_cha
|
|||
|
||||
/* Release */
|
||||
g_assert (nm_platform_link_release (master, ifindex));
|
||||
g_assert (nm_platform_link_get_master (ifindex) == 0); no_error ();
|
||||
g_assert_cmpint (nm_platform_link_get_master (ifindex), ==, 0); no_error ();
|
||||
accept_signal (link_changed);
|
||||
accept_signal (master_changed);
|
||||
|
||||
|
|
@ -240,7 +240,7 @@ test_virtual (NMLinkType link_type)
|
|||
g_assert (nm_platform_link_exists (DEVICE_NAME));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
g_assert (ifindex >= 0);
|
||||
g_assert (nm_platform_link_get_type (ifindex) == link_type);
|
||||
g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, link_type);
|
||||
accept_signal (link_added);
|
||||
|
||||
/* Add again */
|
||||
|
|
@ -263,7 +263,7 @@ test_virtual (NMLinkType link_type)
|
|||
no_error ();
|
||||
value = nm_platform_master_get_option (ifindex, "forward_delay");
|
||||
no_error ();
|
||||
g_assert (!g_strcmp0 (value, "789"));
|
||||
g_assert_cmpstr (value, ==, "789");
|
||||
g_free (value);
|
||||
break;
|
||||
case NM_LINK_TYPE_BOND:
|
||||
|
|
@ -296,7 +296,7 @@ test_virtual (NMLinkType link_type)
|
|||
g_assert (nm_platform_link_delete_by_name (DEVICE_NAME));
|
||||
no_error ();
|
||||
g_assert (!nm_platform_link_exists (DEVICE_NAME)); no_error ();
|
||||
g_assert (nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_NONE);
|
||||
g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, NM_LINK_TYPE_NONE);
|
||||
error (NM_PLATFORM_ERROR_NOT_FOUND);
|
||||
accept_signal (link_removed);
|
||||
|
||||
|
|
@ -353,8 +353,8 @@ test_internal (void)
|
|||
/* Check device index, name and type */
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
g_assert (ifindex > 0);
|
||||
g_assert (!g_strcmp0 (nm_platform_link_get_name (ifindex), DEVICE_NAME));
|
||||
g_assert (nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_DUMMY);
|
||||
g_assert_cmpstr (nm_platform_link_get_name (ifindex), ==, DEVICE_NAME);
|
||||
g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, NM_LINK_TYPE_DUMMY);
|
||||
|
||||
/* Up/connected */
|
||||
g_assert (!nm_platform_link_is_up (ifindex)); no_error ();
|
||||
|
|
@ -422,8 +422,8 @@ test_external (void)
|
|||
g_assert (nm_platform_link_exists (DEVICE_NAME));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
g_assert (ifindex > 0);
|
||||
g_assert (!g_strcmp0 (nm_platform_link_get_name (ifindex), DEVICE_NAME));
|
||||
g_assert (nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_DUMMY);
|
||||
g_assert_cmpstr (nm_platform_link_get_name (ifindex), ==, DEVICE_NAME);
|
||||
g_assert_cmpint (nm_platform_link_get_type (ifindex), ==, NM_LINK_TYPE_DUMMY);
|
||||
|
||||
/* Up/connected/arp */
|
||||
g_assert (!nm_platform_link_is_up (ifindex));
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ test_ip4_route ()
|
|||
rts[1].ifindex = ifindex;
|
||||
rts[1].gateway = gateway;
|
||||
rts[1].metric = metric;
|
||||
g_assert (routes->len == 2);
|
||||
g_assert_cmpint (routes->len, ==, 2);
|
||||
g_assert (!memcmp (routes->data, rts, sizeof (rts)));
|
||||
g_array_unref (routes);
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ test_ip6_route ()
|
|||
rts[1].ifindex = ifindex;
|
||||
rts[1].gateway = gateway;
|
||||
rts[1].metric = metric;
|
||||
g_assert (routes->len == 2);
|
||||
g_assert_cmpint (routes->len, ==, 2);
|
||||
g_assert (!memcmp (routes->data, rts, sizeof (rts)));
|
||||
g_array_unref (routes);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue