From ddf5c42f67757000d6ec7686b92a667c2a252dca Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 23 Oct 2009 04:29:39 +0000 Subject: Imported from iksemel-1.3.tar.gz. --- test/tst-ikstack.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/tst-ikstack.c (limited to 'test/tst-ikstack.c') diff --git a/test/tst-ikstack.c b/test/tst-ikstack.c new file mode 100644 index 0000000..9e8459f --- /dev/null +++ b/test/tst-ikstack.c @@ -0,0 +1,54 @@ +/* iksemel (XML parser for Jabber) +** Copyright (C) 2000-2004 Gurer Ozen +** This code is free software; you can redistribute it and/or +** modify it under the terms of GNU Lesser General Public License. +*/ + +#include +#include +#include + +#include "iksemel.h" + +struct align_test { char a; double b; }; +#define DEFAULT_ALIGNMENT ((size_t) ((char *) &((struct align_test *) 0)->b - (char *) 0)) +#define ALIGN_MASK ( DEFAULT_ALIGNMENT - 1 ) + +const char buf[] = "1234567890abcdefghijklmnopqrstuv"; + +void +test_stack (int cs) +{ + ikstack *s; + char *mem, *old; + int i; + + s = iks_stack_new (cs, cs); + old = NULL; + for (i = 0; i < strlen (buf); i++) { + iks_stack_strdup (s, buf, i); + mem = iks_stack_alloc (s, i); + if (((unsigned long) mem) & ALIGN_MASK) { + printf ("ikstack bug, addr %p should be a multiply of %d\n", + mem, DEFAULT_ALIGNMENT); + exit (1); + } + memset (mem, 'x', i); + old = iks_stack_strcat (s, old, 0, buf + i, 1); + } + if (strcmp (old, buf) != 0) { + printf ("ikstack strcat bug:\nExpected: %s\n Result: %s\n", buf, old); + exit (1); + } + iks_stack_delete (s); +} + +int main (int argc, char *argv[]) +{ + test_stack (0); + test_stack (16); + test_stack (237); + test_stack (1024); + + return 0; +} -- cgit