KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pads_sch_import.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
22
23#include <schematic.h>
25#include <sch_io/sch_io_mgr.h>
26#include <sch_screen.h>
27#include <sch_sheet.h>
28#include <sch_sheet_path.h>
29#include <sch_symbol.h>
31
32
33namespace
34{
35
36struct PADS_SCH_IMPORT_FIXTURE
37{
38 PADS_SCH_IMPORT_FIXTURE() : m_schematic( nullptr )
39 {
40 m_settingsManager.LoadProject( "" );
41 m_schematic.SetProject( &m_settingsManager.Prj() );
42 m_schematic.Reset();
43 }
44
45 ~PADS_SCH_IMPORT_FIXTURE()
46 {
47 m_schematic.Reset();
48 }
49
50 SETTINGS_MANAGER m_settingsManager;
51 SCHEMATIC m_schematic;
52};
53
54} // namespace
55
56
57BOOST_FIXTURE_TEST_SUITE( PadsSchImport, PADS_SCH_IMPORT_FIXTURE )
58
59
60BOOST_AUTO_TEST_CASE( CanReadSchematicFile )
61{
62 SCH_IO_PADS plugin;
63
64 wxString padsFile = wxString::FromUTF8(
65 KI_TEST::GetEeschemaTestDataDir() + "/plugins/pads/simple_schematic.txt" );
66
67 BOOST_CHECK( plugin.CanReadSchematicFile( padsFile ) );
68}
69
70
71BOOST_AUTO_TEST_CASE( CanReadSchematicFile_RejectNonPads )
72{
73 SCH_IO_PADS plugin;
74
75 wxString kicadFile = wxString::FromUTF8(
76 KI_TEST::GetEeschemaTestDataDir() + "/plugins/pads/simple_schematic.txt" );
77
78 BOOST_CHECK( plugin.CanReadSchematicFile( kicadFile ) );
79}
80
81
83{
84 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_PADS ) );
85 BOOST_CHECK_NE( pi.get(), nullptr );
86}
87
88
89BOOST_AUTO_TEST_CASE( MultiGateImport )
90{
91 SCH_IO_PADS plugin;
92
93 wxString padsFile = wxString::FromUTF8(
94 KI_TEST::GetEeschemaTestDataDir() + "/plugins/pads/multigate_schematic.txt" );
95
96 SCH_SHEET* rootSheet = plugin.LoadSchematicFile( padsFile, &m_schematic );
97 BOOST_REQUIRE( rootSheet );
98 BOOST_REQUIRE( rootSheet->GetScreen() );
99
100 SCH_SCREEN* screen = rootSheet->GetScreen();
101
102 // Collect U1 symbols
103 std::vector<SCH_SYMBOL*> u1Symbols;
104 SCH_SHEET_PATH rootPath;
105 rootPath.push_back( rootSheet );
106
107 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
108 {
109 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
110
111 if( sym->GetRef( &rootPath ) == wxT( "U1" ) )
112 u1Symbols.push_back( sym );
113 }
114
115 BOOST_REQUIRE_EQUAL( u1Symbols.size(), 2u );
116
117 // Sort by unit number for deterministic checks
118 std::sort( u1Symbols.begin(), u1Symbols.end(),
119 []( const SCH_SYMBOL* a, const SCH_SYMBOL* b )
120 {
121 return a->GetUnit() < b->GetUnit();
122 } );
123
124 // Unit 1 (gate A with TL082A decal) should have 5 pins
125 BOOST_CHECK_EQUAL( u1Symbols[0]->GetUnit(), 1 );
126 BOOST_CHECK_EQUAL( u1Symbols[0]->GetLibPins().size(), 5u );
127
128 // Unit 2 (gate B with TL082 decal) should have 3 pins
129 BOOST_CHECK_EQUAL( u1Symbols[1]->GetUnit(), 2 );
130 BOOST_CHECK_EQUAL( u1Symbols[1]->GetLibPins().size(), 3u );
131
132 // Both should share the same multi-unit LIB_SYMBOL with 2 units
133 BOOST_CHECK( u1Symbols[0]->IsMultiUnit() );
134 BOOST_CHECK_EQUAL( u1Symbols[0]->GetUnitCount(), 2 );
135
136 // Both references should be "U1" (not "U1-A" or "U1-B")
137 BOOST_CHECK_EQUAL( u1Symbols[0]->GetRef( &rootPath ), wxT( "U1" ) );
138 BOOST_CHECK_EQUAL( u1Symbols[1]->GetRef( &rootPath ), wxT( "U1" ) );
139}
140
141
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
A SCH_IO derivation for loading PADS Logic schematic files.
Definition sch_io_pads.h:40
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:119
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:140
Schematic symbol object.
Definition sch_symbol.h:76
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CanReadSchematicFile)
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:176