tst-ikstack.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* iksemel (XML parser for Jabber)
  2. ** Copyright (C) 2000-2004 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 "iksemel.h"
  10. struct align_test { char a; double b; };
  11. #define DEFAULT_ALIGNMENT ((size_t) ((char *) &((struct align_test *) 0)->b - (char *) 0))
  12. #define ALIGN_MASK ( DEFAULT_ALIGNMENT - 1 )
  13. const char buf[] = "1234567890abcdefghijklmnopqrstuv";
  14. void
  15. test_stack (int cs)
  16. {
  17. ikstack *s;
  18. char *mem, *old;
  19. int i;
  20. s = iks_stack_new (cs, cs);
  21. old = NULL;
  22. for (i = 0; i < strlen (buf); i++) {
  23. iks_stack_strdup (s, buf, i);
  24. mem = iks_stack_alloc (s, i);
  25. if (((unsigned long) mem) & ALIGN_MASK) {
  26. printf ("ikstack bug, addr %p should be a multiply of %d\n",
  27. mem, DEFAULT_ALIGNMENT);
  28. exit (1);
  29. }
  30. memset (mem, 'x', i);
  31. old = iks_stack_strcat (s, old, 0, buf + i, 1);
  32. }
  33. if (strcmp (old, buf) != 0) {
  34. printf ("ikstack strcat bug:\nExpected: %s\n Result: %s\n", buf, old);
  35. exit (1);
  36. }
  37. iks_stack_delete (&s);
  38. }
  39. int main (int argc, char *argv[])
  40. {
  41. test_stack (0);
  42. test_stack (16);
  43. test_stack (237);
  44. test_stack (1024);
  45. return 0;
  46. }