home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / reviewed / volume03 / chipset2 / 10 < prev    next >
Encoding:
Text File  |  1993-03-13  |  25.6 KB  |  986 lines

  1. From decwrl!athertn!sander.cupertino.ca.us!paul@cs.purdue.edu Wed Jan  6 13:53:48 EST 1993
  2. Submit chipset-2 10/10 
  3. #! /bin/sh
  4. # This is a shell archive.  Remove anything before this line, then unpack
  5. # it by saving it into a file and typing "sh file".  To overwrite existing
  6. # files, type "sh file -c".  You can also feed this as standard input via
  7. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  8. # will see the following message at the end:
  9. #        "End of archive 10 (of 10)."
  10. # Contents:  src/list/test.c
  11. # Wrapped by paul@sander on Sun Nov 22 15:41:56 1992
  12. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  13. if test -f src/list/test.c -a "${1}" != "-c" ; then 
  14.   echo shar: Will not over-write existing file \"src/list/test.c\"
  15. else
  16. echo shar: Extracting \"src/list/test.c\" \(23698 characters\)
  17. sed "s/^X//" >src/list/test.c <<'END_OF_src/list/test.c'
  18. X/************************************************************************
  19. X *
  20. X * test.c -- This program tests the doubly-linked list implementation.  It
  21. X *           attempts to cover all branches of control less those taken
  22. X *           when malloc fails.  Perhaps one day a debugging allocator can
  23. X *           be hooked in to test those as well.
  24. X *
  25. X * This file is part of a suite of programs called Software Chipset.
  26. X * The source code for Software Chipset has been released into the
  27. X * public domain by its author, Paul Sander.
  28. X *
  29. X ************************************************************************/
  30. X
  31. X#include <stdio.h>
  32. X#include "dlist.h"
  33. X
  34. X/* These are the list operations that the program tests */
  35. X
  36. Xenum ops { SETUP, FREESETUP, NEW, DESTROY, INSERT, DELETE, SEARCH,
  37. X           TRAVERSE, FIRST, LAST, NEXT, PREV, RANK, DELRANK, DATA, SETDATA,
  38. X           PUSH, PUSHF, PUSHR, POP, POPF, POPR, PEEK, PEEKF, PEEKR,
  39. X           END
  40. X};
  41. X
  42. Xtypedef enum ops OP;
  43. X
  44. Xchar *opnames[] = {"setup","freesetup","new","destroy","insert","delete",
  45. X                   "search","traverse","first","last","next","prev","rank",
  46. X                   "delrank","data","setdata","push","pushf","pushr","pop",
  47. X                   "popf","popr","peek","peekf","peekr","end"
  48. X};
  49. X
  50. X/*
  51. X * The following structure describes a test case.  An array of these
  52. X * is given to an interpreter which performs each test and reports the
  53. X * results.
  54. X */
  55. X
  56. Xstruct testcase {
  57. X    OP    op;        /* Operation */
  58. X    int    key;        /* Insertion/seek key */
  59. X    int    data;        /* Application-specific or expected data */
  60. X    int    data2;        /* Secondary data */
  61. X    int    result;        /* Return code or expected result */
  62. X    int    dump;        /* If not zero, dumps list for debugging */
  63. X};
  64. X
  65. Xtypedef struct testcase CASE;
  66. X
  67. X/* Value of "key" when calling dll_destroy */
  68. X#define    FREEKEY        1    /* call freeKey() */
  69. X#define    FREEDATA    2    /* call freeData() */
  70. X
  71. X/* Invalid value of "key" when calling the push, pop, or peek functions */
  72. X#define    DLL_INVALID    2
  73. X
  74. X/* This is the list of test cases that make up the suite. */
  75. X
  76. XCASE suite[] = {
  77. X/* ------------    OP        key    data    data2    result    dump    */
  78. X    {    DATA,        0,    0,    0,    0,    0    },
  79. X    {    SETDATA,    0,    0,    0,    0,    0    },
  80. X    {    DELETE,        0,    0,    0,    0,    0    },
  81. X    {    DELRANK,    0,    0,    0,    0,    0    },
  82. X    {    DESTROY,    0,    0,    0,    0,    0    },
  83. X    {    DESTROY,    1,    0,    0,    0,    0    },
  84. X    {    DESTROY,    2,    0,    0,    0,    0    },
  85. X    {    DESTROY,    3,    0,    0,    0,    0    },
  86. X    {    FIRST,        0,    0,    0,    0,    0    },
  87. X    {    INSERT,        0,    0,    0,    0,    0    },
  88. X    {    LAST,        0,    0,    0,    0,    0    },
  89. X    {    NEXT,        0,    0,    0,    0,    0    },
  90. X    {    PEEK,        0,    0,    0,    0,    0    },
  91. X    {    PEEK,        0,    0,    1,    0,    0    },
  92. X    {    PEEK,        0,    0,    2,    0,    0    },
  93. X    {    PEEKF,        0,    0,    0,    0,    0    },
  94. X    {    PEEKR,        0,    0,    0,    0,    0    },
  95. X    {    POP,        0,    0,    0,    0,    0    },
  96. X    {    POP,        0,    0,    1,    0,    0    },
  97. X    {    POP,        0,    0,    2,    0,    0    },
  98. X    {    POPF,        0,    0,    0,    0,    0    },
  99. X    {    POPR,        0,    0,    0,    0,    0    },
  100. X    {    PREV,        0,    0,    0,    0,    0    },
  101. X    {    PUSH,        0,    0,    0,    0,    0    },
  102. X    {    PUSH,        0,    0,    1,    0,    0    },
  103. X    {    PUSH,        0,    0,    2,    0,    0    },
  104. X    {    PUSHF,        0,    0,    0,    0,    0    },
  105. X    {    PUSHR,        0,    0,    0,    0,    0    },
  106. X    {    RANK,        0,    0,    0,    0,    0    },
  107. X    {    SEARCH,        0,    0,    0,    0,    0    },
  108. X    {    FREESETUP,    0,    0,    0,    0,    0    },
  109. X    {    TRAVERSE,    1,    0,    0,    0,    0    },
  110. X    {    SETUP,        0,    0,    0,    1,    0    },
  111. X    {    NEW,        0,    0,    0,    1,    0    },
  112. X    {    DATA,        0,    0,    0,    0,    0    },
  113. X    {    SETDATA,    0,    0,    0,    0,    0    },
  114. X    {    DELETE,        0,    0,    0,    0,    0    },
  115. X    {    DELRANK,    0,    0,    0,    0,    0    },
  116. X    {    DELRANK,    -1,    0,    0,    0,    0    },
  117. X    {    FIRST,        0,    0,    0,    0,    0    },
  118. X    {    INSERT,        0,    0,    0,    0,    0    },
  119. X    {    LAST,        0,    0,    0,    0,    0    },
  120. X    {    NEXT,        0,    0,    0,    0,    0    },
  121. X    {    PEEKF,        0,    0,    0,    0,    0    },
  122. X    {    PEEKR,        0,    0,    0,    0,    0    },
  123. X    {    POPF,        0,    0,    0,    0,    0    },
  124. X    {    POPR,        0,    0,    0,    0,    0    },
  125. X    {    PREV,        0,    0,    0,    0,    0    },
  126. X    {    RANK,        0,    0,    0,    0,    0    },
  127. X    {    RANK,        -1,    0,    0,    0,    0    },
  128. X    {    SEARCH,        0,    0,    0,    0,    0    },
  129. X    {    TRAVERSE,    1,    0,    0,    0,    0    },
  130. X    {    FREESETUP,    0,    0,    0,    0,    0    },
  131. X    {    DESTROY,    0,    50,    0,    0,    0    },
  132. X    {    SETUP,        0,    23,    1,    1,    0    },
  133. X    {    NEW,        0,    0,    0,    1,    0    },
  134. X    {    INSERT,        1000,    100,    0,    1,    0    },
  135. X    {    INSERT,        3000,    300,    0,    1,    0    },
  136. X    {    INSERT,        2000,    200,    0,    1,    0    },
  137. X    {    INSERT,        4000,    400,    0,    1,    0    },
  138. X    {    INSERT,        2000,    0,    0,    -1,    0    },
  139. X    {    INSERT,        0,    0,    0,    0,    0    },
  140. X    {    DATA,        0,    23,    0,    0,    0    },
  141. X    {    SETDATA,    0,    75,    0,    0,    0    },
  142. X    {    DATA,        0,    75,    0,    0,    0    },
  143. X    {    NEXT,        0,    0,    0,    0,    0    },
  144. X    {    PREV,        0,    0,    0,    0,    0    },
  145. X    {    FIRST,        1000,    0,    0,    1,    0    },
  146. X    {    FIRST,        1000,    100,    0,    1,    0    },
  147. X    {    NEXT,        2000,    200,    0,    1,    0    },
  148. X    {    NEXT,        3000,    0,    0,    1,    0    },
  149. X    {    NEXT,        4000,    400,    0,    1,    0    },
  150. X    {    NEXT,        0,    0,    0,    0,    0    },
  151. X    {    NEXT,        0,    0,    0,    0,    0    },
  152. X    {    SEARCH,        1000,    100,    0,    1,    0    },
  153. X    {    SEARCH,        2000,    200,    0,    1,    0    },
  154. X    {    NEXT,        3000,    0,    0,    1,    0    },
  155. X    {    SEARCH,        4000,    400,    0,    1,    0    },
  156. X    {    NEXT,        0,    0,    0,    0,    0    },
  157. X    {    SEARCH,        2500,    0,    0,    0,    0    },
  158. X    {    NEXT,        3000,    0,    0,    1,    0    },
  159. X    {    SEARCH,        500,    0,    0,    0,    0    },
  160. X    {    NEXT,        1000,    0,    0,    1,    0    },
  161. X    {    SEARCH,        4500,    0,    0,    0,    0    },
  162. X    {    NEXT,        0,    0,    0,    0,    0    },
  163. X    {    LAST,        4000,    0,    0,    1,    0    },
  164. X    {    LAST,        4000,    400,    0,    1,    0    },
  165. X    {    PREV,        3000,    300,    0,    1,    0    },
  166. X    {    PREV,        2000,    0,    0,    1,    0    },
  167. X    {    PREV,        1000,    100,    0,    1,    0    },
  168. X    {    PREV,        0,    0,    0,    0,    0    },
  169. X    {    PREV,        0,    0,    0,    0,    0    },
  170. X    {    SEARCH,        3000,    300,    0,    1,    0    },
  171. X    {    PREV,        2000,    0,    0,    1,    0    },
  172. X    {    SEARCH,        1000,    100,    0,    1,    0    },
  173. X    {    PREV,        0,    0,    0,    0,    0    },
  174. X    {    SEARCH,        2500,    0,    0,    0,    0    },
  175. X    {    PREV,        2000,    0,    0,    1,    0    },
  176. X    {    SEARCH,        4500,    0,    0,    0,    0    },
  177. X    {    PREV,        4000,    0,    0,    1,    0    },
  178. X    {    SEARCH,        500,    0,    0,    0,    0    },
  179. X    {    PREV,        0,    0,    0,    0,    0    },
  180. X    {    TRAVERSE,    1,    83,    0,    4,    0    },
  181. X    {    TRAVERSE,    0,    0,    0,    0,    0    },
  182. X    {    RANK,        -1,    0,    0,    0,    0    },
  183. X    {    RANK,        0,    100,    0,    1000,    0    },
  184. X    {    RANK,        0,    0,    0,    1000,    0    },
  185. X    {    RANK,        1,    200,    0,    2000,    0    },
  186. X    {    RANK,        2,    300,    0,    3000,    0    },
  187. X    {    RANK,        3,    400,    0,    4000,    0    },
  188. X    {    RANK,        4,    0,    0,    0,    0    },
  189. X    {    SEARCH,        2000,    200,    0,    0,    0    },
  190. X    {    INSERT,        6000,    600,    0,    1,    0    },
  191. X    {    NEXT,        0,    0,    0,    0,    0    },
  192. X    {    PREV,        0,    0,    0,    0,    0    },
  193. X    {    NEXT,        0,    0,    0,    0,    0    },
  194. X    {    DESTROY,    3,    0,    0,    5,    0    },
  195. X    {    NEW,        0,    0,    0,    1,    0    },
  196. X    {    INSERT,        1000,    100,    0,    1,    0    },
  197. X    {    INSERT,        2000,    200,    0,    1,    0    },
  198. X    {    INSERT,        3000,    300,    0,    1,    0    },
  199. X    {    INSERT,        4000,    400,    0,    1,    0    },
  200. X    {    INSERT,        5000,    500,    0,    1,    0    },
  201. X    {    DELETE,        500,    0,    0,    0,    0    },
  202. X    {    DELETE,        2500,    0,    0,    0,    0    },
  203. X    {    DELETE,        5500,    0,    0,    0,    0    },
  204. X    {    DELETE,        2000,    200,    0,    1,    0    },
  205. X    {    DELETE,        3000,    0,    0,    1,    0    },
  206. X    {    DELETE,        5000,    500,    0,    1,    0    },
  207. X    {    DELETE,        1000,    100,    0,    1,    0    },
  208. X    {    DELETE,        4000,    400,    0,    1,    0    },
  209. X    {    INSERT,        1000,    100,    0,    1,    0    },
  210. X    {    INSERT,        2000,    200,    0,    1,    0    },
  211. X    {    INSERT,        3000,    300,    0,    1,    0    },
  212. X    {    INSERT,        4000,    400,    0,    1,    0    },
  213. X    {    INSERT,        5000,    500,    0,    1,    0    },
  214. X    {    DELRANK,    -1,    0,    0,    0,    0    },
  215. X    {    DELRANK,    5,    0,    0,    0,    0    },
  216. X    {    DELRANK,    1,    200,    0,    2000,    0    },
  217. X    {    DELRANK,    1,    0,    0,    3000,    0    },
  218. X    {    DELRANK,    2,    500,    0,    5000,    0    },
  219. X    {    DELRANK,    0,    100,    0,    1000,    0    },
  220. X    {    DELRANK,    0,    400,    0,    4000,    0    },
  221. X    {    DESTROY,    0,    0,    0,    0,    0    },
  222. X    {    FREESETUP,    0,    0,    0,    0,    0    },
  223. X    {    SETUP,        0,    0,    0,    1,    0    },
  224. X    {    NEW,        0,    0,    0,    1,    0    },
  225. X    {    PEEKF,        0,    0,    0,    0,    0    },
  226. X    {    PEEKR,        0,    0,    0,    0,    0    },
  227. X    {    PUSHF,        3000,    300,    0,    1,    0    },
  228. X    {    INSERT,        4000,    0,    0,    0,    0    },
  229. X    {    SEARCH,        3000,    0,    0,    0,    0    },
  230. X    {    DELETE,        4000,    0,    0,    0,    0    },
  231. X    {    PUSHF,        2000,    200,    0,    1,    0    },
  232. X    {    PEEKF,        2000,    200,    0,    1,    0    },
  233. X    {    PEEKF,        2000,    0,    0,    1,    0    },
  234. X    {    FIRST,        2000,    0,    0,    1,    0    },
  235. X    {    NEXT,        3000,    0,    0,    1,    0    },
  236. X    {    NEXT,        0,    0,    0,    0,    0    },
  237. X    {    POPF,        2000,    0,    0,    1,    0    },
  238. X    {    POPF,        3000,    300,    0,    1,    0    },
  239. X    {    POPF,        0,    0,    0,    0,    0    },
  240. X    {    PUSHR,        2000,    200,    0,    1,    0    },
  241. X    {    PEEKR,        2000,    200,    0,    1,    0    },
  242. X    {    PEEKF,        2000,    200,    0,    1,    0    },
  243. X    {    PUSHR,        3000,    0,    0,    1,    0    },
  244. X    {    FIRST,        2000,    0,    0,    1,    0    },
  245. X    {    NEXT,        3000,    0,    0,    1,    0    },
  246. X    {    NEXT,        0,    0,    0,    0,    0    },
  247. X    {    FIRST,        2000,    0,    0,    1,    0    },
  248. X    {    PUSHR,        4000,    0,    0,    1,    0    },
  249. X    {    NEXT,        0,    0,    0,    0,    0    },
  250. X    {    LAST,        4000,    0,    0,    1,    0    },
  251. X    {    PUSHF,        1000,    0,    0,    1,    0    },
  252. X    {    PREV,        0,    0,    0,    0,    0    },
  253. X    {    FIRST,        1000,    0,    0,    1,    0    },
  254. X    {    NEXT,        2000,    0,    0,    1,    0    },
  255. X    {    PEEKF,        1000,    0,    0,    1,    0    },
  256. X    {    PEEKR,        4000,    0,    0,    1,    0    },
  257. X    {    NEXT,        3000,    0,    0,    1,    0    },
  258. X    {    POPR,        4000,    0,    0,    1,    0    },
  259. X    {    POPR,        3000,    0,    0,    1,    0    },
  260. X    {    POPR,        2000,    200,    0,    1,    0    },
  261. X    {    POPR,        1000,    0,    0,    1,    0    },
  262. X    {    POPR,        0,    0,    0,    0,    0    },
  263. X/* ------------    OP        key    data    data2    result    dump    */
  264. X    {    END,        0,    0,    0,    0,    0    }
  265. X};
  266. X
  267. X/* This is the comparison function */
  268. X
  269. X#ifdef __STDC__
  270. Xint comp(void *key1, void *key2)
  271. X#else
  272. Xint comp(key1,key2)
  273. Xvoid    *key1;
  274. Xvoid    *key2;
  275. X#endif
  276. X{
  277. X    return *((int*)key1) - *((int*)key2);
  278. X}
  279. X
  280. X/* This function displays a key and its data */
  281. X#ifdef __STDC__
  282. Xvoid dumpKey(void *key,void *data,void *info)
  283. X#else
  284. Xvoid dumpKey(key,data,info)
  285. Xvoid    *key;
  286. Xvoid    *data;
  287. Xvoid    *info;
  288. X#endif
  289. X{
  290. X    printf("key = %4.4d, data = ",*(int*)key);
  291. X    if (data != NULL) printf("%4.4d\n",*(int*)data);
  292. X    else printf("(NULL)\n");
  293. X    return;
  294. X}
  295. X
  296. X/*
  297. X * These functions are called by dll_destroy, and count the number of
  298. X * key and data structures are freed, and also verify that the info
  299. X * parameter is passed properly.  Some attempt is made to be sure that
  300. X * the data are freed before the key.
  301. X */
  302. X
  303. Xint    freedKeys;    /* Number of keys freed */
  304. Xint    freedData;    /* Number of data records freed */
  305. Xint    *expInfo;    /* Expected value of info */
  306. Xint    infoOk;        /* Indicates that the info was always correct */
  307. Xint    freeOk;        /* Indicates that the freeKey and freeData functions
  308. X             * were called correctly
  309. X             */
  310. X
  311. X#ifdef __STDC__
  312. Xvoid freeKey(void *key, void *info)
  313. X#else
  314. Xvoid freeKey(key,info)
  315. Xvoid    *key;
  316. Xvoid    *info;
  317. X#endif
  318. X{
  319. X    freedKeys++;
  320. X    if ((int*) info != expInfo) infoOk = 0;
  321. X    if ((freedData >= 0) && (freedKeys != freedData)) freeOk = 0;
  322. X}
  323. X
  324. X#ifdef __STDC__
  325. Xvoid freeData(void *key, void *info)
  326. X#else
  327. Xvoid freeData(key,info)
  328. Xvoid    *key;
  329. Xvoid    *info;
  330. X#endif
  331. X{
  332. X    if ((freedKeys >= 0) && (freedKeys != freedData)) freeOk = 0;
  333. X    freedData++;
  334. X    if ((int*) info != expInfo) infoOk = 0;
  335. X}
  336. X
  337. X/*
  338. X * The following variables and the visit() function are used for testing
  339. X * the dll_traverse() function.
  340. X */
  341. X
  342. Xint    lastKey;    /* Last key encountered by dll_traverse */
  343. Xint    travOk;        /* Traversal successful */
  344. Xint    visited;    /* Number of nodes visited */
  345. X
  346. X#ifdef __STDC__
  347. Xvoid visit(void *key, void *info, void *data)
  348. X#else
  349. Xvoid visit(key,info,data)
  350. Xvoid    *key;
  351. Xvoid    *info;
  352. Xvoid    *data;
  353. X#endif
  354. X{
  355. X    visited++;
  356. X    if ((lastKey != 0) && (*(int*)key <= lastKey)) travOk = 0;
  357. X    else if ((int*) info != expInfo) travOk = 0;
  358. X    lastKey = *(int*) key;
  359. X    return;
  360. X}
  361. X
  362. X/* The test suite starts here... */
  363. X
  364. X#ifdef __STDC__
  365. Xint main(int argc, char **argv)
  366. X#else
  367. Xint main(argc,argv)
  368. Xint    argc;
  369. Xchar    **argv;
  370. X#endif
  371. X{
  372. X    int        i;        /* Loop counter */
  373. X    int        ok;        /* Current test succeeded */
  374. X    int        fail;        /* Any test failed */
  375. X    int        done;        /* Holds size of test table */
  376. X    int        intval;        /* Integer value */
  377. X    void        *ptrval;    /* Pointer value */
  378. X    void        *ptrval2;    /* Pointer value */
  379. X    DL_LIST        list;        /* B-list under test */
  380. X    DLL_SETUP    setup;        /* Configuration data for B-list */
  381. X
  382. X    /* Initialization */
  383. X    fail = 0;
  384. X    list = (DL_LIST) NULL;
  385. X    setup = (DLL_SETUP) NULL;
  386. X
  387. X    /* Compute the number of test cases there are */
  388. X    done = sizeof(suite)/sizeof(CASE);
  389. X
  390. X    /* Display heading */
  391. X    printf("test OP         key   data  data2  result  intval ptrval  ptrval2  pass\n");
  392. X    for (i = 0; (i < done) && (suite[i].op != END); i++)
  393. X    {
  394. X        /* Initialize test case */
  395. X        ok = 1;
  396. X        intval = 0;
  397. X        ptrval = NULL;
  398. X        ptrval2 = NULL;
  399. X
  400. X        /* Perform test */
  401. X        switch (suite[i].op)
  402. X        {
  403. X    case SETUP:
  404. X            /*
  405. X             * Test case:  data2 = 0 if no comparison function,
  406. X             *             data = global data,
  407. X             *             result = 0 if NULL expected
  408. X             */
  409. X            setup = dll_setup(
  410. X                      (suite[i].data2 ? comp : (int (*)()) NULL),
  411. X                      (void*) (suite[i].data ? &suite[i].data
  412. X                                             : NULL));
  413. X            ok = (suite[i].result != (setup == (DLL_SETUP) NULL));
  414. X            break;
  415. X
  416. X    case FREESETUP:
  417. X            dll_freeSetup(setup);
  418. X            setup = (DLL_SETUP) NULL;
  419. X            break;
  420. X
  421. X    case NEW:
  422. X            /* Test case:  result = 0 if NULL expected */
  423. X            list = dll_new(setup);
  424. X            ok = (suite[i].result != (list == (DL_LIST) NULL));
  425. X            break;
  426. X
  427. X    case DESTROY:
  428. X            /* Test case:  result = number of keys to be freed,
  429. X             *             key    = 0 if neither free fn is called,
  430. X             *                      FREEKEY if freeKey() only
  431. X             *                      FREEDATA if freeData() only
  432. X             *                      FREEKEY+FREEDATA if both
  433. X             *             data   = info parameter
  434. X             */
  435. X            infoOk = 1;
  436. X            freeOk = 1;
  437. X            expInfo = &suite[i].data;
  438. X            switch (suite[i].key)
  439. X            {
  440. X        case 0:
  441. X                /* Fails only if dumps core or hangs */
  442. X                freedKeys = -1;
  443. X                freedData = -1;
  444. X                dll_destroy(list,NULL,NULL,&suite[i].data);
  445. X                break;
  446. X        case FREEKEY:
  447. X                freedKeys = 0;
  448. X                freedData = -1;
  449. X                dll_destroy(list,freeKey,NULL,&suite[i].data);
  450. X                break;
  451. X        case FREEDATA:
  452. X                freedKeys = -1;
  453. X                freedData = 0;
  454. X                dll_destroy(list,NULL,freeData,&suite[i].data);
  455. X                break;
  456. X        default:
  457. X                freedKeys = 0;
  458. X                freedData = 0;
  459. X                dll_destroy(list,freeKey,freeData,
  460. X                           &suite[i].data);
  461. X                break;
  462. X            }
  463. X            list = NULL;
  464. X            if (!freeOk || !infoOk) ok = 0;
  465. X            if ((freedKeys >= 0) && (freedKeys != suite[i].result))
  466. X                ok = 0;
  467. X            if ((freedData >= 0) && (freedData != suite[i].result))
  468. X                ok = 0;
  469. X            break;
  470. X
  471. X    case INSERT:
  472. X            /* Test case:  key    = key to be inserted
  473. X             *             data   = data to be stored with it
  474. X             *             result = expected val of dll_insert()
  475. X             */
  476. X            intval = dll_insert(list,
  477. X                            suite[i].key ? &suite[i].key : NULL,
  478. X                            suite[i].data ? &suite[i].data : NULL);
  479. X            if (intval != suite[i].result) ok = 0;
  480. X            break;
  481. X
  482. X    case PUSHF:
  483. X            /* Test case:  key    = key to be inserted
  484. X             *             data   = data to be stored with it
  485. X             *             result = 0 if failure expected
  486. X             */
  487. X            ptrval = (suite[i].key ? &suite[i].key : NULL);
  488. X            ptrval2 = dll_pushf(list, ptrval,
  489. X                            suite[i].data ? &suite[i].data : NULL);
  490. X            if ((suite[i].result && (ptrval != ptrval2)) ||
  491. X                (!suite[i].result && (ptrval2 != NULL))) ok = 0;
  492. X            break;
  493. X
  494. X    case PUSHR:
  495. X            /* Test case:  key    = key to be inserted
  496. X             *             data   = data to be stored with it
  497. X             *             result = 0 if failure expected
  498. X             */
  499. X            ptrval = (suite[i].key ? &suite[i].key : NULL);
  500. X            ptrval2 = dll_pushr(list, ptrval,
  501. X                            suite[i].data ? &suite[i].data : NULL);
  502. X            if ((suite[i].result && (ptrval != ptrval2)) ||
  503. X                (!suite[i].result && (ptrval2 != NULL))) ok = 0;
  504. X            break;
  505. X
  506. X    case PUSH:
  507. X            /* Test case:  key    = key to be inserted
  508. X             *             data   = data to be stored with it
  509. X             *             data2  = which end to push onto
  510. X             *             result = 0 if failure expected
  511. X             */
  512. X            ptrval = (suite[i].key ? &suite[i].key : NULL);
  513. X            ptrval2 = dll_push(list, suite[i].data2, ptrval,
  514. X                            suite[i].data ? &suite[i].data : NULL);
  515. X            if ((suite[i].result && (ptrval != ptrval2)) ||
  516. X                (!suite[i].result && (ptrval2 != NULL))) ok = 0;
  517. X            break;
  518. X
  519. X    case DELETE:
  520. X            /* Test case:  key    = key to be deleted
  521. X             *             data   = expected data returned by
  522. X             *                      dll_delete
  523. X             *             result = 0 if failure expected
  524. X             */
  525. X            ptrval2 = dll_delete(list,
  526. X                              suite[i].key ? &suite[i].key : NULL,
  527. X                              suite[i].data ? &ptrval : NULL);
  528. X            if (suite[i].key == 0)
  529. X            {
  530. X                if (ptrval2 != NULL) ok = 0;
  531. X            }
  532. X            else
  533. X            {
  534. X                if (ptrval2 == NULL)
  535. X                {
  536. X                    if (suite[i].result) ok = 0;
  537. X                }
  538. X                else
  539. X                {
  540. X                    if (*(int*)ptrval2 != suite[i].key)
  541. X                    {
  542. X                        ok = 0;
  543. X                    }
  544. X                }
  545. X            }
  546. X            if (suite[i].data != 0)
  547. X            {
  548. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  549. X            }
  550. X            else
  551. X            {
  552. X                if (ptrval != NULL) ok = 0;
  553. X            }
  554. X            break;
  555. X
  556. X    case SEARCH:
  557. X            /* Test case:  key    = key to be sought
  558. X             *             data   = expected data returned by
  559. X             *                      dll_search
  560. X             *             result = 0 if failure expected
  561. X             */
  562. X            ptrval2 = dll_search(list,
  563. X                              suite[i].key ? &suite[i].key : NULL,
  564. X                              suite[i].data ? &ptrval : NULL);
  565. X            if (suite[i].key == 0)
  566. X            {
  567. X                if (ptrval2 != NULL) ok = 0;
  568. X            }
  569. X            else
  570. X            {
  571. X                if (ptrval2 == NULL)
  572. X                {
  573. X                    if (suite[i].result) ok = 0;
  574. X                }
  575. X                else
  576. X                {
  577. X                    if (*(int*)ptrval2 != suite[i].key)
  578. X                    {
  579. X                        ok = 0;
  580. X                    }
  581. X                }
  582. X            }
  583. X            if (suite[i].data != 0)
  584. X            {
  585. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  586. X            }
  587. X            else
  588. X            {
  589. X                if (ptrval != NULL) ok = 0;
  590. X            }
  591. X            break;
  592. X
  593. X    case TRAVERSE:
  594. X            /* Test case:  data   = info passed to dll_traverse
  595. X             *             key    = 0 if NULL passed as fn
  596. X             *             result = the expected number of times
  597. X             *                      visit() is called
  598. X             */
  599. X            visited = 0;
  600. X            travOk = 1;
  601. X            expInfo = &suite[i].data;
  602. X            lastKey = 0;
  603. X            dll_traverse(list, (suite[i].key ? visit : NULL),
  604. X                         &suite[i].data);
  605. X            ok = travOk;
  606. X            if (visited != suite[i].result) ok = 0;
  607. X            break;
  608. X
  609. X    case FIRST:
  610. X            /* Test case:  key    = expected key returned
  611. X             *             data   = expected data
  612. X             *             result = 0 if list is empty
  613. X             */
  614. X            ptrval2 = dll_first(list,
  615. X                               suite[i].data ? &ptrval : NULL);
  616. X            if (suite[i].result)
  617. X            {
  618. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  619. X            }
  620. X            else
  621. X            {
  622. X                if (ptrval2 != NULL) ok = 0;
  623. X            }
  624. X            if (suite[i].data)
  625. X            {
  626. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  627. X            }
  628. X            else
  629. X            {
  630. X                if (ptrval != NULL) ok = 0;
  631. X            }
  632. X            break;
  633. X
  634. X    case LAST:
  635. X            /* Test case:  key    = expected key returned
  636. X             *             data   = expected data
  637. X             *             result = 0 if list is empty
  638. X             */
  639. X            ptrval2 = dll_last(list,
  640. X                               suite[i].data ? &ptrval : NULL);
  641. X            if (suite[i].result)
  642. X            {
  643. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  644. X            }
  645. X            else
  646. X            {
  647. X                if (ptrval2 != NULL) ok = 0;
  648. X            }
  649. X            if (suite[i].data)
  650. X            {
  651. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  652. X            }
  653. X            else
  654. X            {
  655. X                if (ptrval != NULL) ok = 0;
  656. X            }
  657. X            break;
  658. X
  659. X    case NEXT:
  660. X            /* Test case:  key    = expected key returned
  661. X             *             data   = expected data
  662. X             *             result = 0 if last key was found
  663. X             */
  664. X            ptrval2 = dll_next(list,
  665. X                               suite[i].data ? &ptrval : NULL);
  666. X            if (suite[i].result)
  667. X            {
  668. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  669. X            }
  670. X            else
  671. X            {
  672. X                if (ptrval2 != NULL) ok = 0;
  673. X            }
  674. X            if (suite[i].data)
  675. X            {
  676. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  677. X            }
  678. X            else
  679. X            {
  680. X                if (ptrval != NULL) ok = 0;
  681. X            }
  682. X            break;
  683. X
  684. X    case PREV:
  685. X            /* Test case:  key    = expected key returned
  686. X             *             data   = expected data
  687. X             *             result = 0 if first key was found
  688. X             */
  689. X            ptrval2 = dll_prev(list,
  690. X                               suite[i].data ? &ptrval : NULL);
  691. X            if (suite[i].result)
  692. X            {
  693. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  694. X            }
  695. X            else
  696. X            {
  697. X                if (ptrval2 != NULL) ok = 0;
  698. X            }
  699. X            if (suite[i].data)
  700. X            {
  701. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  702. X            }
  703. X            else
  704. X            {
  705. X                if (ptrval != NULL) ok = 0;
  706. X            }
  707. X            break;
  708. X
  709. X    case RANK:
  710. X            /* Test case:  key    = rank searched for
  711. X             *             data   = expected data
  712. X             *             result = expected key
  713. X             */
  714. X            ptrval2 = dll_rank(list,suite[i].key,
  715. X                              suite[i].data ? &ptrval : NULL);
  716. X            if (suite[i].result != 0)
  717. X            {
  718. X                if (*(int*)ptrval2 != suite[i].result) ok = 0;
  719. X            }
  720. X            else
  721. X            {
  722. X                if (ptrval2 != NULL) ok = 0;
  723. X            }
  724. X            if (suite[i].data != 0)
  725. X            {
  726. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  727. X            }
  728. X            break;
  729. X
  730. X    case DELRANK:
  731. X            /* Test case:  key    = rank to be deleted
  732. X             *             data   = expected data
  733. X             *             result = expected key
  734. X             */
  735. X            ptrval2 = dll_delRank(list,suite[i].key,
  736. X                                 suite[i].data ? &ptrval : NULL);
  737. X            if (suite[i].result != 0)
  738. X            {
  739. X                if (*(int*)ptrval2 != suite[i].result) ok = 0;
  740. X            }
  741. X            else
  742. X            {
  743. X                if (ptrval2 != NULL) ok = 0;
  744. X            }
  745. X            if (suite[i].data != 0)
  746. X            {
  747. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  748. X            }
  749. X            break;
  750. X
  751. X    case DATA:
  752. X            /* Test case:  data = expected data */
  753. X            ptrval = dll_data(list);
  754. X            if (suite[i].data != 0)
  755. X            {
  756. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  757. X            }
  758. X            else
  759. X            {
  760. X                if (ptrval != NULL) ok = 0;
  761. X            }
  762. X            break;
  763. X
  764. X    case SETDATA:
  765. X            /* Test case:  data = new data */
  766. X            dll_setData(list,&suite[i].data);
  767. X            break;
  768. X
  769. X    case POPF:
  770. X            /* Test case:  key    = expected key returned
  771. X             *             data   = expected data
  772. X             *             result = 0 if list is empty
  773. X             */
  774. X            ptrval2 = dll_popf(list,
  775. X                               suite[i].data ? &ptrval : NULL);
  776. X            if (suite[i].result)
  777. X            {
  778. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  779. X            }
  780. X            else
  781. X            {
  782. X                if (ptrval2 != NULL) ok = 0;
  783. X            }
  784. X            if (suite[i].data)
  785. X            {
  786. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  787. X            }
  788. X            else
  789. X            {
  790. X                if (ptrval != NULL) ok = 0;
  791. X            }
  792. X            break;
  793. X
  794. X    case POPR:
  795. X            /* Test case:  key    = expected key returned
  796. X             *             data   = expected data
  797. X             *             result = 0 if list is empty
  798. X             */
  799. X            ptrval2 = dll_popr(list,
  800. X                               suite[i].data ? &ptrval : NULL);
  801. X            if (suite[i].result)
  802. X            {
  803. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  804. X            }
  805. X            else
  806. X            {
  807. X                if (ptrval2 != NULL) ok = 0;
  808. X            }
  809. X            if (suite[i].data)
  810. X            {
  811. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  812. X            }
  813. X            else
  814. X            {
  815. X                if (ptrval != NULL) ok = 0;
  816. X            }
  817. X            break;
  818. X
  819. X    case POP:
  820. X            /* Test case:  key    = expected key returned
  821. X             *             data   = expected data
  822. X             *             data2  = end to pop from
  823. X             *             result = 0 if list is empty
  824. X             */
  825. X            ptrval2 = dll_pop(list,suite[i].data2,
  826. X                               suite[i].data ? &ptrval : NULL);
  827. X            if (suite[i].result)
  828. X            {
  829. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  830. X            }
  831. X            else
  832. X            {
  833. X                if (ptrval2 != NULL) ok = 0;
  834. X            }
  835. X            if (suite[i].data)
  836. X            {
  837. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  838. X            }
  839. X            else
  840. X            {
  841. X                if (ptrval != NULL) ok = 0;
  842. X            }
  843. X            break;
  844. X
  845. X    case PEEKF:
  846. X            /* Test case:  key    = expected key returned
  847. X             *             data   = expected data
  848. X             *             result = 0 if list is empty
  849. X             */
  850. X            ptrval2 = dll_peekf(list,
  851. X                               suite[i].data ? &ptrval : NULL);
  852. X            if (suite[i].result)
  853. X            {
  854. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  855. X            }
  856. X            else
  857. X            {
  858. X                if (ptrval2 != NULL) ok = 0;
  859. X            }
  860. X            if (suite[i].data)
  861. X            {
  862. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  863. X            }
  864. X            else
  865. X            {
  866. X                if (ptrval != NULL) ok = 0;
  867. X            }
  868. X            break;
  869. X
  870. X    case PEEKR:
  871. X            /* Test case:  key    = expected key returned
  872. X             *             data   = expected data
  873. X             *             result = 0 if list is empty
  874. X             */
  875. X            ptrval2 = dll_peekr(list,
  876. X                               suite[i].data ? &ptrval : NULL);
  877. X            if (suite[i].result)
  878. X            {
  879. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  880. X            }
  881. X            else
  882. X            {
  883. X                if (ptrval2 != NULL) ok = 0;
  884. X            }
  885. X            if (suite[i].data)
  886. X            {
  887. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  888. X            }
  889. X            else
  890. X            {
  891. X                if (ptrval != NULL) ok = 0;
  892. X            }
  893. X            break;
  894. X
  895. X    case PEEK:
  896. X            /* Test case:  key    = expected key returned
  897. X             *             data   = expected data
  898. X             *             data2  = end to peek into
  899. X             *             result = 0 if list is empty
  900. X             */
  901. X            ptrval2 = dll_peek(list,suite[i].data2,
  902. X                               suite[i].data ? &ptrval : NULL);
  903. X            if (suite[i].result)
  904. X            {
  905. X                if (*(int*)ptrval2 != suite[i].key) ok = 0;
  906. X            }
  907. X            else
  908. X            {
  909. X                if (ptrval2 != NULL) ok = 0;
  910. X            }
  911. X            if (suite[i].data)
  912. X            {
  913. X                if (*(int*)ptrval != suite[i].data) ok = 0;
  914. X            }
  915. X            else
  916. X            {
  917. X                if (ptrval != NULL) ok = 0;
  918. X            }
  919. X            break;
  920. X
  921. X    default:
  922. X            break;
  923. X        }
  924. X
  925. X        /* Note test case failure */
  926. X        if (!ok) fail = 1;
  927. X
  928. X        /* Display result of test case */
  929. X        printf("%4.4d %-9.9s %5.4d %5.4d %5.4d  %5.4d   %5.4d   ",
  930. X               i,opnames[suite[i].op],suite[i].key,suite[i].data,
  931. X               suite[i].data2,suite[i].result,intval);
  932. X        if (ptrval == NULL) printf(" NULL   ");
  933. X        else printf("%5.4d   ",*(int*)ptrval);
  934. X        if (ptrval2 == NULL) printf(" NULL    ");
  935. X        else printf("%5.4d    ",*(int*)ptrval2);
  936. X        if (ok) printf("yes  ");
  937. X        else printf("no   ");
  938. X        printf("\n");
  939. X
  940. X        /* Dump the list if requested */
  941. X        if ((suite[i].dump) && (list != NULL))
  942. X        {
  943. X            printf("Contents of list:\n");
  944. X            dll_dump(list,dumpKey,NULL);
  945. X        }
  946. X    }
  947. X    if (suite[i].op == END)
  948. X    {
  949. X        i = done;
  950. X    }
  951. X
  952. X    /* Display summary */
  953. X    printf("TEST %s\n",(fail ? "FAILED" : "PASSED"));
  954. X
  955. X    /* Return 0 on success, non-zero on failure */
  956. X    return ((i != done) || fail);
  957. X}
  958. X
  959. X/********* End of file *********/
  960. X
  961. END_OF_src/list/test.c
  962. if test 23698 -ne `wc -c <src/list/test.c`; then
  963.     echo shar: \"src/list/test.c\" unpacked with wrong size!
  964. fi
  965. # end of overwriting check
  966. fi
  967. echo shar: End of archive 10 \(of 10\).
  968. cp /dev/null ark10isdone
  969. MISSING=""
  970. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  971.     if test ! -f ark${I}isdone ; then
  972.     MISSING="${MISSING} ${I}"
  973.     fi
  974. done
  975. if test "${MISSING}" = "" ; then
  976.     echo You have unpacked all 10 archives.
  977.     echo "Now edit common.mk and do a 'make all'"
  978.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  979. else
  980.     echo You still need to unpack the following archives:
  981.     echo "        " ${MISSING}
  982. fi
  983. ##  End of shell archive.
  984. exit 0
  985.  
  986.