2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * cb_test: A test of the gator text circular buffer package.
12 *------------------------------------------------------------------------*/
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include "gtxtextcb.h" /*Module interface */
23 #include "AFS_component_version_number.c"
31 register afs_int32 code; /*Return code */
32 struct gator_textcb_hdr *newCB; /*Ptr to new CB hdr */
33 char buf[1024]; /*Text buffer */
34 int do_debugging; /*Print out debugging info? */
35 int i, j, k; /*Loop variables */
36 struct gator_textcb_entry *curr_ent; /*Ptr to text entry */
37 char *curr_char; /*Current char to print */
39 printf("\nTesting the gator text object circular buffer package\n\n");
40 printf("Enter 1 to turn debugging on, 0 otherwise: ");
41 scanf("%d", &do_debugging);
42 printf("Initializing CB package: debugging %s\n",
43 (do_debugging ? "YES" : "NO"));
44 code = gator_textcb_Init(do_debugging);
46 printf("Initialization failed\n");
49 printf("Creating a CB with up to 100 entries of 80 chars each\n");
50 newCB = gator_textcb_Create(100, 80);
51 if (newCB == (struct gator_textcb_hdr *)0) {
52 printf("Can't create new circular buffer.");
57 * Start writing stuff to this circ buff.
59 printf("First write\n");
60 sprintf(buf, "%s", "0123456789");
61 code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 0);
63 printf("First write failed, code is %d\n", code);
65 printf("Second write, highlighted\n");
66 code = gator_textcb_Write(newCB, buf, 10, 1, 0);
68 printf("Second write failed, code is %d\n", code);
70 printf("Third write, bulk\n");
72 "Now is the time for all good men to come to the aid of their country");
73 code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 1);
75 printf("Third write failed, code is %d\n", code);
77 printf("Writing out 3 blank lines\n");
78 code = gator_textcb_BlankLine(newCB, 3);
80 printf("Blank lines failed with error %d\n", code);
83 * Print out the CB status.
85 printf("\nStatus of the circular buffer after the writes:\n");
86 printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored);
87 printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry);
88 printf("\tcurrEnt : %d\n", newCB->currEnt);
89 printf("\tcurrEntIdx : %d\n", newCB->currEntIdx);
90 printf("\toldestEnt : %d\n", newCB->oldestEnt);
91 printf("\toldestEntIdx : %d\n", newCB->oldestEntIdx);
93 printf("\nType in any number to continue: ");
96 curr_ent = newCB->entry + newCB->oldestEntIdx;
97 for (j = 0, i = newCB->oldestEntIdx; j < 5; j++) {
98 printf("\nEntry %d, idx %d\n", curr_ent->ID, i);
99 printf("\thighlight : %d\n", curr_ent->highlight);
100 printf("\tnumInversions : %d\n", curr_ent->numInversions);
101 printf("\tinversions : ");
102 for (k = 0; k < GATOR_TEXTCB_MAXINVERSIONS; k++)
103 printf("%d ", curr_ent->inversion[k]);
105 printf("\tcharsUsed : %d\n", curr_ent->charsUsed);
106 printf("\ttextp : '");
107 curr_char = curr_ent->textp;
108 for (k = 0; k < curr_ent->charsUsed; k++)
109 printf("%c", *curr_char++);
111 if (i == newCB->maxEntriesStored - 1) {
113 curr_ent = newCB->entry;
120 printf("\nMaking small writes ('a') to force the buffer to circulate\n");
121 printf("Enter any number to continue: ");
123 sprintf(buf, "%s", "a");
124 for (i = 0; i < 100; i++) {
126 code = gator_textcb_Write(newCB, buf, 1, 0, 1 /*skip */ );
128 printf("Small write %d failed, code is %d\n", i, code);
133 * Print out the CB status.
135 printf("\nStatus of the circular buffer after the writes:\n");
136 printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored);
137 printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry);
138 printf("\tcurrEnt : %d\n", newCB->currEnt);
139 printf("\tcurrEntIdx : %d\n", newCB->currEntIdx);
140 printf("\toldestEnt : %d\n", newCB->oldestEnt);
141 printf("\toldestEntIdx : %d\n", newCB->oldestEntIdx);
143 printf("\nType in any number to continue: ");
146 curr_ent = newCB->entry + newCB->oldestEntIdx;
147 for (j = 0, i = newCB->oldestEntIdx; j < 100; j++) {
148 printf("\nEntry %d, idx %d\n", curr_ent->ID, i);
149 printf("\thighlight : %d\n", curr_ent->highlight);
150 printf("\tnumInversions : %d\n", curr_ent->numInversions);
151 printf("\tinversions : ");
152 for (k = 0; k < GATOR_TEXTCB_MAXINVERSIONS; k++)
153 printf("%d ", curr_ent->inversion[k]);
155 printf("\tcharsUsed : %d\n", curr_ent->charsUsed);
156 printf("\ttextp : '");
157 curr_char = curr_ent->textp;
158 for (k = 0; k < curr_ent->charsUsed; k++)
159 printf("%c", *curr_char++);
161 if (i == newCB->maxEntriesStored - 1) {
163 curr_ent = newCB->entry;
173 code = gator_textcb_Delete(newCB);
175 printf("CB deletion failed, code is %d\n", code);
180 * It worked, mon! Goombay!!