2
0

tst-jid.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* iksemel (XML parser for Jabber)
  2. ** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
  3. ** This code is free software; you can redistribute it and/or
  4. ** modify it under the terms of GNU Lesser General Public License.
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <locale.h>
  10. #include "iksemel.h"
  11. ikstack *my_stack;
  12. void
  13. print_id (iksid *id)
  14. {
  15. printf (" Full: [%s]\n Partial: [%s]\n User: [%s]\n Server: [%s]\n Resource: [%s]\n",
  16. id->full, id->partial, id->user, id->server, id->resource);
  17. }
  18. #define BUG(x) { print_id ( (x) ); exit (1); }
  19. void
  20. test_id (char *id, char *partial, char *user, char *server, char *resource)
  21. {
  22. iksid *a;
  23. a = iks_id_new (my_stack, id);
  24. if ((a->partial || partial) && iks_strcmp (a->partial, partial) != 0) BUG(a);
  25. if ((a->user || user) && iks_strcmp (a->user, user) != 0) BUG(a);
  26. if ((a->server || server) && iks_strcmp (a->server, server) != 0) BUG(a);
  27. if ((a->resource || resource) && iks_strcmp (a->resource, resource) != 0) BUG(a);
  28. }
  29. void
  30. test_cmp (char *stra, char *strb, int parts, int diff)
  31. {
  32. iksid *a, *b;
  33. a = iks_id_new (my_stack, stra);
  34. b = iks_id_new (my_stack, strb);
  35. if (diff != iks_id_cmp (a, b, parts)) exit (1);
  36. }
  37. int main (int argc, char *argv[])
  38. {
  39. my_stack = iks_stack_new (1024, 1024);
  40. test_id ("jabber:madcat@jabber.org/cabbar", "madcat@jabber.org", "madcat", "jabber.org", "cabbar");
  41. test_id ("bob@silent.org", "bob@silent.org", "bob", "silent.org", NULL);
  42. test_cmp ("dante@jabber.org/hell", "dante@jabber.org/heaven", IKS_ID_PARTIAL, 0);
  43. test_cmp ("madcat@jabber.org/cabbar", "madcat@jabber.org/jabberx", IKS_ID_FULL, IKS_ID_RESOURCE);
  44. test_cmp ("dean@unseen.edu/pda", "librarian@unseen.edu/jabberx", IKS_ID_FULL, IKS_ID_USER | IKS_ID_RESOURCE);
  45. test_cmp ("patrician@morpork.gov/gabber", "cohen@guild.org/gsm", IKS_ID_FULL, IKS_ID_FULL);
  46. test_cmp ("peter@family.com", "peter@family.com/clam", IKS_ID_PARTIAL, 0);
  47. iks_stack_delete (&my_stack);
  48. return 0;
  49. }