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 <afs/param.h>
15 #include <afsconfig.h>
19 #include "gtxtextcb.h" /*Module interface*/
22 #include "AFS_component_version_number.c"
30 register afs_int32 code; /*Return code*/
31 struct gator_textcb_hdr *newCB; /*Ptr to new CB hdr*/
32 char buf[1024]; /*Text buffer*/
33 int do_debugging; /*Print out debugging info?*/
34 int i, j, k; /*Loop variables*/
35 struct gator_textcb_entry *curr_ent; /*Ptr to text entry*/
36 char *curr_char; /*Current char to print*/
38 printf("\nTesting the gator text object circular buffer package\n\n");
39 printf("Enter 1 to turn debugging on, 0 otherwise: ");
40 scanf("%d", &do_debugging);
41 printf("Initializing CB package: debugging %s\n", (do_debugging ? "YES" : "NO"));
42 code = gator_textcb_Init(do_debugging);
44 printf("Initialization failed\n");
47 printf("Creating a CB with up to 100 entries of 80 chars each\n");
48 newCB = gator_textcb_Create(100, 80);
49 if (newCB == (struct gator_textcb_hdr *)0) {
50 printf("Can't create new circular buffer.");
55 * Start writing stuff to this circ buff.
57 printf("First write\n");
58 sprintf(buf, "%s", "0123456789");
59 code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 0);
61 printf("First write failed, code is %d\n", code);
63 printf("Second write, highlighted\n");
64 code = gator_textcb_Write(newCB, buf, 10, 1, 0);
66 printf("Second write failed, code is %d\n", code);
68 printf("Third write, bulk\n");
69 sprintf(buf, "%s", "Now is the time for all good men to come to the aid of their country");
70 code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 1);
72 printf("Third write failed, code is %d\n", code);
74 printf("Writing out 3 blank lines\n");
75 code = gator_textcb_BlankLine(newCB, 3);
77 printf("Blank lines failed with error %d\n", code);
80 * Print out the CB status.
82 printf("\nStatus of the circular buffer after the writes:\n");
83 printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored);
84 printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry);
85 printf("\tcurrEnt : %d\n", newCB->currEnt);
86 printf("\tcurrEntIdx : %d\n", newCB->currEntIdx);
87 printf("\toldestEnt : %d\n", newCB->oldestEnt);
88 printf("\toldestEntIdx : %d\n", newCB->oldestEntIdx);
90 printf("\nType in any number to continue: ");
93 curr_ent = newCB->entry + newCB->oldestEntIdx;
94 for (j = 0, i = newCB->oldestEntIdx; j < 5; j++) {
95 printf("\nEntry %d, idx %d\n", curr_ent->ID, i);
96 printf("\thighlight : %d\n", curr_ent->highlight);
97 printf("\tnumInversions : %d\n", curr_ent->numInversions);
98 printf("\tinversions : ");
99 for (k=0; k < GATOR_TEXTCB_MAXINVERSIONS; k++)
100 printf("%d ", curr_ent->inversion[k]);
102 printf("\tcharsUsed : %d\n", curr_ent->charsUsed);
103 printf("\ttextp : '");
104 curr_char = curr_ent->textp;
105 for (k=0; k < curr_ent->charsUsed; k++)
106 printf("%c", *curr_char++);
108 if (i == newCB->maxEntriesStored - 1) {
110 curr_ent = newCB->entry;
118 printf("\nMaking small writes ('a') to force the buffer to circulate\n");
119 printf("Enter any number to continue: ");
121 sprintf(buf, "%s", "a");
122 for (i=0; i < 100; i++) {
124 code = gator_textcb_Write(newCB, buf, 1, 0, 1 /*skip*/);
126 printf("Small write %d failed, code is %d\n", i, code);
131 * Print out the CB status.
133 printf("\nStatus of the circular buffer after the writes:\n");
134 printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored);
135 printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry);
136 printf("\tcurrEnt : %d\n", newCB->currEnt);
137 printf("\tcurrEntIdx : %d\n", newCB->currEntIdx);
138 printf("\toldestEnt : %d\n", newCB->oldestEnt);
139 printf("\toldestEntIdx : %d\n", newCB->oldestEntIdx);
141 printf("\nType in any number to continue: ");
144 curr_ent = newCB->entry + newCB->oldestEntIdx;
145 for (j = 0, i = newCB->oldestEntIdx; j < 100; j++) {
146 printf("\nEntry %d, idx %d\n", curr_ent->ID, i);
147 printf("\thighlight : %d\n", curr_ent->highlight);
148 printf("\tnumInversions : %d\n", curr_ent->numInversions);
149 printf("\tinversions : ");
150 for (k=0; k < GATOR_TEXTCB_MAXINVERSIONS; k++)
151 printf("%d ", curr_ent->inversion[k]);
153 printf("\tcharsUsed : %d\n", curr_ent->charsUsed);
154 printf("\ttextp : '");
155 curr_char = curr_ent->textp;
156 for (k=0; k < curr_ent->charsUsed; k++)
157 printf("%c", *curr_char++);
159 if (i == newCB->maxEntriesStored - 1) {
161 curr_ent = newCB->entry;
172 code = gator_textcb_Delete(newCB);
174 printf("CB deletion failed, code is %d\n", code);
179 * It worked, mon! Goombay!!