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>
18 #include "gtxtextcb.h" /*Module interface */
21 #include "AFS_component_version_number.c"
29 afs_int32 code
; /*Return code */
30 struct gator_textcb_hdr
*newCB
; /*Ptr to new CB hdr */
31 char buf
[1024]; /*Text buffer */
32 int do_debugging
; /*Print out debugging info? */
33 int i
, j
, k
; /*Loop variables */
34 struct gator_textcb_entry
*curr_ent
; /*Ptr to text entry */
35 char *curr_char
; /*Current char to print */
37 printf("\nTesting the gator text object circular buffer package\n\n");
38 printf("Enter 1 to turn debugging on, 0 otherwise: ");
39 scanf("%d", &do_debugging
);
40 printf("Initializing CB package: debugging %s\n",
41 (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");
70 "Now is the time for all good men to come to the aid of their country");
71 code
= gator_textcb_Write(newCB
, buf
, strlen(buf
), 0, 1);
73 printf("Third write failed, code is %d\n", code
);
75 printf("Writing out 3 blank lines\n");
76 code
= gator_textcb_BlankLine(newCB
, 3);
78 printf("Blank lines failed with error %d\n", code
);
81 * Print out the CB status.
83 printf("\nStatus of the circular buffer after the writes:\n");
84 printf("\tmaxEntriesStored: %d\n", newCB
->maxEntriesStored
);
85 printf("\tmaxCharsPerEntry: %d\n", newCB
->maxCharsPerEntry
);
86 printf("\tcurrEnt : %d\n", newCB
->currEnt
);
87 printf("\tcurrEntIdx : %d\n", newCB
->currEntIdx
);
88 printf("\toldestEnt : %d\n", newCB
->oldestEnt
);
89 printf("\toldestEntIdx : %d\n", newCB
->oldestEntIdx
);
91 printf("\nType in any number to continue: ");
94 curr_ent
= newCB
->entry
+ newCB
->oldestEntIdx
;
95 for (j
= 0, i
= newCB
->oldestEntIdx
; j
< 5; j
++) {
96 printf("\nEntry %d, idx %d\n", curr_ent
->ID
, i
);
97 printf("\thighlight : %d\n", curr_ent
->highlight
);
98 printf("\tnumInversions : %d\n", curr_ent
->numInversions
);
99 printf("\tinversions : ");
100 for (k
= 0; k
< GATOR_TEXTCB_MAXINVERSIONS
; k
++)
101 printf("%d ", curr_ent
->inversion
[k
]);
103 printf("\tcharsUsed : %d\n", curr_ent
->charsUsed
);
104 printf("\ttextp : '");
105 curr_char
= curr_ent
->textp
;
106 for (k
= 0; k
< curr_ent
->charsUsed
; k
++)
107 printf("%c", *curr_char
++);
109 if (i
== newCB
->maxEntriesStored
- 1) {
111 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
;
171 code
= gator_textcb_Delete(newCB
);
173 printf("CB deletion failed, code is %d\n", code
);
178 * It worked, mon! Goombay!!