--- xds_test_lib.c 2001/08/09 19:58:35 1.2
+++ xds_test_lib.c 2001/08/09 20:59:05 1.3
@@ -34,13 +34,12 @@
#ifdef XDS_TEST_XDS_CORE
-int main()
+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)
ctx[i] = xds_init(XDS_ENCODE);
@@ -58,7 +57,6 @@
#ifdef NDEBUG
/* Check how the library deals with errorneous arguments. */
-
if (xds_init((xds_mode_t) 42) != NULL || errno != EINVAL) {
printf
("Called xds_init() with invalid mode but didn't get EINVAL.\n");
@@ -66,13 +64,11 @@
}
/* Call xds_destroy() with an invalid context and see whether we survive
- * that. */
-
+ that. */
xds_destroy(NULL);
#endif
/* Everything went fine. */
-
return 0;
}
@@ -80,7 +76,7 @@
#ifdef XDS_TEST_XDS_FIND_ENGINE
-int main()
+int main(int argc, char *argv[])
{
const engine_map_t engines[] = {
{"alan", NULL, 0},
@@ -101,118 +97,83 @@
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");
+ 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);
+ 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);
+ 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);
+ 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. */
-
+ 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");
+ 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);
+ 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");
+ 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);
+ 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. */
-
+ /* 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");
+ 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);
+ 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");
+ 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);
+ 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");
+ 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);
+ 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");
+ 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);
+ printf("xds_find_engine() would insert 'harald' at position %d, but 7 is correct.\n", pos);
exit(1);
}
/* Everything went fine. */
-
return 0;
}
@@ -220,14 +181,14 @@
#ifdef XDS_TEST_XDS_REGISTER
-static int dummy_engine(xds_t * xds, void *engine_context,
+static int dummy_engine(xds_t *xds, void *engine_context,
void *buffer, size_t buffer_size,
- size_t * used_buffer_size, va_list * args)
+ size_t *used_buffer_size, va_list *args)
{
return 0;
}
-int main()
+int main(int argc, char *argv[])
{
const char *test_names[] = {
"foo",
@@ -242,7 +203,6 @@
size_t i;
/* Create context. */
-
xds = xds_init(XDS_ENCODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -250,8 +210,7 @@
}
/* Register the dummy callback under an invalid name to see whether the
- * routine fails correctly. */
-
+ routine fails correctly. */
if (xds_register(xds, "abcdefh1230#", &dummy_engine, NULL) !=
XDS_ERR_INVALID_ARG) {
printf
@@ -260,7 +219,6 @@
}
/* 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]);
@@ -269,14 +227,12 @@
}
/* 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);
@@ -287,15 +243,12 @@
}
/* 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");
+ 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]);
@@ -303,7 +256,6 @@
}
/* 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",
@@ -312,18 +264,15 @@
}
/* 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;
}
@@ -331,9 +280,9 @@
#ifdef XDS_TEST_XDS_SETBUFFER
-static int dummy_engine(xds_t * xds, void *engine_context,
+static int dummy_engine(xds_t *xds, void *engine_context,
void *buffer, size_t buffer_size,
- size_t * used_buffer_size, va_list * args)
+ size_t *used_buffer_size, va_list *args)
{
assert(xds != NULL);
assert(buffer != NULL);
@@ -348,14 +297,13 @@
return XDS_OK;
}
-int main()
+int main(int argc, char *argv[])
{
xds_t *xds;
char *buffer;
size_t buffer_size;
/* Create XDS context. */
-
xds = xds_init(XDS_ENCODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -363,15 +311,13 @@
}
/* 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 back and see whether it has been enlarged or not. */
buffer_size = 32;
buffer = malloc(buffer_size);
if (buffer == NULL) {
@@ -386,22 +332,19 @@
printf("xds_encode() failed!\n");
return 1;
}
- if (xds_getbuffer(xds, XDS_GIFT, (void **)&buffer, &buffer_size) !=
- XDS_OK) {
+ 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("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'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");
@@ -419,11 +362,9 @@
free(buffer);
/* Clean up. */
-
xds_destroy(xds);
/* Everything went fine. */
-
return 0;
}
@@ -431,20 +372,19 @@
#ifdef XDS_TEST_XDS_GETBUFFER
-static int dummy_engine(xds_t * xds, void *engine_context,
+static int dummy_engine(xds_t *xds, void *engine_context,
void *buffer, size_t buffer_size,
- size_t * used_buffer_size, va_list * args)
+ 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 main(int argc, char *argv[])
{
xds_t *xds;
char *old;
@@ -453,7 +393,6 @@
size_t new_len;
/* Create XDS context. */
-
xds = xds_init(XDS_ENCODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -461,16 +400,14 @@
}
/* 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. */
-
+ 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;
@@ -496,9 +433,8 @@
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. */
-
+ 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;
@@ -530,11 +466,9 @@
}
/* Clean up. */
-
xds_destroy(xds);
/* Everything went fine. */
-
return 0;
}
@@ -542,9 +476,9 @@
#ifdef XDS_TEST_XDS_ENCODE
-static int dummy_engine(xds_t * xds, void *engine_context,
+static int dummy_engine(xds_t *xds, void *engine_context,
void *buffer, size_t buffer_size,
- size_t * used_buffer_size, va_list * args)
+ size_t *used_buffer_size, va_list *args)
{
if (xds == NULL) {
printf("XDS context isn't passed through to registered engine.\n");
@@ -577,12 +511,11 @@
return XDS_OK;
}
-int main()
+int main(int argc, char *argv[])
{
xds_t *xds;
/* Create XDS context. */
-
xds = xds_init(XDS_ENCODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -590,7 +523,6 @@
}
/* 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 ||
@@ -600,7 +532,6 @@
}
/* Let's go and encode something. */
-
if (xds_encode(xds, "int:text double double float") != XDS_OK) {
printf("xds_encode() failed!\n");
return 1;
@@ -611,11 +542,9 @@
}
/* Clean up. */
-
xds_destroy(xds);
/* Everything went fine. */
-
return 0;
}
@@ -623,9 +552,9 @@
#ifdef XDS_TEST_XDS_DECODE
-static int dummy_engine(xds_t * xds, void *engine_context,
+static int dummy_engine(xds_t *xds, void *engine_context,
void *buffer, size_t buffer_size,
- size_t * used_buffer_size, va_list * args)
+ size_t *used_buffer_size, va_list *args)
{
if (xds == NULL) {
printf("XDS context isn't passed through to registered engine.\n");
@@ -656,21 +585,19 @@
exit(1);
}
if (memcmp(buffer, "Hallo!", 6) != 0) {
- printf
- ("The contents of the decode buffer are not what we expected.\n");
+ 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 main(int argc, char *argv[])
{
xds_t *xds;
char buffer[] = "Hallo!Hallo!Hallo!";
/* Create XDS context. */
-
xds = xds_init(XDS_DECODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -678,27 +605,22 @@
}
/* 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. */
-
+ /* 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. */
@@ -710,9 +632,9 @@
#ifdef XDS_TEST_XDS_ENGINE_RESTART
-static int dummy_engine(xds_t * xds, void *engine_context,
+static int dummy_engine(xds_t *xds, void *engine_context,
void *buffer, size_t buffer_size,
- size_t * used_buffer_size, va_list * args)
+ size_t *used_buffer_size, va_list *args)
{
if (xds == NULL) {
printf("XDS context isn't passed through to registered engine.\n");
@@ -749,19 +671,18 @@
return XDS_OK;
}
-int main()
+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. */
-
+ 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. */
xds = xds_init(XDS_ENCODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -798,9 +719,9 @@
xds_uint32_t positive;
};
-static int encode_mystruct_engine(xds_t * xds, void *engine_context,
+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)
+ size_t *used_buffer_size, va_list *args)
{
struct mystruct *ms;
@@ -814,9 +735,9 @@
return xds_encode(xds, "int32 uint32", ms->small, ms->positive);
}
-static int decode_mystruct_engine(xds_t * xds, void *engine_context,
+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)
+ size_t *used_buffer_size, va_list *args)
{
struct mystruct *ms;
@@ -830,7 +751,7 @@
return xds_decode(xds, "int32 uint32", &(ms->small), &(ms->positive));
}
-int main()
+int main(int argc, char *argv[])
{
xds_t *xds;
char *buffer;
@@ -841,14 +762,13 @@
ms.positive = 42;
/* Encode our copy of mystruct using our encoding callback. Then get a
- * the buffer and destroy the context again. */
-
+ the buffer and destroy the context again. */
xds = xds_init(XDS_ENCODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
return 1;
}
- if (xds_register(xds, "mystruct", &encode_mystruct_engine, NULL) != XDS_OK
+ 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");
@@ -881,7 +801,6 @@
printf("The encoded representation is %u bytes long.\n", buffer_size);
/* Now create a decoding context and decode the whole thing again. */
-
xds = xds_init(XDS_DECODE);
if (xds == NULL) {
printf("Failed to initialize XDS context.\n");
@@ -904,7 +823,6 @@
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");
@@ -912,8 +830,8 @@
}
/* Everything went fine. */
-
return 0;
}
#endif /* XDS_TEST_XDS_MYSTRUCT */
+
|