IChecksum.hh 2.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.

#ifndef BASE_ICHECKSUM_HH_INCLUDE
#define BASE_ICHECKSUM_HH_INCLUDE

#ifndef TEST_ON
# define TEST_only(CC)
#else
#include "types.hh"

#include <functional>
#include <list>
#include <map>
#include <set>
#include <sstream>

namespace Test {
namespace Checksum {

/*!
Base class for test checksum. Whatever check we want to add in the test system,
it must be an instance of a class derived from Checksum. All derived classes
must be instantiated as global variable in such a way that they are always available.
*/
class IChecksum
{
public:
36
  //! Checksum name. 
37
38
  const char* name() const { return name_; }

39
40
  /*!
  Override report to log any "interesting value" that the check has in 
41
42
43
44
  directory _dir. For example a number of face defects greater that 0.
  Return an estimation of the severity.
  */
  virtual Severity report(
45
46
    const Path& _dir, //!< [in] Directory with the date to report.
    std::stringstream& _os //!< [out] Description of the retrieved information.
47
48
    ) const = 0;

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  /*!
  Override compare to perform a comparison of the results stored in
  directories _dir0 and _dir1.
  Returns an estimation of the difference between the two test run.
  */
  virtual Severity compare(
    const Path& _dir0, //!< [in] Directory with the reference result
    const Path& _dir1, //!< [in] Directory with the new result
    std::stringstream& _os //!< [out] Description of the difference.
    ) const = 0;

protected:
  /*!
  Performs an automatic registration of the new checksum in a 
  global list, and verifies that the name is unique.
  */
  IChecksum(unsigned _order, const char* _name);

67
private:
68
  const char* name_;
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
};

/*!
Definition of the checksums registry. It is a map with a key made of an order 
(inverse of a priority) and a name.
This allows to have a unique order for checksum execution and output.
The idea is to have high priority checksums executed first.
*/
typedef std::tuple<unsigned, std::string> Key; // Order and test name.
typedef std::map<Key, IChecksum*> Registry; 

/*!
Function to get a static map with all the registered checksums.
*/
const Registry& registry();

}//namespace Checksum
}//namespace Test
#define TEST_only(CC) CC

#endif//TEST_ON
#endif//BASE_ICHECKSUM_HH_INCLUDE