00001 /* Copyright (C) 2000-2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* Test of all stringfunktions that is coded in assembler */ 00018 00019 #include <my_global.h> 00020 #include <stdarg.h> 00021 #include "m_string.h" 00022 00023 #define F_LEN 8 00024 #define F_CHAR 'A' 00025 #define F_FILL 'B' 00026 #define T_LEN 15 00027 #define T_CHAR 'D' 00028 #define T_FILL 'E' 00029 #define F_PREFILL '0' 00030 #define T_PREFILL '1' 00031 00032 static char from_buff[100],to_buff[100]; 00033 static my_string from,to; 00034 static int errors,tests; 00035 static int test_strarg(const char *name,...); 00036 static void init_strings (void); /* Init from and to */ 00037 void test_arg (const char *message,long func_value,long value); 00038 int compare_buff(const char *message,my_string b1,my_string b2,int length, 00039 pchar fill, pchar prefill); 00040 00041 static int my_test(int a) 00042 { 00043 return a ? 1 : 0; 00044 } 00045 00046 int main(void) 00047 { 00048 static char v1[]="Monty",v2[]="on",v3[]="Montys",v4[]="ty",v5[]="gr", 00049 v6[]="hohohoo",v7[]="hohoo",v8[]="hohooo",v9[]="t", 00050 cont[]="qwet"; 00051 errors=tests=0; 00052 init_strings(); 00053 00054 test_arg("bcmp(from,to,5)",(long) my_test(bcmp(from,to,5)),1L); 00055 test_arg("bcmp(from,from,5)",(long) bcmp(from,from,5),0L); 00056 00057 test_arg("bcmp(from,to,0)",(long) bcmp(from,to,0),0L); 00058 test_arg("strend(from)",(long) strend(from),(long) from+F_LEN); 00059 test_arg("strchr(v1,'M')",(long) strchr(v1,'M'),(long) v1); 00060 test_arg("strchr(v1,'y')",(long) strchr(v1,'y'),(long) v1+4); 00061 test_arg("strchr(v1,'x')",(long) strchr(v1,'x'),0L); 00062 test_arg("strcont(v1,cont)",(long) strcont(v1,cont),(long) v1+3); 00063 test_arg("strcont(v1,v2)",(long) strcont(v1,v2),(long) v1+1); 00064 test_arg("strcont(v1,v5)",(long) strcont(v1,v5),0L); 00065 test_arg("is_prefix(v3,v1)",(long) is_prefix(v3,v1),1L); 00066 test_arg("is_prefix(v1,v3)",(long) is_prefix(v1,v3),0L); 00067 test_arg("is_prefix(v3,v4)",(long) is_prefix(v3,v4),0L); 00068 test_arg("strstr(v1,v1)",(long) strstr(v1,v1),(long) v1); 00069 test_arg("strstr(v1,v2)",(long) strstr(v1,v2),(long) v1+1); 00070 test_arg("strstr(v1,v4)",(long) strstr(v1,v4),(long) v1+3); 00071 test_arg("strstr(v6,v7)",(long) strstr(v6,v7),(long) v6+2); 00072 test_arg("strstr(v1,v9)",(long) strstr(v1,v9),(long) v1+3); 00073 test_arg("strstr(v1,v3)",(long) strstr(v1,v3),0L); 00074 test_arg("strstr(v1,v5)",(long) strstr(v1,v5),0L); 00075 test_arg("strstr(v6,v8)",(long) strstr(v6,v8),0L); 00076 00077 test_arg("strinstr(v1,v4)",(long) strinstr(v1,v4),4L); 00078 test_arg("strinstr(v1,v5)",(long) strinstr(v1,v5),0L); 00079 test_arg("strlen(from)",(long) strlen(from),(long) F_LEN); 00080 test_arg("strlen(\"\")",(long) strlen(""),0L); 00081 #ifdef HAVE_STRNLEN 00082 test_arg("strnlen(from,3)",(long) strnlen(from,3),3L); 00083 test_arg("strnlen(from,0)",(long) strnlen(from,0),0L); 00084 test_arg("strnlen(from,1000)",(long) strnlen(from,1000),(long) F_LEN); 00085 #endif 00086 00087 test_strarg("bfill(to,4,' ')",(bfill(to,4,' '),0L),INT_MAX32,4,' ',0,0); 00088 test_strarg("bfill(from,0,' ')",(bfill(from,0,' '),0L),INT_MAX32,0,0); 00089 test_strarg("bzero(to,3)",(bzero(to,3),0L),INT_MAX32,3,0,0,0); 00090 test_strarg("bzero(to,0)",(bzero(to,0),0L),INT_MAX32,0,0); 00091 test_strarg("bmove(to,from,4)",(bmove(to,from,4),0L),INT_MAX32,4,F_CHAR, 00092 0,0); 00093 test_strarg("bmove(to,from,0)",(bmove(to,from,0),0L),INT_MAX32,0,0); 00094 test_strarg("bmove_upp(to+6,from+6,3)",(bmove_upp(to+6,from+6,3),0L),INT_MAX32, 00095 3,T_CHAR,3,F_CHAR,0,0); 00096 test_strarg("bmove_upp(to,from,0)",(bmove_upp(to,from,0),0L),INT_MAX32,0,0); 00097 test_strarg("bmove_align(to,from,8)",(bmove_align(to,from,8),0L),INT_MAX32, 00098 8,F_CHAR,0,0); 00099 test_strarg("strappend(to,3,' ')",(strappend(to,3,' '),0L),INT_MAX32, 00100 3,T_CHAR,1,0,T_LEN-4,T_CHAR,1,0,0,0); 00101 test_strarg("strappend(to,T_LEN+5,' ')",(strappend(to,T_LEN+5,' '),0L),INT_MAX32, 00102 T_LEN,T_CHAR,5,' ',1,0,0,0); 00103 test_strarg("strcat(to,from)",strcat(to,from),to,T_LEN,T_CHAR, 00104 F_LEN,F_CHAR,1,0,0,0); 00105 test_strarg("strcat(to,\"\")",strcat(to,""),INT_MAX32,0,0); 00106 test_strarg("strfill(to,4,' ')",strfill(to,4,' '),to+4,4,' ',1,0,0,0); 00107 test_strarg("strfill(from,0,' ')",strfill(from,0,' '),from,0,1,0,0); 00108 test_strarg("strmake(to,from,4)",strmake(to,from,4),to+4,4,F_CHAR, 00109 1,0,0,0); 00110 test_strarg("strmake(to,from,0)",strmake(to,from,0),to+0,1,0,0,0); 00111 test_strarg("strmov(to,from)",strmov(to,from),to+F_LEN,F_LEN,F_CHAR,0,0); 00112 test_strarg("strmov(to,\"\")",strmov(to,""),to,1,0,0,0); 00113 test_strarg("strnmov(to,from,2)",strnmov(to,from,2),to+2,2,F_CHAR,0,0); 00114 test_strarg("strnmov(to,from,F_LEN+5)",strnmov(to,from,F_LEN+5),to+F_LEN, 00115 F_LEN,F_CHAR,1,0,0,0); 00116 test_strarg("strnmov(to,\"\",2)",strnmov(to,"",2),to,1,0,0,0); 00117 test_strarg("strxmov(to,from,\"!!\",NullS)",strxmov(to,from,"!!",NullS),to+F_LEN+2,F_LEN,F_CHAR,2,'!',0,0,0); 00118 test_strarg("strxmov(to,NullS)",strxmov(to,NullS),to,1,0,0,0); 00119 test_strarg("strxmov(to,from,from,from,from,from,'!!',from,NullS)",strxmov(to,from,from,from,from,from,"!!",from,NullS),to+F_LEN*6+2,F_LEN,F_CHAR,F_LEN,F_CHAR,F_LEN,F_CHAR,F_LEN,F_CHAR,F_LEN,F_CHAR,2,'!',F_LEN,F_CHAR,1,0,0,0); 00120 00121 test_strarg("strxnmov(to,100,from,\"!!\",NullS)",strxnmov(to,100,from,"!!",NullS),to+F_LEN+2,F_LEN,F_CHAR,2,'!',0,0,0); 00122 test_strarg("strxnmov(to,2,NullS)",strxnmov(to,2,NullS),to,1,0,0,0); 00123 test_strarg("strxnmov(to,100,from,from,from,from,from,'!!',from,NullS)",strxnmov(to,100,from,from,from,from,from,"!!",from,NullS),to+F_LEN*6+2,F_LEN,F_CHAR,F_LEN,F_CHAR,F_LEN,F_CHAR,F_LEN,F_CHAR,F_LEN,F_CHAR,2,'!',F_LEN,F_CHAR,1,0,0,0); 00124 test_strarg("strxnmov(to,2,\"!!!\",NullS)",strxnmov(to,2,"!!!",NullS),to+2,2,'!',0,0,0); 00125 test_strarg("strxnmov(to,2,\"!!\",NullS)",strxnmov(to,2,"!!","xx",NullS),to+2,2,'!',0,0,0); 00126 test_strarg("strxnmov(to,2,\"!\",\"x\",\"y\",NullS)",strxnmov(to,2,"!","x","y",NullS),to+2,1,'!',1,'x',0,0,0); 00127 00128 test_strarg("bchange(to,2,from,4,6)",(bchange(to,2,from,4,6),0L),INT_MAX32, 00129 4,F_CHAR,2,T_CHAR,0,0); 00130 00131 printf("tests: %d errors: %d\n",tests,errors); 00132 if (errors) 00133 fputs("--- Some functions doesn't work!! Fix them\n",stderr); 00134 return(errors > 0); 00135 } /* main */ 00136 00137 00138 /* Init strings */ 00139 00140 void init_strings(void) 00141 { 00142 reg1 int i; 00143 reg2 char *pos; 00144 00145 from=from_buff+3; to=to_buff+3; 00146 00147 pos=from_buff; *pos++= F_FILL; *pos++=F_FILL; *pos++=F_PREFILL; 00148 for (i=0 ; i < F_LEN ; i++) 00149 *pos++=F_CHAR; 00150 *pos++=0; 00151 for (i=0; i<50 ; i++) 00152 *pos++= F_FILL; 00153 00154 pos=to_buff; *pos++= T_FILL; *pos++=T_FILL; *pos++=T_PREFILL; 00155 for (i=0 ; i < T_LEN ; i++) 00156 *pos++=T_CHAR; 00157 *pos++=0; 00158 for (i=0; i<50 ; i++) 00159 *pos++= T_FILL; 00160 } /* init_strings */ 00161 00162 00163 /* Test that function return rigth value */ 00164 00165 void test_arg(const char *message, long int func_value, long int value) 00166 { 00167 tests++; 00168 printf("testing '%s'\n",message); 00169 if (func_value != value) 00170 { 00171 printf("func: '%s' = %ld Should be: %ld\n",message,func_value,value); 00172 errors++; 00173 } 00174 } /* test_arg */ 00175 00176 /* Test function return value and from and to arrays */ 00177 00178 static int test_strarg(const char *message,...) 00179 { 00180 long func_value,value; 00181 int error,length; 00182 char chr,cmp_buff[100],*pos,*pos2; 00183 va_list pvar; 00184 00185 tests++; 00186 va_start(pvar,message); 00187 func_value=va_arg(pvar,long); 00188 value=va_arg(pvar,long); 00189 00190 printf("testing '%s'\n",message); 00191 if (func_value != value && value != INT_MAX32) 00192 { 00193 printf("func: '%s' = %ld Should be: %ld\n",message,func_value,value); 00194 errors++; 00195 } 00196 pos= cmp_buff; 00197 while ((length = va_arg(pvar, int)) != 0) 00198 { 00199 chr= (char) (va_arg(pvar, int)); 00200 while (length--) 00201 *pos++=chr; 00202 } 00203 pos2=to+ (int)(pos-cmp_buff); 00204 while (pos <= cmp_buff+T_LEN) 00205 *pos++= *pos2++; 00206 if (compare_buff(message,to,cmp_buff,(int) (pos-cmp_buff),T_FILL,T_PREFILL)) 00207 { 00208 init_strings(); 00209 va_end(pvar); 00210 return 1; 00211 } 00212 00213 pos= cmp_buff; 00214 while ((length = va_arg(pvar, int)) != 0) 00215 { 00216 chr= (char) (va_arg(pvar, int)); 00217 while (length--) 00218 *pos++=chr; 00219 } 00220 pos2=from+ (int)(pos-cmp_buff); 00221 while (pos <= cmp_buff+F_LEN) 00222 *pos++= *pos2++; 00223 error=compare_buff(message,from,cmp_buff,(int) (pos-cmp_buff),F_FILL,F_PREFILL); 00224 init_strings(); 00225 va_end(pvar); 00226 return (error != 0); 00227 } /* test_strarg */ 00228 00229 00230 /* test if function made right value */ 00231 00232 int compare_buff(const char *message, my_string b1, my_string b2, int length, 00233 pchar fill, pchar prefill) 00234 { 00235 int i,error=0; 00236 00237 if (bcmp(b1,b2,length)) 00238 { 00239 errors++; 00240 printf("func: '%s' Buffers differ\nIs: ",message); 00241 for (i=0 ; i<length ; i++) 00242 printf("%3d ",b1[i]); 00243 printf("\nShould be: "); 00244 for (i=0 ; i<length ; i++) 00245 printf("%3d ",b2[i]); 00246 puts(""); 00247 } 00248 else if (b1[-1] != prefill || b1[-2] != fill || b1[-3] != fill) 00249 { 00250 printf("func: '%s' Chars before buffer is changed\n",message); 00251 errors++; 00252 error=1; 00253 } 00254 else if (b1[length] != fill || b1[length+1] != fill) 00255 { 00256 printf("func: '%s' Chars after buffer is changed\n",message); 00257 errors++; 00258 error=1; 00259 } 00260 return error; 00261 } /* compare_buff */ 00262 00263 /* These are here to be loaded and examined */ 00264 00265 extern void dummy_functions(void); 00266 00267 void dummy_functions(void) 00268 { 00269 VOID(memchr(from,'a',5)); 00270 VOID(memcmp(from,to,5)); 00271 VOID(memcpy(from,to,5)); 00272 VOID(memset(from,' ',5)); 00273 VOID(strcmp(from,to)); 00274 VOID(strcpy(from,to)); 00275 VOID(strstr(from,to)); 00276 VOID(strrchr(from,'a')); 00277 return; 00278 }
1.4.7

