libnm/tests: rename test functions to follow common pattern

Like the test utility functions in nm-test-utils.h and
platform's common.h, rename the helper functions to have
a nmtst(c) prefix.
This commit is contained in:
Thomas Haller 2015-12-21 10:22:33 +01:00
parent fa3093e167
commit bc06dd9332
7 changed files with 97 additions and 117 deletions

View file

@ -15,12 +15,10 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2014 Red Hat, Inc.
* Copyright 2014 - 2015 Red Hat, Inc.
*/
#include <NetworkManager.h>
#include "nm-default.h"
#include "NetworkManager.h"
#include "nm-test-utils.h"
@ -29,23 +27,23 @@ typedef struct {
GDBusProxy *proxy;
GPid pid;
int keepalive_fd;
} NMTestServiceInfo;
} NMTstcServiceInfo;
NMTestServiceInfo *nm_test_service_init (void);
void nm_test_service_cleanup (NMTestServiceInfo *info);
NMTstcServiceInfo *nmtstc_service_init (void);
void nmtstc_service_cleanup (NMTstcServiceInfo *info);
#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB)
NMDevice *nm_test_service_add_device (NMTestServiceInfo *info,
NMClient *client,
const char *method,
const char *ifname);
NMDevice *nmtstc_service_add_device (NMTstcServiceInfo *info,
NMClient *client,
const char *method,
const char *ifname);
NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo,
NMClient *client,
const char *ifname,
const char *hwaddr,
const char **subchannels);
NMDevice * nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo,
NMClient *client,
const char *ifname,
const char *hwaddr,
const char **subchannels);
#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */

View file

@ -53,10 +53,10 @@ name_exists (GDBusConnection *c, const char *name)
return exists;
}
NMTestServiceInfo *
nm_test_service_init (void)
NMTstcServiceInfo *
nmtstc_service_init (void)
{
NMTestServiceInfo *info;
NMTstcServiceInfo *info;
const char *args[2] = { TEST_NM_SERVICE, NULL };
GError *error = NULL;
int i;
@ -98,7 +98,7 @@ nm_test_service_init (void)
}
void
nm_test_service_cleanup (NMTestServiceInfo *info)
nmtstc_service_cleanup (NMTstcServiceInfo *info)
{
int i;
@ -175,16 +175,16 @@ static GVariant *
call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error)
{
return g_dbus_proxy_call_sync (proxy,
method,
g_variant_new ("(s)", ifname),
G_DBUS_CALL_FLAGS_NO_AUTO_START,
3000,
NULL,
error);
method,
g_variant_new ("(s)", ifname),
G_DBUS_CALL_FLAGS_NO_AUTO_START,
3000,
NULL,
error);
}
static NMDevice *
add_device_common (NMTestServiceInfo *sinfo, NMClient *client,
add_device_common (NMTstcServiceInfo *sinfo, NMClient *client,
const char *method, const char *ifname,
const char *hwaddr, const char **subchannels)
{
@ -221,16 +221,16 @@ add_device_common (NMTestServiceInfo *sinfo, NMClient *client,
}
NMDevice *
nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client,
const char *method, const char *ifname)
nmtstc_service_add_device (NMTstcServiceInfo *sinfo, NMClient *client,
const char *method, const char *ifname)
{
return add_device_common (sinfo, client, method, ifname, NULL, NULL);
}
NMDevice *
nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client,
const char *ifname, const char *hwaddr,
const char **subchannels)
nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, NMClient *client,
const char *ifname, const char *hwaddr,
const char **subchannels)
{
return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels);
}

View file

