ChecksumLogValueT.cc 2.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
// (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.

#ifdef TEST_ON

#include "ChecksumLogValueT.hh"
14
#include "ReadValuesT.hh"
15
16

#include "Base/Debug/DebOut.hh"
17
18
19
20
21
22
23
24
25
26
27
28

#include <boost/filesystem.hpp>

#include <vector>

namespace Test {
namespace Checksum {

// class ChecksumLog implementation
  
namespace { // ChecksumLog locals

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define ARITHMETICTYPE(ValueT) \
  typename std::enable_if<std::is_arithmetic<ValueT>::value, ValueT>::type

#define NOTARITHMETICTYPE(ValueT) \
  typename std::enable_if<!std::is_arithmetic<ValueT>::value, ValueT>::type

// Arithmetic types prints the value difference.
template <typename ValueT> void print_values(OStream& _os, 
                                             const ARITHMETICTYPE(ValueT)& _a,
                                             const ARITHMETICTYPE(ValueT)& _b)
{
  _os << "Diff: " << double(_b) - double(_a) << ", L = " << _a << ", R = " <<  _b;
}

// Not arithmetic types prints the two value.
template <typename ValueT> void print_values(OStream& _os, 
                                             const NOTARITHMETICTYPE(ValueT)& _a, 
                                             const NOTARITHMETICTYPE(ValueT)& _b)
{
  _os << _a << " , " << _b;
}

#undef NOTARITHMETICTYPE
#undef ARITHMETICTYPE

54
}//namespace
55
56
57
58

// Class LogValueT

template <typename ValueT, class CompareT> 
59
60
LogValueT<ValueT, CompareT>::LogValueT(const char* _name, const CompareT& _comp)
  : IChecksum(_name), comp_(_comp)
61
62
63
{}

template <typename ValueT, class CompareT>
64
65
66
Severity LogValueT<ValueT, CompareT>::compare(IStream& _str0, IStream& _str1,
                                              OStream& _os, 
                                              const Path*, const Path*) const
67
{
68
69
70
71
  ValueT val[2];
  _str0 >> val[0];
  _str1 >> val[1];
  if (val[0] == val[1])
72
    return 0;
73
74
75

  print_values<ValueT>(_os, val[0], val[1]);
  return 1;
76
77
78
}

template <typename ValueT, class CompareT>
79
void LogValueT<ValueT, CompareT>::record(const Result& _rep_res, const ValueT& _val)
80
{
81
  IChecksum::record(_rep_res) << _val << Base::LF;
82
83
84
}

}//namespace Checksum
85
}//namespace Test
86
87

#endif//TEST_ON