Skip to content

Commit

Permalink
[test_resize] Don't use g_file_copy, it crashes qemu
Browse files Browse the repository at this point in the history
Now it should be possible to automatically run unit tests in OBS
  • Loading branch information
monich committed Apr 12, 2014
1 parent 6a87b89 commit 08b6188
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions mms-lib/test/resize/test_resize.c
Expand Up @@ -319,6 +319,31 @@ test_png_size(
return ok;
}

static
gboolean
test_file_copy(
const char* src,
const char* dest)
{
gboolean ok = FALSE;
FILE* in = fopen(src, "rb");
if (in) {
FILE* out = fopen(dest, "wb");
if (out) {
const size_t buflen = 4096;
size_t nbytes;
void* buf = g_malloc(buflen);
while ((nbytes = fread(buf, 1, buflen, in)) > 0 &&
fwrite(buf, 1, nbytes, out) == nbytes);
ok = (feof(in) && !ferror(in) && !ferror(out));
g_free(buf);
fclose(out);
}
fclose(in);
}
return ok;
}

static
int
test_run_one(
Expand All @@ -334,9 +359,7 @@ test_run_one(
if (dir) {
GError* error = NULL;
char* testfile = g_strconcat(dir, "/", name, NULL);
GFile* src = g_file_new_for_path(test->file);
GFile* dest = g_file_new_for_path(testfile);
if (g_file_copy(src, dest, 0, NULL, NULL, NULL, &error)) {
if (test_file_copy(test->file, testfile)) {
MMSAttachment* at;
MMSAttachmentInfo info;
MMSConfig test_config = *config;
Expand Down Expand Up @@ -377,11 +400,8 @@ test_run_one(
g_error_free(error);
}
} else {
MMS_ERR("%s", MMS_ERRMSG(error));
g_error_free(error);
MMS_ERR("Failed to copy %s -> %s", test->file, testfile);
}
g_object_unref(src);
g_object_unref(dest);
g_free(testfile);
}
MMS_INFO("%s: %s", (ret == RET_OK) ? "OK" : "FAILED", test->name);
Expand Down

0 comments on commit 08b6188

Please sign in to comment.