/ocr/ocrservice/jni/hydrogen/include/leptonica/regutils.h

http://eyes-free.googlecode.com/ · C Header · 130 lines · 12 code · 7 blank · 111 comment · 0 complexity · c8c7ef98b14581dfc436ade1e30bc4c1 MD5 · raw file

  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. - This software is distributed in the hope that it will be
  4. - useful, but with NO WARRANTY OF ANY KIND.
  5. - No author or distributor accepts responsibility to anyone for the
  6. - consequences of using this software, or for whether it serves any
  7. - particular purpose or works at all, unless he or she says so in
  8. - writing. Everyone is granted permission to copy, modify and
  9. - redistribute this source code, for commercial or non-commercial
  10. - purposes, with the following restrictions: (1) the origin of this
  11. - source code must not be misrepresented; (2) modified versions must
  12. - be plainly marked as such; and (3) this notice may not be removed
  13. - or altered from any source or modified source distribution.
  14. *====================================================================*/
  15. #ifndef LEPTONICA_REGUTILS_H
  16. #define LEPTONICA_REGUTILS_H
  17. /*
  18. * regutils.h
  19. *
  20. * Contains this regression test parameter packaging struct
  21. * struct L_RegParams
  22. *
  23. *
  24. * The regression test utility allows you to write regression tests
  25. * that compare results with existing "golden files".
  26. *
  27. * Such regression tests can be called in three ways.
  28. * For example, for distance_reg:
  29. *
  30. * Case 1: distance_reg generate
  31. * This generates golden files in /tmp for the reg test.
  32. *
  33. * Case 2: distance_reg outfile.txt
  34. * This runs the test against the set of golden files. It
  35. * appends to 'outfile.txt' either "SUCCESS" or "FAILURE",
  36. * as well as the details of any parts of the test that failed.
  37. *
  38. * Case 3: distance_reg
  39. * This runs the test against the set of golden files. The
  40. * minimal output, which in case 2 went to a file, is
  41. * instead sent to stderr. In addition, this displays
  42. * images and plots that are specified in the test under
  43. * control of the @display variable. The @display is
  44. * only enabled when the regression test is called without
  45. * any arguments (case 3).
  46. *
  47. * Regression tests follow the pattern given below. In an actual
  48. * case, comparisons of pix and of files can occur in any order.
  49. * We give a specific order here for clarity.
  50. *
  51. * l_int32 success, display, count;
  52. * FILE *fp; // stream only opened for case 2
  53. * L_REGPARAMS *rp; // needed for either convenient argument
  54. * // passthrough to subroutines or for
  55. * // automated "write and check"
  56. *
  57. * // Setup variables; optionally open stream
  58. * if (regTestSetup(argc, argv, &fp, &display, &success, &rp))
  59. * return 1;
  60. *
  61. * // Test pairs of generated pix for identity. Here we label
  62. * // the count on the golden files (0 and 1) explicitly.
  63. * regTestComparePix(fp, argv, pix1, pix2, 0, &success);
  64. * regTestComparePix(fp, argv, pix1, pix2, 1, &success);
  65. *
  66. * // Test pairs of generated pix for similarity. These
  67. * // generate or test against golden files 2 and 3.
  68. * regTestCompareSimilarPix(fp, argv, pix1, pix2, 15, 0.001, 2,
  69. * &success, 0);
  70. * regTestCompareSimilarPix(fp, argv, pix1, pix2, 15, 0.0005, 3,
  71. * &success, 0);
  72. *
  73. * // Generation of <newfile*> outputs and testing for identity
  74. * // These files can be anything, of course.
  75. * regTestCheckFile(fp, argv, <newfile0>, 4, &success);
  76. * regTestCheckFile(fp, argv, <newfile1>, 5, &success);
  77. *
  78. * // Test pairs of output golden files for identity. Here we
  79. * // are comparing golden files 4 and 5.
  80. * regTestCompareFiles(fp, argv, 4, 5, &success);
  81. *
  82. * // "Write and check". This writes a pix using a canonical
  83. * // formulation for the local filename and either (a) generates a
  84. * // golden file if requested or (b) tests the local file
  85. * // against a golden file. Here we are generating or testing
  86. * // golden files 6 and 7, which are pix that have been
  87. * // compressed with png and jpeg, respectively. Each time that
  88. * // regTestWritePixAndCheck() is called, the count is increased
  89. * // by 1 and embedded in the local filename (and, if generating,
  90. * // in the golden filename as well).
  91. * count = 6; // initialize it
  92. * regTestWritePixAndCheck(pix1, IFF_PNG, &count, rp);
  93. * regTestWritePixAndCheck(pix2, IFF_JFIF_JPEG, &count, rp);
  94. *
  95. * // Display when reg test called with only one argument
  96. * pixDisplayWithTitle(pix1, 100, 100, NULL, display);
  97. *
  98. * // Clean up and output result
  99. * regTestCleanup(argc, argv, fp, success, rp);
  100. *
  101. * Note that the optional returned regparams (defined below) can be
  102. * used to pass the parameters cleanly through to subroutines; e.g.,
  103. *
  104. * TestAll(Pix *pixs, L_RegParams *rp) {
  105. * ...
  106. * regTestCheckFile(rp->fp, rp->argv, fname, n, &rp->success);
  107. * ...
  108. * }
  109. *
  110. */
  111. #include <stdio.h>
  112. /*-------------------------------------------------------------------------*
  113. * Regression test parameter packer *
  114. *-------------------------------------------------------------------------*/
  115. struct L_RegParams
  116. {
  117. FILE *fp;
  118. char **argv;
  119. l_int32 success;
  120. l_int32 display;
  121. };
  122. typedef struct L_RegParams L_REGPARAMS;
  123. #endif /* LEPTONICA_REGUTILS_H */