@ -27,19 +27,16 @@
#include <sys/types.h>
#include <signal.h>
#include <NetworkManager.h>
#include "nm-default.h"
#include "nm-client.h"
#include "nm-device-wifi.h"
#include "nm-device-ethernet.h"
#include "nm-device-wimax.h"
#include "nm-test-utils.h"
#include "nm-test-libnm-utils.h"
static GMainLoop *loop = NULL;
static NMTestServiceInfo *sinfo;
static NMTstcServiceInfo *sinfo;
/*******************************************************************/
@ -184,7 +181,7 @@ test_device_added (void)
NMDevice *device;
DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 };
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = test_client_new ();
devices = nm_client_get_devices (client);
@ -224,7 +221,7 @@ test_device_added (void)
g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -341,7 +338,7 @@ test_wifi_ap_added_removed (void)
GError *error = NULL;
char *expected_path = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = test_client_new ();
/*************************************/
@ -447,7 +444,7 @@ test_wifi_ap_added_removed (void)
g_free (expected_path);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -564,7 +561,7 @@ test_wimax_nsp_added_removed (void)
GError *error = NULL;
char *expected_path = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = test_client_new ();
/*************************************/
@ -670,7 +667,7 @@ test_wimax_nsp_added_removed (void)
g_free (expected_path);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -749,7 +746,7 @@ test_devices_array (void)
GError *error = NULL;
GVariant *ret;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = test_client_new ();
/*************************************/
@ -833,7 +830,7 @@ test_devices_array (void)
g_free (paths[2]);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
static void
@ -871,7 +868,7 @@ test_client_manager_running (void)
g_clear_error (&error);
/* Now start the test service. */
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client2 = test_client_new ();
/* client2 should know that NM is running, but the previously-created
@ -889,7 +886,7 @@ test_client_manager_running (void)
g_source_remove (quit_id);
/* And kill it */
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
g_assert (nm_client_get_manager_running (client1));

View file

@ -27,19 +27,18 @@
#include <sys/types.h>
#include <signal.h>
#include <NetworkManager.h>
#include "NetworkManager.h"
#include <nm-setting-connection.h>
#include <nm-setting-wired.h>
#include <nm-utils.h>
#include "nm-setting-connection.h"
#include "nm-setting-wired.h"
#include "nm-utils.h"
#include "nm-default.h"
#include "nm-remote-settings.h"
#include "nm-test-libnm-utils.h"
#include "nm-test-utils.h"
static NMTestServiceInfo *sinfo;
static NMTstcServiceInfo *sinfo;
static NMRemoteSettings *settings = NULL;
DBusGConnection *bus = NULL;
NMRemoteConnection *remote = NULL;
@ -377,7 +376,7 @@ test_service_running (void)
g_assert (running == TRUE);
/* Now kill the test service. */
nm_test_service_cleanup (sinfo);
nmtstc_service_cleanup (sinfo);
settings2 = nm_remote_settings_new (bus);
@ -406,7 +405,7 @@ test_service_running (void)
g_assert (running == FALSE);
/* Now restart it */
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
quit_id = g_timeout_add_seconds (5, loop_quit, loop);
g_main_loop_run (loop);
@ -436,7 +435,7 @@ main (int argc, char **argv)
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
g_assert_no_error (error);
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
settings = nm_remote_settings_new (bus);
g_assert (settings != NULL);
@ -452,7 +451,7 @@ main (int argc, char **argv)
ret = g_test_run ();
nm_test_service_cleanup (sinfo);
nmtstc_service_cleanup (sinfo);
g_object_unref (settings);
dbus_g_connection_unref (bus);

View file

