[gnome-keyring/gck-work] [gck] Add gck_attributes_add_all() for copying GckAttributes



commit a2cd618604d6b5f599e0e6452c5adb596cba43ff
Author: Stef Walter <stef memberwebs com>
Date:   Sat Sep 18 17:13:02 2010 +0000

    [gck] Add gck_attributes_add_all() for copying GckAttributes
    
    New function allows deep copying of a GckAttributes array.

 gck/gck-attributes.c            |   16 ++++++++++++++++
 gck/gck.h                       |    3 +++
 gck/tests/test-gck-attributes.c |   23 +++++++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/gck/gck-attributes.c b/gck/gck-attributes.c
index eb5b3aa..0c33fc1 100644
--- a/gck/gck-attributes.c
+++ b/gck/gck-attributes.c
@@ -1003,6 +1003,22 @@ gck_attributes_add_ulong (GckAttributes *attrs, gulong attr_type, gulong value)
 	return added;
 }
 
+void
+gck_attributes_add_all (GckAttributes *attrs, GckAttributes *from)
+{
+	GckAttribute *attr;
+	guint i;
+
+	g_return_if_fail (attrs && attrs->array);
+	g_return_if_fail (from && from->array);
+	g_return_if_fail (!attrs->locked);
+
+	for (i = 0; i < from->array->len; ++i) {
+		attr = &g_array_index (from->array, GckAttribute, i);
+		gck_attributes_add (attrs, attr);
+	}
+}
+
 /**
  * gck_attributes_count:
  * @attrs: The attributes array to count.
diff --git a/gck/gck.h b/gck/gck.h
index f4b321d..153d23c 100644
--- a/gck/gck.h
+++ b/gck/gck.h
@@ -175,6 +175,9 @@ GckAttribute*       gck_attributes_at                       (GckAttributes *attr
 GckAttribute*       gck_attributes_add                      (GckAttributes *attrs,
                                                              GckAttribute *attr);
 
+void                gck_attributes_add_all                  (GckAttributes *attrs,
+                                                             GckAttributes *from);
+
 GckAttribute*       gck_attributes_add_data                 (GckAttributes *attrs,
                                                              gulong attr_type,
                                                              gconstpointer value,
diff --git a/gck/tests/test-gck-attributes.c b/gck/tests/test-gck-attributes.c
index e24b897..be6998c 100644
--- a/gck/tests/test-gck-attributes.c
+++ b/gck/tests/test-gck-attributes.c
@@ -462,6 +462,29 @@ DEFINE_TEST(add_attributes)
 	gck_attributes_unref (attrs);
 }
 
+DEFINE_TEST(add_all_attributes)
+{
+	GckAttributes *attrs;
+	GckAttributes *copy;
+	GDate *date = g_date_new_dmy (11, 12, 2008);
+	attrs = gck_attributes_new ();
+	gck_attributes_add_boolean (attrs, 0UL, TRUE);
+	gck_attributes_add_ulong (attrs, 101UL, 888);
+	gck_attributes_add_string (attrs, 202UL, "string");
+	gck_attributes_add_date (attrs, 303UL, date);
+	g_date_free (date);
+	gck_attributes_add_data (attrs, 404UL, ATTR_DATA, N_ATTR_DATA);
+	gck_attributes_add_invalid (attrs, 505UL);
+	gck_attributes_add_empty (attrs, 606UL);
+
+	copy = gck_attributes_new ();
+	gck_attributes_add_all (copy, attrs);
+	test_attributes_contents (copy, TRUE);
+
+	gck_attributes_unref (attrs);
+	gck_attributes_unref (copy);
+}
+
 
 DEFINE_TEST(find_attributes)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]