Re: bonobo-storage-memory.c
- From: ERDI Gergo <cactus cactus rulez org>
- To: Michael Meeks <michael ximian com>
- Cc: gnome-components-list gnome org
- Subject: Re: bonobo-storage-memory.c
- Date: Fri, 9 Nov 2001 00:10:31 +0100 (CET)
On Thu, 8 Nov 2001, Michael Meeks wrote:
> :-) great; did you turn on the bonobo_debug_shutdown () ?
I turned it on for testing and turned it back off before checking it in.
> can you send the patch to me and CC the list as you commit ? ( the
> g_strsplit bug was not particularly pleasant - good catch :-)
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libbonobo/ChangeLog,v
retrieving revision 1.238
diff -u -u -r1.238 ChangeLog
--- ChangeLog 2001/11/07 22:38:36 1.238
+++ ChangeLog 2001/11/08 23:09:06
@@ -1,3 +1,18 @@
+2001-11-09 ERDI Gergo <cactus cactus rulez org>
+
+ * bonobo/bonobo-storage-memory.c (smem_rename_impl):
+ (smem_open_stream_impl):
+ (smem_open_storage_impl): Do proper ref/unref stuff (you have to
+ bonobo_object_release_unref the return value of openStream/openStorage)
+
+2001-11-07 ERDI Gergo <cactus cactus rulez org>
+
+ * bonobo/bonobo-storage-memory.c (split_path): use new GLib
+ g_strsplit API
+
+ * tests/test-storage-mem.c: more intelligent counting of number of
+ tests
+
2001-11-08 Michael Meeks <michael ximian com>
* idl/Bonobo_UI.idl: more spelling fixage from Darin.
Index: bonobo/bonobo-storage-memory.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-storage-memory.c,v
retrieving revision 1.6
diff -u -u -r1.6 bonobo-storage-memory.c
--- bonobo/bonobo-storage-memory.c 2001/10/31 04:03:51 1.6
+++ bonobo/bonobo-storage-memory.c 2001/11/08 23:09:06
@@ -41,7 +41,7 @@
{
BonoboStorageMemEntry *entry = (BonoboStorageMemEntry*) data;
- if (!data)
+ if (!entry)
return;
bonobo_object_unref (entry->child);
@@ -72,7 +72,7 @@
if (g_path_is_absolute (path))
path = g_path_skip_root (path);
- path_parts = g_strsplit (path, "/", 1);
+ path_parts = g_strsplit (path, "/", 2);
*path_head = path_parts[0];
*path_tail = path_parts[1];
@@ -110,10 +110,9 @@
/* No child is found */
if (!entry) {
g_free (path_head);
- g_free (path_tail);
if (filename)
- *filename = NULL;
+ *filename = path_tail;
if (ret_entry)
*ret_entry = NULL;
@@ -391,20 +390,20 @@
CORBA_Environment *ev)
{
BonoboStorageMem *storage;
- BonoboStorageMem *last_storage;
+ BonoboStorageMem *parent;
BonoboStorageMemEntry *entry;
gchar *path_last;
BonoboObject *stream = NULL;
storage = BONOBO_STORAGE_MEM (bonobo_object (servant));
- last_storage = smem_get_last_storage (storage, path, &path_last);
+ parent = smem_get_last_storage (storage, path, &path_last);
- if (!last_storage || !path_last) {
+ if (!parent) {
bonobo_exception_set (ev, ex_Bonobo_Storage_NotFound);
goto ex_out;
}
-
- entry = g_hash_table_lookup (last_storage->priv->entries, path_last);
+
+ entry = g_hash_table_lookup (parent->priv->entries, path_last);
/* Error cases */
/* Case 1: Stream not found */
@@ -429,7 +428,7 @@
entry->is_directory = FALSE;
entry->child = stream;
- g_hash_table_insert (last_storage->priv->entries,
+ g_hash_table_insert (parent->priv->entries,
g_strdup (path_last),
entry);
goto ok_out;
@@ -440,7 +439,8 @@
ok_out:
g_free (path_last);
- return bonobo_object_corba_objref (stream);
+ return bonobo_object_dup_ref (bonobo_object_corba_objref (stream),
+ NULL);
ex_out:
g_free (path_last);
@@ -504,7 +504,8 @@
ok_out:
g_free (path_last);
- return bonobo_object_corba_objref (ret);
+ return bonobo_object_dup_ref (bonobo_object_corba_objref (ret),
+ NULL);
ex_out:
g_free (path_last);
@@ -642,7 +643,6 @@
BonoboStorageMem *parent_storage, *target_storage;
BonoboStorageMemEntry *entry;
gchar *filename, *new_filename;
- BonoboStorageMemEntry *tmp_entry;
if (!strcmp (path, "/") || !strcmp (path, "")) {
bonobo_exception_set (ev, ex_Bonobo_Storage_IOError);
@@ -667,20 +667,17 @@
goto out;
}
- tmp_entry = bonobo_storage_mem_entry_dup (entry);
g_hash_table_remove (parent_storage->priv->entries, filename);
- entry = NULL;
/* If target does not exists, new_filename will be non-NULL */
if (new_filename)
g_hash_table_insert (target_storage->priv->entries,
- new_filename, tmp_entry);
+ new_filename, entry);
else
g_hash_table_insert (target_storage->priv->entries,
- g_strdup (filename), tmp_entry);
-
+ g_strdup (filename), entry);
+
out:
- bonobo_storage_mem_entry_free (entry);
g_free (filename);
}
Index: tests/test-storage-mem.c
===================================================================
RCS file: /cvs/gnome/libbonobo/tests/test-storage-mem.c,v
retrieving revision 1.3
diff -u -u -r1.3 test-storage-mem.c
--- tests/test-storage-mem.c 2001/11/05 04:56:35 1.3
+++ tests/test-storage-mem.c 2001/11/08 23:09:06
@@ -5,18 +5,19 @@
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-exception.h>
-#define NUM_TESTS 14
-
int
main (int argc, char *argv [])
{
BonoboObject *storage;
Bonobo_Storage corba_storage;
+ Bonobo_Storage ret_storage;
+ Bonobo_Stream ret_stream;
CORBA_Environment real_ev, *ev;
Bonobo_StorageInfo *info;
Bonobo_Storage_DirectoryList *dir_list;
int num_ok = 0;
-
+ int num_tests = 0;
+
ev = &real_ev;
if (!bonobo_init (&argc, argv))
@@ -28,10 +29,11 @@
CORBA_exception_init (ev);
printf ("creating storage:\t");
- Bonobo_Storage_openStorage (corba_storage,
- "/foo",
- Bonobo_Storage_CREATE,
- ev);
+ num_tests++;
+ ret_storage = Bonobo_Storage_openStorage (corba_storage,
+ "/foo",
+ Bonobo_Storage_CREATE,
+ ev);
if (!BONOBO_EX (ev)) {
printf ("passed\t'/foo'\n");
num_ok++;
@@ -39,51 +41,59 @@
printf ("failed\t'/foo'\n");
CORBA_exception_free (ev);
}
+ bonobo_object_release_unref (ret_storage, NULL);
printf ("creating sub-storage:\t");
- Bonobo_Storage_openStorage (corba_storage,
- "/foo/bar",
- Bonobo_Storage_CREATE,
- ev);
+ num_tests++;
+ ret_stream = Bonobo_Storage_openStorage (corba_storage,
+ "/foo/bar",
+ Bonobo_Storage_CREATE,
+ ev);
if (!BONOBO_EX (ev)) {
printf ("passed\t'/foo/bar'\n");
num_ok++;
} else {
- printf ("failed\t'/foo/bar'\n");
+ printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
+ bonobo_object_release_unref (ret_stream, NULL);
printf ("creating stream:\t");
- Bonobo_Storage_openStream (corba_storage,
- "/foo/bar/baz",
- Bonobo_Storage_CREATE,
- ev);
+ num_tests++;
+ ret_stream = Bonobo_Storage_openStream (corba_storage,
+ "/foo/bar/baz",
+ Bonobo_Storage_CREATE,
+ ev);
if (!BONOBO_EX (ev)) {
printf ("passed\t'/foo/bar/baz'\n");
num_ok++;
} else {
- printf ("failed\t'/foo/bar/baz'\n");
+ printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
+ bonobo_object_release_unref (ret_stream, NULL);
printf ("creating stream:\t");
- Bonobo_Storage_openStream (corba_storage,
- "/foo/quux",
- Bonobo_Storage_CREATE,
- ev);
+ num_tests++;
+ ret_stream = Bonobo_Storage_openStream (corba_storage,
+ "/foo/quux",
+ Bonobo_Storage_CREATE,
+ ev);
if (!BONOBO_EX (ev)) {
printf ("passed\t'/foo/quux'\n");
num_ok++;
} else {
- printf ("failed\t'/foo/quux'\n");
+ printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
+ bonobo_object_release_unref (ret_stream, NULL);
printf ("opening stream:\t\t");
- Bonobo_Storage_openStream (corba_storage,
- "/foo/quux",
- Bonobo_Storage_READ,
- ev);
+ num_tests++;
+ ret_stream = Bonobo_Storage_openStream (corba_storage,
+ "/foo/quux",
+ Bonobo_Storage_READ,
+ ev);
if (!BONOBO_EX (ev)) {
printf ("passed\n");
num_ok++;
@@ -91,8 +101,10 @@
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
+ bonobo_object_release_unref (ret_stream, NULL);
printf ("opening missing stream:\t");
+ num_tests++;
Bonobo_Storage_openStream (corba_storage,
"/foo/dummy",
Bonobo_Storage_READ,
@@ -100,6 +112,7 @@
if (BONOBO_EX (ev) &&
!strcmp (BONOBO_EX_REPOID (ev), ex_Bonobo_Storage_NotFound)) {
printf ("passed\n");
+ CORBA_exception_free (ev);
num_ok++;
} else {
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
@@ -107,6 +120,7 @@
}
printf ("rename (storage):\t");
+ num_tests++;
Bonobo_Storage_rename (corba_storage,
"/foo", "/renamed",
ev);
@@ -119,15 +133,17 @@
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
-
+
+#if 1
printf ("getInfo (storage):\t");
+ num_tests++;
info = Bonobo_Storage_getInfo (corba_storage,
"/renamed",
Bonobo_FIELD_TYPE,
ev);
if (!BONOBO_EX (ev)) {
printf ("passed\n");
- printf ("\t\t\t\tname:\t%s\n", info->name);
+ printf ("\t\t\t\tname:\t'%s'\n", info->name);
printf ("\t\t\t\ttype:\t%s\n",
info->type ? "storage" : "stream" );
@@ -139,13 +155,14 @@
}
printf ("getInfo (stream):\t");
+ num_tests++;
info = Bonobo_Storage_getInfo (corba_storage,
"/renamed/quux",
Bonobo_FIELD_TYPE | Bonobo_FIELD_SIZE | Bonobo_FIELD_CONTENT_TYPE,
ev);
if (!BONOBO_EX (ev)) {
printf ("passed\n");
- printf ("\t\t\t\tname:\t%s\n", info->name);
+ printf ("\t\t\t\tname:\t'%s'\n", info->name);
printf ("\t\t\t\ttype:\t%s\n",
info->type ? "storage" : "stream" );
printf ("\t\t\t\tmime:\t%s\n", info->content_type);
@@ -159,6 +176,7 @@
}
printf ("getInfo (root):\t\t");
+ num_tests++;
info = Bonobo_Storage_getInfo (corba_storage,
"/",
Bonobo_FIELD_TYPE,
@@ -176,9 +194,9 @@
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
-
printf ("listContents:\t\t");
+ num_tests++;
dir_list = Bonobo_Storage_listContents (corba_storage,
"/renamed",
0,
@@ -202,6 +220,7 @@
}
printf ("erase (stream):\t\t");
+ num_tests++;
Bonobo_Storage_erase (corba_storage,
"/renamed/bar/baz",
ev);
@@ -214,20 +233,21 @@
}
printf ("erase (empty storage):\t");
+ num_tests++;
Bonobo_Storage_erase (corba_storage,
"/renamed/bar",
ev);
- if (BONOBO_EX (ev) &&
- !strcmp (BONOBO_EX_REPOID (ev), ex_Bonobo_Storage_NotFound)) {
+ if (!BONOBO_EX (ev)) {
printf ("passed\n");
+ CORBA_exception_free (ev);
num_ok++;
} else {
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
-
-
+
printf ("getInfo (dltd stream):\t");
+ num_tests++;
info = Bonobo_Storage_getInfo (
corba_storage,
"/renamed/bar/baz",
@@ -238,28 +258,30 @@
!strcmp (BONOBO_EX_REPOID (ev), ex_Bonobo_Storage_NotFound)) {
printf ("passed\n");
num_ok++;
+ CORBA_exception_free (ev);
} else {
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
printf ("getInfo (dltd storage):\t");
+ num_tests++;
info = Bonobo_Storage_getInfo (corba_storage,
"/renamed/bar",
Bonobo_FIELD_TYPE,
ev);
-
if (BONOBO_EX (ev) &&
!strcmp (BONOBO_EX_REPOID (ev), ex_Bonobo_Storage_NotFound)) {
printf ("passed\n");
+ CORBA_exception_free (ev);
num_ok++;
} else {
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
-
printf ("listContents (deleted):\t");
+ num_tests++;
dir_list = Bonobo_Storage_listContents (corba_storage,
"/renamed/bar",
0, ev);
@@ -268,21 +290,23 @@
!strcmp (BONOBO_EX_REPOID (ev), ex_Bonobo_Storage_NotFound)) {
printf ("passed\n");
num_ok++;
+ CORBA_exception_free (ev);
} else {
printf ("failed: %s\n", BONOBO_EX_REPOID (ev));
CORBA_exception_free (ev);
}
-
CORBA_exception_free (ev);
-
- printf ("%d of %d tests passed\n", num_ok, NUM_TESTS);
+#endif
+
+ printf ("%d of %d tests passed\n", num_ok, num_tests);
- if (num_ok != NUM_TESTS)
+ if (num_ok != num_tests)
return 1;
-
- printf ("FIXME: these tests fail, there is much brokenness "
- "and leakage in bonobo-storage-memory.c\n");
-/* return bonobo_debug_shutdown (); */
+ bonobo_object_unref (BONOBO_OBJECT (storage));
+
+ printf ("FIXME: bonobo-storage-memory is just too perfect!\n");
+
+ /* return bonobo_debug_shutdown (); */
return 0;
}
--
.--= ULLA! =---------------------. `We are not here to give users what
\ http://cactus.rulez.org \ they want' -- RMS, at GUADEC 2001
`---= cactus cactus rulez org =---'
How did the fool and his money get together in the first place?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]