KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_annotation.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, see <https://www.gnu.org/licenses/>.
18 */
19
20
22#include "eeschema_test_utils.h"
23
24#include <erc/erc.h>
25#include <erc/erc_item.h>
26#include <sch_marker.h>
27#include <sch_reference_list.h>
28#include <sch_screen.h>
29#include <sch_symbol.h>
30#include <schematic.h>
32
33
34BOOST_FIXTURE_TEST_SUITE( ERCAnnotation, KI_TEST::SCHEMATIC_TEST_FIXTURE )
35
36
37// kicad-cli runs ERC without the schematic editor, which used to be the only place annotation was checked
38BOOST_AUTO_TEST_CASE( HeadlessRunFlagsDuplicateReferences )
39{
40 LoadSchematic( wxFileName( KI_TEST::GetEeschemaTestDataDir(), wxS( "issue13212" ),
42
43 SCH_SHEET_LIST hierarchy = m_schematic->Hierarchy();
45
46 hierarchy.GetSymbols( refs, SYMBOL_FILTER_NON_POWER );
47 BOOST_REQUIRE_GE( refs.GetCount(), 2 );
48
49 refs[1].GetSymbol()->SetRef( &refs[1].GetSheetPath(), refs[0].GetSymbol()->GetRef( &refs[0].GetSheetPath() ) );
50 ERC_TESTER( m_schematic.get() ).RunTests( nullptr, nullptr, nullptr, &m_schematic->Project(), nullptr );
51
52 int duplicates = 0;
53
54 for( const SCH_SHEET_PATH& path : hierarchy )
55 {
56 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_MARKER_T ) )
57 {
58 std::shared_ptr<RC_ITEM> rcItem = static_cast<SCH_MARKER*>( item )->GetRCItem();
59
60 if( rcItem->GetErrorCode() != ERCE_DUPLICATE_REFERENCE )
61 continue;
62
63 // Exclusions saved from the editor dialog have no sheet path, so they must keep matching
64 BOOST_CHECK( !std::static_pointer_cast<ERC_ITEM>( rcItem )->IsSheetSpecific() );
65 duplicates++;
66 }
67 }
68
69 BOOST_CHECK_GE( duplicates, 1 );
70}
71
72
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:3522
A generic fixture for loading schematics and associated settings for qa tests.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
@ ERCE_DUPLICATE_REFERENCE
More than one symbol with the same reference.
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName, REPORTER *aReporter)
@ SYMBOL_FILTER_NON_POWER
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_AUTO_TEST_SUITE_END()
std::string path
@ SCH_MARKER_T
Definition typeinfo.h:154
Definition of file extensions used in Kicad.