~ubuntu-branches/ubuntu/vivid/whoopsie/vivid-proposed

« back to all changes in this revision

Viewing changes to src/tests/test_monitor.c

  • Committer: Package Import Robot
  • Author(s): Brian Murray, Evan Dandrea, Brian Murray
  • Date: 2014-10-29 10:28:24 UTC
  • Revision ID: package-import@ubuntu.com-20141029102824-tu50jiz9eqtmob2h
Tags: 0.2.40
[ Evan Dandrea ]
* Wait for network-manager to start when it's installed.

[ Brian Murray ]
* tests/monitor: Stop using mktemp, and clean up after ourselves in the
  callback_not_triggered_without_upload_file test.
* Change ownership of whoopsie-id so that it is not world readable.
  (LP: #1386752)

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
void
132
132
test_callback_triggered_once (void)
133
133
{
134
 
    char template[12] = "/tmp/XXXXXX";
135
 
    char* path = NULL;
 
134
    gchar template[PATH_MAX] = "/tmp/whoopsie-test-XXXXXX";
 
135
    gchar *path = NULL;
 
136
    gchar *test_dir = NULL;
136
137
    const char* fake_files[] = { "crash", "upload", "uploaded", NULL };
137
138
    const char** p = fake_files;
138
139
    struct stat fake_stat;
139
140
    int id;
140
141
    GFileMonitor* monitor = NULL;
141
142
 
142
 
    mktemp (template);
143
 
    if (*template == '\0') {
144
 
        g_warning ("Couldn't create temporary file.");
145
 
        g_test_fail ();
146
 
        return;
147
 
    }
148
 
 
149
 
    if (mkdir (template, 0755) < 0) {
150
 
        g_warning ("Couldn't create temporary directory.");
151
 
        g_test_fail ();
152
 
        return;
153
 
    }
 
143
    test_dir = g_mkdtemp (template);
 
144
    g_assert (test_dir != NULL);
 
145
    path = g_strdup_printf ("%s", test_dir);
154
146
 
155
147
    g_idle_add ((GSourceFunc) _create_crash_file, template);
156
148
    g_idle_add ((GSourceFunc) _create_upload_file, template);
192
184
void
193
185
test_callback_not_triggered_without_upload_file (void)
194
186
{
195
 
    char template[12] = "/tmp/XXXXXX";
 
187
    gchar template[PATH_MAX] = "/tmp/whoopsie-test-XXXXXX";
 
188
    gchar *path = NULL;
 
189
    gchar *test_dir = NULL;
196
190
    GFileMonitor* monitor = NULL;
197
191
 
198
 
    mktemp (template);
199
 
    if (*template == '\0') {
200
 
        g_warning ("Couldn't create temporary file.");
201
 
        g_test_fail ();
202
 
        return;
203
 
    }
204
 
 
205
 
    if (mkdir (template, 0755) < 0) {
206
 
        g_warning ("Couldn't create temporary directory.");
207
 
        g_test_fail ();
208
 
        return;
209
 
    }
 
192
    test_dir = g_mkdtemp (template);
 
193
    g_assert (test_dir != NULL);
210
194
 
211
195
    g_idle_add ((GSourceFunc) _create_crash_file, template);
212
196
    loop = g_main_loop_new (NULL, FALSE);
217
201
    if (monitor)
218
202
        unmonitor_directory (monitor, _test_callback_never_triggered_callback);
219
203
    g_main_loop_unref (loop);
 
204
 
 
205
    path = g_strdup_printf ("%s/fake.crash", template);
 
206
    if (unlink (path) < 0) {
 
207
        g_warning ("Couldn't remove temporary file, %s", path);
 
208
        g_test_fail ();
 
209
        g_free (path);
 
210
        return;
 
211
    }
 
212
 
 
213
    if (rmdir (template) < 0) {
 
214
        g_warning ("Couldn't remove temporary directory.");
 
215
        g_test_fail ();
 
216
        return;
 
217
    }
220
218
}
221
219
 
222
220
int