You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rspamd_fuzzy_test.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "config.h"
  2. #include "main.h"
  3. #include "fuzzy.h"
  4. #include "tests.h"
  5. static char *s1 = "This is sample test text.\r\n"
  6. "abcdefghijklmnopqrstuvwx.\r\n"
  7. "abcdefghijklmnopqrstuvwx.\r\n"
  8. "abcdefghijklmnopqrstuvwx.\r\n"
  9. "abcdefghijklmnopqrstuvwx.\r\n"
  10. "abcdefghijklmnopqrstuvwx.\r\n"
  11. "abcdefghijklmnopqrstuvwx.\r\n"
  12. "abcdefghijklmnopqrstuvwx.\r\n"
  13. "abcdefghijklmnopqrstuvwx.\r\n";
  14. static char *s2 = "This is sample test text.\r\n"
  15. "abcdefghijklmnopqrstuvwx.\r\n"
  16. "abcdefghijklmnopzrstuvwx.\r\n"
  17. "abcdefghijklmnopqrstuvwx.\r\n"
  18. "abcdefghijklmnopqrstuvwx.\r\n"
  19. "abcdefghijklmnopqrstuvwx.\r\n"
  20. "abcdefghijklmnopqrstuvwx.\r\n"
  21. "abcdefghijklmnopqrstuvwx.\r\n"
  22. "abcdefghijklmnopqrstuvwx.\r\n";
  23. static char *s3 = "";
  24. static char *s4 = "abcdefghijklmn\r\n";
  25. static char *s5 = "This is sample test text.\r\n"
  26. "abcdefghijklmnopqrstuvwx.\r\n"
  27. "abcdefghijklmnopzrstuvwx.\r\n"
  28. "abcdefghijklmnopqrstuvwx.\r\n"
  29. "abcdefghijklmnopqrstuvwx.\r\n"
  30. "abcdefghijklmnopqrstuvwx.\r\n"
  31. "abcdefghijklmnopqrstuvwx.\r\n"
  32. "abcdefghijklmnopqrstuvwx.\r\n"
  33. "abcdefghijklmnopqrstuvwx.\r\n";
  34. void
  35. rspamd_fuzzy_test_func ()
  36. {
  37. rspamd_mempool_t *pool;
  38. rspamd_fuzzy_t *h1, *h2, *h3, *h4, *h5;
  39. rspamd_fstring_t f1, f2, f3, f4, f5;
  40. int diff2;
  41. pool = rspamd_mempool_new (1024);
  42. f1.begin = s1;
  43. f1.len = strlen (s1);
  44. f2.begin = s2;
  45. f2.len = strlen (s2);
  46. f3.begin = s3;
  47. f3.len = strlen (s3);
  48. f4.begin = s4;
  49. f4.len = strlen (s4);
  50. f5.begin = s5;
  51. f5.len = strlen (s5);
  52. h1 = rspamd_fuzzy_init (&f1, pool);
  53. h2 = rspamd_fuzzy_init (&f2, pool);
  54. h3 = rspamd_fuzzy_init (&f3, pool);
  55. h4 = rspamd_fuzzy_init (&f4, pool);
  56. h5 = rspamd_fuzzy_init (&f5, pool);
  57. diff2 = rspamd_fuzzy_compare (h2, h5);
  58. msg_debug ("rspamd_fuzzy_test_func: s1, s2 difference between strings is %d", rspamd_fuzzy_compare (h1, h2));
  59. msg_debug ("rspamd_fuzzy_test_func: s1, s3 difference between strings is %d", rspamd_fuzzy_compare (h1, h3));
  60. msg_debug ("rspamd_fuzzy_test_func: s3, s4 difference between strings is %d", rspamd_fuzzy_compare (h3, h4));
  61. msg_debug ("rspamd_fuzzy_test_func: s2, s4 difference between strings is %d", rspamd_fuzzy_compare (h2, h4));
  62. msg_debug ("rspamd_fuzzy_test_func: s2, s5 difference between strings is %d", diff2);
  63. /* Identical strings */
  64. if (diff2 != 100) {
  65. msg_err ("hash difference is %d", diff2);
  66. g_assert (diff2 == 100);
  67. }
  68. rspamd_mempool_delete (pool);
  69. }