head 1.13; access; symbols XDS_0_9_3:1.13 XDS_0_9_2:1.13 XDS_0_9_1:1.12 XDS_0_9_0:1.11; locks; strict; comment @ * @; 1.13 date 2005.06.02.18.51.44; author rse; state Exp; branches; next 1.12; 1.12 date 2004.09.12.17.32.14; author rse; state Exp; branches; next 1.11; 1.11 date 2003.02.17.12.36.02; author rse; state Exp; branches; next 1.10; 1.10 date 2003.02.17.12.27.51; author rse; state Exp; branches; next 1.9; 1.9 date 2002.03.17.10.25.53; author rse; state Exp; branches; next 1.8; 1.8 date 2002.01.02.17.13.45; author rse; state Exp; branches; next 1.7; 1.7 date 2001.08.30.10.42.24; author simons; state Exp; branches; next 1.6; 1.6 date 2001.08.23.08.41.34; author simons; state Exp; branches; next 1.5; 1.5 date 2001.08.22.20.21.32; author simons; state Exp; branches; next 1.4; 1.4 date 2001.08.12.11.31.45; author rse; state Exp; branches; next 1.3; 1.3 date 2001.08.09.20.59.05; author rse; state Exp; branches; next 1.2; 1.2 date 2001.08.09.19.58.35; author rse; state Exp; branches; next 1.1; 1.1 date 2001.08.08.19.15.23; author rse; state Exp; branches; next ; desc @@ 1.13 log @Bumped year in copyright messages for year 2005. @ text @/* ** OSSP xds - Extensible Data Serialization ** Copyright (c) 2001-2005 Ralf S. Engelschall ** Copyright (c) 2001-2005 The OSSP Project ** Copyright (c) 2001-2005 Cable & Wireless ** ** This file is part of OSSP xds, an extensible data serialization ** library which can be found at http://www.ossp.org/pkg/lib/xds/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** xds_test_lib.c: test suite for library framework */ #include #include #include #include "xds_p.h" #ifdef XDS_TEST_XDS_CORE int main(int argc, char *argv[]) { xds_t *ctx[50]; size_t i; /* Open a bunch of contextes and close them again. */ for (i = 0; i < sizeof (ctx) / sizeof (xds_t *); ++i) { if (i % 2 == 0) xds_init(&ctx[i], XDS_ENCODE); else xds_init(&ctx[i], XDS_DECODE); if (ctx[i] == 0) { printf("Failed to initialize xds context: i = %d\n", i); return 1; } } for (i = 0; i < sizeof (ctx) / sizeof (xds_t *); ++i) xds_destroy(ctx[i]); #ifdef NDEBUG /* Check how the library deals with errorneous arguments. */ if (xds_init(NULL, (xds_mode_t)42) != NULL || errno != EINVAL) { printf ("Called xds_init() with invalid mode but didn't get EINVAL.\n"); return 1; } /* Call xds_destroy() with an invalid context and see whether we survive that. */ xds_destroy(NULL); #endif /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_CORE */ #ifdef XDS_TEST_XDS_REGISTER static int dummy_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { return 0; } int main(int argc, char *argv[]) { const char *test_names[] = { "foo", "bar", "zarah", "caesar", "claus", "heinz", }; size_t test_names_len = sizeof (test_names) / sizeof (char *); xds_t *xds; size_t i; /* Create context. */ if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } /* Register the dummy callback under an invalid name to see whether the routine fails correctly. */ if (xds_register(xds, "abcdefh1230#", &dummy_engine, NULL) != XDS_ERR_INVALID_ARG) { printf ("xds_register() illegally accepted an invalid name for the engine.\n"); return 1; } /* Register the dummy callback under multiple names. */ for (i = 0; i < test_names_len; ++i) { if (xds_register(xds, test_names[i], &dummy_engine, NULL) != XDS_OK) { printf("Failed to register engine for '%s'.\n", test_names[i]); return 1; } } /* Register the callback again, overwriting an existing entry. */ if (xds_register(xds, "claus", &dummy_engine, NULL) != XDS_OK) { printf("Failed to re-register engine for 'claus'.\n"); return 1; } /* Ensure that everything is in alphabetical order. */ for (i = 1; i < xds->engines_len; ++i) { assert(xds->engines[i - 1].name != NULL); assert(xds->engines[i].name != NULL); if (strcmp(xds->engines[i - 1].name, xds->engines[i].name) >= 0) { printf("xds->engines is not in alphabetical order!\n"); exit(1); } } /* Try to remove an unknown entry. */ if (xds_unregister(xds, "abacadabra") != XDS_ERR_UNKNOWN_ENGINE) { printf("xds_unregister() succeeded at removing 'abacadabra' even though it is not there.\n"); exit(1); } /* Remove an entry from the middle. */ if (xds_unregister(xds, test_names[test_names_len / 2]) != XDS_OK) { printf("xds_unregister() failed to remove '%s'.\n", test_names[test_names_len / 2]); exit(1); } /* Remove the last entry. */ assert(test_names_len > 0); if (xds_unregister(xds, test_names[test_names_len - 1]) != XDS_OK) { printf("xds_unregister() failed to remove '%s'.\n", test_names[test_names_len - 1]); exit(1); } /* Remove the first entry. */ if (xds_unregister(xds, test_names[0]) != XDS_OK) { printf("xds_unregister() failed to remove '%s'.\n", test_names[0]); exit(1); } /* Clean up. */ xds_destroy(xds); /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_REGISTER */ #ifdef XDS_TEST_XDS_SETBUFFER static int dummy_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { assert(xds != NULL); assert(buffer != NULL); assert(buffer_size != 0); assert(used_buffer_size != NULL); assert(args != NULL); if (buffer_size < 64) return XDS_ERR_OVERFLOW; else *used_buffer_size = 64; memset(buffer, 'a', 64); return XDS_OK; } int main(int argc, char *argv[]) { xds_t *xds; char *buffer; size_t buffer_size; /* Create XDS context. */ if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } /* Register the callback. */ if (xds_register(xds, "dummy", &dummy_engine, NULL) != XDS_OK) { printf("Failed to register my encoding engine.\n"); return 1; } /* Give the library a buffer of 32 byte, call the engine once, get the buffer back and see whether it has been enlarged or not. */ buffer_size = 32; buffer = malloc(buffer_size); if (buffer == NULL) { printf("Failed to allocate my memory.\n"); return 1; } if (xds_setbuffer(xds, XDS_GIFT, buffer, buffer_size) != XDS_OK) { printf("xds_setbuffer() failed!\n"); return 1; } if (xds_encode(xds, "dummy") != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) != XDS_OK) { printf("xds_getbuffer() failed!\n"); return 1; } if (buffer_size < 64) { printf("xds_encode() did not enlarge the buffer after processing the callback\n"); printf("even though all capacity was used up!\n"); return 1; } /* Loan the library a buffer we own, call the engine once to exceed the buffer's capacity and check, whether the library returns the correct error code. */ buffer = malloc(32); if (buffer == NULL) { printf("Failed to allocate my memory.\n"); return 1; } buffer_size = 32; if (xds_setbuffer(xds, XDS_LOAN, buffer, buffer_size) != XDS_OK) { printf("xds_setbuffer() failed!\n"); return 1; } if (xds_encode(xds, "dummy") != XDS_ERR_OVERFLOW) { printf("xds_encode() was supposed to fail with XDS_ERR_OVERFLOW!\n"); return 1; } free(buffer); /* Clean up. */ xds_destroy(xds); /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_SETBUFFER */ #ifdef XDS_TEST_XDS_GETBUFFER static int dummy_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { if (buffer_size < 6) return XDS_ERR_OVERFLOW; else *used_buffer_size = 6; memmove(buffer, "Hallo!", 6); return XDS_OK; } int main(int argc, char *argv[]) { xds_t *xds; char *old; size_t old_len; char *new; size_t new_len; /* Create XDS context. */ if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } /* Register the dummy callback under multiple names. */ if (xds_register(xds, "text", &dummy_engine, (void *)42) != XDS_OK) { printf("Failed to register my encoding engine.\n"); return 1; } /* Encode something, then flush the buffer by calling xds_getbuffer(), then encode something new and verify that the old buffer hasn't ben overwritten and that the new one contains the correct string. */ if (xds_encode(xds, "text text") != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (xds_getbuffer(xds, XDS_GIFT, (void **)&old, &old_len) != XDS_OK) { printf("xds_getbuffer() failed for the first buffer!\n"); return 1; } if (xds_encode(xds, "text") != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (xds_getbuffer(xds, XDS_GIFT, (void **)&new, &new_len) != XDS_OK) { printf("xds_getbuffer() failed for the second buffer!\n"); return 1; } if ((memcmp(old, "Hallo!Hallo!", 12) != 0 || old_len != 12) && (memcmp(new, "Hallo!", 6) != 0 || new_len != 6)) { printf("xds_encode() did not yield the expected result.\n"); return 1; } free(old); free(new); /* Encode somthing, then get the buffer via XDS_LOAN and verify the contents. Encode something new and compare the new content with what we expect. */ if (xds_encode(xds, "text text") != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (xds_getbuffer(xds, XDS_LOAN, (void **)&old, &old_len) != XDS_OK) { printf("xds_getbuffer() failed for the first buffer!\n"); return 1; } if (memcmp(old, "Hallo!Hallo!", 12) != 0 || old_len != 12) { printf("xds_encode() did not yield the expected result.\n"); return 1; } if (xds_encode(xds, "text") != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (xds_getbuffer(xds, XDS_LOAN, (void **)&new, &new_len) != XDS_OK) { printf("xds_getbuffer() failed for the second buffer!\n"); return 1; } if (old != new) { printf ("xds_encode() allocated a new buffer even though we used XDS_LOAN.\n"); return 1; } if (memcmp(new, "Hallo!", 6) != 0 || new_len != 6) { printf("xds_encode() did not yield the expected result.\n"); return 1; } /* Clean up. */ xds_destroy(xds); /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_GETBUFFER */ #ifdef XDS_TEST_XDS_ENCODE static int dummy_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { if (xds == NULL) { printf("XDS context isn't passed through to registered engine.\n"); exit(1); } if (engine_context != (void *)42) { printf("Engine context isn't passed through to registered engine.\n"); exit(1); } if (buffer == NULL) { printf("Buffer passed to engine is NULL.\n"); exit(1); } if (buffer_size == 0) { printf("buffer_size passed to engine is zero!\n"); exit(1); } if (used_buffer_size == NULL) { printf("used_buffer_size pointer passed to engine is NULL!\n"); exit(1); } if (args == NULL) { printf("args pointer passed to engine is NULL!\n"); exit(1); } *used_buffer_size = 6; if (buffer_size < 6) return XDS_ERR_OVERFLOW; memmove(buffer, "Hallo ", 6); return XDS_OK; } int main(int argc, char *argv[]) { xds_t *xds; /* Create XDS context. */ if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } /* Register the dummy callback under multiple names. */ if (xds_register(xds, "int", &dummy_engine, (void *)42) != XDS_OK || xds_register(xds, "float", &dummy_engine, (void *)42) != XDS_OK || xds_register(xds, "double", &dummy_engine, (void *)42) != XDS_OK || xds_register(xds, "text", &dummy_engine, (void *)42) != XDS_OK) { printf("Failed to register my encoding engines.\n"); return 1; } /* Let's go and encode something. */ if (xds_encode(xds, "int:text double double float") != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (memcmp(xds->buffer, "Hallo Hallo Hallo Hallo Hallo ", 30) != 0) { printf("xds_encode() did not yield the expected result.\n"); return 1; } /* Clean up. */ xds_destroy(xds); /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_ENCODE */ #ifdef XDS_TEST_XDS_DECODE static int dummy_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { if (xds == NULL) { printf("XDS context isn't passed through to registered engine.\n"); exit(1); } if (engine_context != (void *)42) { printf("Engine context isn't passed through to registered engine.\n"); exit(1); } if (buffer == NULL) { printf("Buffer passed to engine is NULL.\n"); exit(1); } if (buffer_size == 0) { printf("Buffer size passed to engine is zero!\n"); exit(1); } if (used_buffer_size == NULL) { printf("used_buffer_size passed to engine is zero!\n"); exit(1); } if (args == NULL) { printf("args pointer passed to engine is NULL!\n"); exit(1); } if (buffer_size < 6) { printf("The buffer is too small; can't verify my encoded string.\n"); exit(1); } if (memcmp(buffer, "Hallo!", 6) != 0) { printf("The contents of the decode buffer are not what we expected.\n"); exit(1); } *used_buffer_size = 6; return XDS_OK; } int main(int argc, char *argv[]) { xds_t *xds; char buffer[] = "Hallo!Hallo!Hallo!"; /* Create XDS context. */ if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } /* Register the dummy callback under multiple names. */ if (xds_register(xds, "text", &dummy_engine, (void *)42) != XDS_OK) { printf("Failed to register my decoding engines.\n"); return 1; } /* Decode the buffer and have the callback report when something is wrong. */ if (xds_setbuffer(xds, XDS_LOAN, buffer, sizeof (buffer) - 1) != XDS_OK) { printf("xds_decode() failed!"); return 1; } if (xds_decode(xds, "text::text text") != XDS_OK) { printf("xds_decode() failed!"); return 1; } /* Clean up. */ xds_destroy(xds); /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_DECODE */ #ifdef XDS_TEST_XDS_ENGINE_RESTART static int dummy_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { if (xds == NULL) { printf("XDS context isn't passed through to registered engine.\n"); exit(1); } if (engine_context != (void *)42) { printf("Engine context isn't passed through to registered engine.\n"); exit(1); } if (buffer == NULL) { printf("Buffer passed to engine is NULL.\n"); exit(1); } if (buffer_size == 0) { printf("Buffer size passed to engine is zero!\n"); exit(1); } if (used_buffer_size == NULL) { printf("used_buffer_size pointer passed to engine is NULL!\n"); exit(1); } if (args == NULL) { printf("args pointer passed to engine is NULL!\n"); exit(1); } if (va_arg(*args, int) != 42) { printf("The varadic argument is not what the engine expected!\n"); exit(1); } if (buffer_size < 64) return XDS_ERR_OVERFLOW; else *used_buffer_size = 64; return XDS_OK; } int main(int argc, char *argv[]) { xds_t *xds; char *buffer; size_t buffer_size; /* Create an XDS context and set a buffer that's too small for the first encode() call. Then call encode() with two parameters: the one the engine is expecting and a different one after that. The engine will complain if it sees the second value -- what would mean that the args parameter was not resetted to the original value before the engine is restarted after buffer enlargement. */ if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } if (xds_register(xds, "int", &dummy_engine, (void *)42) != XDS_OK) { printf("Failed to register my encoding engines.\n"); return 1; } buffer = malloc(32); if (buffer == NULL) { printf("malloc() failed!\n"); return 1; } buffer_size = 32; if (xds_setbuffer(xds, XDS_GIFT, buffer, buffer_size) != XDS_OK) { printf("xds_setbuffer() failed!\n"); return 1; } if (xds_encode(xds, "int", 42, 13) != XDS_OK) { printf("xds_encode() failed!"); return 1; } xds_destroy(xds); return 0; } #endif /* XDS_TEST_XDS_ENGINE_RESTART */ #ifdef XDS_TEST_XDS_MYSTRUCT struct mystruct { xds_int32_t small; xds_uint32_t positive; }; static int encode_mystruct_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { struct mystruct *ms; assert(xds != NULL); assert(buffer != NULL); assert(buffer_size != 0); assert(used_buffer_size != NULL); assert(args != NULL); ms = va_arg(*args, struct mystruct *); return xds_encode(xds, "int32 uint32", ms->small, ms->positive); } static int decode_mystruct_engine(xds_t *xds, void *engine_context, void *buffer, size_t buffer_size, size_t *used_buffer_size, va_list *args) { struct mystruct *ms; assert(xds != NULL); assert(buffer != NULL); assert(buffer_size != 0); assert(used_buffer_size != NULL); assert(args != NULL); ms = va_arg(*args, struct mystruct *); return xds_decode(xds, "int32 uint32", &(ms->small), &(ms->positive)); } int main(int argc, char *argv[]) { xds_t *xds; char *buffer; size_t buffer_size; struct mystruct ms, new_ms; ms.small = -0x1234567; ms.positive = 42; /* Encode our copy of mystruct using our encoding callback. Then get a the buffer and destroy the context again. */ if (xds_init(&xds, XDS_ENCODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } if ( xds_register(xds, "mystruct", &encode_mystruct_engine, NULL) != XDS_OK || xds_register(xds, "int32", &xdr_encode_int32, NULL) != XDS_OK || xds_register(xds, "uint32", &xdr_encode_uint32, NULL) != XDS_OK) { printf("Failed to register my encoding engines.\n"); return 1; } buffer_size = 4; buffer = malloc(buffer_size); if (buffer == NULL) { printf("Failed to allocate memory for buffer.\n"); return 1; } if (xds_setbuffer(xds, XDS_GIFT, buffer, buffer_size) != XDS_OK) { printf("xds_setbuffer() failed!\n"); return 1; } if (xds_encode(xds, "mystruct", &ms) != XDS_OK) { printf("xds_encode() failed!\n"); return 1; } if (xds->buffer_capacity <= buffer_size) { printf("Buffer should have been enlarged after xds_encode()!\n"); return 1; } if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) != XDS_OK) { printf("xds_getbuffer() failed!\n"); return 1; } xds_destroy(xds); /* Now create a decoding context and decode the whole thing again. */ if (xds_init(&xds, XDS_DECODE) != XDS_OK) { printf("Failed to initialize XDS context.\n"); return 1; } if (xds_register(xds, "mystruct", &decode_mystruct_engine, NULL) != XDS_OK || xds_register(xds, "int32", &xdr_decode_int32, NULL) != XDS_OK || xds_register(xds, "uint32", &xdr_decode_uint32, NULL) != XDS_OK) { printf("Failed to register my decoding engines.\n"); return 1; } if (xds_setbuffer(xds, XDS_GIFT, buffer, buffer_size) != XDS_OK) { printf("xds_setbuffer() failed!\n"); return 1; } if (xds_decode(xds, "mystruct", &new_ms) != XDS_OK) { printf("xds_decode() failed!\n"); return 1; } xds_destroy(xds); /* Both structures must be identical. */ if (ms.small != new_ms.small || ms.positive != new_ms.positive) { printf("Decoded data does not match the original!\n"); return 1; } /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_MYSTRUCT */ @ 1.12 log @Bumped year in copyright messages for year 2004. @ text @d3 3 a5 3 ** Copyright (c) 2001-2004 Ralf S. Engelschall ** Copyright (c) 2001-2004 The OSSP Project ** Copyright (c) 2001-2004 Cable & Wireless @ 1.11 log @upgrade to standard OSSP copyright and bump year to 2003 @ text @d3 3 a5 3 ** Copyright (c) 2001-2003 Ralf S. Engelschall ** Copyright (c) 2001-2003 The OSSP Project ** Copyright (c) 2001-2003 Cable & Wireless Germany @ 1.10 log @cleanup API by returning xds_rc_t in xds_init, too @ text @d3 3 a5 2 ** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.9 log @update texts @ text @d45 1 a45 1 ctx[i] = xds_init(XDS_ENCODE); d47 1 a47 1 ctx[i] = xds_init(XDS_DECODE); d60 1 a60 1 if (xds_init((xds_mode_t) 42) != NULL || errno != EINVAL) { d101 1 a101 2 xds = xds_init(XDS_ENCODE); if (xds == NULL) { d201 1 a201 2 xds = xds_init(XDS_ENCODE); if (xds == NULL) { d289 1 a289 2 xds = xds_init(XDS_ENCODE); if (xds == NULL) { d411 1 a411 2 xds = xds_init(XDS_ENCODE); if (xds == NULL) { d492 1 a492 2 xds = xds_init(XDS_DECODE); if (xds == NULL) { d576 1 a576 2 xds = xds_init(XDS_ENCODE); if (xds == NULL) { d655 1 a655 2 xds = xds_init(XDS_ENCODE); if (xds == NULL) { d691 1 a691 2 xds = xds_init(XDS_DECODE); if (xds == NULL) { @ 1.8 log @bump copyright year @ text @d2 1 a2 1 ** XDS - OSSP Extensible Data Serialization Library d6 2 a7 2 ** This file is part of OSSP XDS, an extensible data serialization ** library which can be found at http://www.ossp.org/pkg/xds/. @ 1.7 log @Removed unnecessary debug output. @ text @d3 2 a4 2 ** Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.6 log @Removed test suite for xds_find_engine(). After the reorganisation of the build system, the routine is static and can't be accessed from outside the library anymore. @ text @a695 1 printf("The encoded representation is %u bytes long.\n", buffer_size); @ 1.5 log @Removed trailing whitespace. @ text @a76 105 #ifdef XDS_TEST_XDS_FIND_ENGINE int main(int argc, char *argv[]) { const engine_map_t engines[] = { {"alan", NULL, 0}, {"berta", NULL, 0}, {"caesar", NULL, 0}, {"doris", NULL, 0}, {"egon", NULL, 0}, {"franziska", NULL, 0}, {"gudrun", NULL, 0}, {"heinz", NULL, 0}, {"igor", NULL, 0}, {"jamila", NULL, 0}, {"karin", NULL, 0}, {"louis", NULL, 0}, }; size_t engines_len = sizeof (engines) / sizeof (engine_map_t); size_t pos; size_t i; /* Does xds_find_engine handle an empty array? */ if (xds_find_engine(engines, 0, "whatever", &pos)) { printf("xds_find_engine() said 'whatever' would be in the array, but that's wrong.\n"); exit(1); } if (pos != 0) { printf("xds_find_engine() would insert 'whatever' at position %d, but 0 is correct.\n", pos); exit(1); } /* Search for every single entry in the array and check the results. */ for (i = 0; i < engines_len; ++i) { if (!xds_find_engine(engines, engines_len, engines[i].name, &pos)) { printf("xds_find_engine() said '%s' wouldn't be in the array, but that's wrong.\n", engines[i].name); exit(1); } if (pos != i) { printf("xds_find_engine() would insert '%s' at position %d, but %d is correct.\n", engines[i].name, pos, i); exit(1); } } /* Search for non-existing name that would be inserted at the first position. */ if (xds_find_engine(engines, engines_len, "aaron", &pos)) { printf("xds_find_engine() said 'aaron' would be in the array, but that's wrong.\n"); exit(1); } if (pos != 0) { printf("xds_find_engine() would insert 'aaron' at position %d, but 0 is correct.\n", pos); exit(1); } /* Search for non-existing name that would be inserted at last position. */ if (xds_find_engine(engines, engines_len, "zerberos", &pos)) { printf("xds_find_engine() said 'zerberos' would be in the array, but that's wrong.\n"); exit(1); } if (pos != engines_len) { printf("xds_find_engine() would insert 'zerberos' at position %d, but %d is correct.\n", pos, engines_len); exit(1); } /* Search for non-existing names that would be inserted at random positions. */ if (xds_find_engine(engines, engines_len, "balthasar", &pos)) { printf("xds_find_engine() said 'balthasar' would be in the array, but that's wrong.\n"); exit(1); } if (pos != 1) { printf("xds_find_engine() would insert 'balthasar' at position %d, but 1 is correct.\n", pos); exit(1); } if (xds_find_engine(engines, engines_len, "bulli", &pos)) { printf("xds_find_engine() said 'bulli' would be in the array, but that's wrong.\n"); exit(1); } if (pos != 2) { printf("xds_find_engine() would insert 'bulli' at position %d, but 2 is correct.\n", pos); exit(1); } if (xds_find_engine(engines, engines_len, "hildegard", &pos)) { printf("xds_find_engine() said 'hildegard' would be in the array, but that's wrong.\n"); exit(1); } if (pos != 8) { printf("xds_find_engine() would insert 'hildegard' at position %d, but 8 is correct.\n", pos); exit(1); } if (xds_find_engine(engines, engines_len, "harald", &pos)) { printf("xds_find_engine() said 'harald' would be in the array, but that's wrong.\n"); exit(1); } if (pos != 7) { printf("xds_find_engine() would insert 'harald' at position %d, but 7 is correct.\n", pos); exit(1); } /* Everything went fine. */ return 0; } #endif /* XDS_TEST_XDS_FIND_ENGINE */ @ 1.4 log @Hhmm... who has introduced ossp.com?! Our project's domain is ossp.org, of course. @ text @a836 1 @ 1.3 log @Final adjustments to coding style in order to make OSSP XDS look equal in style to all other OSSP parts. This should remove most of the strangeness GNU indent usually introduces. @ text @d7 1 a7 1 ** library which can be found at http://www.ossp.com/pkg/xds/. @ 1.2 log @Use the license consistently. @ text @d37 1 a37 1 int main() a42 1 a59 1 d67 1 a67 2 * that. */ a71 1 d79 1 a79 1 int main() a99 1 d101 1 a101 2 printf ("xds_find_engine() said 'whatever' would be in the array, but that's wrong.\n"); d105 1 a105 3 printf ("xds_find_engine() would insert 'whatever' at position %d, but 0 is correct.\n", pos); a109 1 d112 1 a112 3 printf ("xds_find_engine() said '%s' wouldn't be in the array, but that's wrong.\n", engines[i].name); d116 1 a116 3 printf ("xds_find_engine() would insert '%s' at position %d, but %d is correct.\n", engines[i].name, pos, i); d122 1 a122 2 * position. */ d124 1 a124 2 printf ("xds_find_engine() said 'aaron' would be in the array, but that's wrong.\n"); d128 1 a128 3 printf ("xds_find_engine() would insert 'aaron' at position %d, but 0 is correct.\n", pos); a132 1 d134 1 a134 2 printf ("xds_find_engine() said 'zerberos' would be in the array, but that's wrong.\n"); d138 1 a138 3 printf ("xds_find_engine() would insert 'zerberos' at position %d, but %d is correct.\n", pos, engines_len); d142 1 a142 3 /* Search for non-existing names that would be inserted at random * positions. */ d144 1 a144 2 printf ("xds_find_engine() said 'balthasar' would be in the array, but that's wrong.\n"); d148 1 a148 3 printf ("xds_find_engine() would insert 'balthasar' at position %d, but 1 is correct.\n", pos); a150 1 d152 1 a152 2 printf ("xds_find_engine() said 'bulli' would be in the array, but that's wrong.\n"); d156 1 a156 3 printf ("xds_find_engine() would insert 'bulli' at position %d, but 2 is correct.\n", pos); a158 1 d160 1 a160 2 printf ("xds_find_engine() said 'hildegard' would be in the array, but that's wrong.\n"); d164 1 a164 3 printf ("xds_find_engine() would insert 'hildegard' at position %d, but 8 is correct.\n", pos); a166 1 d168 1 a168 2 printf ("xds_find_engine() said 'harald' would be in the array, but that's wrong.\n"); d172 1 a172 3 printf ("xds_find_engine() would insert 'harald' at position %d, but 7 is correct.\n", pos); a176 1 d184 1 a184 1 static int dummy_engine(xds_t * xds, void *engine_context, d186 1 a186 1 size_t * used_buffer_size, va_list * args) d191 1 a191 1 int main() a205 1 d213 1 a213 2 * routine fails correctly. */ a221 1 a229 1 a235 1 a245 1 d247 1 a247 2 printf ("xds_unregister() succeeded at removing 'abacadabra' even though it is not there.\n"); a251 1 a258 1 a266 1 a272 1 a275 1 d283 1 a283 1 static int dummy_engine(xds_t * xds, void *engine_context, d285 1 a285 1 size_t * used_buffer_size, va_list * args) d300 1 a300 1 int main() a306 1 a313 1 d320 1 a320 2 * buffer back and see whether it has been enlarged or not. */ d335 1 a335 2 if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) != XDS_OK) { d340 1 a340 2 printf ("xds_encode() did not enlarge the buffer after processing the callback\n"); d346 2 a347 3 * buffer's capacity and check, whether the library returns the correct * error code. */ a364 1 a367 1 d375 1 a375 1 static int dummy_engine(xds_t * xds, void *engine_context, d377 1 a377 1 size_t * used_buffer_size, va_list * args) a382 1 d387 1 a387 1 int main() a395 1 a402 1 d409 2 a410 3 * then encode something new and verify that the old buffer hasn't ben * overwritten and that the new one contains the correct string. */ d436 2 a437 3 * contents. Encode something new and compare the new content with what * we expect. */ a468 1 a471 1 d479 1 a479 1 static int dummy_engine(xds_t * xds, void *engine_context, d481 1 a481 1 size_t * used_buffer_size, va_list * args) d514 1 a514 1 int main() a518 1 a525 1 a534 1 a544 1 a547 1 d555 1 a555 1 static int dummy_engine(xds_t * xds, void *engine_context, d557 1 a557 1 size_t * used_buffer_size, va_list * args) d588 1 a588 2 printf ("The contents of the decode buffer are not what we expected.\n"); d595 1 a595 1 int main() a600 1 a607 1 d613 1 a613 3 /* Decode the buffer and have the callback report when something is * wrong. */ a617 1 a623 1 d635 1 a635 1 static int dummy_engine(xds_t * xds, void *engine_context, d637 1 a637 1 size_t * used_buffer_size, va_list * args) d674 1 a674 1 int main() d681 5 a685 6 * encode() call. Then call encode() with two parameters: the one the * engine is expecting and a different one after that. The engine will * complain if it sees the second value -- what would mean that the args * parameter was not resetted to the original value before the engine is * restarted after buffer enlargement. */ d722 1 a722 1 static int encode_mystruct_engine(xds_t * xds, void *engine_context, d724 1 a724 1 size_t * used_buffer_size, va_list * args) d738 1 a738 1 static int decode_mystruct_engine(xds_t * xds, void *engine_context, d740 1 a740 1 size_t * used_buffer_size, va_list * args) d754 1 a754 1 int main() d765 1 a765 2 * the buffer and destroy the context again. */ d771 1 a771 1 if (xds_register(xds, "mystruct", &encode_mystruct_engine, NULL) != XDS_OK a803 1 a825 1 a832 1 d837 1 @ 1.1 log @First cut of the ruthless style adjustments to OSSP XDS: o adjust source tree to follow OSSP source tree style by heavily combining sources into smaller sets (needs more work when still missing parts are added later) o automatic re-indentation of sources with GNU indent (still needs manual review and adjustments; will follow) These two heavy steps were mostly done automatically with the help of two helper scripts written in Perl. So expect more manual adjustments to follow... @ text @d1 28 a28 23 /* * XDS - OSSP Extensible Data Serialization Library Copyright (c) 2001 The * OSSP Project (http://www.ossp.org/) Copyright (c) 2001 Cable & Wireless * Deutschland (http://www.cw.com/de/) * * This file is part of OSSP XDS, an extensible data serialization library * which can be found at http://www.ossp.com/pkg/xds/. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ @