2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "dataascii.h"
22 #define CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjiklmnopqrstuvwxyz\n"
23 #define CHARS_SIZE sizeof(CHARS)
26 #include <stdlib.h> /* malloc */
29 static char Errmsg[80];
32 dataasciigen(listofchars, buffer, bsize, offset)
33 char *listofchars; /* a null terminated list of characters */
40 int ind; /* index into CHARS array */
48 if ( listofchars == NULL ) {
50 chars_size=CHARS_SIZE;
54 chars_size=strlen(listofchars);
57 for(cnt=offset; cnt<total; cnt++) {
64 } /* end of dataasciigen */
67 dataasciichk(listofchars, buffer, bsize, offset, errmsg)
68 char *listofchars; /* a null terminated list of characters */
76 int ind; /* index into CHARS array */
84 if ( listofchars == NULL ) {
86 chars_size=CHARS_SIZE;
90 chars_size=strlen(listofchars);
93 if ( errmsg != NULL ) {
97 for(cnt=offset; cnt<total; chr++, cnt++) {
99 if ( *chr != charlist[ind] ) {
101 "data mismatch at offset %d, exp:%#o, act:%#o", cnt,
102 charlist[ind], *chr);
107 sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
108 return -1; /* buffer is ok */
110 } /* end of dataasciichk */
115 /***********************************************************************
116 * main for doing unit testing
117 ***********************************************************************/
129 if ((buffer=(char *)malloc(size)) == NULL ) {
134 dataasciigen(NULL, buffer, size, 0);
135 printf("dataasciigen(NULL, buffer, %d, 0)\n", size);
137 ret=dataasciichk(NULL, buffer, size, 0, &errmsg);
138 printf("dataasciichk(NULL, buffer, %d, 0, &errmsg) returned %d %s\n",
142 printf("\tPASS return value is -1 as expected\n");
144 printf("\tFAIL return value is %d, expected -1\n", ret);
146 ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
147 printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
148 size-1, ret, errmsg);
151 printf("\tPASS return value is -1 as expected\n");
153 printf("\tFAIL return value is %d, expected -1\n", ret);
156 printf("changing char 25\n");
158 ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
159 printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
160 size-1, ret, errmsg);
163 printf("\tPASS return value is 25 as expected\n");
165 printf("\tFAIL return value is %d, expected 25\n", ret);
167 dataasciigen("this is a test of the my string" , buffer, size, 0);
168 printf("dataasciigen(\"this is a test of the my string\", buffer, %d, 0)\n", size);
170 ret=dataasciichk("this is a test of the my string", buffer, size, 0, &errmsg);
171 printf("dataasciichk(\"this is a test of the my string\", buffer, %d, 0, &errmsg) returned %d %s\n",
175 printf("\tPASS return value is -1 as expected\n");
177 printf("\tFAIL return value is %d, expected -1\n", ret);
179 ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
180 printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
181 size-1, ret, errmsg);
184 printf("\tPASS return value is -1 as expected\n");
186 printf("\tFAIL return value is %d, expected -1\n", ret);
189 printf("changing char 25\n");
191 ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
192 printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
193 size-1, ret, errmsg);
196 printf("\tPASS return value is 25 as expected\n");
198 printf("\tFAIL return value is %d, expected 25\n", ret);