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