mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 15:48:06 +02:00
shared: add test for NM_SET_OUT()
This commit is contained in:
parent
d27ae4a8fe
commit
ee86069601
2 changed files with 36 additions and 0 deletions
|
|
@ -5399,6 +5399,36 @@ test_nm_in_strset (void)
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
static gboolean
|
||||
do_test_nm_set_out_called (gint *call_count)
|
||||
{
|
||||
(*call_count)++;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_nm_set_out (void)
|
||||
{
|
||||
gboolean val;
|
||||
gboolean *p_val;
|
||||
int call_count;
|
||||
|
||||
/* NM_SET_OUT() has an unexpected non-function like behavior
|
||||
* wrt. side-effects of the value argument. Test it */
|
||||
|
||||
p_val = &val;
|
||||
call_count = 0;
|
||||
NM_SET_OUT (p_val, do_test_nm_set_out_called (&call_count));
|
||||
g_assert_cmpint (call_count, ==, 1);
|
||||
|
||||
p_val = NULL;
|
||||
call_count = 0;
|
||||
NM_SET_OUT (p_val, do_test_nm_set_out_called (&call_count));
|
||||
g_assert_cmpint (call_count, ==, 0);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
|
@ -5521,6 +5551,7 @@ int main (int argc, char **argv)
|
|||
g_test_add_func ("/core/general/_nm_utils_validate_json", test_nm_utils_check_valid_json);
|
||||
g_test_add_func ("/core/general/_nm_utils_team_config_equal", test_nm_utils_team_config_equal);
|
||||
g_test_add_func ("/core/general/test_nm_utils_enum", test_nm_utils_enum);
|
||||
g_test_add_func ("/core/general/nm-set-out", test_nm_set_out);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,6 +164,11 @@ NM_G_ERROR_MSG (GError *error)
|
|||
/* macro to return strlen() of a compile time string. */
|
||||
#define NM_STRLEN(str) ( sizeof ("" str) - 1 )
|
||||
|
||||
/* Note: @value is only evaluated when *out_val is present.
|
||||
* Thus,
|
||||
* NM_SET_OUT (out_str, g_strdup ("hallo"));
|
||||
* does the right thing.
|
||||
*/
|
||||
#define NM_SET_OUT(out_val, value) \
|
||||
G_STMT_START { \
|
||||
typeof(*(out_val)) *_out_val = (out_val); \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue