summaryrefslogtreecommitdiff
path: root/egg
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-01-30 16:07:55 +0100
committerStef Walter <stefw@gnome.org>2012-02-03 20:44:45 +0100
commitdea9a3a043b866076fec215e9787c31626a64883 (patch)
treed238369f7b0351a123f43c11c1c4601c290d5dbe /egg
parentf1bd681e8a6a8fc9a92e5645495e1b32003f32f3 (diff)
downloadlibsecret-dea9a3a043b866076fec215e9787c31626a64883.tar.gz
Test creating items and collections
Diffstat (limited to 'egg')
-rw-r--r--egg/egg-testing.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 7fa2a60..5a4f3e5 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -29,7 +29,11 @@
#include <valgrind/valgrind.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+
#include <errno.h>
+#include <fcntl.h>
#include <unistd.h>
static const char HEXC[] = "0123456789ABCDEF";
@@ -56,6 +60,19 @@ hex_dump (const guchar *data, gsize n_data)
return g_string_free (result, FALSE);
}
+static gboolean
+is_readable_ptr (gpointer was_object)
+{
+ static gint test_memory_fd = -1;
+
+ /* First make sure this memory is still accessible */
+ if (test_memory_fd < 0)
+ test_memory_fd = g_open ("/dev/null", O_WRONLY, 0);
+ if (write (test_memory_fd, was_object, 1) > 0)
+ return TRUE;
+ return (errno != EFAULT);
+}
+
void
egg_assertion_not_object (const char *domain,
const char *file,
@@ -68,6 +85,10 @@ egg_assertion_not_object (const char *domain,
if (RUNNING_ON_VALGRIND)
return;
+
+ if (!is_readable_ptr (was_object))
+ return;
+
if (G_IS_OBJECT (was_object)) {
s = g_strdup_printf ("assertion failed: %s is still referenced", expr);
g_assertion_message (domain, file, line, func, s);