Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of libdom test suite.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
  6.  */
  7.  
  8. #include "comparators.h"
  9. #include "domts.h"
  10.  
  11. #include <string.h>
  12.  
  13. #include <dom/dom.h>
  14.  
  15. /* Compare to integer, return zero if equal */
  16. int int_comparator(const void* a, const void* b) {
  17.         return *((const int *)a) - *((const int *)b);
  18. }
  19.  
  20. /* Compare two string. The first one is a char * and the second
  21.  * one is a dom_string, return zero if equal */
  22. int str_cmp(const void *a, const void *b)
  23. {
  24.         const uint8_t *expected = (const uint8_t *) a;
  25.         dom_string *actual = (dom_string *) b;
  26.         dom_string *exp;
  27.         dom_exception err;
  28.         bool ret;
  29.  
  30.         err = dom_string_create(expected, strlen((const char *)expected),
  31.                         &exp);
  32.         if (err != DOM_NO_ERR)
  33.                 return false;
  34.  
  35.         ret = dom_string_isequal(exp, actual);
  36.        
  37.         dom_string_unref(exp);
  38.  
  39.         if (ret == true)
  40.                 return 0;
  41.         else
  42.                 return 1;
  43. }
  44.  
  45. /* Similar with str_cmp but the first param is a dom_string the second
  46.  * param is a char *  */
  47. int str_cmp_r(const void *a, const void *b)
  48. {
  49.         return str_cmp(b, a);
  50. }
  51.  
  52. /* Similar with str_cmp but ignore the case of letters */
  53. int str_icmp(const void *a, const void *b)
  54. {
  55.         const uint8_t *expected = (const uint8_t *) a;
  56.         dom_string *actual = (dom_string *) b;
  57.         dom_string *exp;
  58.         dom_exception err;
  59.         bool ret;
  60.  
  61.         err = dom_string_create(expected, strlen((const char *)expected),
  62.                         &exp);
  63.         if (err != DOM_NO_ERR)
  64.                 return false;
  65.  
  66.         ret = dom_string_caseless_isequal(exp, actual);
  67.        
  68.         dom_string_unref(exp);
  69.  
  70.         if (ret == true)
  71.                 return 0;
  72.         else
  73.                 return 1;
  74. }
  75.  
  76. /* Similar with str_icmp, but the param order are reverse */
  77. int str_icmp_r(const void *a, const void *b)
  78. {
  79.         return str_icmp(b, a);
  80. }
  81.