summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Playfair Cal <daniel.playfair.cal@gmail.com>2019-01-07 22:33:15 +1100
committerDaniel Playfair Cal <daniel.playfair.cal@gmail.com>2019-02-12 19:47:56 +1100
commit8cbaee1c341b97d81fc597a4571b459baaac5c11 (patch)
tree1a1d58e7110fb231f0ea04d9b8626ec283e4a3c2 /tests
parent38e625da7f47e457d150efedc598437e2e867ef7 (diff)
downloaddconf-8cbaee1c341b97d81fc597a4571b459baaac5c11.tar.gz
Tests: replace usage of dlsym with separate modules containing functions that need to be mocked out
Diffstat (limited to 'tests')
-rw-r--r--tests/engine.c9
-rw-r--r--tests/meson.build4
-rw-r--r--tests/shm.c16
3 files changed, 8 insertions, 21 deletions
diff --git a/tests/engine.c b/tests/engine.c
index 7f2a748..fd2a348 100644
--- a/tests/engine.c
+++ b/tests/engine.c
@@ -2,6 +2,7 @@
#include "../engine/dconf-engine.h"
#include "../engine/dconf-engine-profile.h"
+#include "../engine/dconf-engine-mockable.h"
#include "../common/dconf-enums.h"
#include "dconf-mock.h"
@@ -17,13 +18,9 @@ static const gchar *filename_to_replace;
static const gchar *filename_to_replace_it_with;
FILE *
-fopen (const char *filename,
+dconf_engine_fopen (const char *filename,
const char *mode)
{
- static FILE * (*real_fopen) (const char *, const char *);
-
- if (!real_fopen)
- real_fopen = dlsym (RTLD_NEXT, "fopen");
if (filename_to_replace && g_str_equal (filename, filename_to_replace))
{
@@ -32,7 +29,7 @@ fopen (const char *filename,
filename = filename_to_replace_it_with;
}
- return (* real_fopen) (filename, mode);
+ return fopen (filename, mode);
}
static void assert_no_messages (void);
diff --git a/tests/meson.build b/tests/meson.build
index 247ad76..8aa5837 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -24,11 +24,11 @@ unit_tests = [
# [name, sources, c_args, dependencies, link_with]
['paths', 'paths.c', [], libdconf_common_dep, []],
['changeset', 'changeset.c', [], libdconf_common_dep, []],
- ['shm', ['shm.c', 'tmpdir.c'], [], [dl_dep, libdconf_common_dep, libdconf_shm_dep], []],
+ ['shm', ['shm.c', 'tmpdir.c'], [], [dl_dep, libdconf_common_dep, libdconf_shm_test_dep], []],
['gvdb', 'gvdb.c', '-DSRCDIR="@0@"'.format(test_dir), libgvdb_dep, []],
['gdbus-thread', 'dbus.c', '-DDBUS_BACKEND="/gdbus/thread"', libdconf_gdbus_thread_dep, []],
['gdbus-filter', 'dbus.c', '-DDBUS_BACKEND="/gdbus/filter"', libdconf_gdbus_filter_dep, []],
- ['engine', 'engine.c', '-DSRCDIR="@0@"'.format(test_dir), [dl_dep, libdconf_engine_dep, m_dep], libdconf_mock],
+ ['engine', 'engine.c', '-DSRCDIR="@0@"'.format(test_dir), [dl_dep, libdconf_engine_test_dep, m_dep], libdconf_mock],
['client', 'client.c', '-DSRCDIR="@0@"'.format(test_dir), [libdconf_client_dep, libdconf_engine_dep], libdconf_mock],
['writer', 'writer.c', '-DSRCDIR="@0@"'.format(test_dir), [glib_dep, dl_dep, m_dep, libdconf_service_dep], [libdconf_mock]],
]
diff --git a/tests/shm.c b/tests/shm.c
index 26c5160..69d683f 100644
--- a/tests/shm.c
+++ b/tests/shm.c
@@ -10,6 +10,7 @@
#include <dlfcn.h>
#include "../shm/dconf-shm.h"
+#include "../shm/dconf-shm-mockable.h"
#include "tmpdir.h"
static void
@@ -87,29 +88,18 @@ test_flag_nonexistent (void)
dconf_shm_flag ("does-not-exist");
}
-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
-#define PWRITE_SYM "pwrite64"
-#else
-#define PWRITE_SYM "pwrite"
-#endif
-
static gboolean should_fail_pwrite;
/* interpose */
ssize_t
-pwrite (int fd, const void *buf, size_t count, off_t offset)
+dconf_shm_pwrite (int fd, const void *buf, size_t count, off_t offset)
{
- static ssize_t (* real_pwrite) (int, const void *, size_t, off_t);
-
- if (!real_pwrite)
- real_pwrite = dlsym (RTLD_NEXT, PWRITE_SYM);
-
if (should_fail_pwrite)
{
errno = ENOSPC;
return -1;
}
- return (* real_pwrite) (fd, buf, count, offset);
+ return pwrite (fd, buf, count, offset);
}
static void