Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 /* 00017 * alltests_reg.c 00018 * 00019 * Tests all the reg tests: 00020 * 00021 * alltests_reg command 00022 * 00023 * where 00024 * <command> == "generate" to make the golden files in /tmp/golden 00025 * <command> == "compare" to make local files and compare with 00026 * the golden files 00027 * <command> == "display" to make local files and display 00028 * 00029 * You can also run each test individually with any one of these 00030 * arguments. 00031 */ 00032 00033 #include <string.h> 00034 #include "allheaders.h" 00035 00036 static const char *tests[] = { 00037 "alphaxform_reg", 00038 "binarize_reg", 00039 "colormask_reg", 00040 "colorquant_reg", 00041 "convolve_reg", 00042 "dewarp_reg", 00043 /* "distance_reg", */ 00044 "dwamorph1_reg", 00045 "enhance_reg", 00046 "findpattern_reg", 00047 "fpix_reg", 00048 "gifio_reg", 00049 "graymorph2_reg", 00050 "hardlight_reg", 00051 "ioformats_reg", 00052 "kernel_reg", 00053 "maze_reg", 00054 "overlap_reg", 00055 "pdfseg_reg", 00056 "pixa2_reg", 00057 "pixserial_reg", 00058 "pngio_reg", 00059 "projection_reg", 00060 "psio_reg", 00061 "psioseg_reg", 00062 "rankbin_reg", 00063 "rankhisto_reg", 00064 "rotateorth_reg", 00065 "rotate1_reg", 00066 "rotate2_reg", 00067 "scale_reg", 00068 "seedspread_reg", 00069 "selio_reg", 00070 "shear_reg", 00071 "shear2_reg", 00072 "skew_reg", 00073 "splitcomp_reg", 00074 "subpixel_reg", 00075 "threshnorm_reg", 00076 "translate_reg", 00077 "warper_reg", 00078 "writetext_reg", 00079 }; 00080 00081 static const char *header = {"\n=======================\n" 00082 "Regression Test Results\n" 00083 "======================="}; 00084 00085 main(int argc, 00086 char **argv) 00087 { 00088 char *str, *results_file; 00089 char command[256], buf[256]; 00090 l_int32 i, ntests, dotest, nfail, ret, start, stop; 00091 SARRAY *sa; 00092 L_TIMER timer; 00093 static char mainName[] = "alltests_reg"; 00094 00095 00096 if (argc != 2) 00097 return ERROR_INT(" Syntax alltests_reg [generate | compare | display]", 00098 mainName, 1); 00099 00100 l_getCurrentTime(&start, NULL); 00101 ntests = sizeof(tests) / sizeof(char *); 00102 fprintf(stderr, "Running alltests_reg:\n" 00103 "This currently tests %d of the 97 Regression Test\n" 00104 "programs in the /prog directory.\n", ntests); 00105 00106 /* Clear the output file if we're doing the set of reg tests */ 00107 dotest = strcmp(argv[1], "compare") ? 0 : 1; 00108 if (dotest) { 00109 results_file = genPathname("/tmp", "reg_results.txt"); 00110 sa = sarrayCreate(3); 00111 sarrayAddString(sa, (char *)header, L_COPY); 00112 sarrayAddString(sa, getLeptonicaVersion(), L_INSERT); 00113 sarrayAddString(sa, getImagelibVersions(), L_INSERT); 00114 str = sarrayToString(sa, 1); 00115 sarrayDestroy(&sa); 00116 l_binaryWrite("/tmp/reg_results.txt", "w", str, strlen(str)); 00117 lept_free(str); 00118 } 00119 00120 nfail = 0; 00121 for (i = 0; i < ntests; i++) { 00122 snprintf(command, sizeof(command) - 2, "%s %s", tests[i], argv[1]); 00123 ret = system(command); 00124 if (ret) { 00125 snprintf(buf, sizeof(buf), "Failed to complete %s\n", tests[i]); 00126 if (dotest) { 00127 l_binaryWrite("/tmp/reg_results.txt", "a", buf, strlen(buf)); 00128 nfail++; 00129 } 00130 else 00131 fprintf(stderr, "%s", buf); 00132 } 00133 } 00134 00135 if (dotest) { 00136 #ifndef _WIN32 00137 snprintf(command, sizeof(command) - 2, "cat %s", results_file); 00138 #else 00139 snprintf(command, sizeof(command) - 2, "type \"%s\"", results_file); 00140 #endif /* !_WIN32 */ 00141 lept_free(results_file); 00142 ret = system(command); 00143 fprintf(stderr, "Success in %d of %d *_reg programs (output matches" 00144 " the \"golden\" files)\n", ntests - nfail, ntests); 00145 } 00146 00147 l_getCurrentTime(&stop, NULL); 00148 fprintf(stderr, "Time for all regression tests: %d sec\n", stop - start); 00149 return 0; 00150 } 00151