@ -24,15 +24,10 @@
#include <sys/types.h>
#include <signal.h>
#include <NetworkManager.h>
#include "nm-default.h"
#include "nm-test-libnm-utils.h"
#include "nm-test-utils.h"
static GMainLoop *loop = NULL;
static NMTestServiceInfo *sinfo;
static NMTstcServiceInfo *sinfo;
/*******************************************************************/
@ -74,7 +69,7 @@ test_device_added (void)
gboolean notified = FALSE;
GError *error = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
@ -87,7 +82,7 @@ test_device_added (void)
&notified);
/* Tell the test service to add a new device */
nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
/* coverity[loop_condition] */
while (!notified)
@ -108,7 +103,7 @@ test_device_added (void)
g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -166,7 +161,7 @@ test_device_added_signal_after_init (void)
guint result = 0;
GError *error = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
@ -184,7 +179,7 @@ test_device_added_signal_after_init (void)
&result);
/* Tell the test service to add a new device */
nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
/* Ensure the 'device-added' signal doesn't show up before
* the 'Devices' property change notification */
@ -207,7 +202,7 @@ test_device_added_signal_after_init (void)
g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -314,13 +309,13 @@ test_wifi_ap_added_removed (void)
GError *error = NULL;
char *expected_path = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
/*************************************/
/* Add the wifi device */
wifi = (NMDeviceWifi *) nm_test_service_add_device (sinfo, client, "AddWifiDevice", "wlan0");
wifi = (NMDeviceWifi *) nmtstc_service_add_device (sinfo, client, "AddWifiDevice", "wlan0");
g_assert (NM_IS_DEVICE_WIFI (wifi));
/*************************************/
@ -406,7 +401,7 @@ test_wifi_ap_added_removed (void)
g_free (expected_path);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -513,13 +508,13 @@ test_wimax_nsp_added_removed (void)
GError *error = NULL;
char *expected_path = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
/*************************************/
/* Add the wimax device */
wimax = (NMDeviceWimax *) nm_test_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0");
wimax = (NMDeviceWimax *) nmtstc_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0");
g_assert (NM_IS_DEVICE_WIMAX (wimax));
/*************************************/
@ -605,7 +600,7 @@ test_wimax_nsp_added_removed (void)
g_free (expected_path);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/
@ -689,7 +684,7 @@ test_devices_array (void)
GError *error = NULL;
GVariant *ret;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
/* Make sure that we test the async codepath in at least one test... */
nm_client_new_async (NULL, new_client_cb, &client);
@ -698,9 +693,9 @@ test_devices_array (void)
/*************************************/
/* Add some devices */
wlan0 = nm_test_service_add_device (sinfo, client,"AddWifiDevice", "wlan0");
eth0 = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
eth1 = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth1");
wlan0 = nmtstc_service_add_device (sinfo, client,"AddWifiDevice", "wlan0");
eth0 = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
eth1 = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth1");
/* Ensure the devices now exist */
devices = nm_client_get_devices (client);
@ -765,7 +760,7 @@ test_devices_array (void)
g_assert (device == eth1);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
static void
@ -804,7 +799,7 @@ test_client_nm_running (void)
g_clear_error (&error);
/* Now start the test service. */
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client2 = nm_client_new (NULL, &error);
g_assert_no_error (error);
@ -823,7 +818,7 @@ test_client_nm_running (void)
g_source_remove (quit_id);
/* And kill it */
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
g_assert (nm_client_get_nm_running (client1));
@ -937,12 +932,12 @@ test_active_connections (void)
TestACInfo info = { loop, NULL, 0 };
GError *error = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
/* Tell the test service to add a new device */
device = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
conn = nmtst_create_minimal_connection ("test-ac", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
nm_client_add_and_activate_connection_async (client, conn, device, NULL,
@ -979,7 +974,7 @@ test_active_connections (void)
assert_ac_and_device (client);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
static void
@ -1067,11 +1062,11 @@ test_activate_virtual (void)
TestConnectionInfo conn_info = { loop, NULL };
GError *error = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
conn = nmtst_create_minimal_connection ("test-ac", NULL, NM_SETTING_VLAN_SETTING_NAME, &s_con);
g_object_set (s_con,
@ -1112,7 +1107,7 @@ test_activate_virtual (void)
g_object_unref (info.ac);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
static void
@ -1140,11 +1135,11 @@ test_activate_failed (void)
NMConnection *conn;
GError *error = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
device = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0");
/* Note that test-networkmanager-service.py checks for this exact name */
conn = nmtst_create_minimal_connection ("object-creation-failed-test", NULL,
@ -1157,7 +1152,7 @@ test_activate_failed (void)
g_object_unref (conn);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
static void
@ -1174,13 +1169,13 @@ test_device_connection_compatibility (void)
const char *hw_addr1 = "52:54:00:ab:db:23";
const char *hw_addr2 = "52:54:00:ab:db:24";
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
/* Create two devices */
device1 = nm_test_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels);
device2 = nm_test_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL);
device1 = nmtstc_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels);
device2 = nmtstc_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL);
g_assert_cmpstr (nm_device_get_hw_address (device1), ==, hw_addr1);
g_assert_cmpstr (nm_device_get_hw_address (device2), ==, hw_addr2);
@ -1228,7 +1223,7 @@ test_device_connection_compatibility (void)
g_object_unref (conn);
g_object_unref (client);
g_clear_pointer (&sinfo, nm_test_service_cleanup);
g_clear_pointer (&sinfo, nmtstc_service_cleanup);
}
/*******************************************************************/

