regutils.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions
  6. - are met:
  7. - 1. Redistributions of source code must retain the above copyright
  8. - notice, this list of conditions and the following disclaimer.
  9. - 2. Redistributions in binary form must reproduce the above
  10. - copyright notice, this list of conditions and the following
  11. - disclaimer in the documentation and/or other materials
  12. - provided with the distribution.
  13. -
  14. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  18. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *====================================================================*/
  26. #ifndef LEPTONICA_REGUTILS_H
  27. #define LEPTONICA_REGUTILS_H
  28. /*
  29. * regutils.h
  30. *
  31. * Contains this regression test parameter packaging struct
  32. * struct L_RegParams
  33. *
  34. * The regression test utility allows you to write regression tests
  35. * that compare results with existing "golden files" and with
  36. * compiled in data.
  37. *
  38. * Regression tests can be called in three ways.
  39. * For example, for distance_reg:
  40. *
  41. * Case 1: distance_reg [generate]
  42. * This generates golden files in /tmp for the reg test.
  43. *
  44. * Case 2: distance_reg compare
  45. * This runs the test against the set of golden files. It
  46. * appends to 'outfile.txt' either "SUCCESS" or "FAILURE",
  47. * as well as the details of any parts of the test that failed.
  48. * It writes to a temporary file stream (fp)
  49. *
  50. * Case 3: distance_reg display
  51. * This runs the test but makes no comparison of the output
  52. * against the set of golden files. In addition, this displays
  53. * images and plots that are specified in the test under
  54. * control of the display variable. Display is enabled only
  55. * for this case. Using 'display' on the command line is optional.
  56. *
  57. * Regression tests follow the pattern given below. Tests are
  58. * automatically numbered sequentially, and it is convenient to
  59. * comment each with a number to keep track (for comparison tests
  60. * and for debugging). In an actual case, comparisons of pix and
  61. * of files can occur in any order. We give a specific order here
  62. * for clarity.
  63. *
  64. * L_REGPARAMS *rp; // holds data required by the test functions
  65. *
  66. * // Setup variables; optionally open stream
  67. * if (regTestSetup(argc, argv, &rp))
  68. * return 1;
  69. *
  70. * // Test pairs of generated pix for identity. This compares
  71. * // two pix; no golden file is generated.
  72. * regTestComparePix(rp, pix1, pix2); // 0
  73. *
  74. * // Test pairs of generated pix for similarity. This compares
  75. * // two pix; no golden file is generated. The last arg determines
  76. * // if stats are to be written to stderr.
  77. * regTestCompareSimilarPix(rp, pix1, pix2, 15, 0.001, 0); // 1
  78. *
  79. * // Generation of <newfile*> outputs and testing for identity
  80. * // These files can be anything, of course.
  81. * regTestCheckFile(rp, <newfile0>); // 2
  82. * regTestCheckFile(rp, <newfile1>); // 3
  83. *
  84. * // Test pairs of output golden files for identity. Here we
  85. * // are comparing golden files 2 and 3.
  86. * regTestCompareFiles(rp, 2, 3); // 4
  87. *
  88. * // "Write and check". This writes a pix using a canonical
  89. * // formulation for the local filename and either:
  90. * // case 1: generates a golden file
  91. * // case 2: compares the local file with a golden file
  92. * // case 3: generates local files and displays
  93. * // Here we write the pix compressed with png and jpeg, respectively;
  94. * // Then check against the golden file. The internal @index
  95. * // is incremented; it is embedded in the local filename and,
  96. * // if generating, in the golden file as well.
  97. * regTestWritePixAndCheck(rp, pix1, IFF_PNG); // 5
  98. * regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); // 6
  99. *
  100. * // Display if reg test was called in 'display' mode
  101. * pixDisplayWithTitle(pix1, 100, 100, NULL, rp->display);
  102. *
  103. * // Clean up and output result
  104. * regTestCleanup(rp);
  105. */
  106. /*-------------------------------------------------------------------------*
  107. * Regression test parameter packer *
  108. *-------------------------------------------------------------------------*/
  109. struct L_RegParams
  110. {
  111. FILE *fp; /* stream to temporary output file for compare mode */
  112. char *testname; /* name of test, without '_reg' */
  113. char *tempfile; /* name of temp file for compare mode output */
  114. l_int32 mode; /* generate, compare or display */
  115. l_int32 index; /* index into saved files for this test; 0-based */
  116. l_int32 success; /* overall result of the test */
  117. l_int32 display; /* 1 if in display mode; 0 otherwise */
  118. L_TIMER tstart; /* marks beginning of the reg test */
  119. };
  120. typedef struct L_RegParams L_REGPARAMS;
  121. /* Running modes for the test */
  122. enum {
  123. L_REG_GENERATE = 0,
  124. L_REG_COMPARE = 1,
  125. L_REG_DISPLAY = 2
  126. };
  127. #endif /* LEPTONICA_REGUTILS_H */