ChecksumDebugEvent.cc 2.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// (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.

#if defined(TEST_ON) && defined(DEB_ON)

#include "ChecksumDebugEvent.hh"
#include "TestResult.hh"
#include "Base/Code/CodeLink.hh"
#include "Base/Debug/DebOut.hh"

18
19
#include <algorithm>

20
21
22
23
24
25
26
27
28
namespace Test {
namespace Checksum {
namespace Debug {

// put test checksum tag and separators in the required format

void Event::record(const std::string& _evnt, const Base::CodeLink& _lnk)
{
  Result res(name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING);
29
30
  IChecksum::record(res) << "#" << nmbr_++ << ": " << _evnt << " reported " 
    << _lnk << Base::LF;
31
32
33
34
35
36
}

void Event::record_number() const
{
  Result res(nmbr_ == 0 ? Result::OK : // the checksum will appear in all cases
    (name() == ::Debug::ERROR ? Result::ERROR : Result::WARNING));
37
  IChecksum::record(res) << " total#: " << nmbr_ << Base::LF;
38
39
40
41
42
43
}

Severity Event::compare(
  IStream& _str0,
  IStream& _str1,
  OStream& _os,
44
  const Path* /*_dir0*/,
45
46
47
48
49
50
51
52
53
  const Path* /*_dir1*/
  ) const 
{ 
  std::string line0, line1; 
  std::getline(_str0, (line0));
  std::getline(_str1, (line1));

  if (line0 == line1)
  {
54
    _os << line0;
55
56
57
    return 0;
  }

58
59
60
61
62
63
64
65
66
67
68
  std::string diff;
  diff.resize((std::max(line0.length(), line1.length())));
  for (int i = 0; i < diff.size(); ++i)
  {
    diff[i] = i < line0.length() && i < line1.length() && line0[i] == line1[i] ?
      ' ' : '*';
  }
  _os << Base::LF <<
    "\tL: " << line0 << Base::LF <<
    "\tR: " << line1 << Base::LF <<
    "\tD: " << diff;
69
70
71
72
73
74
75
76
77
78
79
  return 1;
} 

Event error(::Debug::ERROR);
Event warning(::Debug::WARNING);

}//namespace Debug
}//Checksum
}//namespace Test

#endif//defined(TEST_ON) && defined(DEB_ON)