diff options
author | Jonathan Beck | 2009-02-15 17:15:29 +0100 |
---|---|---|
committer | Jonathan Beck | 2009-02-15 17:15:29 +0100 |
commit | bb3097cb2266b55719b955c93d09a0e2d6f8eccb (patch) | |
tree | 478a6dd7b31b1640d79bc645052fc9843cc74ca1 /src/plist.c | |
parent | 8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4 (diff) | |
download | libplist-bb3097cb2266b55719b955c93d09a0e2d6f8eccb.tar.gz libplist-bb3097cb2266b55719b955c93d09a0e2d6f8eccb.tar.bz2 |
Add more regression test and fix Integer and Real type handling.
Diffstat (limited to 'src/plist.c')
-rw-r--r-- | src/plist.c | 67 |
1 files changed, 67 insertions, 0 deletions
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 ); +} |