From 08b61888ef3429dc23023609dd49137b465795d9 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sat, 12 Apr 2014 16:44:13 +0300 Subject: [PATCH] [test_resize] Don't use g_file_copy, it crashes qemu Now it should be possible to automatically run unit tests in OBS --- mms-lib/test/resize/test_resize.c | 34 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/mms-lib/test/resize/test_resize.c b/mms-lib/test/resize/test_resize.c index f3dbb82..82210ba 100644 --- a/mms-lib/test/resize/test_resize.c +++ b/mms-lib/test/resize/test_resize.c @@ -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( @@ -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; @@ -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);