r1731 - in trunk/src/target/OM-2007/openmoko-libs: . libmokojournal/src libmokojournal/tests

dodji at sita.openmoko.org dodji at sita.openmoko.org
Thu Apr 12 13:47:35 CEST 2007


Author: dodji
Date: 2007-04-12 13:47:32 +0200 (Thu, 12 Apr 2007)
New Revision: 1731

Added:
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete-uid.c
Modified:
   trunk/src/target/OM-2007/openmoko-libs/ChangeLog
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/Makefile.am
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c
Log:
Support entry removal by UID

	* openmoko-libs/libmokojournal/src/moko-journal.c,h:
	  (moko_journal_remove_entry_by_uid): added this new entry point.
	  (moko_journal_entry_get_uid): ditto
	* openmoko-libs/libmokojournal/tests/test-delete-uid.c: added
	  this to test/debug removal by uid.


Modified: trunk/src/target/OM-2007/openmoko-libs/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/ChangeLog	2007-04-12 09:21:34 UTC (rev 1730)
+++ trunk/src/target/OM-2007/openmoko-libs/ChangeLog	2007-04-12 11:47:32 UTC (rev 1731)
@@ -1,5 +1,13 @@
 2007-04-12 Dodji Seketeli <dodji at openedhand.com>
 
