GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 77.0% 47 / 0 / 61
Functions: 81.8% 9 / 0 / 11
Branches: 47.9% 35 / 0 / 73

src/utilities/idf/ValidityReport.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "ValidityReport.hpp"
7 #include "IdfObject.hpp"
8
9 #include "../idd/IddObject.hpp"
10
11 #include "../core/Assert.hpp"
12
13 namespace openstudio {
14
15 18508 ValidityReport::ValidityReport(StrictnessLevel level) : m_level(level), m_scope(Scope::Collection) {
16 18508 m_currentError = m_errors.end();
17 18508 }
18
19 996670 ValidityReport::ValidityReport(StrictnessLevel level, const IdfObject& object)
20
3/3
✓ Branch 2 taken 996670 times.
✓ Branch 5 taken 996670 times.
✓ Branch 8 taken 996670 times.
996670 : m_level(level), m_scope(Scope::Object), m_objectType(object.iddObject().type()) {
21 996670 m_currentError = m_errors.end();
22
1/1
✓ Branch 1 taken 996670 times.
996670 OptionalString oName = object.name();
23
2/2
✓ Branch 0 taken 758292 times.
✓ Branch 1 taken 238378 times.
996670 if (oName) {
24
2/2
✓ Branch 1 taken 758292 times.
✓ Branch 4 taken 758292 times.
758292 m_objectName = *oName;
25 }
26 996670 }
27
28 8 ValidityReport::ValidityReport(const ValidityReport& other)
29
2/2
✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
8 : m_level(other.m_level), m_scope(other.m_scope), m_objectType(other.m_objectType), m_objectName(other.m_objectName), m_errors(other.m_errors) {
30 // reset the currentError counter
31 8 m_currentError = m_errors.end();
32 8 }
33
34 174 void ValidityReport::insertError(const DataError& error) {
35 174 m_errors.insert(error);
36 174 m_currentError = m_errors.end();
37 174 }
38
39 15703624 StrictnessLevel ValidityReport::level() const {
40 15703624 return m_level;
41 }
42
43 9 Scope ValidityReport::scope() const {
44 9 return m_scope;
45 }
46
47 ✗ std::string ValidityReport::objectName() const {
48 ✗ return m_objectName;
49 }
50
51 ✗ boost::optional<IddObjectType> ValidityReport::objectType() const {
52 ✗ return m_objectType;
53 }
54
55 617355 unsigned ValidityReport::numErrors() const {
56 617355 return m_errors.size();
57 }
58
59 397917 boost::optional<DataError> ValidityReport::nextError() {
60 // cycle through errors
61
2/2
✓ Branch 2 taken 397847 times.
✓ Branch 3 taken 70 times.
397917 if (m_currentError == m_errors.end()) {
62 397847 m_currentError = m_errors.begin();
63 } else {
64 70 ++m_currentError;
65 }
66
67 // if not at end, report error
68 397917 OptionalDataError result;
69
2/2
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 397845 times.
397917 if (m_currentError != m_errors.end()) {
70
1/1
✓ Branch 2 taken 72 times.
72 result = *m_currentError;
71 }
72
73 397917 return result;
74 ✗ }
75
76 9 std::ostream& operator<<(std::ostream& os, const ValidityReport& report) {
77
3/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 if (report.scope() == Scope::Collection) {
78
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 8 times.
9 if (report.numErrors() == 0) {
79
3/3
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
1 os << "The collection is VALID at strictness level '" << report.level().valueName();
80 1 os << "'. There are no errors to report." << '\n';
81 } else {
82
3/3
✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
✓ Branch 8 taken 8 times.
8 os << "The collection is INVALID at strictness level '" << report.level().valueName();
83 8 os << "', because of the errors:" << '\n';
84 }
85 } else {
86 ✗ OS_ASSERT(report.scope() == Scope::Object);
87 ✗ OS_ASSERT(report.objectType());
88 ✗ if (report.numErrors() == 0) {
89 ✗ os << "The object of type '" << report.objectType()->valueDescription() << "', named '";
90 ✗ os << report.objectName() << "', is VALID at strictness level '";
91 ✗ os << report.level().valueName() << "'. There are no errors to report." << '\n';
92 } else {
93 ✗ os << "The object of type '" << report.objectType()->valueDescription() << "', named '";
94 ✗ os << report.objectName() << "', is INVALID at strictness level '";
95 ✗ os << report.level().valueName() << "', because of the errors:" << '\n';
96 }
97 }
98
99 // print errors
100
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 time.
9 if (report.numErrors() > 0) {
101
1/1
✓ Branch 1 taken 8 times.
8 ValidityReport reportCopy(report);
102
1/1
✓ Branch 1 taken 8 times.
8 OptionalDataError error = reportCopy.nextError();
103
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
28 while (error) {
104
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 os << *error;
105
1/1
✓ Branch 1 taken 12 times.
12 error = reportCopy.nextError();
106 }
107 8 }
108
109 9 return os;
110 }
111
112 } // namespace openstudio
113