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( BoardRefDesPresent )
92{
93 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
94
95 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
96
97 BOOST_REQUIRE( board );
98
99 std::set<wxString> refDesSet;
100
101 for( const FOOTPRINT* fp : board->Footprints() )
102 {
103 wxString ref = fp->GetReference();
104
105 if( !ref.IsEmpty() )
106 refDesSet.insert( ref );
107 }
108
109 // The Z80 board should have a substantial number of unique reference designators
110 BOOST_CHECK_GT( refDesSet.size(), 10 );
111
112 // Verify that reference designators follow expected patterns (Uxx, Rxx, Cxx, etc.)
113 bool hasIC = false;
114
115 for( const wxString& ref : refDesSet )
116 {
117 if( ref.StartsWith( "U" ) || ref.StartsWith( "IC" ) || ref.StartsWith( "DD" ) )
118 {
119 hasIC = true;
120 break;
121 }
122 }
123
124 BOOST_CHECK_MESSAGE( hasIC,
125 "Z80 board should have at least one IC/U-prefixed reference" );
126}
127
128
134BOOST_AUTO_TEST_CASE( BoardNetsPresent )
135{
136 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
137
138 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
139
140 BOOST_REQUIRE( board );
141
142 std::set<wxString> netNames;
143
144 for( NETINFO_ITEM* net : board->GetNetInfo() )
145 {
146 if( net->GetNetCode() > 0 )
147 netNames.insert( net->GetNetname() );
148 }
149
150 // Z80 board has ~97 named nets (address bus, data bus, control signals, etc.)
151 BOOST_CHECK_GT( netNames.size(), 20 );
152
153 // Verify that known Z80-board net names are present
154 BOOST_CHECK( netNames.count( wxT( "GND" ) ) > 0 );
155 BOOST_CHECK( netNames.count( wxT( "A0" ) ) > 0 );
156 BOOST_CHECK( netNames.count( wxT( "D0" ) ) > 0 );
157}
158
159
165{
166 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
167
168 m_pcbPlugin.LoadBoard( GetPcbTestDataDir() + "z80_board.dip", board.get() );
169
170 BOOST_REQUIRE( board );
171 BOOST_CHECK_GT( board->Footprints().size(), 10 );
172
173 int totalPads = 0;
174
175 for( const FOOTPRINT* fp : board->Footprints() )
176 totalPads += static_cast<int>( fp->Pads().size() );
177
178 BOOST_CHECK_GT( totalPads, 0 );
179}
180
181
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)