1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000 Silicon Graphics, Inc.
10 #define CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjiklmnopqrstuvwxyz\n"
11 #define CHARS_SIZE sizeof(CHARS)
14 #include <stdlib.h> /* malloc */
17 static char Errmsg[80];
20 dataasciigen(listofchars, buffer, bsize, offset)
21 char *listofchars; /* a null terminated list of characters */
28 int ind; /* index into CHARS array */
36 if ( listofchars == NULL ) {
38 chars_size=CHARS_SIZE;
42 chars_size=strlen(listofchars);
45 for(cnt=offset; cnt<total; cnt++) {
52 } /* end of dataasciigen */
55 dataasciichk(listofchars, buffer, bsize, offset, errmsg)
56 char *listofchars; /* a null terminated list of characters */
64 int ind; /* index into CHARS array */
72 if ( listofchars == NULL ) {
74 chars_size=CHARS_SIZE;
78 chars_size=strlen(listofchars);
81 if ( errmsg != NULL ) {
85 for(cnt=offset; cnt<total; chr++, cnt++) {
87 if ( *chr != charlist[ind] ) {
89 "data mismatch at offset %d, exp:%#o, act:%#o", cnt,
95 sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
96 return -1; /* buffer is ok */
98 } /* end of dataasciichk */
103 /***********************************************************************
104 * main for doing unit testing
105 ***********************************************************************/
117 if ((buffer=(char *)malloc(size)) == NULL ) {
122 dataasciigen(NULL, buffer, size, 0);
123 printf("dataasciigen(NULL, buffer, %d, 0)\n", size);
125 ret=dataasciichk(NULL, buffer, size, 0, &errmsg);
126 printf("dataasciichk(NULL, buffer, %d, 0, &errmsg) returned %d %s\n",
130 printf("\tPASS return value is -1 as expected\n");
132 printf("\tFAIL return value is %d, expected -1\n", ret);
134 ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
135 printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
136 size-1, ret, errmsg);
139 printf("\tPASS return value is -1 as expected\n");
141 printf("\tFAIL return value is %d, expected -1\n", ret);
144 printf("changing char 25\n");
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 25 as expected\n");
153 printf("\tFAIL return value is %d, expected 25\n", ret);
155 dataasciigen("this is a test of the my string" , buffer, size, 0);
156 printf("dataasciigen(\"this is a test of the my string\", buffer, %d, 0)\n", size);
158 ret=dataasciichk("this is a test of the my string", buffer, size, 0, &errmsg);
159 printf("dataasciichk(\"this is a test of the my string\", buffer, %d, 0, &errmsg) returned %d %s\n",
163 printf("\tPASS return value is -1 as expected\n");
165 printf("\tFAIL return value is %d, expected -1\n", ret);
167 ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
168 printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
169 size-1, ret, errmsg);
172 printf("\tPASS return value is -1 as expected\n");
174 printf("\tFAIL return value is %d, expected -1\n", ret);
177 printf("changing char 25\n");
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 25 as expected\n");
186 printf("\tFAIL return value is %d, expected 25\n", ret);