diff options
Diffstat (limited to 'src/dhcp/tests')
| -rw-r--r-- | src/dhcp/tests/test-dhcp-dhclient.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index a8284b23..2f369aac 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -785,17 +785,18 @@ static void test_write_existing_duid (void) { const char *duid = "\\000\\001\\000\\001\\023o\\023n\\000\\\"\\372\\214\\326\\302"; - const char *expected_contents = "default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n"; + const char *original_contents = "default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n"; + const char *expected_contents = "default-duid \"\\000\\001\\000\\001\\023o\\023n\\000\\\"\\372\\214\\326\\302\";\n"; GError *error = NULL; char *contents = NULL; gboolean success; const char *path = "test-dhclient-write-existing-duid.leases"; - success = g_file_set_contents (path, expected_contents, -1, &error); + success = g_file_set_contents (path, original_contents, -1, &error); g_assert_no_error (error); g_assert (success); - /* Save other DUID; should be a no-op */ + /* Save other DUID; should be overwritten */ success = nm_dhcp_dhclient_save_duid (path, duid, &error); g_assert_no_error (error); g_assert (success); @@ -811,14 +812,14 @@ test_write_existing_duid (void) g_free (contents); } +#define DUID "\\000\\001\\000\\001\\023o\\023n\\000\\\"\\372\\214\\326\\302" static void test_write_existing_commented_duid (void) { - #define DUID "\\000\\001\\000\\001\\023o\\023n\\000\\\"\\372\\214\\326\\302" - #define ORIG_CONTENTS "#default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n" - const char *expected_contents = \ - "default-duid \"" DUID "\";\n" - ORIG_CONTENTS; +#define ORIG_CONTENTS "#default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n" + const char *expected_contents = + "default-duid \"" DUID "\";\n" + ORIG_CONTENTS; GError *error = NULL; char *contents = NULL; gboolean success; @@ -828,7 +829,7 @@ test_write_existing_commented_duid (void) g_assert_no_error (error); g_assert (success); - /* Save other DUID; should be a no-op */ + /* Save other DUID; should be saved on top */ success = nm_dhcp_dhclient_save_duid (path, DUID, &error); g_assert_no_error (error); g_assert (success); @@ -842,6 +843,33 @@ test_write_existing_commented_duid (void) g_assert_cmpstr (expected_contents, ==, contents); g_free (contents); +#undef ORIG_CONTENTS +} + +static void +test_write_existing_multiline_duid (void) +{ +#define ORIG_CONTENTS "### Commented old DUID ###\n" \ + "#default-duid \"\\000\\001\\000\\001\\027X\\350X\\000#\\025\\010~\\254\";\n" + const char *expected_contents = \ + "default-duid \"" DUID "\";\n" + ORIG_CONTENTS; + GError *error = NULL; + gs_free char *contents = NULL; + gboolean success; + nmtst_auto_unlinkfile char *path = g_strdup ("test-dhclient-write-existing-multiline-duid.leases"); + + success = g_file_set_contents (path, ORIG_CONTENTS, -1, &error); + nmtst_assert_success (success, error); + + success = nm_dhcp_dhclient_save_duid (path, DUID, &error); + nmtst_assert_success (success, error); + + success = g_file_get_contents (path, &contents, NULL, &error); + nmtst_assert_success (success, error); + + g_assert_cmpstr (expected_contents, ==, contents); +#undef ORIG_CONTENTS } /*****************************************************************************/ @@ -1025,6 +1053,7 @@ main (int argc, char **argv) g_test_add_func ("/dhcp/dhclient/write_duid", test_write_duid); g_test_add_func ("/dhcp/dhclient/write_existing_duid", test_write_existing_duid); g_test_add_func ("/dhcp/dhclient/write_existing_commented_duid", test_write_existing_commented_duid); + g_test_add_func ("/dhcp/dhclient/write_existing_multiline_duid", test_write_existing_multiline_duid); return g_test_run (); } |