+	* openmoko-libs/libmokojournal/src/moko-journal.c,h:
+	  (moko_journal_remove_entry_by_uid): added this new entry point.
+	  (moko_journal_entry_get_uid): ditto
+	* openmoko-libs/libmokojournal/tests/test-delete-uid.c: added
+	  this to test/debug removal by uid.
+
+2007-04-12 Dodji Seketeli <dodji at openedhand.com>
+
 	*  openmoko-libs/libmokojournal/src/moko-journal.[c|h]:
 	   change moko_j_entry* into moko_journal_entry*,
 	   MokoJEntry, into MokoJournalEntry, etc.

Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c	2007-04-12 09:21:34 UTC (rev 1730)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c	2007-04-12 11:47:32 UTC (rev 1731)
@@ -686,6 +686,37 @@
 }
 
 /**
+ * moko_journal_remove_entry_by_uid:
+ * @journal: the current instance of journal
+ * @uid: the uid of the journal entry to remove
+ *
+ * Remove the journal entry that has a given UID.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean
+moko_journal_remove_entry_by_uid (MokoJournal *a_journal,
+                                  const gchar* a_uid)
+{
+  int i=0 ;
+  MokoJournalEntry *entry=NULL ;
+
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_journal->entries, FALSE) ;
+  g_return_val_if_fail (a_uid, FALSE) ;
+
+  for (i=0 ; i < a_journal->entries->len ; ++i)
+  {
+    entry = g_array_index (a_journal->entries, MokoJournalEntry*, i) ;
+    if (entry && entry->uid && !strcmp (entry->uid, a_uid))
+    {
+      return moko_journal_remove_entry_at (a_journal, i) ;
+    }
+  }
+  return FALSE ;
+}
+
+/**
  * moko_journal_write_to_storage:
  * @journal: the journal to save to storage
  *
@@ -1055,6 +1086,24 @@
 }
 
 /**
+ * moko_journal_entry_get_uid:
+ * @entry: the current instance of journal entry
+ *
+ * Gets the UID of the current entry. This UID is non NULL if and
+ * only if the entry has been persistet at least once.
+ *
+ * Return value: the UID in case the entry has been persisted at least once,
+ * NULL otherwise. The client code must *NOT* free the returned string.
+ */
+const gchar*
+moko_journal_entry_get_uid (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  return a_entry->uid ;
+}
+
+/**
  * moko_journal_entry_get_contact_uid:
  * @entry: the current instance of journal entry
  *

Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h	2007-04-12 09:21:34 UTC (rev 1730)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h	2007-04-12 11:47:32 UTC (rev 1731)
@@ -114,12 +114,26 @@
  * @index: the index to remove the entry from
  *
  * Remove a journal entry from index #index
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
  */
 gboolean moko_journal_remove_entry_at (MokoJournal *journal,
                                        guint index) ;
 
 /**
- * moko_journal_weite_to_storage:
+ * moko_journal_remove_entry_by_uid:
+ * @journal: the current instance of journal
+ * @uid: the uid of the journal entry to remove
+ *
+ * Remove the journal entry that has a given UID.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean moko_journal_remove_entry_by_uid (MokoJournal *journal,
+                                           const gchar* uid) ;
+
+/**
+ * moko_journal_write_to_storage:
  * @journal: the journal to save to storage
  *
  * Saves the journal to persistent storage (e.g disk) using the
@@ -188,6 +202,18 @@
                                   MokoJournalEntryType type) ;
 
 /**
+ * moko_journal_entry_get_uid:
+ * @entry: the current instance of journal entry
+ *
+ * Gets the UID of the current entry. This UID is non NULL if and
+ * only if the entry has been persistet at least once.
+ *
+ * Return value: the UID in case the entry has been persisted at least once,
+ * NULL otherwise. The client code must *NOT* free the returned string.
+ */
+const gchar* moko_journal_entry_get_uid (MokoJournalEntry *entry) ;
+
+/**
  * moko_journal_entry_get_contact_uid:
  * @entry: the current instance of journal entry
  *

Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/Makefile.am	2007-04-12 09:21:34 UTC (rev 1730)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/Makefile.am	2007-04-12 11:47:32 UTC (rev 1731)
@@ -1,4 +1,4 @@
-noinst_PROGRAMS=testcreate testdelete
+noinst_PROGRAMS=testcreate testdelete testdeleteuid
 
 testcreate_SOURCES=test-create.c
 testcreate_LDADD=@LIBS@ $(top_srcdir)/libmokojournal/src/libmokojournal.la
@@ -6,4 +6,8 @@
 testdelete_SOURCES=test-delete.c
 testdelete_LDADD=@LIBS@ $(top_srcdir)/libmokojournal/src/libmokojournal.la
 
+testdeleteuid_SOURCES=test-delete-uid.c
+testdeleteuid_LDADD=@LIBS@ $(top_srcdir)/libmokojournal/src/libmokojournal.la
+
 INCLUDES= -I $(top_srcdir)/libmokojournal/src
+

Copied: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete-uid.c (from rev 1730, trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c)
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c	2007-04-12 09:21:34 UTC (rev 1730)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete-uid.c	2007-04-12 11:47:32 UTC (rev 1731)
@@ -0,0 +1,94 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info at openedhand.com>
+ * All Rights Reserved
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <glib-object.h>
+#include "moko-journal.h"
+
+int
+main ()
+{
+    MokoJournal *journal=NULL ;
+    MokoJournalEntry *entry=NULL ;
+    int result=-1 ;
+
+    g_type_init () ;
+
+    /*open the journal*/
+    journal = moko_journal_open_default () ;
+    g_return_val_if_fail (journal, -1) ;
+
+    if (!moko_journal_load_from_storage (journal))
+    {
+        g_warning ("failed to load journal from storage\n") ;
+        goto out ;
+    }
+    g_message ("initial number of journal entries: %d\n",
+               moko_journal_get_nb_entries (journal)) ;
+
+    /*remove all entries from journal starting from the oldest one*/
+    while (moko_journal_get_nb_entries (journal) > 0)
+    {
+        entry = NULL ;
+        /*get the oldest entry*/
+        if (!moko_journal_get_entry_at (journal, 0, &entry) || !entry)
+        {
+            g_message ("failed to get entry at index 0\n") ;
+            goto out ;
+        }
+        /*make sure it has an UID*/
+        if (!moko_journal_entry_get_uid (entry))
+        {
+            g_message ("error: came accross an entry without UID\n") ;
+            goto out ;
+        }
+        /*remove the entry from the journal, using its UID*/
+        if (!moko_journal_remove_entry_by_uid
+                                        (journal,
+                                         moko_journal_entry_get_uid (entry)))
+        {
+            g_message ("failed to remove entry of UID '%s' from journal\n",
+                       moko_journal_entry_get_uid (entry)) ;
+            goto out ;
+        }
+    }
+    /*write the modifications we did, back to persistent storage*/
+    if (!moko_journal_write_to_storage (journal))
+    {
+        g_message ("failed to write to storage\n") ;
+        goto out ;
+    }
+
+    if (moko_journal_get_nb_entries (journal) != 0)
+    {
+        g_message ("test failed, we still have %d entries left\n",
+                   moko_journal_get_nb_entries (journal)) ;
+        goto out ;
+    }
+
+    /*if we reached this place, the test is prolly successful*/
+    g_message ("test succeeded") ;
+    result = 0 ;
+
+out:
+    if (journal)
+        moko_journal_close (journal) ;
+
+    return result ;
+}

Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c	2007-04-12 09:21:34 UTC (rev 1730)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c	2007-04-12 11:47:32 UTC (rev 1731)
@@ -29,6 +29,7 @@
 
     g_type_init () ;
 
+    /*open the journal*/
     journal = moko_journal_open_default () ;
     g_return_val_if_fail (journal, -1) ;
 





More information about the commitlog mailing list