diff options
author | Rashi Aswani <aswanirashi19@gmail.com> | 2015-06-12 20:00:46 +0530 |
---|---|---|
committer | Rashi Aswani <aswanirashi19@gmail.com> | 2015-08-27 15:16:42 +0530 |
commit | 6bc4ca5623974ec9eab0ed90256ca6baf239a3a6 (patch) | |
tree | d0643d6ed73b7fc06650394754e0df18fd9d2c29 | |
parent | b79ec2c5071e926d767bec32deee1be3d8929507 (diff) | |
download | gnome-logs-6bc4ca5623974ec9eab0ed90256ca6baf239a3a6.tar.gz |
Update Makefile and rename mock_gl_journal to gl_mock_journal in gl-journal-mock files
-rw-r--r-- | Makefile.am | 37 | ||||
-rw-r--r-- | tests/gl-journal-mock.c | 177 | ||||
-rw-r--r-- | tests/gl-journal-mock.h | 64 |
3 files changed, 153 insertions, 125 deletions
diff --git a/Makefile.am b/Makefile.am index 3759fe6..89ecbff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} DISTCHECK_CONFIGURE_FLAGS = \ --enable-appstream-util \ - --enable-tests + --enable-tests=yes SUBDIRS = help po @@ -107,8 +107,6 @@ endif if LOGS_ENABLE_TESTS tests/basic.py: gnome-logs -tests/gl-journal-mock.c: gnome-logs -tests/gl-journal-mock.h: gnome-logs test-desktop-file-validate.sh: Makefile $(AM_V_GEN)echo "#!/bin/sh -e" > $@; \ @@ -147,16 +145,35 @@ tests_test_gl_util_SOURCES = \ tests/test-gl-util.c \ src/gl-util.c -tests_test_gl_journal_CFLAGS = \ +tests_gl_journal_mock_CFLAGS = \ $(LOGS_CFLAGS) -tests_test_gl_journal_SOURCES = \ - tests/gl-journal-mock.c +tests_gl_journal_mock_LDADD = \ + $(LOGS_LIBS) + +tests_gl_journal_mock_SOURCES = \ + tests/gl-journal-mock.c \ src/gl-journal.c +tests_test_gnome_logs_test_CPPFLAGS = \ + -DLOCALEDIR=\""$(localedir)"\" \ + -I$(top_builddir) \ + -I$(top_srcdir)/src \ + $(WARN_CFLAGS) + +tests_gnome_logs_test_CFLAGS = \ + $(LOGS_CFLAGS) + +tests_gnome_logs_test_LDADD = \ + $(LOGS_LIBS) + +tests_gnome_logs_test_SOURCES = \ + tests/gnome-logs-test.c \ + tests/gl-journal-mock.c + check_PROGRAMS = \ - tests/test-gl-util - tests/gl-journal-mock + tests/test-gl-util \ + tests/gnome-logs-test TESTS = \ $(check_PROGRAMS) \ @@ -242,9 +259,7 @@ dist_noinst_DATA = \ dist_noinst_SCRIPTS = \ autogen.sh \ - tests/basic.py \ - tests/gl-journal-mock.c \ - tests/gl-journal-mock.h + tests/basic.py dist-hook: git-changelog-hook diff --git a/tests/gl-journal-mock.c b/tests/gl-journal-mock.c index f0fa533..6925ba2 100644 --- a/tests/gl-journal-mock.c +++ b/tests/gl-journal-mock.c @@ -17,14 +17,32 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define gl_journal_error_quack (void) gl_mock_journal_error_quack (void) +#define gl_journal_finalize (GObject *object) gl_mock_journal_finalize (GObject *object) +#define gl_journal_class_init (GlJournalClass *klass) gl_mock_journal_class_init (GlMockJournalClass *klass) +#define gl_journal_init (GlJournal *self) gl_mock_journal_init (GlMockJournal *self) +#define gl_journal_get_data (GlJournal *self, const gchar *field, GError **error) gl_mock_journal_get_data(GlMockJournal *self, const gchar *field, GError **error) +#define gl_journal_query_entry (GlJournal *self) gl_mock_journal_query_entry (GlMockJournal *self) +#define gl_journal_set_matches (GlJournal *journal, const gchar * const *matches) gl_mock_journal_set_matches (GlMockJournal *journal, const gchar * const *matches) +#define gl_journal_previous (GlJournal *journal) gl_mock_journal_previous (GlMockJournal *journal) +#define gl_journal_new (void) gl_mock_journal_new (void) +#define gl_journal_entry_init (GlJournalEntry *entry) gl_mock_journal_entry_init (GlMockJournalEntry *entry) +#define gl_journal_entry_get_timestamp (GlJournalEntry *entry) gl_mock_journal_entry_get_timestamp (GlMockJournalEntry *entry) +#define gl_journal_entry_get_message (GlJournalEntry *entry) gl_mock_journal_entry_get_message (GlMockJournalEntry *entry) +#define gl_journal_entry_get_command_line (GlJournalEntry *entry) gl_mock_journal_entry_get_command_line (GlMockJournalEntry *entry) +#define gl_journal_entry_get_kernel_device (GlJournalEntry *entry) gl_mock_journal_entry_get_kernel_device (GlMockJournalEntry *entry) +#define gl_journal_entry_get_audit_session (GlJournalEntry *entry) gl_mock_journal_entry_get_audit_session (GlMockJournalEntry *entry) +#define gl_journal_entry_get_catalog (GlJournalEntry *entry) gl_mock_journal_entry_get_catalog (GlMockJournalEntry *entry) +#define gl_journal_entry_get_priority (GlJournalEntry *entry) gl_mock_journal_entry_get_priority(GlMockJournalEntry *entry) + #include "gl-journal-mock.h" #include <glib-unix.h> #include <gio/gio.h> #include <stdlib.h> -#include <systemd/sd-journal.h> +#include <string.h> -struct MockGlJournalEntry +struct _GlMockJournalEntry { GObject parent_instance; @@ -38,113 +56,112 @@ struct MockGlJournalEntry guint priority; }; -G_DEFINE_TYPE (MockGlJournalEntry, gl_journal_entry, G_TYPE_OBJECT); - typedef struct { gint fd; guint source_id; gchar **mandatory_fields; -} MockGlJournalPrivate; +} GlMockJournalPrivate; -G_DEFINE_TYPE_WITH_PRIVATE (MockGlJournal, gl_journal, G_TYPE_OBJECT) +G_DEFINE_TYPE_WITH_PRIVATE (GlMockJournal, gl_mock_journal, G_TYPE_OBJECT) GQuark -mock_gl_journal_error_quark (void) +gl_mock_journal_error_quark (void) { - return g_quark_from_static_string ("gl-journal-error-quark"); + return g_quark_from_static_string ("gl-mock-journal-error-quark"); } static void -mock_gl_journal_finalize (GObject *object) +gl_mock_journal_finalize (GObject *object) { - MockGlJournal *journal = GL_JOURNAL (object); - MockGlJournalPrivate *priv = gl_journal_get_instance_private (journal); + GlMockJournal *journal = GL_MOCK_JOURNAL (object); + GlMockJournalPrivate *priv = gl_mock_journal_get_instance_private (journal); g_source_remove (priv->source_id); g_clear_pointer (&priv->mandatory_fields, g_strfreev); } static void -mock_gl_journal_class_init (GlJournalClass *klass) +gl_mock_journal_class_init (GlMockJournalClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - gobject_class->finalize = gl_journal_finalize; + gobject_class->finalize = gl_mock_journal_finalize; } static void -mock_gl_journal_init (GlJournal *self) +gl_mock_journal_init (GlMockJournal *self) { } static gchar * -gl_journal_mock_get_data (MockGlJournal *self, +gl_mock_journal_get_data (GlMockJournal *self, const gchar *field, GError **error) { - gconstpointer data; - gsize length; - gsize prefix_len; - g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (field != NULL, NULL); - /* Field data proper starts after the first '='. */ - prefix_len = strchr (data, '=') - (const gchar *)data + 1; + if (strcmp(field,"message")==0) + return "Test"; + + if (strcmp(field,"priority")==0) + return "Low"; + + if(strcmp(field,"comm")==0) + return "No idea"; + + if(strcmp(field,"kernel_device")==0) + return "Something"; - /* Trim the prefix off the beginning of the field. */ - return g_strndup ((const gchar *)data + prefix_len, length - prefix_len); + if(strcmp(field,"audit_session")==0) + return "Session"; + + if(strcmp(field,"transport")==0) + return "Transport"; + + if(strcmp(field,"uid")==0) + return "0001"; + return NULL; } -static MockGlJournalEntry * -gl_journal_mock_query_entry (GlJournal *self) +static GlMockJournalEntry * +gl_mock_journal_query_entry (GlMockJournal *self) { - MockGlJournalPrivate *priv; - MockGlJournalEntry *entry; - gint ret; + GlMockJournalEntry *entry; GError *error = NULL; - gchar *priority; - priv = gl_journal_get_instance_private (self); + entry = g_object_new (GL_TYPE_MOCK_JOURNAL_ENTRY, NULL); - entry = g_object_new (GL_TYPE_JOURNAL_ENTRY, NULL); - - entry->message = gl_journal_get_data (self, "MESSAGE", NULL); + entry->message = gl_mock_journal_get_data (self, "MESSAGE", NULL); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); - free (entry->cursor); - free (entry->catalog); goto out; } - priority = gl_journal_get_data (self, "PRIORITY", NULL); + /* FIXME: priority is an int, not a char*. */ + entry->priority = gl_mock_journal_get_data (self, "PRIORITY", NULL); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); - free (entry->cursor); - free (entry->catalog); g_free (entry->message); goto out; } - entry->priority = priority ? atoi (priority) : LOG_INFO; - g_free (priority); - - entry->comm = gl_journal_get_data (self, "_COMM", &error); + entry->comm = gl_mock_journal_get_data (self, "_COMM", &error); - if (error != NULL) - { + if(error!=NULL) + { g_debug ("%s", error->message); g_clear_error (&error); } - entry->kernel_device = gl_journal_get_data (self, "_KERNEL_DEVICE", NULL); + entry->kernel_device = gl_mock_journal_get_data (self, "_KERNEL_DEVICE", NULL); if (error != NULL) { @@ -152,7 +169,7 @@ gl_journal_mock_query_entry (GlJournal *self) g_clear_error (&error); } - entry->audit_session = gl_journal_get_data (self, "_AUDIT_SESSION", NULL); + entry->audit_session = gl_mock_journal_get_data (self, "_AUDIT_SESSION", NULL); return entry; @@ -163,23 +180,21 @@ out: } /** - * gl_journal_set_matches: - * @journal: a #GlJournal + * gl_mock_journal_set_matches: + * @journal: a #GlMockJournal * @matches: new matches to set * * Sets @matches on @journal. Will reset the cursor position to the * beginning. */ void -gl_journal_mock_set_matches (GlJournal *journal, - const gchar * const *matches) +gl_mock_journal_set_matches (GlMockJournal *journal, + const gchar * const *matches) { - MockGlJournalPrivate *priv = gl_journal_get_instance_private (journal); + GlMockJournalPrivate *priv = gl_mock_journal_get_instance_private (journal); GPtrArray *mandatory_fields; - int r; gint i; gboolean has_boot_id = FALSE; - g_return_if_fail (matches != NULL); if (priv->mandatory_fields) @@ -208,27 +223,27 @@ gl_journal_mock_set_matches (GlJournal *journal, priv->mandatory_fields = (gchar **) g_ptr_array_free (mandatory_fields, FALSE); } -MockGlJournalEntry * -_gl_journal_mock_previous (MockGlJournal *journal) +GlMockJournalEntry * +gl_mock_journal_previous (GlMockJournal *journal) { - return _gl_journal_query_entry (journal); + return gl_mock_journal_query_entry (journal); } -GlJournal * -gl_journal_mock_new (void) +GlMockJournal * +gl_mock_journal_new (void) { - return g_object_new (GL_TYPE_JOURNAL, NULL); + return g_object_new (GL_TYPE_MOCK_JOURNAL, NULL); } static void -gl_journal_mock_entry_init (MockGlJournalEntry *entry) +gl_mock_journal_entry_init (GlMockJournalEntry *entry) { } static void -gl_journal_mock_entry_finalize (GObject *object) +gl_mock_journal_entry_finalize (GObject *object) { - MockGlJournalEntry *entry = GL_JOURNAL_ENTRY (object); + GlMockJournalEntry *entry = GL_MOCK_JOURNAL_ENTRY (object); free (entry->cursor); free (entry->catalog); @@ -237,69 +252,65 @@ gl_journal_mock_entry_finalize (GObject *object) g_free (entry->kernel_device); g_free (entry->audit_session); - G_OBJECT_CLASS (gl_journal_entry_parent_class)->finalize (object); + G_OBJECT_CLASS (gl_mock_journal_entry_parent_class)->finalize (object); } static void -gl_journal_mock_entry_class_init (MockGlJournalEntryClass *class) +gl_mock_journal_entry_class_init (GlMockJournalEntryClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - object_class->finalize = gl_journal_entry_finalize; + object_class->finalize = gl_mock_journal_entry_finalize; } guint64 -gl_journal_mock_entry_get_timestamp (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_timestamp (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), 0); + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), 0); return entry->timestamp; } const gchar * -gl_journal_mock_entry_get_message (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_message (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL); + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), NULL); return entry->message; } const gchar * -gl_journal_mock_entry_get_command_line (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_command_line (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL); - + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), NULL); return entry->comm; } const gchar * -gl_journal_mock_entry_get_kernel_device (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_kernel_device (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL); - + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), NULL); return entry->kernel_device; } const gchar * -gl_journal_mock_entry_get_audit_session (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_audit_session (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL); + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), NULL); return entry->audit_session; } const gchar * -gl_journal_mock_entry_get_catalog (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_catalog (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL); - + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), NULL); return entry->catalog; } guint -gl_journal_mock_entry_get_priority (MockGlJournalEntry *entry) +gl_mock_journal_entry_get_priority (GlMockJournalEntry *entry) { - g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), 0); - + g_return_val_if_fail (GL_IS_MOCK_JOURNAL_ENTRY (entry), 0); return entry->priority; } diff --git a/tests/gl-journal-mock.h b/tests/gl-journal-mock.h index f41554b..eb55832 100644 --- a/tests/gl-journal-mock.h +++ b/tests/gl-journal-mock.h @@ -17,64 +17,66 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GL_JOURNAL_H_ -#define GL_JOURNAL_H_ +#ifndef GL_MOCK_JOURNAL_H_ +#define GL_MOCK_JOURNAL_H_ #include <gio/gio.h> G_BEGIN_DECLS /* - * GlJournalError: - * @GL_JOURNAL_ERROR_NO_FIELD: the requested field was not found in the current + * GlMockJournalError: + * @GL_MOCK_JOURNAL_ERROR_NO_FIELD: the requested field was not found in the current * journal entry - * @GL_JOURNAL_ERROR_INVALID_POINTER: the pointer to the current journal entry + * @GL_MOCK_JOURNAL_ERROR_INVALID_POINTER: the pointer to the current journal entry * is not valid - * @GL_JOURNAL_ERROR_FAILED: unknown failure + * @GL_MOCK_JOURNAL_ERROR_FAILED: unknown failure */ typedef enum { - GL_JOURNAL_ERROR_NO_FIELD, - GL_JOURNAL_ERROR_INVALID_POINTER, - GL_JOURNAL_ERROR_FAILED -} MockGlJournalError; + GL_MOCK_JOURNAL_ERROR_NO_FIELD, + GL_MOCK_JOURNAL_ERROR_INVALID_POINTER, + GL_MOCK_JOURNAL_ERROR_FAILED +} GlMockJournalError; -#define GL_JOURNAL_ERROR gl_journal_error_quark () +#define GL_MOCK_JOURNAL_ERROR gl_mock_journal_error_quark () -GQuark mock_gl_journal_error_quark (void); +GQuark gl_mock_journal_error_quark (void); -#define GL_TYPE_JOURNAL_ENTRY gl_journal_entry_get_type() -G_DECLARE_FINAL_TYPE (MockGlJournalEntry, gl_journal_entry, GL, JOURNAL_ENTRY, GObject) +#define GL_TYPE_MOCK_JOURNAL_ENTRY gl_mock_journal_entry_get_type() +G_DECLARE_FINAL_TYPE (GlMockJournalEntry, gl_mock_journal_entry, GL, MOCK_JOURNAL_ENTRY, GObject) +G_DECLARE_FINAL_TYPE (GlIsMockJournalEntry, gl_is_mock_journal_entry, GL, JOURNAL_ENTRY, GObject) +G_DECLARE_FINAL_TYPE (GlMockJournalEntryParentClass, gl_mock_journal_entry_parent_class, GL, JOURNAL_ENTRY_PARENT_CLASS, GObject) typedef struct { /*< private >*/ GObject parent_instance; -} MockGlJournal; +} GlMockJournal; typedef struct { /*< private >*/ GObjectClass parent_class; -} MockGlJournalClass; +} GlMockJournalClass; -#define GL_TYPE_JOURNAL (gl_journal_get_type ()) -#define GL_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_JOURNAL, GlJournal)) +#define GL_TYPE_MOCK_JOURNAL (gl_mock_journal_get_type ()) +#define GL_MOCK_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_MOCK_JOURNAL, GlMockJournal)) -GType gl_journal_mock_result_get_type (void); -GType gl_journal_mock_get_type (void); -void gl_journal_mock_set_matches (MockGlJournal *journal, const gchar * const *matches); -MockGlJournalEntry * gl_journal_mock_previous (MockGlJournal *journal); -GlJournal * gl_journal_mock_new (void); +GType gl_mock_journal_result_get_type (void); +GType gl_mock_journal_get_type (void); +void gl_mock_journal_set_matches (GlMockJournal *journal, const gchar * const *matches); +GlMockJournalEntry * gl_mock_journal_previous (GlMockJournal *journal); +GlMockJournal * gl_mock_journal_new (void); -guint64 gl_journal_mock_entry_get_timestamp (MockGlJournalEntry *entry); -const gchar * gl_journal_mock_entry_get_message (MockGlJournalEntry *entry); -const gchar * gl_journal_mock_entry_get_command_line (MockGlJournalEntry *entry); -const gchar * gl_journal_mock_entry_get_kernel_device (MockGlJournalEntry *entry); -const gchar * gl_journal_mock_entry_get_audit_session (MockGlJournalEntry *entry); -const gchar * gl_journal_mock_entry_get_catalog (MockGlJournalEntry *entry); -guint gl_journal_mock_entry_get_priority (MockGlJournalEntry *entry); +guint64 gl_mock_journal_entry_get_timestamp (GlMockJournalEntry *entry); +const gchar * gl_mock_journal_entry_get_message (GlMockJournalEntry *entry); +const gchar * gl_mock_journal_entry_get_command_line (GlMockJournalEntry *entry); +const gchar * gl_mock_journal_entry_get_kernel_device (GlMockJournalEntry *entry); +const gchar * gl_mock_journal_entry_get_audit_session (GlMockJournalEntry *entry); +const gchar * gl_mock_journal_entry_get_catalog (GlMockJournalEntry *entry); +guint gl_mock_journal_entry_get_priority (GlMockJournalEntry *entry); G_END_DECLS -#endif /* GL_JOURNAL_H_ */ +#endif /* GL_MOCK_JOURNAL_H_ */ |