r1729 - 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 10:53:38 CEST 2007
Author: dodji
Date: 2007-04-12 10:53:35 +0200 (Thu, 12 Apr 2007)
New Revision: 1729
Added:
trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.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/tests/Makefile.am
trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-create.c
Log:
Made entries deletion work, fixed leaks, added comments to test cases.
* openmoko-libs/libmokojournal/src/moko-journal.c:
(moko_j_entry_free_real): fix a leak in here.
(moko_journal_remove_entry_at): make this really remove
the entries from MokoJournal::entries.
(moko_journal_write_to_storage): fix a leak.
* openmoko-libs/libmokojournal/tests/test-create.c: added comments
and licensing blurb.
* openmoko-libs/libmokojournal/tests/test-delete.c: added
this new file to test/debug entries deletion.
Modified: trunk/src/target/OM-2007/openmoko-libs/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/ChangeLog 2007-04-11 20:06:22 UTC (rev 1728)
+++ trunk/src/target/OM-2007/openmoko-libs/ChangeLog 2007-04-12 08:53:35 UTC (rev 1729)
@@ -1,3 +1,15 @@
+2007-04-12 Dodji Seketeli <dodji at openedhand.com>
+
+ * openmoko-libs/libmokojournal/src/moko-journal.c:
+ (moko_j_entry_free_real): fix a leak in here.
+ (moko_journal_remove_entry_at): make this really remove
+ the entries from MokoJournal::entries.
+ (moko_journal_write_to_storage): fix a leak.
+ * openmoko-libs/libmokojournal/tests/test-create.c: added comments
+ and licensing blurb.
+ * openmoko-libs/libmokojournal/tests/test-delete.c: added
+ this new file to test/debug entries deletion.
+
2007-04-11 Dodji Seketeli <dodji at openedhand.com>
* openmoko-libs/libmokojournal/src/moko-journal.c,h:
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-11 20:06:22 UTC (rev 1728)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c 2007-04-12 08:53:35 UTC (rev 1729)
@@ -265,6 +265,7 @@
g_warning ("unknown journal entry type. This is a leak!\n") ;
break ;
}
+ g_free (a_entry) ;
}
static gboolean
@@ -673,13 +674,14 @@
a_journal->entries_to_delete =
g_list_prepend (a_journal->entries_to_delete,
g_array_index (a_journal->entries, MokoJEntry*, a_index));
+ g_array_remove_index (a_journal->entries, a_index) ;
return TRUE ;
}
return FALSE ;
}
/**
- * moko_journal_weite_to_storage:
+ * moko_journal_write_to_storage:
* @journal: the journal to save to storage
*
* Saves the journal to persistent storage (e.g disk) using the
@@ -818,6 +820,15 @@
a_journal->entries_to_delete = NULL ;
}
+ if (ecal_comps)
+ {
+ GList *cur;
+
+ for (cur = ecal_comps ; cur ; cur = cur->next)
+ g_object_unref (cur->data) ;
+ g_list_free (ecal_comps) ;
+ }
+
return result ;
}
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-11 20:06:22 UTC (rev 1728)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/Makefile.am 2007-04-12 08:53:35 UTC (rev 1729)
@@ -1,5 +1,9 @@
-noinst_PROGRAMS=testcreate
+noinst_PROGRAMS=testcreate testdelete
testcreate_SOURCES=test-create.c
testcreate_LDADD=@LIBS@ $(top_srcdir)/libmokojournal/src/libmokojournal.la
+
+testdelete_SOURCES=test-delete.c
+testdelete_LDADD=@LIBS@ $(top_srcdir)/libmokojournal/src/libmokojournal.la
+
INCLUDES= -I $(top_srcdir)/libmokojournal/src
Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-create.c
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-create.c 2007-04-11 20:06:22 UTC (rev 1728)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-create.c 2007-04-12 08:53:35 UTC (rev 1729)
@@ -1,9 +1,29 @@
+/* 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 <unistd.h>
-#include <gtk/gtk.h>
+#include <glib-object.h>
#include "moko-journal.h"
int
-main (int argc, char **argv)
+main ()
{
MokoJournal *journal=NULL ;
MokoJEntry *entry=NULL ;
@@ -12,22 +32,21 @@
g_type_init () ;
+ /*open the journal*/
journal = moko_journal_open_default () ;
g_return_val_if_fail (journal, 1) ;
+ /*load all journal entries from the journal on storage*/
if (!moko_journal_load_from_storage (journal))
{
g_message ("failed to load journal from storage\n") ;
- return FALSE ;
+ goto out ;
}
- while (g_main_context_pending (g_main_context_default ()))
- {
- g_main_context_iteration (g_main_context_default (), FALSE) ;
- }
g_message ("loaded journal from storage okay\n") ;
g_message ("number journal entries: %d\n",
moko_journal_get_nb_entries (journal)) ;
+ /*create a journal entry of type 'email journal entry'*/
entry = moko_j_entry_new (EMAIL_JOURNAL_ENTRY) ;
if (!entry)
{
@@ -35,6 +54,9 @@
goto out ;
}
+ /*****************************
+ * <fill the entry with data>
+ *****************************/
moko_j_entry_set_contact_uid (entry, "foobarbazuid") ;
moko_j_entry_set_summary (entry, "back from fostel") ;
moko_j_entry_set_dtstart (entry, moko_time_new_today ()) ;
@@ -44,20 +66,44 @@
goto out ;
}
moko_j_email_info_set_was_sent (email_info, TRUE) ;
+ /*****************************
+ * </fill the entry with data>
+ *****************************/
+ /*add the entry we created to the journal*/
if (!moko_journal_add_entry (journal, entry))
{
g_warning ("could not add entry to journal\n") ;
goto out ;
}
+ /*
+ * the entry is now owned by the journal, make sure we won't ever
+ * free it ourselves (by accident)
+ */
entry = NULL ;
+
+ /*sync the journal to persistent storage*/
if (!moko_journal_write_to_storage (journal))
{
g_warning ("Could not write journal to storage") ;
goto out ;
}
+ /*
+ * sleep a bit to wait for possible notifications, in case
+ * another process has added new journal entries as well
+ * this is not mandatory, but is there for the sake of testing.
+ */
sleep (2) ;
+
+ /*
+ * notifications of new journal entries being added to the journal
+ * is done via dbus, using the glib event loop to dispatch the
+ * notifications. So let's give the event loop a chance to
+ * let us notified of new entries that could have been added.
+ * Note that when using gtk+, you usually don't have to do this,
+ * as gtk+ does it for you magically.
+ */
while (g_main_context_pending (g_main_context_default ()))
{
g_main_context_iteration (g_main_context_default (), FALSE) ;
@@ -65,6 +111,7 @@
g_message ("number journal entries after one got added: %d\n",
moko_journal_get_nb_entries (journal)) ;
+ /*if we reached this point, the test has probably succeeded*/
result = 0;
g_print ("test succeeded\n") ;
Added: 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-11 20:06:22 UTC (rev 1728)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/tests/test-delete.c 2007-04-12 08:53:35 UTC (rev 1729)
@@ -0,0 +1,76 @@
+/* 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 ;
+ int result=-1 ;
+
+ g_type_init () ;
+
+ 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)
+ {
+ if (!moko_journal_remove_entry_at (journal, 0))
+ {
+ g_message ("failed to remove an entry from journal") ;
+ goto out ;
+ }
+ }
+
+ /*write the modifications we did 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 ;
+}
More information about the commitlog
mailing list