[gnome-photos/gnome-3-34] glib: Add photos_glib_assert_strv_contains
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/gnome-3-34] glib: Add photos_glib_assert_strv_contains
- Date: Wed, 1 Apr 2020 16:44:03 +0000 (UTC)
commit 3a3f9e292486bd5183f8b3b75def7f6a98560574
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Mar 31 21:22:50 2020 +0200
glib: Add photos_glib_assert_strv_contains
It's a debugging macro to assert that a GStrv contains a given string.
A subsequent commit will use this to support having multiple reference
SHA256 checksums in the test suite. Hence, photos-glib.[ch] needs to be
moved to the private shared library.
https://gitlab.gnome.org/GNOME/gnome-photos/-/merge_requests/126
src/meson.build | 2 +-
src/photos-glib.c | 42 +++++++++++++++++++++++++++++++++++++++++-
src/photos-glib.h | 27 ++++++++++++++++++++++++++-
3 files changed, 68 insertions(+), 3 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index a4f25576..1b29d045 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -4,6 +4,7 @@ sources = files(
'photos-debug.c',
'photos-error.c',
'photos-gegl.c',
+ 'photos-glib.c',
'photos-jpeg-count.c',
'photos-operation-insta-curve.c',
'photos-operation-insta-filter.c',
@@ -136,7 +137,6 @@ sources = common_sources + files(
'photos-filterable.c',
'photos-flickr-item.c',
'photos-gesture-zoom.c',
- 'photos-glib.c',
'photos-google-item.c',
'photos-image-view.c',
'photos-image-view-helper.c',
diff --git a/src/photos-glib.c b/src/photos-glib.c
index 1da2dc6d..6191d19b 100644
--- a/src/photos-glib.c
+++ b/src/photos-glib.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 – 2019 Red Hat, Inc.
+ * Copyright © 2015 – 2020 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -71,6 +71,46 @@ photos_glib_app_info_launch_uri (GAppInfo *appinfo,
}
+void
+photos_glib_assertion_message_strv_contains (const gchar *domain,
+ const gchar *file,
+ gint line,
+ const gchar *function,
+ const gchar *expression,
+ const gchar *const *strv,
+ const gchar *str)
+{
+ g_auto (GStrv) strv_escaped = NULL;
+ g_autofree gchar *message = NULL;
+ g_autofree gchar *str_escaped = NULL;
+ g_autofree gchar *str_quoted = NULL;
+ g_autofree gchar *strv_joined = NULL;
+ g_autofree gchar *strv_joined_tmp = NULL;
+ guint i;
+ guint length;
+
+ length = g_strv_length ((GStrv) strv);
+ strv_escaped = (GStrv) g_malloc0_n (length + 1, sizeof (gchar *));
+ for (i = 0; strv[i] != NULL; i++)
+ strv_escaped[i] = g_strescape (strv[i], NULL);
+
+ strv_joined_tmp = g_strjoinv ("\", \"", strv_escaped);
+ strv_joined = g_strconcat ("[\"", strv_joined_tmp, "\"]", NULL);
+
+ if (str != NULL)
+ str_escaped = g_strescape (str, NULL);
+
+ if (str_escaped == NULL)
+ str_quoted = g_strdup ("NULL");
+ else
+ str_quoted = g_strconcat ("\"", str_escaped, "\"", NULL);
+
+ message = g_strdup_printf ("assertion failed (%s): (%s contains %s)", expression, strv_joined, str_quoted);
+
+ g_assertion_message (domain, file, line, function, message);
+}
+
+
static void
photos_glib_file_copy_data_free (PhotosGLibFileCopyData *data)
{
diff --git a/src/photos-glib.h b/src/photos-glib.h
index e9c632e9..985a976e 100644
--- a/src/photos-glib.h
+++ b/src/photos-glib.h
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 – 2019 Red Hat, Inc.
+ * Copyright © 2015 – 2020 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,11 +27,36 @@
G_BEGIN_DECLS
+#define photos_glib_assert_strv_contains(strv, str) \
+ G_STMT_START { \
+ const gchar *const *__strv = (strv); \
+ const gchar *__str = (str); \
+ if (g_strv_contains (__strv, __str)); else \
+ { \
+ const gchar *expression = #strv " contains " #str; \
+ photos_glib_assertion_message_strv_contains (G_LOG_DOMAIN, \
+ __FILE__, \
+ __LINE__, \
+ G_STRFUNC, \
+ expression, \
+ strv, \
+ str); \
+ } \
+ } G_STMT_END
+
gboolean photos_glib_app_info_launch_uri (GAppInfo *appinfo,
const gchar *uri,
GAppLaunchContext *launch_context,
GError **error);
+void photos_glib_assertion_message_strv_contains (const gchar *domain,
+ const gchar *file,
+ gint line,
+ const gchar *function,
+ const gchar *expression,
+ const gchar *const *strv,
+ const gchar *str);
+
void photos_glib_file_copy_async (GFile *source,
GFile *destination,
GFileCopyFlags flags,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]