KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_validation_pipeline.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 3
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, you may find one here:
18
* http://www.gnu.org/licenses/gpl-3.0.html
19
* or you may search the http://www.gnu.org website for the version 3 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#include <boost/test/unit_test.hpp>
25
26
#include <
diff_merge/merge_validation_pipeline.h
>
27
28
29
using namespace
KICAD_DIFF
;
30
31
32
BOOST_AUTO_TEST_SUITE
( ValidationPipeline )
33
34
35
// An empty input (no refdes, planRequiredRebuild and applierReportedRebuild
36
// both false, all schema versions zero) should pass cleanly.
37
BOOST_AUTO_TEST_CASE
( EmptyInputPasses )
38
{
39
VALIDATION_INPUT
input;
40
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
41
42
BOOST_CHECK( report.
Passed
() );
43
BOOST_CHECK_EQUAL
( report.
Count
(), 0u );
44
}
45
46
47
// A single refdes collision must surface as a failure with the colliding
48
// items pinned in relatedItems for cross-probe.
49
BOOST_AUTO_TEST_CASE
( RefdesCollisionReportsRelatedItems )
50
{
51
VALIDATION_INPUT
input;
52
KIID_PATH
idA;
53
idA.push_back(
KIID
() );
54
KIID_PATH
idB;
55
idB.push_back(
KIID
() );
56
57
input.
refdesEntries
.push_back( { wxS(
"R1"
), idA } );
58
input.
refdesEntries
.push_back( { wxS(
"R1"
), idB } );
59
60
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
61
62
BOOST_REQUIRE
( !report.
Passed
() );
63
BOOST_CHECK_EQUAL
( report.
Count
(), 1u );
64
65
const
VALIDATION_FAILURE
& f = report.
failures
[0];
66
BOOST_CHECK( f.
severity
==
RPT_SEVERITY_ERROR
);
67
BOOST_CHECK( !f.
relatedItems
.empty() );
68
}
69
70
71
// Plan-required + applier-reported = pass (the contract was honoured).
72
BOOST_AUTO_TEST_CASE
( ConnectivityRebuildContractHonoured )
73
{
74
VALIDATION_INPUT
input;
75
input.
planRequiredRebuild
=
true
;
76
input.
applierReportedRebuild
=
true
;
77
78
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
79
BOOST_CHECK( report.
Passed
() );
80
}
81
82
83
// Plan-required + applier-NOT-reported = failure (the applier missed the
84
// rebuild the plan asked for).
85
BOOST_AUTO_TEST_CASE
( ConnectivityRebuildContractBroken )
86
{
87
VALIDATION_INPUT
input;
88
input.
planRequiredRebuild
=
true
;
89
input.
applierReportedRebuild
=
false
;
90
91
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
92
BOOST_REQUIRE
( !report.
Passed
() );
93
94
bool
foundRebuildFailure =
false
;
95
96
for
(
const
VALIDATION_FAILURE
& f : report.
failures
)
97
{
98
if
( f.
validator
.Find( wxS(
"Connectivity"
) ) != wxNOT_FOUND )
99
foundRebuildFailure =
true
;
100
}
101
102
BOOST_CHECK( foundRebuildFailure );
103
}
104
105
106
// Plan-NOT-required + applier-reported = passes (no harm in an extra rebuild).
107
BOOST_AUTO_TEST_CASE
( ExtraRebuildIsNotFlagged )
108
{
109
VALIDATION_INPUT
input;
110
input.
planRequiredRebuild
=
false
;
111
input.
applierReportedRebuild
=
true
;
112
113
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
114
BOOST_CHECK( report.
Passed
() );
115
}
116
117
118
// Identical schema versions = pass.
119
BOOST_AUTO_TEST_CASE
( SchemaVersionMatchPasses )
120
{
121
VALIDATION_INPUT
input;
122
input.
ancestorSchemaVersion
= 20240101;
123
input.
oursSchemaVersion
= 20240101;
124
input.
theirsSchemaVersion
= 20240101;
125
126
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
127
BOOST_CHECK( report.
Passed
() );
128
}
129
130
131
// Major schema version mismatch surfaces an error.
132
BOOST_AUTO_TEST_CASE
( SchemaVersionMajorMismatchReportsError )
133
{
134
VALIDATION_INPUT
input;
135
input.
ancestorSchemaVersion
= 20240101;
136
input.
oursSchemaVersion
= 20240101;
137
input.
theirsSchemaVersion
= 20990101;
// 5-year jump
138
139
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
140
BOOST_REQUIRE
( !report.
Passed
() );
141
142
bool
foundSchemaFailure =
false
;
143
144
for
(
const
VALIDATION_FAILURE
& f : report.
failures
)
145
{
146
if
( f.
validator
.Find( wxS(
"Schema"
) ) != wxNOT_FOUND )
147
foundSchemaFailure =
true
;
148
}
149
150
BOOST_CHECK( foundSchemaFailure );
151
}
152
153
154
// Multiple validator failures all surface in the same report -- the pipeline
155
// aggregates rather than short-circuiting on the first failure.
156
BOOST_AUTO_TEST_CASE
( MultipleFailuresAggregate )
157
{
158
VALIDATION_INPUT
input;
159
160
KIID_PATH
idA;
161
idA.push_back(
KIID
() );
162
KIID_PATH
idB;
163
idB.push_back(
KIID
() );
164
input.
refdesEntries
.push_back( { wxS(
"U1"
), idA } );
165
input.
refdesEntries
.push_back( { wxS(
"U1"
), idB } );
166
167
input.
planRequiredRebuild
=
true
;
168
input.
applierReportedRebuild
=
false
;
169
170
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
171
172
BOOST_REQUIRE
( !report.
Passed
() );
173
BOOST_CHECK_GE( report.
Count
(), 2u );
174
}
175
176
177
// HasErrors() vs Passed(): a WARNING-only failure is NOT considered Passed
178
// (per VALIDATION_REPORT::Passed() == failures.empty()), but it's also
179
// distinguishable from an ERROR via HasErrors().
180
BOOST_AUTO_TEST_CASE
( PassedAndHasErrorsAreDistinguishable )
181
{
182
VALIDATION_INPUT
input;
183
input.
planRequiredRebuild
=
true
;
184
input.
applierReportedRebuild
=
false
;
185
186
VALIDATION_REPORT
report =
RunPostApplyValidators
( input );
187
188
BOOST_CHECK( !report.
Passed
() );
189
190
// The rebuild failure is ERROR severity in the existing validator impl.
191
bool
sawError =
false
;
192
193
for
(
const
VALIDATION_FAILURE
& f : report.
failures
)
194
{
195
if
( f.
severity
==
RPT_SEVERITY_ERROR
)
196
sawError =
true
;
197
}
198
199
BOOST_CHECK_EQUAL
( sawError, report.
HasErrors
() );
200
}
201
202
203
BOOST_AUTO_TEST_SUITE_END
()
KIID_PATH
Definition
kiid.h:165
KIID
Definition
kiid.h:44
merge_validation_pipeline.h
KICAD_DIFF
Definition
auto_resolution.cpp:34
KICAD_DIFF::RunPostApplyValidators
VALIDATION_REPORT RunPostApplyValidators(const VALIDATION_INPUT &aInput)
Run every standard post-apply validator and merge their reports.
Definition
merge_validation_pipeline.cpp:30
RPT_SEVERITY_ERROR
@ RPT_SEVERITY_ERROR
Definition
report_severity.h:35
KICAD_DIFF::VALIDATION_FAILURE
Outcome of a single validator run.
Definition
merge_validators.h:44
KICAD_DIFF::VALIDATION_FAILURE::relatedItems
std::vector< KIID_PATH > relatedItems
Definition
merge_validators.h:48
KICAD_DIFF::VALIDATION_FAILURE::severity
SEVERITY severity
Definition
merge_validators.h:45
KICAD_DIFF::VALIDATION_FAILURE::validator
wxString validator
Definition
merge_validators.h:46
KICAD_DIFF::VALIDATION_INPUT
Inputs needed to run the post-apply validator pipeline.
Definition
merge_validation_pipeline.h:56
KICAD_DIFF::VALIDATION_INPUT::refdesEntries
std::vector< REFDES_ENTRY > refdesEntries
Definition
merge_validation_pipeline.h:57
KICAD_DIFF::VALIDATION_INPUT::oursSchemaVersion
int oursSchemaVersion
Definition
merge_validation_pipeline.h:61
KICAD_DIFF::VALIDATION_INPUT::theirsSchemaVersion
int theirsSchemaVersion
Definition
merge_validation_pipeline.h:62
KICAD_DIFF::VALIDATION_INPUT::planRequiredRebuild
bool planRequiredRebuild
Definition
merge_validation_pipeline.h:58
KICAD_DIFF::VALIDATION_INPUT::applierReportedRebuild
bool applierReportedRebuild
Definition
merge_validation_pipeline.h:59
KICAD_DIFF::VALIDATION_INPUT::ancestorSchemaVersion
int ancestorSchemaVersion
Definition
merge_validation_pipeline.h:60
KICAD_DIFF::VALIDATION_REPORT
Definition
merge_validators.h:53
KICAD_DIFF::VALIDATION_REPORT::failures
std::vector< VALIDATION_FAILURE > failures
Definition
merge_validators.h:54
KICAD_DIFF::VALIDATION_REPORT::Passed
bool Passed() const
Definition
merge_validators.h:56
KICAD_DIFF::VALIDATION_REPORT::Count
size_t Count() const
Definition
merge_validators.h:58
KICAD_DIFF::VALIDATION_REPORT::HasErrors
bool HasErrors() const
Definition
merge_validators.cpp:33
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(EmptyInputPasses)
Definition
test_validation_pipeline.cpp:37
src
qa
tests
diff_merge
test_validation_pipeline.cpp
Generated on Thu Jun 18 2026 00:07:05 for KiCad PCB EDA Suite by
1.13.2