KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_block_additional.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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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
25
26#include "allegro_block_tests.h"
27
28#include <hash.h>
29
30
43
44
45using namespace ALLEGRO;
46using namespace KI_TEST;
47
48
53{
54 std::string m_BoardName;
56
57 bool operator==( const BLOCK_TEST_KEY& other ) const
58 {
59 return m_BoardName == other.m_BoardName &&
61 }
62};
63
64
65namespace std
66{
67template <>
68struct hash<BLOCK_TEST_KEY>
69{
70 size_t operator()( const BLOCK_TEST_KEY& key ) const
71 {
72 return hash_val( key.m_BoardName, key.m_BlockOffset );
73 }
74};
75} // namespace std
76
77
78using BLOCK_TEST_FUNC = std::function<void( const BLOCK_BASE& )>;
79using DB_OBJ_TEST_FUNC = std::function<void( const DB_OBJ& )>;
80
81
82static void TestOlympus0x20( const BLOCK_BASE& aBlock )
83{
84 BOOST_REQUIRE( aBlock.GetBlockType() == 0x20 );
85
86 const auto& blk = static_cast<const BLOCK<BLK_0x20_UNKNOWN>&>( aBlock ).GetData();
87 BOOST_TEST( blk.m_R == 0x0507 );
88 BOOST_TEST( blk.m_Key == 0x812AB498 );
89 BOOST_TEST( blk.m_Next == 0x824DF8F0 );
90}
91
92
96static void TestBeagleBoneBlack_0x0F_SlotG1( const BLOCK_BASE& aBlock )
97{
98 BOOST_REQUIRE( aBlock.GetBlockType() == 0x0f );
99
100 const auto& blk = static_cast<const BLOCK<BLK_0x0F_FUNCTION_SLOT>&>( aBlock ).GetData();
101 BOOST_TEST( blk.m_Key == 0xbf0 );
102
103 BOOST_TEST( blk.m_Ptr0x06 == 0xb91 );
104 BOOST_TEST( blk.m_Next.value_or( 0 ) == 0xb91 ); // Last slot in component
105
106 BOOST_TEST( blk.m_SlotName == 0x2ba );
107 BOOST_TEST( blk.m_Ptr0x11 == 0x060aa );
108
109 BOOST_TEST( blk.GetCompDeviceTypeStr() == "RES_10K_1/16W_1%_0402_402_10K,1" );
110}
111
112
117{
118 BOOST_REQUIRE( aBlock.GetBlockType() == 0x0f );
119
120 const auto& blk = static_cast<const BLOCK<BLK_0x0F_FUNCTION_SLOT>&>( aBlock ).GetData();
121 BOOST_TEST( blk.m_Key == 0x12d );
122
123 BOOST_TEST( blk.m_Ptr0x06 == 0x126 );
124 BOOST_TEST( blk.m_Next.value_or( 0 ) == 0x126 ); // Last slot in component
125
126 BOOST_TEST( blk.m_SlotName == 0x87 );
127 BOOST_TEST( blk.m_Ptr0x11 == 0x264 ); // ptr to "ZERO"
128
129 BOOST_TEST( blk.GetCompDeviceTypeStr() == "AM4096" );
130}
131
132
136static void TestParallellaV163_PS_56X55RT( const BLOCK_BASE& aBlock )
137{
138 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
139
140 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
141
142 BOOST_TEST( blk.m_Key == 0x0acda700 );
143
144 BOOST_TEST( blk.GetLayerCount() == 1 );
145 BOOST_TEST( blk.m_Components.size() == 10 + 3 * 1);
146}
147
148
149static void TestParallellaV163_PS_28C128N( const BLOCK_BASE& aBlock )
150{
151 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
152
153 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
154
155 BOOST_TEST( blk.m_Key == 0x0acd0920 );
156
157 const auto& hdr16x = std::get<BLK_0x1C_PADSTACK::HEADER_v16x>( blk.m_Header );
158
159 BOOST_TEST( blk.IsPlated() == false );
160
161 BOOST_TEST( hdr16x.m_DrillChar == 'L' );
162}
163
164
166{
167 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
168
169 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
170
171 BOOST_TEST( blk.m_Key == 0x0acd1ea0 );
172
173 const auto& hdr16x = std::get<BLK_0x1C_PADSTACK::HEADER_v16x>( blk.m_Header );
174
175 BOOST_TEST( hdr16x.m_DrillSize == 2559 );
176
177 BOOST_TEST( hdr16x.m_SlotX == 2559 );
178 BOOST_TEST( hdr16x.m_SlotY == 6693 );
179
180 BOOST_TEST( blk.IsPlated() == true );
181}
182
183
185{
186 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
187
188 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
189
190 BOOST_TEST( blk.m_Key == 0x1421 );
191 BOOST_TEST( blk.GetLayerCount() == 6 );
192
193 const auto& hdr17x = std::get<BLK_0x1C_PADSTACK::HEADER_v17x>( blk.m_Header );
194
195 BOOST_TEST( hdr17x.m_DrillSize == 4000 );
196
197 BOOST_TEST( hdr17x.m_SlotX == 12000 );
198 BOOST_TEST( hdr17x.m_SlotY == 4000 );
199
200 BOOST_TEST( hdr17x.m_TolerancePos == 300 );
201 BOOST_TEST( hdr17x.m_ToleranceNeg == 300 );
202 BOOST_TEST( hdr17x.m_ToleranceTravelPos == 300 );
203 BOOST_TEST( hdr17x.m_ToleranceTravelNeg == 300 );
204
205 BOOST_TEST( blk.IsPlated() == true );
206}
207
208
209static void TestBeagleBoneAI_PS_200C125D( const BLOCK_BASE& aBlock )
210{
211 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
212
213 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
214
215 BOOST_TEST( blk.m_Key == 0x1fda );
216 BOOST_TEST( blk.GetLayerCount() == 12 );
217
218 BOOST_TEST( blk.GetDrillSize() == 125000 );
219
220 BOOST_TEST( blk.m_Components.size() == 21 + 4 * 12 );
221
222 BOOST_TEST( blk.m_Components[0].m_Type == PADSTACK_COMPONENT::TYPE_RECTANGLE );
223 BOOST_TEST( blk.m_Components[0].m_W == 244000 );
224 BOOST_TEST( blk.m_Components[0].m_H == 244000 );
225
226 BOOST_TEST( blk.IsPlated() == true );
227}
228
229
230static void TestCutiePiV166_PS_C50H340M700N( const BLOCK_BASE& aBlock )
231{
232 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
233
234 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
235
236 BOOST_TEST( blk.m_Key == 0x0bfa9588 );
237
238 BOOST_TEST( blk.GetLayerCount() == 6 );
239 BOOST_TEST( blk.GetDrillSize() == 133858 );
240
241 BOOST_TEST( blk.m_Components.size() == 11 + 3 * 6 );
242
243 BOOST_TEST( blk.m_Components[0].m_Type == PADSTACK_COMPONENT::TYPE_CIRCLE );
244 BOOST_TEST( blk.m_Components[0].m_W == 275591 );
245 BOOST_TEST( blk.m_Components[0].m_H == 275591 );
246
247 BOOST_TEST( blk.IsPlated() == false );
248}
249
250
259// clang-format off
260static const std::unordered_map<BLOCK_TEST_KEY, BLOCK_TEST_FUNC> additionalBlockTests{
261 { { "Olympus_15061-1b_v165", 0x0131553c }, TestOlympus0x20 },
262
263 // 0x0F
264 { { "BeagleBone_Black_RevC", 0x0000c8b8 }, TestBeagleBoneBlack_0x0F_SlotG1 },
265 { { "OpenBreath_encoder_v174", 0x00001c3c }, TestOpenBreath_0x0F_SlotAM4096_G1 },
266
267 // Padstacks
268 { { "BeagleBone_Black_RevC", 0x0007c420 }, TestBeagleBoneBlack_PS_120X040SLOT },
269 { { "BeagleBone-AI", 0x00047f44 }, TestBeagleBoneAI_PS_200C125D },
270 { { "CutiePi_V2_3_v166", 0x0001ef8c }, TestCutiePiV166_PS_C50H340M700N },
271 { { "parallella_v163", 0x000368c8 }, TestParallellaV163_PS_56X55RT },
272 { { "parallella_v163", 0x0002cc08 }, TestParallellaV163_PS_28C128N },
273 { { "parallella_v163", 0x0002e168 }, TestParallellaV163_PS_P65X1P7SLT },
274};
275
276
277static const std::unordered_map<BLOCK_TEST_KEY, DB_OBJ_TEST_FUNC> additionalDbObjTests{
278 { { "Olympus_15061-1b_v165", 0x0131553c }, []( const DB_OBJ& obj )
279 {
280 BOOST_REQUIRE( obj.GetType() == BRD_x20 );
281
282 const auto& blk = static_cast<const UNKNOWN_0x20&>( obj );
283 BOOST_TEST( blk.m_Next.m_TargetKey == 0x824DF8F0 );
284 }
285 },
286};
287
288// clang-format on
289
290
291void KI_TEST::RunAdditionalBlockTest( const std::string& aBoardName, size_t aBlockOffset, const BLOCK_BASE& block )
292{
293 const BLOCK_TEST_KEY key{ aBoardName, aBlockOffset };
294
295 auto it = additionalBlockTests.find( key );
296 if( it != additionalBlockTests.end() )
297 {
298 const auto& testFunc = it->second;
299 BOOST_REQUIRE( testFunc );
300
301 testFunc( block );
302 }
303 else
304 {
305 BOOST_TEST_FAIL( "No additional test defined for this block" );
306 }
307}
308
309
310void KI_TEST::RunAdditionalObjectTest( const std::string& aBoardName, size_t aBlockOffset, const DB_OBJ& obj )
311{
312 const BLOCK_TEST_KEY key{ aBoardName, aBlockOffset };
313
314 auto it = additionalDbObjTests.find( key );
315 if( it != additionalDbObjTests.end() )
316 {
317 const auto& testFunc = it->second;
318 BOOST_REQUIRE( testFunc );
319
320 testFunc( obj );
321 }
322 else
323 {
324 BOOST_TEST_FAIL( "No additional test defined for this DB_OBJ" );
325 }
326}
The base class for all blocks in the main body of an Allegro file.
uint8_t GetBlockType() const
static constexpr std::size_t hash_val(const Types &... args)
Definition hash.h:51
void RunAdditionalObjectTest(const std::string &aBoardName, size_t aBlockOffset, const ALLEGRO::DB_OBJ &aDbObj)
Look up and run any additional ad-hoc tests for a DB_OBJ (parsed and converted block)
void RunAdditionalBlockTest(const std::string &aBoardName, size_t aBlockOffset, const ALLEGRO::BLOCK_BASE &aBlock)
Look up and run any additional ad-hoc tests for a block.
STL namespace.
A DB_OBJ represents one object in an Allegro database.
Definition allegro_db.h:168
Unique key for identifying a block test, used for looking up additional validation functions.
bool operator==(const BLOCK_TEST_KEY &other) const
size_t operator()(const BLOCK_TEST_KEY &key) const
static void TestBeagleBoneBlack_0x0F_SlotG1(const BLOCK_BASE &aBlock)
Tests a V17.2 slot def.
static const std::unordered_map< BLOCK_TEST_KEY, DB_OBJ_TEST_FUNC > additionalDbObjTests
static void TestOlympus0x20(const BLOCK_BASE &aBlock)
static void TestBeagleBoneBlack_PS_120X040SLOT(const BLOCK_BASE &aBlock)
static void TestCutiePiV166_PS_C50H340M700N(const BLOCK_BASE &aBlock)
std::function< void(const DB_OBJ &)> DB_OBJ_TEST_FUNC
std::function< void(const BLOCK_BASE &)> BLOCK_TEST_FUNC
static const std::unordered_map< BLOCK_TEST_KEY, BLOCK_TEST_FUNC > additionalBlockTests
The registry of additional block tests, keyed by board name and block offset.
static void TestParallellaV163_PS_P65X1P7SLT(const BLOCK_BASE &aBlock)
static void TestBeagleBoneAI_PS_200C125D(const BLOCK_BASE &aBlock)
static void TestOpenBreath_0x0F_SlotAM4096_G1(const BLOCK_BASE &aBlock)
Tests a V17.4 slot def.
static void TestParallellaV163_PS_28C128N(const BLOCK_BASE &aBlock)
static void TestParallellaV163_PS_56X55RT(const BLOCK_BASE &aBlock)
This is a 1-layer SMD padstack in v16.3 format.
BOOST_TEST(contains==c.ExpectedContains)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())