[gnome-logs/wip/test] Update prefix to gl_mock_journal in the mock files and return fake data from gl_mock_journal_get_dat
- From: Rashi Aswani <aswanirashi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/test] Update prefix to gl_mock_journal in the mock files and return fake data from gl_mock_journal_get_dat
- Date: Sun, 14 Jun 2015 22:53:25 +0000 (UTC)
commit 67b09ba97a67b3dcee9563ae95ffcc11d436f8ac
Author: Rashi Aswani <aswanirashi19 gmail com>
Date: Mon Jun 15 04:20:35 2015 +0530
Update prefix to gl_mock_journal in the mock files and return fake data from
gl_mock_journal_get_data function
tests/gl-journal-mock.c | 142 +++++++++++++++++++++++-----------------------
tests/gl-journal-mock.h | 62 ++++++++++----------
2 files changed, 102 insertions(+), 102 deletions(-)
---
diff --git a/tests/gl-journal-mock.c b/tests/gl-journal-mock.c
index 7b16c7c..822db81 100644
--- a/tests/gl-journal-mock.c
+++ b/tests/gl-journal-mock.c
@@ -22,9 +22,8 @@
#include <glib-unix.h>
#include <gio/gio.h>
#include <stdlib.h>
-#include <systemd/sd-journal.h>
-struct MockGlJournalEntry
+struct GlMockJournalEntry
{
GObject parent_instance;
@@ -38,79 +37,84 @@ struct MockGlJournalEntry
guint priority;
};
-G_DEFINE_TYPE (MockGlJournalEntry, mock_gl_journal_entry, G_TYPE_OBJECT);
-
typedef struct
{
gint fd;
guint source_id;
gchar **mandatory_fields;
-} MockGlJournalPrivate;
+} GlMockJournalPrivate;
-G_DEFINE_TYPE_WITH_PRIVATE (MockGlJournal, mock_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");
}
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 (MockGlJournalClass *klass)
+gl_mock_journal_class_init (GlMockJournalClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->finalize = mock_gl_journal_finalize;
+ gobject_class->finalize = gl_mock_journal_finalize;
}
static void
-mock_gl_journal_init (MockGlJournal *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 (field =="message")
+ return "This is a test";
+
+ if (field == "priority")
+ return "Low";
+
+ if(field == "comm")
+ return "No idea";
+
+ if(field == "kernel_device")
+ return "Something";
+
+ if(field == "audit_session")
+ return "Session";
+
+ if(field == "transport")
+ return "Transport";
- /* Trim the prefix off the beginning of the field. */
- return g_strndup ((const gchar *)data + prefix_len, length - prefix_len);
+ if(field == "uid")
+ return "0001";
}
-static MockGlJournalEntry *
-gl_journal_mock_query_entry (MockGlJournal *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_MOCK_TYPE_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)
{
@@ -119,7 +123,7 @@ gl_journal_mock_query_entry (MockGlJournal *self)
goto out;
}
- priority = gl_journal_get_data (self, "PRIORITY", NULL);
+ entry->priority = gl_mock_journal_get_data (self, "PRIORITY", NULL);
if (error != NULL)
{
@@ -129,18 +133,15 @@ gl_journal_mock_query_entry (MockGlJournal *self)
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)
{
@@ -148,7 +149,7 @@ gl_journal_mock_query_entry (MockGlJournal *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;
@@ -159,18 +160,18 @@ 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 (MockGlJournal *journal,
+gl_mockjournal_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;
@@ -204,27 +205,27 @@ gl_journal_mock_set_matches (MockGlJournal *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_mock_query_entry (journal);
+ return gl_mock_journal_query_entry (journal);
}
-MockGlJournal *
-gl_journal_mock_new (void)
+GlMockJournal *
+gl_mock_journal_new (void)
{
- return g_object_new (GL_TYPE_JOURNAL, NULL);
+ return g_object_new (GL_MOCK_TYPE_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);
@@ -233,69 +234,68 @@ gl_journal_mock_entry_finalize (GObject *object)
g_free (entry->kernel_device);
g_free (entry->audit_session);
- G_OBJECT_CLASS (gl_journal_mock_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_mock_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 4754466..2ac158e 100644
--- a/tests/gl-journal-mock.h
+++ b/tests/gl-journal-mock.h
@@ -17,64 +17,64 @@
* 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 MOCK_GL_JOURNAL_ERROR mock_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 MOCK_GL_TYPE_JOURNAL_ENTRY mock_gl_journal_entry_get_type()
-G_DECLARE_FINAL_TYPE (MockGlJournalEntry, mock_gl_journal_entry, GL, JOURNAL_ENTRY, GObject)
+#define GL_MOCK_TYPE_JOURNAL_ENTRY gl_mock_journal_entry_get_type()
+G_DECLARE_FINAL_TYPE (GlMockJournalEntry, gl_mock_journal_entry, GL, MOCK_JOURNAL_ENTRY, GObject)
typedef struct
{
/*< private >*/
GObject parent_instance;
-} MockGlJournal;
+} GlMockJournal;
typedef struct
{
/*< private >*/
GObjectClass parent_class;
-} MockGlJournalClass;
+} GlMockJournalClass;
-#define MOCK_GL_TYPE_JOURNAL (mock_gl_journal_get_type ())
-#define MOCK_GL_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_JOURNAL, MockGlJournal))
+#define GL_MOCK_TYPE_JOURNAL (gl_mock_journal_get_type ())
+#define GL_MOCK_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_MOCK_TYPE_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);
-MockGlJournal * 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_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]