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, see <https://www.gnu.org/licenses/>.
18 */
19
31
35
37
38#include <board.h>
39#include <footprint.h>
40#include <pad.h>
41#include <netinfo.h>
42
43#include <cstring>
44#include <fstream>
45#include <set>
46
47
49{
51
53
54 std::string GetPcbTestDataDir()
55 {
56 return KI_TEST::GetPcbnewTestDataDir() + "plugins/diptrace/";
57 }
58
63 bool HasDipTraceSchematicHeader( const std::string& aFilePath )
64 {
65 std::ifstream file( aFilePath, std::ios::binary );
66
67 if( !file.is_open() )
68 return false;
69
70 uint8_t header[8];
71 file.read( reinterpret_cast<char*>( header ), 8 );
72
73 if( file.gcount() < 8 )
74 return false;
75
76 static const uint8_t expected[] = { 0x07, 'D', 'T', 'S', 'C', 'H', 'E', 'M' };
77
78 return std::memcmp( header, expected, 8 ) == 0;
79 }
80};
81
82
83BOOST_FIXTURE_TEST_SUITE( DipTraceCrossLink, DIPTRACE_CROSS_LINK_FIXTURE )
84
85
86
91BOOST_AUTO_TEST_CASE( SchematicHeaderValid )
92{
93 // The paired schematic lives in the eeschema test data tree
94 std::string schPath = KI_TEST::GetPcbnewTestDataDir()
95 + "../eeschema/plugins/diptrace/z80_board.dch";
96
97 BOOST_CHECK( HasDipTraceSchematicHeader( schPath ) );
98}
99
100
106BOOST_AUTO_TEST_CASE( BoardRefDesPresent )
107{
108 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
109
110 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
111
112 BOOST_REQUIRE( board );
113
114 std::set<wxString> refDesSet;
115
116 for( const FOOTPRINT* fp : board->Footprints() )
117 {
118 wxString ref = fp->GetReference();
119
120 if( !ref.IsEmpty() )
121 refDesSet.insert( ref );
122 }
123
124 // The Z80 board should have a substantial number of unique reference designators
125 BOOST_CHECK_GT( refDesSet.size(), 10 );
126
127 // Verify that reference designators follow expected patterns (Uxx, Rxx, Cxx, etc.)
128 bool hasIC = false;
129
130 for( const wxString& ref : refDesSet )
131 {
132 if( ref.StartsWith( "U" ) || ref.StartsWith( "IC" ) || ref.StartsWith( "DD" ) )
133 {
134 hasIC = true;
135 break;
136 }
137 }
138
139 BOOST_CHECK_MESSAGE( hasIC,
140 "Z80 board should have at least one IC/U-prefixed reference" );
141}
142
143
149BOOST_AUTO_TEST_CASE( BoardNetsPresent )
150{
151 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
152
153 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
154
155 BOOST_REQUIRE( board );
156
157 std::set<wxString> netNames;
158
159 for( NETINFO_ITEM* net : board->GetNetInfo() )
160 {
161 if( net->GetNetCode() > 0 )
162 netNames.insert( net->GetNetname() );
163 }
164
165 // Z80 board has ~97 named nets (address bus, data bus, control signals, etc.)
166 BOOST_CHECK_GT( netNames.size(), 20 );
167
168 // Verify that known Z80-board net names are present
169 BOOST_CHECK( netNames.count( wxT( "GND" ) ) > 0 );
170 BOOST_CHECK( netNames.count( wxT( "A0" ) ) > 0 );
171 BOOST_CHECK( netNames.count( wxT( "D0" ) ) > 0 );
172}
173
174
180{
181 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
182
183 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
184
185 BOOST_REQUIRE( board );
186 BOOST_CHECK_GT( board->Footprints().size(), 10 );
187
188 int totalPads = 0;
189
190 for( const FOOTPRINT* fp : board->Footprints() )
191 totalPads += static_cast<int>( fp->Pads().size() );
192
193 BOOST_CHECK_GT( totalPads, 0 );
194}
195
196
General utilities for PCB file IO for QA programs.
Handle the data for a net.
Definition netinfo.h:46
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")