nmtst: introduce nmtst_setting_ip_config_add_{address,route} helpers
authorBeniamino Galvani <bgalvani@redhat.com>
Tue, 2 Feb 2016 13:30:15 +0000 (14:30 +0100)
committerBeniamino Galvani <bgalvani@redhat.com>
Thu, 11 Feb 2016 20:57:09 +0000 (21:57 +0100)
shared/nm-test-utils.h

index 89d32cc..fcae761 100644 (file)
@@ -1325,6 +1325,56 @@ nmtst_ip6_config_clone (NMIP6Config *config)
 
 #endif
 
+#ifdef NM_SETTING_IP_CONFIG_H
+inline static void
+nmtst_setting_ip_config_add_address (NMSettingIPConfig *s_ip,
+                                     const char *address,
+                                     guint prefix)
+{
+       NMIPAddress *addr;
+       int family;
+
+       g_assert (s_ip);
+
+       if (nm_utils_ipaddr_valid (AF_INET, address))
+               family = AF_INET;
+       else if (nm_utils_ipaddr_valid (AF_INET6, address))
+               family = AF_INET6;
+       else
+               g_assert (FALSE);
+
+       addr = nm_ip_address_new (family, address, prefix, NULL);
+       g_assert (addr);
+       g_assert (nm_setting_ip_config_add_address (s_ip, addr));
+       nm_ip_address_unref (addr);
+}
+
+inline static void
+nmtst_setting_ip_config_add_route (NMSettingIPConfig *s_ip,
+                                   const char *dest,
+                                   guint prefix,
+                                   const char *next_hop,
+                                   gint64 metric)
+{
+       NMIPRoute *route;
+       int family;
+
+       g_assert (s_ip);
+
+       if (nm_utils_ipaddr_valid (AF_INET, dest))
+               family = AF_INET;
+       else if (nm_utils_ipaddr_valid (AF_INET6, dest))
+               family = AF_INET6;
+       else
+               g_assert (FALSE);
+
+       route = nm_ip_route_new (family, dest, prefix, next_hop, metric, NULL);
+       g_assert (route);
+       g_assert (nm_setting_ip_config_add_route (s_ip, route));
+       nm_ip_route_unref (route);
+}
+#endif /* NM_SETTING_IP_CONFIG_H */
+
 #if (defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__)) || (defined(NM_CONNECTION_H))
 
 inline static NMConnection *