tests: Factor out hard-coded file names in mapping test

So the filename we delete at the end of the test is definitely the same
one we created at the start of the test.

This introduces no functional changes, but will make a refactor in the
following commit simpler.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2025-03-19 16:50:58 +00:00
parent 9f75cdc2bc
commit 484fb416c6
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -50,7 +50,13 @@ check_stop (gpointer data)
GMainLoop *loop = data;
#ifdef G_OS_WIN32
stop = g_file_test ("STOP", G_FILE_TEST_EXISTS);
char *stop_name = NULL;
char *curdir = g_get_current_dir ();
stop_name = g_build_filename (curdir, "maptest.stop", NULL);
stop = g_file_test (stop_name, G_FILE_TEST_EXISTS);
g_free (stop_name);
g_free (curdir);
#endif
if (stop)
@ -151,7 +157,7 @@ test_mapping_flags (void)
g_test_message ("test_mapping: ok");
/* Cleaning left over files */
g_remove ("maptest");
g_remove (global_filename);
g_free (global_filename);
g_free (dir);
@ -186,11 +192,11 @@ test_private (void)
g_assert_cmpstr (buffer, ==, "ABC");
g_free (buffer);
/* Cleaning left over files */
g_remove (global_filename);
g_free (global_filename);
g_free (dir);
/* Cleaning left over files */
g_remove ("maptest");
}
static void
@ -211,14 +217,15 @@ test_child_private (void)
gchar pid[100];
gchar *dir, *global_filename, *childname;
#ifdef G_OS_WIN32
g_remove ("STOP");
g_assert_false (g_file_test ("STOP", G_FILE_TEST_EXISTS));
#endif
dir = g_get_current_dir ();
global_filename = g_build_filename (dir, "maptest", NULL);
childname = g_build_filename (dir, "mapchild", NULL);
stop_name = g_build_filename (dir, "maptest.stop", NULL);
#ifdef G_OS_WIN32
g_remove (stop_name);
g_assert_false (g_file_test (stop_name, G_FILE_TEST_EXISTS));
#endif
write_or_die (global_filename, "ABC", -1);
map = map_or_die (global_filename, TRUE);
@ -260,7 +267,7 @@ test_child_private (void)
#ifndef G_OS_WIN32
kill (child_pid, SIGUSR1);
#else
g_file_set_contents ("STOP", "Hey there\n", -1, NULL);
g_file_set_contents (stop_name, "Hey there\n", -1, NULL);
#endif
#ifndef G_OS_WIN32
@ -283,13 +290,15 @@ test_child_private (void)
g_assert_cmpstr (buffer, ==, "ABC");
g_free (buffer);
/* Cleaning left over files */
g_remove (childname);
g_remove (global_filename);
g_remove (stop_name);
g_free (childname);
g_free (global_filename);
g_free (dir);
/* Cleaning left over files */
g_remove ("mapchild");
g_remove ("maptest");
g_free (stop_name);
}
int