home *** CD-ROM | disk | FTP | other *** search
- From decwrl!athertn!sander.cupertino.ca.us!paul@cs.purdue.edu Wed Jan 6 13:53:43 EST 1993
- Submit chipset-2 09/10
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 9 (of 10)."
- # Contents: src/btree/test.c
- # Wrapped by paul@sander on Sun Nov 22 15:41:55 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f src/btree/test.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"src/btree/test.c\"
- else
- echo shar: Extracting \"src/btree/test.c\" \(23159 characters\)
- sed "s/^X//" >src/btree/test.c <<'END_OF_src/btree/test.c'
- X/************************************************************************
- X *
- X * test.c -- This program tests the in-memory B-tree implementation. It
- X * attempts to cover all branches of control less those taken
- X * when malloc fails. Perhaps one day a debugging allocator can
- X * be hooked in to test those as well.
- X *
- X * This file is part of a suite of programs called Software Chipset.
- X * The source code for Software Chipset has been released into the
- X * public domain by its author, Paul Sander.
- X *
- X ************************************************************************/
- X
- X#include <stdio.h>
- X#include "btree.h"
- X
- X/* These are the B-tree operations that the program tests */
- X
- Xenum ops { SETUP, FREESETUP, NEW, DESTROY, INSERT, DELETE, SEARCH,
- X TRAVERSE, FIRST, LAST, NEXT, PREV, RANK, DELRANK, DATA, SETDATA,
- X END
- X};
- X
- Xtypedef enum ops OP;
- X
- Xchar *opnames[] = {"setup","freesetup","new","destroy","insert","delete",
- X "search","traverse","first","last","next","prev","rank",
- X "delrank","data","setdata","end"
- X};
- X
- X/*
- X * The following structure describes a test case. An array of these
- X * is given to an interpreter which performs each test and reports the
- X * results.
- X */
- X
- Xstruct testcase {
- X OP op; /* Operation */
- X int key; /* Insertion/seek key */
- X int data; /* Application-specific or expected data */
- X int data2; /* Secondary data */
- X int result; /* Return code or expected result */
- X int dump; /* If not zero, dumps tree for debugging */
- X};
- X
- Xtypedef struct testcase CASE;
- X
- X/* Value of "key" when calling bt_destroy */
- X#define FREEKEY 1 /* call freeKey() */
- X#define FREEDATA 2 /* call freeData() */
- X
- X/* This is the list of test cases that make up the suite. */
- X
- XCASE suite[] = {
- X/* ------------ OP key data data2 result dump */
- X { SETUP, 0, 0, 0, 0, 0 },
- X { FREESETUP, 0, 0, 0, 0, 0 },
- X { NEW, 0, 0, 0, 0, 0 },
- X { DESTROY, 0, 0, 0, 0, 0 },
- X { INSERT, 0, 0, 0, 0, 0 },
- X { DELETE, 0, 0, 0, 0, 0 },
- X { SEARCH, 0, 0, 0, 0, 0 },
- X { TRAVERSE, 1, 0, 0, 0, 0 },
- X { FIRST, 0, 0, 0, 0, 0 },
- X { LAST, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { RANK, 0, 0, 0, 0, 0 },
- X { DELRANK, 0, 0, 0, 0, 0 },
- X { SETDATA, 0, 0, 0, 0, 0 },
- X { DATA, 0, 0, 0, 0, 0 },
- X { SETUP, 0, 1, 0, 0, 0 },
- X { SETUP, 2, 1, 1, 0, 0 },
- X { SETUP, 3, 0, 1, 1, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { DELETE, 0, 0, 0, 0, 0 },
- X { SEARCH, 0, 0, 0, 0, 0 },
- X { TRAVERSE, 1, 0, 0, 0, 0 },
- X { FIRST, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { LAST, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { FIRST, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { LAST, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { RANK, 0, 0, 0, 0, 0 },
- X { DELRANK, 0, 0, 0, 0, 0 },
- X { SETDATA, 0, 5, 0, 0, 0 },
- X { DATA, 0, 5, 0, 0, 0 },
- X { DELETE, 5, 0, 0, 0, 0 },
- X { SEARCH, 5, 0, 0, 0, 0 },
- X { RANK, -1, 0, 0, 0, 0 },
- X { RANK, 2, 0, 0, 0, 0 },
- X { DELRANK, -1, 0, 0, 0, 0 },
- X { DELRANK, 2, 0, 0, 0, 0 },
- X { DESTROY, 0, 0, 0, 0, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { INSERT, 500, 0, 0, 1, 0 },
- X { INSERT, 500, 0, 0, -1, 0 },
- X { SEARCH, 500, 0, 0, 1, 0 },
- X { TRAVERSE, 1, 20, 0, 1, 0 },
- X { TRAVERSE, 0, 0, 0, 0, 0 },
- X { FIRST, 500, 0, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { SEARCH, 250, 0, 0, 0, 0 },
- X { NEXT, 500, 0, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { LAST, 500, 0, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { SEARCH, 750, 0, 0, 0, 0 },
- X { PREV, 500, 0, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { RANK, 0, 0, 0, 500, 0 },
- X { RANK, 1, 0, 0, 0, 0 },
- X { DELRANK, 1, 0, 0, 0, 0 },
- X { DESTROY, 0, 0, 0, 0, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { INSERT, 600, 20, 0, 1, 0 },
- X { INSERT, 600, 30, 0, -1, 0 },
- X { SEARCH, 600, 0, 0, 1, 0 },
- X { SEARCH, 600, 20, 0, 1, 0 },
- X { TRAVERSE, 1, 50, 0, 1, 0 },
- X { FIRST, 600, 0, 0, 1, 0 },
- X { FIRST, 600, 20, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { SEARCH, 250, 0, 0, 0, 0 },
- X { NEXT, 600, 0, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { SEARCH, 250, 0, 0, 0, 0 },
- X { NEXT, 600, 20, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { LAST, 600, 0, 0, 1, 0 },
- X { LAST, 600, 20, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { SEARCH, 750, 0, 0, 0, 0 },
- X { PREV, 600, 0, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { SEARCH, 750, 0, 0, 0, 0 },
- X { PREV, 600, 20, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { RANK, 0, 0, 0, 600, 0 },
- X { RANK, 0, 20, 0, 600, 0 },
- X { DESTROY, 0, 0, 0, 0, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { INSERT, 500, 50, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { INSERT, 900, 90, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { INSERT, 100, 10, 0, 1, 0 },
- X { INSERT, 200, 20, 0, 1, 0 },
- X { INSERT, 800, 80, 0, 1, 0 },
- X { INSERT, 700, 70, 0, 1, 0 },
- X { INSERT, 1000, 100, 0, 1, 0 },
- X { INSERT, 600, 60, 0, 1, 0 },
- X { TRAVERSE, 1, 0, 0, 8, 0 },
- X { INSERT, 0, 0, 0, 0, 0 },
- X { INSERT, 500, 0, 0, -1, 0 },
- X { INSERT, 900, 0, 0, -1, 0 },
- X { INSERT, 100, 0, 0, -1, 0 },
- X { INSERT, 200, 0, 0, -1, 0 },
- X { INSERT, 800, 0, 0, -1, 0 },
- X { INSERT, 700, 0, 0, -1, 0 },
- X { INSERT, 1000, 0, 0, -1, 0 },
- X { INSERT, 600, 0, 0, -1, 0 },
- X { SEARCH, 50, 0, 0, 0, 0 },
- X { SEARCH, 100, 0, 0, 1, 0 },
- X { SEARCH, 150, 0, 0, 0, 0 },
- X { SEARCH, 200, 0, 0, 1, 0 },
- X { SEARCH, 250, 0, 0, 0, 0 },
- X { SEARCH, 500, 0, 0, 1, 0 },
- X { SEARCH, 550, 0, 0, 0, 0 },
- X { SEARCH, 600, 0, 0, 1, 0 },
- X { SEARCH, 650, 0, 0, 0, 0 },
- X { SEARCH, 700, 0, 0, 1, 0 },
- X { SEARCH, 750, 0, 0, 0, 0 },
- X { SEARCH, 800, 0, 0, 1, 0 },
- X { SEARCH, 850, 0, 0, 0, 0 },
- X { SEARCH, 900, 0, 0, 1, 0 },
- X { SEARCH, 950, 0, 0, 0, 0 },
- X { SEARCH, 1000, 0, 0, 1, 0 },
- X { SEARCH, 1100, 0, 0, 0, 0 },
- X { FIRST, 100, 0, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { NEXT, 100, 10, 0, 1, 0 },
- X { LAST, 1000, 0, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { PREV, 1000, 100, 0, 1, 0 },
- X { SEARCH, 50, 0, 0, 0, 0 },
- X { NEXT, 100, 10, 0, 1, 0 },
- X { NEXT, 200, 20, 0, 1, 0 },
- X { NEXT, 500, 50, 0, 1, 0 },
- X { NEXT, 600, 60, 0, 1, 0 },
- X { NEXT, 700, 0, 0, 1, 0 },
- X { NEXT, 800, 0, 0, 1, 0 },
- X { NEXT, 900, 0, 0, 1, 0 },
- X { NEXT, 1000, 0, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { SEARCH, 1100, 0, 0, 0, 0 },
- X { PREV, 1000, 100, 0, 1, 0 },
- X { PREV, 900, 90, 0, 1, 0 },
- X { PREV, 800, 80, 0, 1, 0 },
- X { PREV, 700, 70, 0, 1, 0 },
- X { PREV, 600, 0, 0, 1, 0 },
- X { PREV, 500, 0, 0, 1, 0 },
- X { PREV, 200, 0, 0, 1, 0 },
- X { PREV, 100, 0, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { INSERT, 300, 30, 0, 1, 0 },
- X { INSERT, 50, 5, 0, 1, 0 },
- X { INSERT, 1100, 110, 0, 1, 0 },
- X { SEARCH, 10, 0, 0, 0, 0 },
- X { NEXT, 50, 5, 0, 1, 0 },
- X { NEXT, 100, 10, 0, 1, 0 },
- X { NEXT, 200, 20, 0, 1, 0 },
- X { NEXT, 300, 30, 0, 1, 0 },
- X { NEXT, 500, 50, 0, 1, 0 },
- X { NEXT, 600, 60, 0, 1, 0 },
- X { NEXT, 700, 0, 0, 1, 0 },
- X { NEXT, 800, 0, 0, 1, 0 },
- X { NEXT, 900, 0, 0, 1, 0 },
- X { NEXT, 1000, 0, 0, 1, 0 },
- X { NEXT, 1100, 0, 0, 1, 0 },
- X { NEXT, 0, 0, 0, 0, 0 },
- X { SEARCH, 1200, 0, 0, 0, 0 },
- X { PREV, 1100, 110, 0, 1, 0 },
- X { PREV, 1000, 100, 0, 1, 0 },
- X { PREV, 900, 90, 0, 1, 0 },
- X { PREV, 800, 80, 0, 1, 0 },
- X { PREV, 700, 70, 0, 1, 0 },
- X { PREV, 600, 0, 0, 1, 0 },
- X { PREV, 500, 0, 0, 1, 0 },
- X { PREV, 300, 0, 0, 1, 0 },
- X { PREV, 200, 0, 0, 1, 0 },
- X { PREV, 100, 0, 0, 1, 0 },
- X { PREV, 50, 0, 0, 1, 0 },
- X { PREV, 0, 0, 0, 0, 0 },
- X { RANK, 0, 5, 0, 50, 0 },
- X { RANK, 1, 10, 0, 100, 0 },
- X { RANK, 2, 20, 0, 200, 0 },
- X { RANK, 3, 30, 0, 300, 0 },
- X { RANK, 4, 50, 0, 500, 0 },
- X { RANK, 6, 70, 0, 700, 0 },
- X { RANK, 10, 110, 0, 1100, 0 },
- X { RANK, 11, 0, 0, 0, 0 },
- X { DESTROY, 1, 0, 0, 11, 0 },
- X { FREESETUP, 0, 0, 0, 0, 0 },
- X { SETUP, 5, 0, 1, 1, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { TRAVERSE, 1, 23, 0, 0, 0 },
- X { INSERT, 3000, 300, 0, 1, 0 },
- X { INSERT, 5000, 500, 0, 1, 0 },
- X { INSERT, 7000, 700, 0, 1, 0 },
- X { INSERT, 9000, 900, 0, 1, 0 },
- X { INSERT, 2000, 200, 0, 1, 0 },
- X { INSERT, 4000, 400, 0, 1, 0 },
- X { INSERT, 1000, 100, 0, 1, 0 },
- X { INSERT, 4500, 450, 0, 1, 0 },
- X { INSERT, 3500, 350, 0, 1, 0 },
- X { INSERT, 2500, 250, 0, 1, 0 },
- X { INSERT, 8000, 800, 0, 1, 0 },
- X { INSERT, 500, 50, 0, 1, 0 },
- X { INSERT, 1500, 150, 0, 1, 0 },
- X { INSERT, 6000, 600, 0, 1, 0 },
- X { INSERT, 3750, 375, 0, 1, 0 },
- X { INSERT, 7500, 750, 0, 1, 0 },
- X { INSERT, 2750, 275, 0, 1, 0 },
- X { INSERT, 4750, 475, 0, 1, 0 },
- X { INSERT, 3250, 325, 0, 1, 0 },
- X { DELRANK, 0, 50, 0, 500, 0 },
- X { DELRANK, 2, 200, 0, 2000, 0 },
- X { DELRANK, 5, 325, 0, 3250, 0 },
- X { INSERT, 3250, 325, 0, 1, 0 },
- X { INSERT, 2000, 200, 0, 1, 0 },
- X { INSERT, 8500, 850, 0, 1, 0 },
- X { INSERT, 9500, 950, 0, 1, 0 },
- X { INSERT, 3300, 330, 0, 1, 0 },
- X { DELETE, 4000, 400, 0, 1, 0 },
- X { DELETE, 9250, 0, 0, 0, 0 },
- X { DELETE, 6000, 600, 0, 1, 0 },
- X { DELETE, 9500, 950, 0, 1, 0 },
- X { INSERT, 6000, 600, 0, 1, 0 },
- X { INSERT, 9500, 950, 0, 1, 0 },
- X { INSERT, 4000, 400, 0, 1, 0 },
- X { INSERT, 6500, 650, 0, 1, 0 },
- X { INSERT, 8750, 875, 0, 1, 0 },
- X { INSERT, 5500, 550, 0, 1, 0 },
- X { DELETE, 6500, 0, 0, 1, 0 },
- X { DELETE, 7000, 0, 0, 1, 0 },
- X { DELRANK, 13, 500, 0, 5000, 0 },
- X { INSERT, 500, 50, 0, 1, 0 },
- X { INSERT, 9200, 920, 0, 1, 0 },
- X { INSERT, 9600, 960, 0, 1, 0 },
- X { INSERT, 4100, 410, 0, 1, 0 },
- X { INSERT, 4200, 420, 0, 1, 0 },
- X { INSERT, 3100, 310, 0, 1, 0 },
- X { INSERT, 3200, 320, 0, 1, 0 },
- X { INSERT, 1100, 110, 0, 1, 0 },
- X { INSERT, 1200, 120, 0, 1, 0 },
- X { INSERT, 1300, 130, 0, 1, 0 },
- X { INSERT, 1400, 140, 0, 1, 0 },
- X { INSERT, 1600, 160, 0, 1, 0 },
- X { INSERT, 1700, 170, 0, 1, 0 },
- X { INSERT, 1800, 180, 0, 1, 0 },
- X { INSERT, 8250, 825, 0, 1, 0 },
- X { DELETE, 3100, 0, 0, 1, 0 },
- X { DELETE, 3200, 0, 0, 1, 0 },
- X { INSERT, 3200, 320, 0, 1, 0 },
- X { INSERT, 3100, 310, 0, 1, 0 },
- X { DESTROY, 3, 0, 0, 36, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { INSERT, 100, 0, 0, 1, 0 },
- X { INSERT, 99, 0, 0, 1, 0 },
- X { INSERT, 98, 0, 0, 1, 0 },
- X { INSERT, 97, 0, 0, 1, 0 },
- X { INSERT, 96, 0, 0, 1, 0 },
- X { INSERT, 95, 0, 0, 1, 0 },
- X { INSERT, 94, 0, 0, 1, 0 },
- X { INSERT, 93, 0, 0, 1, 0 },
- X { INSERT, 92, 0, 0, 1, 0 },
- X { INSERT, 91, 0, 0, 1, 0 },
- X { INSERT, 90, 0, 0, 1, 0 },
- X { INSERT, 89, 0, 0, 1, 0 },
- X { INSERT, 88, 0, 0, 1, 0 },
- X { INSERT, 87, 0, 0, 1, 0 },
- X { INSERT, 86, 0, 0, 1, 0 },
- X { INSERT, 85, 0, 0, 1, 0 },
- X { INSERT, 84, 0, 0, 1, 0 },
- X { INSERT, 83, 0, 0, 1, 0 },
- X { INSERT, 82, 0, 0, 1, 0 },
- X { INSERT, 81, 0, 0, 1, 0 },
- X { INSERT, 80, 0, 0, 1, 0 },
- X { INSERT, 79, 0, 0, 1, 0 },
- X { INSERT, 78, 0, 0, 1, 0 },
- X { INSERT, 77, 0, 0, 1, 0 },
- X { INSERT, 76, 0, 0, 1, 0 },
- X { INSERT, 75, 0, 0, 1, 0 },
- X { INSERT, 74, 0, 0, 1, 0 },
- X { INSERT, 73, 0, 0, 1, 0 },
- X { INSERT, 72, 0, 0, 1, 0 },
- X { INSERT, 71, 0, 0, 1, 0 },
- X { INSERT, 70, 0, 0, 1, 0 },
- X { INSERT, 69, 0, 0, 1, 0 },
- X { DESTROY, 3, 0, 0, 32, 0 },
- X { FREESETUP, 0, 0, 0, 0, 0 },
- X { SETUP, 10, 0, 1, 1, 0 },
- X { NEW, 0, 0, 0, 1, 0 },
- X { INSERT, 2, 20, 0, 1, 0 },
- X { INSERT, 3, 30, 0, 1, 0 },
- X { INSERT, 4, 40, 0, 1, 0 },
- X { INSERT, 5, 50, 0, 1, 0 },
- X { INSERT, 6, 60, 0, 1, 0 },
- X { INSERT, 7, 70, 0, 1, 0 },
- X { INSERT, 8, 80, 0, 1, 0 },
- X { INSERT, 9, 90, 0, 1, 0 },
- X { INSERT, 10, 100, 0, 1, 0 },
- X { SEARCH, 2, 0, 0, 1, 0 },
- X { SEARCH, 3, 0, 0, 1, 0 },
- X { SEARCH, 4, 0, 0, 1, 0 },
- X { SEARCH, 5, 0, 0, 1, 0 },
- X { SEARCH, 6, 0, 0, 1, 0 },
- X { SEARCH, 7, 0, 0, 1, 0 },
- X { SEARCH, 8, 0, 0, 1, 0 },
- X { SEARCH, 9, 0, 0, 1, 0 },
- X { SEARCH, 10, 0, 0, 1, 0 },
- X { SEARCH, 1, 0, 0, 0, 0 },
- X { SEARCH, 11, 0, 0, 0, 0 },
- X { DESTROY, 2, 0, 0, 9, 0 },
- X { FREESETUP, 0, 0, 0, 0, 0 },
- X/* ------------ OP key data data2 result dump */
- X { END, 0, 0, 0, 0, 0 }
- X};
- X
- X/* This is the comparison function */
- X
- X#ifdef __STDC__
- Xint comp(void *key1, void *key2)
- X#else
- Xint comp(key1,key2)
- Xvoid *key1;
- Xvoid *key2;
- X#endif
- X{
- X return *((int*)key1) - *((int*)key2);
- X}
- X
- X/* This function displays a key and its data */
- X#ifdef __STDC__
- Xvoid dumpKey(void *key,void *data,void *info)
- X#else
- Xvoid dumpKey(key,data,info)
- Xvoid *key;
- Xvoid *data;
- Xvoid *info;
- X#endif
- X{
- X printf("key = %4.4d, data = ",*(int*)key);
- X if (data != NULL) printf("%4.4d\n",*(int*)data);
- X else printf("(NULL)\n");
- X return;
- X}
- X
- X/*
- X * These functions are called by bt_destroy, and count the number of
- X * key and data structures are freed, and also verify that the info
- X * parameter is passed properly. Some attempt is made to be sure that
- X * the data are freed before the key.
- X */
- X
- Xint freedKeys; /* Number of keys freed */
- Xint freedData; /* Number of data records freed */
- Xint *expInfo; /* Expected value of info */
- Xint infoOk; /* Indicates that the info was always correct */
- Xint freeOk; /* Indicates that the freeKey and freeData functions
- X * were called correctly
- X */
- X
- X#ifdef __STDC__
- Xvoid freeKey(void *key, void *info)
- X#else
- Xvoid freeKey(key,info)
- Xvoid *key;
- Xvoid *info;
- X#endif
- X{
- X freedKeys++;
- X if ((int*) info != expInfo) infoOk = 0;
- X if ((freedData >= 0) && (freedKeys != freedData)) freeOk = 0;
- X}
- X
- X#ifdef __STDC__
- Xvoid freeData(void *key, void *info)
- X#else
- Xvoid freeData(key,info)
- Xvoid *key;
- Xvoid *info;
- X#endif
- X{
- X if ((freedKeys >= 0) && (freedKeys != freedData)) freeOk = 0;
- X freedData++;
- X if ((int*) info != expInfo) infoOk = 0;
- X}
- X
- X/*
- X * The following variables and the visit() function are used for testing
- X * the bt_traverse() function.
- X */
- X
- Xint lastKey; /* Last key encountered by bt_traverse */
- Xint travOk; /* Traversal successful */
- Xint visited; /* Number of nodes visited */
- X
- X#ifdef __STDC__
- Xvoid visit(void *key, void *info, void *data)
- X#else
- Xvoid visit(key,info,data)
- Xvoid *key;
- Xvoid *info;
- Xvoid *data;
- X#endif
- X{
- X visited++;
- X if ((lastKey != 0) && (*(int*)key <= lastKey)) travOk = 0;
- X else if ((int*) info != expInfo) travOk = 0;
- X lastKey = *(int*) key;
- X return;
- X}
- X
- X/* The test suite starts here... */
- X
- X#ifdef __STDC__
- Xint main(int argc, char **argv)
- X#else
- Xint main(argc,argv)
- Xint argc;
- Xchar **argv;
- X#endif
- X{
- X int i; /* Loop counter */
- X int ok; /* Current test succeeded */
- X int fail; /* Any test failed */
- X int done; /* Holds size of test table */
- X int intval; /* Integer value */
- X void *ptrval; /* Pointer value */
- X void *ptrval2; /* Pointer value */
- X BTREE tree; /* B-tree under test */
- X BT_SETUP setup; /* Configuration data for B-tree */
- X
- X /* Initialization */
- X fail = 0;
- X tree = (BTREE) NULL;
- X setup = (BT_SETUP) NULL;
- X
- X /* Compute the number of test cases there are */
- X done = sizeof(suite)/sizeof(CASE);
- X
- X /* Display heading */
- X printf("test OP key data data2 result intval ptrval ptrval2 pass\n");
- X for (i = 0; (i < done) && (suite[i].op != END); i++)
- X {
- X /* Initialize test case */
- X ok = 1;
- X intval = 0;
- X ptrval = NULL;
- X ptrval2 = NULL;
- X
- X /* Perform test */
- X switch (suite[i].op)
- X {
- X case SETUP:
- X /*
- X * Test case: key = B-tree order,
- X * data2 = 0 if no comparison function,
- X * data = global data,
- X * result = 0 if NULL expected
- X */
- X setup = bt_setup(suite[i].key,
- X (suite[i].data2 ? comp : (int (*)()) NULL),
- X (void*) (suite[i].data ? &suite[i].data
- X : NULL));
- X ok = (suite[i].result != (setup == (BT_SETUP) NULL));
- X break;
- X
- X case FREESETUP:
- X bt_freeSetup(setup);
- X setup = (BT_SETUP) NULL;
- X break;
- X
- X case NEW:
- X /* Test case: result = 0 if NULL expected */
- X tree = bt_new(setup);
- X ok = (suite[i].result != (tree == (BTREE) NULL));
- X break;
- X
- X case DESTROY:
- X /* Test case: result = number of keys to be freed,
- X * key = 0 if neither free fn is called,
- X * FREEKEY if freeKey() only
- X * FREEDATA if freeData() only
- X * FREEKEY+FREEDATA if both
- X * data = info parameter
- X */
- X infoOk = 1;
- X freeOk = 1;
- X expInfo = &suite[i].data;
- X switch (suite[i].key)
- X {
- X case 0:
- X /* Fails only if dumps core or hangs */
- X freedKeys = -1;
- X freedData = -1;
- X bt_destroy(tree,NULL,NULL,&suite[i].data);
- X break;
- X case FREEKEY:
- X freedKeys = 0;
- X freedData = -1;
- X bt_destroy(tree,freeKey,NULL,&suite[i].data);
- X break;
- X case FREEDATA:
- X freedKeys = -1;
- X freedData = 0;
- X bt_destroy(tree,NULL,freeData,&suite[i].data);
- X break;
- X default:
- X freedKeys = 0;
- X freedData = 0;
- X bt_destroy(tree,freeKey,freeData,
- X &suite[i].data);
- X break;
- X }
- X tree = NULL;
- X if (!freeOk || !infoOk) ok = 0;
- X if ((freedKeys >= 0) && (freedKeys != suite[i].result))
- X ok = 0;
- X if ((freedData >= 0) && (freedData != suite[i].result))
- X ok = 0;
- X break;
- X
- X case INSERT:
- X /* Test case: key = key to be inserted
- X * data = data to be stored with it
- X * result = expected val of bt_insert()
- X */
- X intval = bt_insert(tree,
- X suite[i].key ? &suite[i].key : NULL,
- X suite[i].data ? &suite[i].data : NULL);
- X if (intval != suite[i].result) ok = 0;
- X break;
- X
- X case DELETE:
- X /* Test case: key = key to be deleted
- X * data = expected data returned by
- X * bt_delete
- X * result = 0 if failure expected
- X */
- X ptrval2 = bt_delete(tree,
- X suite[i].key ? &suite[i].key : NULL,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].key == 0)
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 == NULL)
- X {
- X if (suite[i].result) ok = 0;
- X }
- X else
- X {
- X if (*(int*)ptrval2 != suite[i].key)
- X {
- X ok = 0;
- X }
- X }
- X }
- X if (suite[i].data != 0)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case SEARCH:
- X /* Test case: key = key to be sought
- X * data = expected data returned by
- X * bt_search
- X * result = 0 if failure expected
- X */
- X ptrval2 = bt_search(tree,
- X suite[i].key ? &suite[i].key : NULL,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].key == 0)
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 == NULL)
- X {
- X if (suite[i].result) ok = 0;
- X }
- X else
- X {
- X if (*(int*)ptrval2 != suite[i].key)
- X {
- X ok = 0;
- X }
- X }
- X }
- X if (suite[i].data != 0)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case TRAVERSE:
- X /* Test case: data = info passed to bt_traverse
- X * key = 0 if NULL is passed as fn
- X * result = the expected number of times
- X * visit() is called
- X */
- X visited = 0;
- X travOk = 1;
- X expInfo = &suite[i].data;
- X lastKey = 0;
- X bt_traverse(tree, (suite[i].key ? visit : NULL),
- X &suite[i].data);
- X ok = travOk;
- X if (visited != suite[i].result) ok = 0;
- X break;
- X
- X case FIRST:
- X /* Test case: key = expected key returned
- X * data = expected data
- X * result = 0 if tree is empty
- X */
- X ptrval2 = bt_first(tree,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].result)
- X {
- X if (*(int*)ptrval2 != suite[i].key) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X if (suite[i].data)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case LAST:
- X /* Test case: key = expected key returned
- X * data = expected data
- X * result = 0 if tree is empty
- X */
- X ptrval2 = bt_last(tree,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].result)
- X {
- X if (*(int*)ptrval2 != suite[i].key) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X if (suite[i].data)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case NEXT:
- X /* Test case: key = expected key returned
- X * data = expected data
- X * result = 0 if last key was found
- X */
- X ptrval2 = bt_next(tree,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].result)
- X {
- X if (*(int*)ptrval2 != suite[i].key) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X if (suite[i].data)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case PREV:
- X /* Test case: key = expected key returned
- X * data = expected data
- X * result = 0 if first key was found
- X */
- X ptrval2 = bt_prev(tree,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].result)
- X {
- X if (*(int*)ptrval2 != suite[i].key) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X if (suite[i].data)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case RANK:
- X /* Test case: key = rank searched for
- X * data = expected data
- X * result = expected key
- X */
- X ptrval2 = bt_rank(tree,suite[i].key,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].result != 0)
- X {
- X if (*(int*)ptrval2 != suite[i].result) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X if (suite[i].data != 0)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X break;
- X
- X case DELRANK:
- X /* Test case: key = rank to be deleted
- X * data = expected data
- X * result = expected key
- X */
- X ptrval2 = bt_delRank(tree,suite[i].key,
- X suite[i].data ? &ptrval : NULL);
- X if (suite[i].result != 0)
- X {
- X if (*(int*)ptrval2 != suite[i].result) ok = 0;
- X }
- X else
- X {
- X if (ptrval2 != NULL) ok = 0;
- X }
- X if (suite[i].data != 0)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X break;
- X
- X case DATA:
- X /* Test case: data = expected data */
- X ptrval = bt_data(tree);
- X if (suite[i].data != 0)
- X {
- X if (*(int*)ptrval != suite[i].data) ok = 0;
- X }
- X else
- X {
- X if (ptrval != NULL) ok = 0;
- X }
- X break;
- X
- X case SETDATA:
- X /* Test case: data = new data */
- X bt_setData(tree,&suite[i].data);
- X break;
- X
- X default:
- X break;
- X }
- X
- X /* Note test case failure */
- X if (!ok) fail = 1;
- X
- X /* Display result of test case */
- X printf("%4.4d %-9.9s %5.4d %5.4d %5.4d %5.4d %5.4d ",
- X i,opnames[suite[i].op],suite[i].key,suite[i].data,
- X suite[i].data2,suite[i].result,intval);
- X if (ptrval == NULL) printf(" NULL ");
- X else printf("%5.4d ",*(int*)ptrval);
- X if (ptrval2 == NULL) printf(" NULL ");
- X else printf("%5.4d ",*(int*)ptrval2);
- X if (ok) printf("yes ");
- X else printf("no ");
- X printf("\n");
- X
- X /* Dump the tree if requested */
- X if ((suite[i].dump) && (tree != NULL))
- X {
- X printf("Contents of tree:\n");
- X bt_dump(tree,dumpKey,NULL);
- X }
- X }
- X if (suite[i].op == END)
- X {
- X i = done;
- X }
- X
- X /* Display summary */
- X printf("TEST %s\n",(fail ? "FAILED" : "PASSED"));
- X
- X /* Return 0 on success, non-zero on failure */
- X return ((i != done) || fail);
- X}
- X
- X/********* End of file *********/
- X
- END_OF_src/btree/test.c
- if test 23159 -ne `wc -c <src/btree/test.c`; then
- echo shar: \"src/btree/test.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- echo shar: End of archive 9 \(of 10\).
- cp /dev/null ark9isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 10 archives.
- echo "Now edit common.mk and do a 'make all'"
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
-