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 "gtxtextcb.h" /*Module interface*/
17 #include "AFS_component_version_number.c"
25 register afs_int32 code; /*Return code*/
26 struct gator_textcb_hdr *newCB; /*Ptr to new CB hdr*/
27 char buf[1024]; /*Text buffer*/
28 int do_debugging; /*Print out debugging info?*/
29 int i, j, k; /*Loop variables*/
30 struct gator_textcb_entry *curr_ent; /*Ptr to text entry*/
31 char *curr_char; /*Current char to print*/
33 printf("\nTesting the gator text object circular buffer package\n\n");
34 printf("Enter 1 to turn debugging on, 0 otherwise: ");
35 scanf("%d", &do_debugging);
36 printf("Initializing CB package: debugging %s\n", (do_debugging ? "YES" : "NO"));
37 code = gator_textcb_Init(do_debugging);
39 printf("Initialization failed\n");
42 printf("Creating a CB with up to 100 entries of 80 chars each\n");
43 newCB = gator_textcb_Create(100, 80);
44 if (newCB == (struct gator_textcb_hdr *)0) {
45 printf("Can't create new circular buffer.");
50 * Start writing stuff to this circ buff.
52 printf("First write\n");
53 sprintf(buf, "%s", "0123456789");
54 code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 0);
56 printf("First write failed, code is %d\n", code);
58 printf("Second write, highlighted\n");
59 code = gator_textcb_Write(newCB, buf, 10, 1, 0);
61 printf("Second write failed, code is %d\n", code);
63 printf("Third write, bulk\n");
64 sprintf(buf, "%s", "Now is the time for all good men to come to the aid of their country");
65 code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 1);
67 printf("Third write failed, code is %d\n", code);
69 printf("Writing out 3 blank lines\n");
70 code = gator_textcb_BlankLine(newCB, 3);
72 printf("Blank lines failed with error %d\n", code);
75 * Print out the CB status.
77 printf("\nStatus of the circular buffer after the writes:\n");
78 printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored);
79 printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry);
80 printf("\tcurrEnt : %d\n", newCB->currEnt);
81 printf("\tcurrEntIdx : %d\n", newCB->currEntIdx);
82 printf("\toldestEnt : %d\n", newCB->oldestEnt);
83 printf("\toldestEntIdx : %d\n", newCB->oldestEntIdx);
85 printf("\nType in any number to continue: ");
88 curr_ent = newCB->entry + newCB->oldestEntIdx;
89 for (j = 0, i = newCB->oldestEntIdx; j < 5; j++) {
90 printf("\nEntry %d, idx %d\n", curr_ent->ID, i);
91 printf("\thighlight : %d\n", curr_ent->highlight);
92 printf("\tnumInversions : %d\n", curr_ent->numInversions);
93 printf("\tinversions : ");
94 for (k=0; k < GATOR_TEXTCB_MAXINVERSIONS; k++)
95 printf("%d ", curr_ent->inversion[k]);
97 printf("\tcharsUsed : %d\n", curr_ent->charsUsed);
98 printf("\ttextp : '");
99 curr_char = curr_ent->textp;
100 for (k=0; k < curr_ent->charsUsed; k++)
101 printf("%c", *curr_char++);
103 if (i == newCB->maxEntriesStored - 1) {
105 curr_ent = newCB->entry;
113 printf("\nMaking small writes ('a') to force the buffer to circulate\n");
114 printf("Enter any number to continue: ");
116 sprintf(buf, "%s", "a");
117 for (i=0; i < 100; i++) {
119 code = gator_textcb_Write(newCB, buf, 1, 0, 1 /*skip*/);
121 printf("Small write %d failed, code is %d\n", i, code);
126 * Print out the CB status.
128 printf("\nStatus of the circular buffer after the writes:\n");
129 printf("\tmaxEntriesStored: %d\n", newCB->maxEntriesStored);
130 printf("\tmaxCharsPerEntry: %d\n", newCB->maxCharsPerEntry);
131 printf("\tcurrEnt : %d\n", newCB->currEnt);
132 printf("\tcurrEntIdx : %d\n", newCB->currEntIdx);
133 printf("\toldestEnt : %d\n", newCB->oldestEnt);
134 printf("\toldestEntIdx : %d\n", newCB->oldestEntIdx);
136 printf("\nType in any number to continue: ");
139 curr_ent = newCB->entry + newCB->oldestEntIdx;
140 for (j = 0, i = newCB->oldestEntIdx; j < 100; j++) {
141 printf("\nEntry %d, idx %d\n", curr_ent->ID, i);
142 printf("\thighlight : %d\n", curr_ent->highlight);
143 printf("\tnumInversions : %d\n", curr_ent->numInversions);
144 printf("\tinversions : ");
145 for (k=0; k < GATOR_TEXTCB_MAXINVERSIONS; k++)
146 printf("%d ", curr_ent->inversion[k]);
148 printf("\tcharsUsed : %d\n", curr_ent->charsUsed);
149 printf("\ttextp : '");
150 curr_char = curr_ent->textp;
151 for (k=0; k < curr_ent->charsUsed; k++)
152 printf("%c", *curr_char++);
154 if (i == newCB->maxEntriesStored - 1) {
156 curr_ent = newCB->entry;
167 code = gator_textcb_Delete(newCB);
169 printf("CB deletion failed, code is %d\n", code);
174 * It worked, mon! Goombay!!