diff options
| author | 2009-02-15 17:15:29 +0100 | |
|---|---|---|
| committer | 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) | |||
| 414 | *sec = val.tv_sec; | 414 | *sec = val.tv_sec; |
| 415 | *usec = val.tv_usec; | 415 | *usec = val.tv_usec; |
| 416 | } | 416 | } |
| 417 | |||
| 418 | gboolean plist_data_compare(gconstpointer a, gconstpointer b) | ||
| 419 | { | ||
| 420 | plist_data_t val_a = NULL; | ||
| 421 | plist_data_t val_b = NULL; | ||
| 422 | |||
| 423 | if (!a || !b) | ||
| 424 | return FALSE; | ||
| 425 | |||
| 426 | if (!((GNode *) a)->data || !((GNode *) b)->data) | ||
| 427 | return FALSE; | ||
| 428 | |||
| 429 | val_a = plist_get_data((plist_t) a); | ||
| 430 | val_b = plist_get_data((plist_t) b); | ||
| 431 | |||
| 432 | if (val_a->type != val_b->type) | ||
| 433 | return FALSE; | ||
| 434 | |||
| 435 | switch (val_a->type) { | ||
| 436 | case PLIST_BOOLEAN: | ||
| 437 | case PLIST_UINT: | ||
| 438 | case PLIST_REAL: | ||
| 439 | if (val_a->intval == val_b->intval) //it is an union so this is sufficient | ||
| 440 | return TRUE; | ||
| 441 | else | ||
| 442 | return FALSE; | ||
| 443 | |||
| 444 | case PLIST_KEY: | ||
| 445 | case PLIST_STRING: | ||
| 446 | if (!strcmp(val_a->strval, val_b->strval)) | ||
| 447 | return TRUE; | ||
| 448 | else | ||
| 449 | return FALSE; | ||
| 450 | case PLIST_UNICODE: | ||
| 451 | if (!memcmp(val_a->unicodeval, val_b->unicodeval, val_a->length)) | ||
| 452 | return TRUE; | ||
| 453 | else | ||
| 454 | return FALSE; | ||
| 455 | |||
| 456 | case PLIST_DATA: | ||
| 457 | if (!memcmp(val_a->buff, val_b->buff, val_a->length)) | ||
| 458 | return TRUE; | ||
| 459 | else | ||
| 460 | return FALSE; | ||
| 461 | case PLIST_ARRAY: | ||
| 462 | case PLIST_DICT: | ||
| 463 | //compare pointer | ||
| 464 | if (a == b) | ||
| 465 | return TRUE; | ||
| 466 | else | ||
| 467 | return FALSE; | ||
| 468 | break; | ||
| 469 | case PLIST_DATE: | ||
| 470 | if (!memcmp(&(val_a->timeval), &(val_b->timeval), sizeof(GTimeVal))) | ||
| 471 | return TRUE; | ||
| 472 | else | ||
| 473 | return FALSE; | ||
| 474 | default: | ||
| 475 | break; | ||
| 476 | } | ||
| 477 | return FALSE; | ||
| 478 | } | ||
| 479 | |||
| 480 | char plist_compare_node_value(plist_t node_l, plist_t node_r) | ||
| 481 | { | ||
| 482 | return plist_data_compare( node_l , node_r ); | ||
| 483 | } | ||
