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
27
28
29using namespace KICAD_DIFF;
30
31
32BOOST_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.
37BOOST_AUTO_TEST_CASE( EmptyInputPasses )
38{
39 VALIDATION_INPUT 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.
49BOOST_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
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).
72BOOST_AUTO_TEST_CASE( ConnectivityRebuildContractHonoured )
73{
74 VALIDATION_INPUT input;
75 input.planRequiredRebuild = true;
76 input.applierReportedRebuild = true;
77
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).
85BOOST_AUTO_TEST_CASE( ConnectivityRebuildContractBroken )
86{
87 VALIDATION_INPUT input;
88 input.planRequiredRebuild = true;
89 input.applierReportedRebuild = false;
90
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).
107BOOST_AUTO_TEST_CASE( ExtraRebuildIsNotFlagged )
108{
109 VALIDATION_INPUT input;
110 input.planRequiredRebuild = false;
111 input.applierReportedRebuild = true;
112
114 BOOST_CHECK( report.Passed() );
115}
116
117
118// Identical schema versions = pass.
119BOOST_AUTO_TEST_CASE( SchemaVersionMatchPasses )
120{
121 VALIDATION_INPUT input;
122 input.ancestorSchemaVersion = 20240101;
123 input.oursSchemaVersion = 20240101;
124 input.theirsSchemaVersion = 20240101;
125
127 BOOST_CHECK( report.Passed() );
128}
129
130
131// Major schema version mismatch surfaces an error.
132BOOST_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
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.
156BOOST_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
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().
180BOOST_AUTO_TEST_CASE( PassedAndHasErrorsAreDistinguishable )
181{
182 VALIDATION_INPUT input;
183 input.planRequiredRebuild = true;
184 input.applierReportedRebuild = false;
185
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 {
196 sawError = true;
197 }
198
199 BOOST_CHECK_EQUAL( sawError, report.HasErrors() );
200}
201
202
Definition kiid.h:44
VALIDATION_REPORT RunPostApplyValidators(const VALIDATION_INPUT &aInput)
Run every standard post-apply validator and merge their reports.
@ RPT_SEVERITY_ERROR
Outcome of a single validator run.
std::vector< KIID_PATH > relatedItems
Inputs needed to run the post-apply validator pipeline.
std::vector< REFDES_ENTRY > refdesEntries
std::vector< VALIDATION_FAILURE > failures
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(EmptyInputPasses)