Category : C Source Code
Archive   : LLISTMGR.ZIP
Filename : LLTEST.C

 
Output of file : LLTEST.C contained in archive : LLISTMGR.ZIP
/**** lltest.c ********************************************************/
/* This is a test program written by Clifford Chaney. It was written */
/* to provide a means of testing the functions to Clifford Chaney's */
/* LLIST routines. This test, along with the LLIST routines are */
/* donated to the public domain. */
/* */
/* Included with this file should be two .EXE's called LLTESTS.EXE */
/* and LLTESTD.EXE. LLTESTD is compiled to work as a double linked */
/* list, while LLTESTS works with single link lists. Note that ALL */
/* routines of LLIST function in either mode. Using single link */
/* lists will save space, however they may also be quite a bit slower */
/* depending on your usage. */
/* */
/* To compile the LLIST routines to work as single link lists, define */
/* LLSINGLE before compiling them. By default, all lists are double */
/* linked lists. */
/* */
/* This test suite may also serve as an example to how to use LLIST. */
/* Also, if you modify LLIST's routines you can use this to ensure */
/* that all functions still work properly. So, if you add new */
/* functions to LLIST you may wish to add a test for them here. */
/* NOTE: This test currently needs at least 50K of DISK SPACE to */
/* complete. */
/**********************************************************************/


#include
#include
#include
#include
#include
#include "llist.h"

LINKLIST lista;

void showtime(void)
{
unsigned long far *clocktics;
unsigned long timer;
unsigned long sec;
unsigned long min;
unsigned long hdth;

clocktics = MK_FP(0, 0x046C);
timer = *clocktics;
sec = timer / 18;
min = (sec / 60) % 60;
sec = sec % 60;
hdth = timer % 18;

printf("(%02lu:%02lu.%02lu) ", min, sec, hdth);
} /* showtime */

delete(void)
{
int l;

showtime(); puts("Delete all elements from the list...");
ll_seek(lista, 0);
l = 0;
while (!ll_tail(lista)) {
ll_del(lista);
++l;
} /* while */
ll_del(lista);
++l;
if (l != 500) {
printf("Only able to remove %i elements.\n", l);
return(-1);
} /* if */
return(0);
}


test(void)
{
int l, s, r;
long m;
char *c;
int size;

showtime(); puts("Sequential test...");
for (l=1; l<501; ++l) {
size = (l % 100) + 1;
if ((c = malloc(size)) == NULL) {
puts("Out of memory");
return(-1);
}
memset(c, size, size);

if (ll_add(lista, c, size) == NULL) {
puts("Out of memory");
return(-1);
}
free(c);
} /* for */
showtime(); puts("Sequential adds complete... Test the list...");
ll_seek(lista, 0);
for (l=1; l<501; ++l) {
size = (l % 100) + 1;
if ((c = malloc(size)) == NULL) {
puts("Out of memory");
return(-1);
}
memset(c, size, size);
if (memcmp(c, ll_ptr(lista), size) != 0) {
printf("Element %i does NOT match...\n", l);
return(-1);
} /* if */
ll_skip(lista, 1);
free(c);
} /* for */

showtime(); puts("Sequential test OKAY...");
showtime(); puts("Store data.");
if ((m = ll_store(lista, "LLTEST.DAT")) != 0) {
printf("Error %li: Could not save list.\n", m);
return(-1);
} /* if */

if (delete()) return(-1);

showtime(); puts("Reload list from disk.");
if ((m = ll_load(lista, "LLTEST.DAT")) != 0) {
printf("Error %li: Could not load list.\n", m);
return(-1);
} /* if */
showtime(); puts("Recheck list (BACKWORDS) after loading.");
ll_seek(lista, 500);
for (l=500; l>0; --l) {
size = (l % 100) + 1;
if ((c = malloc(size)) == NULL) {
puts("Out of memory");
return(-1);
}
memset(c, size, size);
if (memcmp(c, ll_ptr(lista), size) != 0) {
printf("Element %i does NOT match...\n", l);
return(-1);
} /* if */
ll_skip(lista, -1);
free(c);
} /* for */
if (delete()) return(-1);

showtime(); puts("Set up for RANDOM test...");
for (l=1; l<501; ++l) {
size = (l % 98) + 1;
if ((c = malloc(size+2)) == NULL) {
puts("Out of memory");
return(-1);
}
memset(c, size, size+2);
memmove(c, &size, 2);

if (ll_add(lista, c, size+2) == NULL) {
puts("Out of memory");
return(-1);
}
free(c);
} /* for */

showtime(); puts("Random test (this test may take a while)...");
for (l=1; l<800; ++l) {
size = (l % 98) + 1;
r = (l % 499);
if ((m = ll_seek(lista, r)) < r) {
printf("List is corrupt. Attempt to seek to %i stopped at %li.\n\n", r, m);
return(-1);
} /* if */

memmove(&s, ll_ptr(lista), 2);
if ((c = malloc(s+2)) == NULL) {
puts("Out of memory.");
return(-1);
}
memmove(c, ll_ptr(lista), s+2);
ll_del(lista);
if (r < 498)
if (ll_seek(lista, r+1) != r+1) {
printf("Delete of entry %i failed.\n", r);
return(-1);
} /* if */
/* end of if */

r = random(498);
if ((m = ll_seek(lista, r)) != r) {
printf("List is corrupt! Attempt to seek to %i stopped at %li.\n\n", r, m);
return(-1);
} /* if */

if (ll_ins(lista, c, s+2) == NULL) {
puts("Out of memory.");
return(-1);
} /* if */

if (ll_seek(lista, r+1) != r+1) {
printf("Insert of entry %i failed.\n\n", r);
return(-1);
} /* if */

free(c);
} /* for */
if (ll_seek(lista, 499) != 499) {
puts("Random test corrupted list.");
return(-1);
} /* if */

showtime(); puts("CHANGE test...");
ll_seek(lista, 0);
if ((c = malloc(100)) == NULL) {
puts("Out of memory.");
return(-1);
}
memset(c, 65, 100);
for (l=1; l<501; ++l) {
if (ll_change(lista, c, 100) == NULL) {
puts("Out of memory.");
return(-1);
}
if (l < 500)
if (ll_skip(lista, 1) != 1) {
printf("List is CORRUPT. Could not skip from %i to %i.\n", l, l+1);
return(-1);
} /* if */
} /* for */

showtime(); puts("Test results...");
ll_seek(lista, 0);
for (l=1; l<501; ++l) {
if (memcmp(c, ll_ptr(lista), 100) != 0) {
printf("List is corrupt. Element %i is not correct.\n", l);
return(-1);
} /* if */
if (l < 500)
if (ll_skip(lista, 1) != 1) {
printf("List is CORRUPT. Could not skip from %i to %i.\n", l, l+1);
return(-1);
} /* if */
} /* for */

free(c);
showtime(); puts("ZAP the list");
ll_zap(&lista);

return(0);
}

main()
{
puts("\nTesting LLIST.C -- Written by Cliff Chaney\n");
if (ll_init(&lista, 0) == NULL) {
puts("Not enough memory.");
return(-1);
} /* if error */
if (test() != 0) return(-1);

puts("\n\nRe-run ENTIRE suite with fixed length list.\n");
if (ll_init(&lista, 100) == NULL) {
puts("Not enough memory.");
return(-1);
} /* if error */
if (test() != 0) return(-1);
puts("\nAll tests complete, NO ERRORS found.\n");
return(0);
} /* main */


  3 Responses to “Category : C Source Code
Archive   : LLISTMGR.ZIP
Filename : LLTEST.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/