ChecksumLogValueT.cc 2.3 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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "StreamContainerT.hh"

#include <boost/filesystem.hpp>

#include <vector>

namespace Test {
namespace Checksum {

// class ChecksumLog implementation
  
namespace { // ChecksumLog locals

template <typename ValueT>
std::ostream& operator<<(std::ostream& _out_str, const std::vector<ValueT>& _vals)
{
  return write_container(_out_str, _vals);
}

34
std::ostream& operator<<(std::ostream& _out_str, const std::vector<Count>& _vals)
35
{
36
37
  _out_str << '#' << _vals.size();
  return _out_str;
38
39
}

40
}//namespace
41
42
43
44

// Class LogValueT

template <typename ValueT, class CompareT> 
45
LogValueT<ValueT, CompareT>::LogValueT(
46
47
48
49
50
51
52
53
54
  unsigned _order, const char* _name,
  const char* _key,
  const CompareT& _comp,
  const char* _flnm
  )
  : IChecksum(_order, _name), comp_(_comp), key_(_key),  flnm_(_flnm)
{}

template <typename ValueT, class CompareT>
55
56
Severity LogValueT<ValueT, CompareT>::compare(const Path& _dir0, 
  const Path& _dir1, std::stringstream& _os) const
57
{
58
59
  auto list0 = read_values<ValueT>(key_, flnm_, _dir0);
  auto list1 = read_values<ValueT>(key_, flnm_, _dir1);
60
61
62
63
64
65
66
  if (list0.size() != list1.size())
  {
    _os << '#' << list0.size() << " #" << list1.size();
    return 1;
  }
  for (auto i = list0.size(); i-- > 0; )
  {
67
    if (comp_.same(list0[i], list1[i]))
68
69
70
71
72
73
74
75
76
77
78
    {
      list0.erase(list0.begin() + i);
      list1.erase(list1.begin() + i);
    }
  }
  if (list0.empty() && list1.empty())
    return 0;
  _os << list0 << " " << list1;
  return 0.5;
}

79
// Reads and check the values using the compare object.
80
template <typename ValueT, class CompareT>
81
ReportOutcome LogValueT<ValueT, CompareT>::report(const Path& _dir, 
82
83
  std::stringstream& _os) const
{
84
85
86
  auto vals = read_values<ValueT>(key_, flnm_, _dir);
  _os << vals;
  return comp_.check(vals);
87
88
89
90
91
92
}

}//namespace Test
}//namespace Checksum

#endif//TEST_ON