31Ensure (pidfile, pidfile_create_creates_file_with_correct_pid)
33 gchar *test_pidfile =
"test_pidfile.tmp";
34 pid_t current_pid = getpid ();
35 gchar *expected_content;
36 gchar *actual_content;
39 g_remove (test_pidfile);
47 expected_content = g_strdup_printf (
"%d\n", current_pid);
48 g_file_get_contents (test_pidfile, &actual_content, NULL, NULL);
49 assert_that (actual_content, is_equal_to_string (expected_content));
51 g_free (expected_content);
52 g_free (actual_content);
55 g_remove (test_pidfile);
58Ensure (pidfile, pidfile_create_creates_directory_if_needed)
60 gchar *test_dir =
"test_pid_dir";
61 gchar *test_pidfile =
"test_pid_dir/test_pidfile.tmp";
75 g_remove (test_pidfile);
89Ensure (pidfile, pidfile_remove_deletes_file_with_matching_pid)
91 gchar *test_pidfile =
"test_pidfile_remove.tmp";
92 pid_t current_pid = getpid ();
97 pid_content = g_strdup_printf (
"%d\n", current_pid);
98 file = fopen (test_pidfile,
"w");
99 assert_that (file, is_not_null);
100 fputs (pid_content, file);
112 g_free (pid_content);
115Ensure (pidfile, pidfile_remove_does_not_delete_file_with_different_pid)
117 gchar *test_pidfile =
"test_pidfile_remove_diff.tmp";
118 pid_t current_pid = getpid ();
119 pid_t different_pid = current_pid + 1;
124 pid_content = g_strdup_printf (
"%d\n", different_pid);
125 file = fopen (test_pidfile,
"w");
126 assert_that (file, is_not_null);
127 fputs (pid_content, file);
140 g_remove (test_pidfile);
141 g_free (pid_content);
166 suite = create_test_suite ();
168 add_test_with_context (suite, pidfile,
169 pidfile_create_returns_error_for_null_path);
170 add_test_with_context (suite, pidfile,
171 pidfile_create_creates_file_with_correct_pid);
172 add_test_with_context (suite, pidfile,
173 pidfile_create_creates_directory_if_needed);
174 add_test_with_context (suite, pidfile,
175 pidfile_create_returns_error_when_cannot_create_file);
176 add_test_with_context (suite, pidfile,
177 pidfile_remove_deletes_file_with_matching_pid);
178 add_test_with_context (
179 suite, pidfile, pidfile_remove_does_not_delete_file_with_different_pid);
180 add_test_with_context (suite, pidfile,
181 pidfile_remove_handles_nonexistent_file);
184 ret = run_single_test (suite, argv[1], create_text_reporter ());
186 ret = run_test_suite (suite, create_text_reporter ());
188 destroy_test_suite (suite);