KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_diptrace_cross_link.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 2
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/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 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
35
39
41
42#include <board.h>
43#include <footprint.h>
44#include <pad.h>
45#include <netinfo.h>
46
47#include <cstring>
48#include <fstream>
49#include <set>
50
51
53{
55
57
58 std::string GetPcbTestDataDir()
59 {
60 return KI_TEST::GetPcbnewTestDataDir() + "plugins/diptrace/";
61 }
62
67 bool HasDipTraceSchematicHeader( const std::string& aFilePath )
68 {
69 std::ifstream file( aFilePath, std::ios::binary );
70
71 if( !file.is_open() )
72 return false;
73
74 uint8_t header[8];
75 file.read( reinterpret_cast<char*>( header ), 8 );
76
77 if( file.gcount() < 8 )
78 return false;
79
80 static const uint8_t expected[] = { 0x07, 'D', 'T', 'S', 'C', 'H', 'E', 'M' };
81
82 return std::memcmp( header, expected, 8 ) == 0;
83 }
84};
85
86
87BOOST_FIXTURE_TEST_SUITE( DipTraceCrossLink, DIPTRACE_CROSS_LINK_FIXTURE )
88
89
90
95BOOST_AUTO_TEST_CASE( SchematicHeaderValid )
96{
97 // The paired schematic lives in the eeschema test data tree
98 std::string schPath = KI_TEST::GetPcbnewTestDataDir()
99 + "../eeschema/plugins/diptrace/z80_board.dch";
100
101 BOOST_CHECK( HasDipTraceSchematicHeader( schPath ) );
102}
103
104
110BOOST_AUTO_TEST_CASE( BoardRefDesPresent )
111{
112 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
113
114 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
115
116 BOOST_REQUIRE( board );
117
118 std::set<wxString> refDesSet;
119
120 for( const FOOTPRINT* fp : board->Footprints() )
121 {
122 wxString ref = fp->GetReference();
123
124 if( !ref.IsEmpty() )
125 refDesSet.insert( ref );
126 }
127
128 // The Z80 board should have a substantial number of unique reference designators
129 BOOST_CHECK_GT( refDesSet.size(), 10 );
130
131 // Verify that reference designators follow expected patterns (Uxx, Rxx, Cxx, etc.)
132 bool hasIC = false;
133
134 for( const wxString& ref : refDesSet )
135 {
136 if( ref.StartsWith( "U" ) || ref.StartsWith( "IC" ) || ref.StartsWith( "DD" ) )
137 {
138 hasIC = true;
139 break;
140 }
141 }
142
143 BOOST_CHECK_MESSAGE( hasIC,
144 "Z80 board should have at least one IC/U-prefixed reference" );
145}
146
147
153BOOST_AUTO_TEST_CASE( BoardNetsPresent )
154{
155 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
156
157 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
158
159 BOOST_REQUIRE( board );
160
161 std::set<wxString> netNames;
162
163 for( NETINFO_ITEM* net : board->GetNetInfo() )
164 {
165 if( net->GetNetCode() > 0 )
166 netNames.insert( net->GetNetname() );
167 }
168
169 // Z80 board has ~97 named nets (address bus, data bus, control signals, etc.)
170 BOOST_CHECK_GT( netNames.size(), 20 );
171
172 // Verify that known Z80-board net names are present
173 BOOST_CHECK( netNames.count( wxT( "GND" ) ) > 0 );
174 BOOST_CHECK( netNames.count( wxT( "A0" ) ) > 0 );
175 BOOST_CHECK( netNames.count( wxT( "D0" ) ) > 0 );
176}
177
178
184{
185 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
186
187 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
188
189 BOOST_REQUIRE( board );
190 BOOST_CHECK_GT( board->Footprints().size(), 10 );
191
192 int totalPads = 0;
193
194 for( const FOOTPRINT* fp : board->Footprints() )
195 totalPads += static_cast<int>( fp->Pads().size() );
196
197 BOOST_CHECK_GT( totalPads, 0 );
198}
199
200
General utilities for PCB file IO for QA programs.
Handle the data for a net.
Definition netinfo.h:50
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
Pcbnew PCB_IO for DipTrace binary .dip board files.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
std::vector< std::string > header
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")