Remove the RCSID macro
[openafs.git] / src / gtx / cb_test.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * cb_test: A test of the gator text circular buffer package.
12  *------------------------------------------------------------------------*/
13
14 #include <afsconfig.h>
15 #include <afs/param.h>
16
17
18 #include "gtxtextcb.h"          /*Module interface */
19
20
21 #include "AFS_component_version_number.c"
22
23 main(argc, argv)
24      int argc;
25      char **argv;
26
27 {                               /*main */
28
29     register 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 */
36
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);
43     if (code) {
44         printf("Initialization failed\n");
45         exit(-1);
46     }
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.");
51         exit(-1);
52     }
53
54     /*
55      * Start writing stuff to this circ buff.
56      */
57     printf("First write\n");
58     sprintf(buf, "%s", "0123456789");
59     code = gator_textcb_Write(newCB, buf, strlen(buf), 0, 0);
60     if (code)
61         printf("First write failed, code is %d\n", code);
62
63     printf("Second write, highlighted\n");
64     code = gator_textcb_Write(newCB, buf, 10, 1, 0);
65     if (code)
66         printf("Second write failed, code is %d\n", code);
67
68     printf("Third write, bulk\n");
69     sprintf(buf, "%s",
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);
72     if (code)
73         printf("Third write failed, code is %d\n", code);
74
75     printf("Writing out 3 blank lines\n");
76     code = gator_textcb_BlankLine(newCB, 3);
77     if (code)
78         printf("Blank lines failed with error %d\n", code);
79
80     /*
81      * Print out the CB status.
82      */
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);
90
91     printf("\nType in any number to continue: ");
92     scanf("%d", &i);
93
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]);
102         printf("\n");
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++);
108         printf("'\n");
109         if (i == newCB->maxEntriesStored - 1) {
110             i = 0;
111             curr_ent = newCB->entry;
112         } else {
113             i++;
114             curr_ent++;
115         }
116     }                           /*for loop */
117
118     printf("\nMaking small writes ('a') to force the buffer to circulate\n");
119     printf("Enter any number to continue: ");
120     scanf("%d", &i);
121     sprintf(buf, "%s", "a");
122     for (i = 0; i < 100; i++) {
123         printf("#");
124         code = gator_textcb_Write(newCB, buf, 1, 0, 1 /*skip */ );
125         if (code)
126             printf("Small write %d failed, code is %d\n", i, code);
127     }
128     printf("\n");
129
130     /*
131      * Print out the CB status.
132      */
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);
140
141     printf("\nType in any number to continue: ");
142     scanf("%d", &i);
143
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]);
152         printf("\n");
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++);
158         printf("'\n");
159         if (i == newCB->maxEntriesStored - 1) {
160             i = 0;
161             curr_ent = newCB->entry;
162         } else {
163             i++;
164             curr_ent++;
165         }
166     }                           /*for loop */
167
168     /*
169      * Clean-up time!
170      */
171     code = gator_textcb_Delete(newCB);
172     if (code) {
173         printf("CB deletion failed, code is %d\n", code);
174         exit(-1);
175     }
176
177     /*
178      * It worked, mon!  Goombay!!
179      */
180     exit(0);
181
182 }                               /*main */