Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[test] Updated test_retrieve to use glib test framework
  • Loading branch information
monich committed Aug 14, 2020
1 parent 75c00c0 commit dec19db
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 335 deletions.
29 changes: 29 additions & 0 deletions mms-lib/test/common/test_util.c
Expand Up @@ -58,6 +58,35 @@ test_dirs_cleanup(
g_free(dirs->attic);
}

gboolean
test_files_equal(
const char* path1,
const char* path2)
{
gboolean equal = FALSE;
if (path1 && path2) {
GError* error = NULL;
GMappedFile* f1 = g_mapped_file_new(path1, FALSE, &error);
if (f1) {
GMappedFile* f2 = g_mapped_file_new(path2, FALSE, &error);
if (f2) {
const gsize size = g_mapped_file_get_length(f1);
if (g_mapped_file_get_length(f2) == size) {
const void* data1 = g_mapped_file_get_contents(f1);
const void* data2 = g_mapped_file_get_contents(f2);
equal = !memcmp(data1, data2, size);
}
g_mapped_file_unref(f2);
}
g_mapped_file_unref(f1);
}
}
if (!equal) {
GERR("%s is not identical to %s", path1, path2);
}
return equal;
}

/* Should be invoked after g_test_init */
void
test_init(
Expand Down
5 changes: 5 additions & 0 deletions mms-lib/test/common/test_util.h
Expand Up @@ -42,6 +42,11 @@ test_dirs_cleanup(
TestDirs* dirs,
gboolean remove);

gboolean
test_files_equal(
const char* path1,
const char* path2);

/* Should be invoked after g_test_init */
void
test_init(
Expand Down
1 change: 0 additions & 1 deletion mms-lib/test/test_retrieve/Makefile
@@ -1,7 +1,6 @@
# -*- Mode: makefile-gmake -*-

EXE = test_retrieve
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c \
test_transfer_list.c test_util.c

Expand Down

0 comments on commit dec19db

Please sign in to comment.