tst-iks.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. int main (int argc, char *argv[])
  12. {
  13. static char xml[] =
  14. "<iq type='result' to='ydobon@jabber.org'><query xmlns='jabber:iq:version'>"
  15. "<name>TestClient</name><os>SuxOS 2000</os><version><stable solidity='rock'/>"
  16. "1.2.0 patchlevel 2</version></query></iq>";
  17. static char xml2[] =
  18. "<Ni><C/>lala<br/><A/>Hello World<B/></Ni>";
  19. iks *x, *y, *z;
  20. char *t;
  21. setlocale (LC_ALL, "");
  22. x = iks_new ("iq");
  23. iks_insert_attrib (x, "type", "resultypo");
  24. iks_insert_attrib (x, "type", "result");
  25. iks_insert_attrib (x, "to", "ydobon@jabber.org");
  26. y = iks_new_within ("query", iks_stack (x));
  27. iks_insert_cdata (iks_insert (y, "name"), "TestClient", 10);
  28. iks_insert_cdata (iks_insert (y, "os"), "SuxOS", 0);
  29. z = iks_insert (y, "version");
  30. iks_insert (z, "stable");
  31. iks_insert_cdata (z, "1.2", 3);
  32. iks_insert_cdata (z, ".0 patchlevel 2", 0);
  33. iks_insert_node (x, y);
  34. z = iks_find (y, "os");
  35. iks_insert_attrib (z, "error", "yes");
  36. iks_insert_attrib (z, "error", NULL);
  37. iks_insert_cdata (z, " 2000", 5);
  38. z = iks_next (z);
  39. z = iks_find (z, "stable");
  40. iks_insert_attrib (z, "solidity", "rock");
  41. z = iks_parent (iks_parent (z));
  42. iks_insert_attrib (z, "xmlns", "jabber:iq:version");
  43. t = iks_string (iks_stack (x), x);
  44. if(!t || strcmp(t, xml) != 0) {
  45. printf("Result: %s\n", t);
  46. printf("Expected: %s\n", xml);
  47. return 1;
  48. }
  49. iks_delete(x);
  50. x = iks_new ("Ni");
  51. y = iks_insert (x, "br");
  52. z = iks_prepend_cdata (y, "lala", 4);
  53. iks_prepend (z, "C");
  54. z = iks_insert_cdata (x, "Hello", 5);
  55. y = iks_append (z, "B");
  56. iks_prepend (z, "A");
  57. iks_append_cdata (z, " ", 1);
  58. iks_prepend_cdata (y, "World", 5);
  59. t = iks_string (iks_stack (x), x);
  60. if(!t || strcmp(t, xml2) != 0) {
  61. printf("Result: %s\n", t);
  62. printf("Expected: %s\n", xml2);
  63. return 1;
  64. }
  65. iks_delete(x);
  66. return 0;
  67. }