View file

@ -24,14 +24,9 @@
#include <sys/types.h>
#include <signal.h>
#include <NetworkManager.h>
#include "nm-default.h"
#include "nm-test-libnm-utils.h"
#include "nm-test-utils.h"
static NMTestServiceInfo *sinfo;
static NMTstcServiceInfo *sinfo;
static NMClient *client = NULL;
GDBusConnection *bus = NULL;
NMRemoteConnection *remote = NULL;
@ -517,7 +512,7 @@ main (int argc, char **argv)
bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
@ -536,7 +531,7 @@ main (int argc, char **argv)
ret = g_test_run ();
nm_test_service_cleanup (sinfo);
nmtstc_service_cleanup (sinfo);
g_object_unref (client);
g_object_unref (bus);

View file

@ -24,14 +24,10 @@
#include <sys/types.h>
#include <signal.h>
#include <NetworkManager.h>
#include <nm-secret-agent-old.h>
#include "nm-default.h"
#include "nm-test-libnm-utils.h"
#include "nm-test-utils.h"
/*******************************************************************/
enum {
@ -183,7 +179,7 @@ test_secret_agent_new (void)
/*******************************************************************/
typedef struct {
NMTestServiceInfo *sinfo;
NMTstcServiceInfo *sinfo;
NMClient *client;
NMSecretAgentOld *agent;
@ -250,7 +246,7 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
NMSetting *s_wsec;
GError *error = NULL;
sadata->sinfo = nm_test_service_init ();
sadata->sinfo = nmtstc_service_init ();
sadata->client = nm_client_new (NULL, &error);
g_assert_no_error (error);
@ -262,8 +258,8 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data)
counter++;
/* Create the device */
sadata->device = nm_test_service_add_device (sadata->sinfo, sadata->client,
"AddWifiDevice", sadata->ifname);
sadata->device = nmtstc_service_add_device (sadata->sinfo, sadata->client,
"AddWifiDevice", sadata->ifname);
/* Create the connection */
connection = nmtst_create_minimal_connection (sadata->con_id, NULL, NM_SETTING_WIRELESS_SETTING_NAME, &s_con);
@ -336,7 +332,7 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data)
g_object_unref (sadata->connection);
g_object_unref (sadata->client);
nm_test_service_cleanup (sadata->sinfo);
nmtstc_service_cleanup (sadata->sinfo);
g_source_remove (sadata->timeout_id);
g_main_loop_unref (sadata->loop);
@ -583,12 +579,12 @@ registered_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
static void
test_secret_agent_auto_register (void)
{
NMTestServiceInfo *sinfo;
NMTstcServiceInfo *sinfo;
NMSecretAgentOld *agent;
GMainLoop *loop;
GError *error = NULL;
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
loop = g_main_loop_new (NULL, FALSE);
agent = test_secret_agent_new ();
@ -604,17 +600,17 @@ test_secret_agent_auto_register (void)
g_assert (nm_secret_agent_old_get_registered (agent));
/* Shut down test service */
nm_test_service_cleanup (sinfo);
nmtstc_service_cleanup (sinfo);
g_main_loop_run (loop);
g_assert (!nm_secret_agent_old_get_registered (agent));
/* Restart test service */
sinfo = nm_test_service_init ();
sinfo = nmtstc_service_init ();
g_main_loop_run (loop);
g_assert (nm_secret_agent_old_get_registered (agent));
/* Shut down test service again */
nm_test_service_cleanup (sinfo);
nmtstc_service_cleanup (sinfo);
g_main_loop_run (loop);
g_assert (!nm_secret_agent_old_get_registered (agent));