Back to index

lightning-sunbird  0.9+nobinonly
unitest.c
Go to the documentation of this file.
00001 /* unitest.c: Test driver for Unicode strings module unistring.c */
00002 
00003 /* public declarations */
00004 #include "unistring.h"
00005 
00006 #include <assert.h>
00007 
00008 int main(int argc, char *argv[])
00009 {
00010   UNICHAR dest[6], dest2[6];
00011 
00012   printf("\nTesting ucscopy and ucslen ...\n");
00013 
00014   ucscopy(dest, "abcdef", 0);
00015   printf("ucscopy(dest, \"abcdef\",    0)\n");
00016 
00017   ucscopy(dest, "abcdef", 6);
00018   printf("ucscopy(dest, \"abcdef\",    6): dest=");
00019   ucsprint(stdout, dest, 6);
00020   printf(" (abcdef)\n");
00021 
00022   ucscopy(dest, "",       6);
00023   printf("ucscopy(dest, \"\",          6): dest=");
00024   ucsprint(stdout, dest, 6);
00025   printf(" (^@^@^@^@^@^@)\n");
00026 
00027   printf("ucslen(dest) = %d (0)\n", ucslen(dest));
00028 
00029   ucscopy(dest, "babc",    6);
00030   printf("ucscopy(dest, \"babc\",       6): dest=");
00031   ucsprint(stdout, dest, 6);
00032   printf(" (babc^@^@)\n");
00033 
00034   printf("ucslen(dest) = %d (4)\n", ucslen(dest));
00035 
00036   printf("\nTesting ucschr ...\n");
00037 
00038   printf("*ucschr(\"babc\", U_NUL) = '%c',%d ('',4)\n",
00039          (char) *ucschr(dest, U_NUL), ucschr(dest, U_NUL)-dest);
00040   
00041   printf("*ucschr(\"babc\", U_b_CHAR) = '%c',%d ('b',0)\n",
00042          (char) *ucschr(dest, U_b_CHAR), ucschr(dest, U_b_CHAR)-dest);
00043   
00044   printf("*ucschr(\"babc\", U_a_CHAR) = '%c',%d ('a',1)\n",
00045          (char) *ucschr(dest, U_a_CHAR), ucschr(dest, U_a_CHAR)-dest);
00046   
00047   printf("*ucschr(\"babc\", U_c_CHAR) = '%c',%d ('c',3)\n",
00048          (char) *ucschr(dest, U_c_CHAR), ucschr(dest, U_c_CHAR)-dest);
00049 
00050   printf("ucschr(\"babc\", U_d_CHAR) = 0x%x (0x0)\n", ucschr(dest, U_d_CHAR));
00051   
00052   printf("\nTesting ucsrchr ...\n");
00053 
00054   printf("*ucsrchr(\"babc\", U_NUL) = '%c',%d ('',4)\n",
00055          (char) *ucsrchr(dest, U_NUL), ucsrchr(dest, U_NUL)-dest);
00056 
00057   printf("*ucsrchr(\"babc\", U_b_CHAR) = '%c',%d ('b',2)\n",
00058          (char) *ucsrchr(dest, U_b_CHAR), ucsrchr(dest, U_b_CHAR)-dest);
00059 
00060   printf("*ucsrchr(\"babc\", U_a_CHAR) = '%c', %d ('a',1)\n",
00061          (char) *ucsrchr(dest, U_a_CHAR), ucsrchr(dest, U_a_CHAR)-dest);
00062 
00063   printf("*ucschr(\"babc\", U_c_CHAR) = '%c',%d ('c',3)\n",
00064          (char) *ucschr(dest, U_c_CHAR), ucschr(dest, U_c_CHAR)-dest);
00065 
00066   printf("ucsrchr(\"babc\", U_d_CHAR) = 0x%x (0x0)\n", ucsrchr(dest, U_d_CHAR));
00067 
00068   printf("\nTesting ucscmp ...\n");
00069   ucscopy(dest,  "", 6);
00070   ucscopy(dest2, "", 6);
00071   printf("ucscmp(\"\",\"\") = %d (0)\n", ucscmp(dest,dest));
00072 
00073   ucscopy(dest,  "abc", 6);
00074   printf("ucscmp(\"abc\",\"\") = %d (97)\n", ucscmp(dest,dest2));
00075   printf("ucscmp(\"\",\"abc\") = %d (-97)\n", ucscmp(dest2,dest));
00076 
00077   ucscopy(dest2, "abe", 6);
00078   printf("ucscmp(\"abc\",\"abc\") = %d (0)\n", ucscmp(dest,dest));
00079   printf("ucscmp(\"abc\",\"abe\") = %d (-2)\n", ucscmp(dest,dest2));
00080   printf("ucscmp(\"abe\",\"abc\") = %d (2)\n", ucscmp(dest2,dest));
00081 
00082   ucscopy(dest2, "abcd", 6);
00083   printf("ucscmp(\"abc\",\"abcd\") = %d (-100)\n", ucscmp(dest,dest2));
00084   printf("ucscmp(\"abcd\",\"abc\") = %d (100)\n", ucscmp(dest2,dest));
00085 
00086   printf("\nTesting ucsncmp ...\n");
00087   ucscopy(dest,  "", 6);
00088   ucscopy(dest2, "", 6);
00089   printf("ucsncmp(\"\",\"\",6) = %d (0)\n", ucsncmp(dest,dest,6));
00090 
00091   ucscopy(dest,  "abc", 6);
00092   printf("ucsncmp(\"abc\",\"\",6) = %d (97)\n", ucsncmp(dest,dest2,6));
00093   printf("ucsncmp(\"\",\"abc\",6) = %d (-97)\n", ucsncmp(dest2,dest,6));
00094 
00095   ucscopy(dest2, "abe", 6);
00096   printf("ucsncmp(\"abc\",\"abc\",4) = %d (0)\n", ucsncmp(dest,dest,4));
00097   printf("ucsncmp(\"abc\",\"abc\",3) = %d (0)\n", ucsncmp(dest,dest,3));
00098 
00099   printf("ucsncmp(\"abc\",\"abe\",5) = %d (-2)\n", ucsncmp(dest,dest2,5));
00100   printf("ucsncmp(\"abc\",\"abe\",4) = %d (-2)\n", ucsncmp(dest,dest2,4));
00101   printf("ucsncmp(\"abc\",\"abe\",3) = %d (-2)\n", ucsncmp(dest,dest2,3));
00102   printf("ucsncmp(\"abc\",\"abe\",2) = %d (0)\n", ucsncmp(dest,dest2,2));
00103   printf("ucsncmp(\"abc\",\"abe\",1) = %d (0)\n", ucsncmp(dest,dest2,1));
00104   printf("ucsncmp(\"abc\",\"abe\",0) = %d (0)\n", ucsncmp(dest,dest2,0));
00105 
00106   printf("ucsncmp(\"abe\",\"abc\",4) = %d (2)\n", ucsncmp(dest2,dest,4));
00107   printf("ucsncmp(\"abe\",\"abc\",3) = %d (2)\n", ucsncmp(dest2,dest,3));
00108 
00109   ucscopy(dest,  "abcde", 6);
00110   printf("ucsncmp(\"abcde\",\"abe\",2) = %d (0)\n", ucsncmp(dest,dest2,2));
00111   printf("ucsncmp(\"abcde\",\"abe\",3) = %d (-2)\n", ucsncmp(dest,dest2,3));
00112   printf("ucsncmp(\"abcde\",\"abe\",4) = %d (-2)\n", ucsncmp(dest,dest2,4));
00113   printf("ucsncmp(\"abe\",\"abcde\",2) = %d (0)\n", ucsncmp(dest2,dest,2));
00114   printf("ucsncmp(\"abe\",\"abcde\",6) = %d (2)\n", ucsncmp(dest2,dest,6));
00115 
00116   printf("\nTesting ucsncpy ...\n");
00117   ucscopy(dest2, "abcde", 5);
00118 
00119   ucsncpy(dest, dest2, 0);
00120   printf("ucsncpy(dest, \"abcde\",    0)\n");
00121 
00122   ucsncpy(dest, dest2, 5);
00123   printf("ucsncpy(dest, \"abcde\",    5): dest=");
00124   ucsprint(stdout, dest, 5);
00125   printf(" (abcde)\n");
00126 
00127   ucscopy(dest2, "", 6);
00128   ucsncpy(dest, dest2,       5);
00129   printf("ucsncpy(dest, \"\",         5): dest=");
00130   ucsprint(stdout, dest, 5);
00131   printf(" (^@^@^@^@^@)\n");
00132 
00133   ucscopy(dest2, "bab", 6);
00134   ucsncpy(dest, dest2,    5);
00135   printf("ucsncpy(dest, \"bab\",      5): dest=");
00136   ucsprint(stdout, dest, 5);
00137   printf(" (bab^@^@)\n");
00138 
00139   printf("\nTesting ucsstr ...\n");
00140   ucscopy(dest, "abc", 6);
00141   ucscopy(dest2, "", 6);
00142   printf("ucsstr(\"abc\",\"\") = %d (0)\n", ucsstr(dest, dest2)-dest);
00143   ucscopy(dest2, "a", 6);
00144   printf("ucsstr(\"abc\",\"a\") = %d (0)\n", ucsstr(dest, dest2)-dest);
00145   ucscopy(dest2, "ab", 6);
00146   printf("ucsstr(\"abc\",\"ab\") = %d (0)\n", ucsstr(dest, dest2)-dest);
00147   ucscopy(dest2, "abc", 6);
00148   printf("ucsstr(\"abc\",\"abc\") = %d (0)\n", ucsstr(dest, dest2)-dest);
00149   ucscopy(dest2, "bc", 6);
00150   printf("ucsstr(\"abc\",\"bc\") = %d (1)\n", ucsstr(dest, dest2)-dest);
00151   ucscopy(dest2, "c", 6);
00152   printf("ucsstr(\"abc\",\"c\") = %d (2)\n", ucsstr(dest, dest2)-dest);
00153   ucscopy(dest2, "d", 6);
00154   printf("ucsstr(\"abc\",\"d\") = 0x%x (0x0)\n", ucsstr(dest, dest2));
00155   ucscopy(dest2, "ac", 6);
00156   printf("ucsstr(\"abc\",\"ac\") = 0x%x (0x0)\n", ucsstr(dest, dest2));
00157   ucscopy(dest2, "acb", 6);
00158   printf("ucsstr(\"abc\",\"acb\") = 0x%x (0x0)\n", ucsstr(dest, dest2));
00159   ucscopy(dest2, "abcd", 6);
00160   printf("ucsstr(\"abc\",\"abcd\") = 0x%x (0x0)\n", ucsstr(dest, dest2));
00161 
00162   printf("\nTesting ucsspn ...\n");
00163   ucscopy(dest, "babc", 6);
00164   ucscopy(dest2, "", 6);
00165   printf("ucsspn(\"babc\",\"\") = %d (0)\n", ucsspn(dest, dest2));
00166   ucscopy(dest2, "b", 6);
00167   printf("ucsspn(\"babc\",\"b\") = %d (1)\n", ucsspn(dest, dest2));
00168   ucscopy(dest2, "ab", 6);
00169   printf("ucsspn(\"babc\",\"ab\") = %d (3)\n", ucsspn(dest, dest2));
00170   ucscopy(dest2, "abc", 6);
00171   printf("ucsspn(\"babc\",\"abc\") = %d (4)\n", ucsspn(dest, dest2));
00172   ucscopy(dest2, "cba", 6);
00173   printf("ucsspn(\"babc\",\"cba\") = %d (4)\n", ucsspn(dest, dest2));
00174   ucscopy(dest2, "abcd", 6);
00175   printf("ucsspn(\"babc\",\"abcd\") = %d (4)\n", ucsspn(dest, dest2));
00176   ucscopy(dest2, "abcde", 6);
00177   printf("ucsspn(\"babc\",\"abcde\") = %d (4)\n", ucsspn(dest, dest2));
00178   ucscopy(dest2, "c", 6);
00179   printf("ucsspn(\"babc\",\"c\") = %d (0)\n", ucsspn(dest, dest2));
00180   ucscopy(dest2, "d", 6);
00181   printf("ucsspn(\"babc\",\"d\") = %d (0)\n", ucsspn(dest, dest2));
00182   ucscopy(dest2, "cd", 6);
00183   printf("ucsspn(\"babc\",\"cd\") = %d (0)\n", ucsspn(dest, dest2));
00184 
00185   printf("\nTesting ucscspn ...\n");
00186   ucscopy(dest, "babc", 6);
00187   ucscopy(dest2, "", 6);
00188   printf("ucscspn(\"babc\",\"\") = %d (4)\n", ucscspn(dest, dest2));
00189   ucscopy(dest2, "b", 6);
00190   printf("ucscspn(\"babc\",\"b\") = %d (0)\n", ucscspn(dest, dest2));
00191   ucscopy(dest2, "ab", 6);
00192   printf("ucscspn(\"babc\",\"ab\") = %d (0)\n", ucscspn(dest, dest2));
00193   ucscopy(dest2, "abc", 6);
00194   printf("ucscspn(\"babc\",\"abc\") = %d (0)\n", ucscspn(dest, dest2));
00195   ucscopy(dest2, "cba", 6);
00196   printf("ucscspn(\"babc\",\"cba\") = %d (0)\n", ucscspn(dest, dest2));
00197   ucscopy(dest2, "abcd", 6);
00198   printf("ucscspn(\"babc\",\"abcd\") = %d (0)\n", ucscspn(dest, dest2));
00199   ucscopy(dest2, "abcde", 6);
00200   printf("ucscspn(\"babc\",\"abcde\") = %d (0)\n", ucscspn(dest, dest2));
00201   ucscopy(dest2, "a", 6);
00202   printf("ucscspn(\"babc\",\"a\") = %d (1)\n", ucscspn(dest, dest2));
00203   ucscopy(dest2, "c", 6);
00204   printf("ucscspn(\"babc\",\"c\") = %d (3)\n", ucscspn(dest, dest2));
00205   ucscopy(dest2, "cd", 6);
00206   printf("ucscspn(\"babc\",\"cd\") = %d (3)\n", ucscspn(dest, dest2));
00207   ucscopy(dest2, "d", 6);
00208   printf("ucscspn(\"babc\",\"d\") = %d (4)\n", ucscspn(dest, dest2));
00209 
00210   return;
00211 }