From bb3097cb2266b55719b955c93d09a0e2d6f8eccb Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sun, 15 Feb 2009 17:15:29 +0100 Subject: Add more regression test and fix Integer and Real type handling. --- src/plist.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src/plist.c') diff --git a/src/plist.c b/src/plist.c index 0e73c4b..e800b5c 100644 --- a/src/plist.c +++ b/src/plist.c @@ -414,3 +414,70 @@ void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec) *sec = val.tv_sec; *usec = val.tv_usec; } + +gboolean plist_data_compare(gconstpointer a, gconstpointer b) +{ + plist_data_t val_a = NULL; + plist_data_t val_b = NULL; + + if (!a || !b) + return FALSE; + + if (!((GNode *) a)->data || !((GNode *) b)->data) + return FALSE; + + val_a = plist_get_data((plist_t) a); + val_b = plist_get_data((plist_t) b); + + if (val_a->type != val_b->type) + return FALSE; + + switch (val_a->type) { + case PLIST_BOOLEAN: + case PLIST_UINT: + case PLIST_REAL: + if (val_a->intval == val_b->intval) //it is an union so this is sufficient + return TRUE; + else + return FALSE; + + case PLIST_KEY: + case PLIST_STRING: + if (!strcmp(val_a->strval, val_b->strval)) + return TRUE; + else + return FALSE; + case PLIST_UNICODE: + if (!memcmp(val_a->unicodeval, val_b->unicodeval, val_a->length)) + return TRUE; + else + return FALSE; + + case PLIST_DATA: + if (!memcmp(val_a->buff, val_b->buff, val_a->length)) + return TRUE; + else + return FALSE; + case PLIST_ARRAY: + case PLIST_DICT: + //compare pointer + if (a == b) + return TRUE; + else + return FALSE; + break; + case PLIST_DATE: + if (!memcmp(&(val_a->timeval), &(val_b->timeval), sizeof(GTimeVal))) + return TRUE; + else + return FALSE; + default: + break; + } + return FALSE; +} + +char plist_compare_node_value(plist_t node_l, plist_t node_r) +{ + return plist_data_compare( node_l , node_r ); +} -- cgit v1.1-32-gdbae