KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_footprint_library_adapter.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
20#include <atomic>
21#include <filesystem>
22#include <fstream>
23#include <algorithm>
24#include <iterator>
25#include <memory>
26#include <set>
27#include <thread>
28#include <vector>
29
30#ifdef __unix__
31#include <unistd.h>
32#endif
33
34#include <qa_utils/file_utils.h>
37
38#include <board.h>
39#include <footprint.h>
43#include <netinfo.h>
44#include <pad.h>
45#include <pcb_io/pcb_io_mgr.h>
47
48
49namespace
50{
51
57class TEST_FOOTPRINT_LIBRARY_ADAPTER : public FOOTPRINT_LIBRARY_ADAPTER
58{
59public:
61
62 void SeedLoadError( const wxString& aNickname )
63 {
64 m_libraries[aNickname].status.load_status = LOAD_STATUS::LOAD_ERROR;
65 }
66
72 void SeedLoadedLibrary( const wxString& aNickname, const wxString& aUri )
73 {
74 LIBRARY_TABLE_ROW* row = m_rows.emplace_back( std::make_unique<LIBRARY_TABLE_ROW>() ).get();
75 row->SetNickname( aNickname );
76 row->SetType( wxS( "KiCad" ) );
77 row->SetURI( aUri );
78
79 LIB_DATA& data = m_libraries[aNickname];
81 data.plugin = std::make_unique<PCB_IO_KICAD_SEXPR>();
82 data.row = row;
83 }
84
85private:
86 std::vector<std::unique_ptr<LIBRARY_TABLE_ROW>> m_rows;
87};
88
89
91wxString getResistorLibPath()
92{
93 // qa/data/pcbnew/.. -> qa/data/libraries/Resistor_SMD.pretty
94 wxFileName fn( wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() ), wxEmptyString );
95 fn.RemoveLastDir();
96 fn.AppendDir( wxS( "libraries" ) );
97 fn.AppendDir( wxS( "Resistor_SMD.pretty" ) );
98 return fn.GetPath();
99}
100
101} // namespace
102
103
104BOOST_AUTO_TEST_SUITE( FootprintLibraryAdapter )
105
106
107
115BOOST_AUTO_TEST_CASE( IsFootprintLibWritableHandlesFailedLoad )
116{
117 LIBRARY_MANAGER manager;
118 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
119
120 adapter.SeedLoadError( wxS( "BadLib" ) );
121
122 BOOST_CHECK_EQUAL( adapter.IsFootprintLibWritable( wxS( "BadLib" ) ), false );
123
124 // A library that was never even attempted must also be safe.
125 BOOST_CHECK_EQUAL( adapter.IsFootprintLibWritable( wxS( "NeverSeen" ) ), false );
126}
127
128
136BOOST_AUTO_TEST_CASE( SaveFootprintReadOnlyFilePropagatesError )
137{
138#ifdef __unix__
139 // The superuser ignores mode bits, so a read-only file stays writable and this path
140 // cannot be exercised.
141 if( ::geteuid() == 0 )
142 {
143 BOOST_TEST_MESSAGE( "Skipping read-only footprint save test when running as root." );
144 return;
145 }
146#endif
147
148 // FootprintSave validates the whole containing directory as a library, so it needs a
149 // private directory no unrelated .kicad_mod can pollute.
150 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_adapter_save_readonly" );
151 const std::filesystem::path libPath = tmpLib.CreateChildDir( "kicad_qa_adapter_save_readonly.pretty" );
152
153 LIBRARY_MANAGER manager;
154 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
155
156 const wxString nickname = wxS( "scratch" );
157 adapter.SeedLoadedLibrary( nickname, libPath.string() );
158
159 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
160
161 FOOTPRINT* fp = new FOOTPRINT( board.get() );
162 board->Add( fp );
163 fp->SetFPID( LIB_ID( nickname, wxS( "readonly_fp" ) ) );
164
165 BOOST_REQUIRE( adapter.SaveFootprint( nickname, fp ) == FOOTPRINT_LIBRARY_ADAPTER::SAVE_OK );
166
167 std::filesystem::path savedFile = libPath / "readonly_fp.kicad_mod";
168 BOOST_REQUIRE( std::filesystem::exists( savedFile ) );
169
170 // Mark only the file read-only, mirroring the issue; the directory stays writable so the
171 // writability gate still passes and the temporary directory can unlink it.
172 std::filesystem::permissions( savedFile,
173 std::filesystem::perms::owner_write | std::filesystem::perms::group_write
174 | std::filesystem::perms::others_write,
175 std::filesystem::perm_options::remove );
176
177 BOOST_CHECK_THROW( adapter.SaveFootprint( nickname, fp ), IO_ERROR );
178}
179
180
186BOOST_AUTO_TEST_CASE( SavedFootprintCacheDoesNotRetainBoardNets )
187{
188 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_adapter_cached_nets" );
189 const std::filesystem::path libPath = tmpLib.CreateChildDir( "kicad_qa_adapter_cached_nets.pretty" );
190
191 LIBRARY_MANAGER manager;
192 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
193
194 const wxString nickname = wxS( "CachedNets" );
195 adapter.SeedLoadedLibrary( nickname, libPath.string() );
196 adapter.RefreshLibraryIfChanged( nickname );
197
198 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
199 NETINFO_ITEM* net = new NETINFO_ITEM( board.get(), wxS( "SourceBoardNet" ), 1 );
200 board->Add( net );
201
202 FOOTPRINT* footprint = new FOOTPRINT( board.get() );
203 board->Add( footprint );
204 footprint->SetFPID( LIB_ID( nickname, wxS( "cached_nets" ) ) );
205
206 PAD* pad = new PAD( footprint );
208 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) ) );
209 pad->SetLayerSet( LSET( { F_Cu } ) );
210 pad->SetNet( net );
211 footprint->Add( pad );
212
213 BOOST_REQUIRE( adapter.SaveFootprint( nickname, footprint ) == FOOTPRINT_LIBRARY_ADAPTER::SAVE_OK );
214
215 // The cache entry now outlives the board and every NETINFO_ITEM it owns, as it can when the
216 // user closes the source board before opening the footprint chooser.
217 board.reset();
218
219 std::unique_ptr<FOOTPRINT> loaded( adapter.LoadFootprint( nickname, wxS( "cached_nets" ), false ) );
220 BOOST_REQUIRE( loaded );
221 BOOST_REQUIRE_EQUAL( loaded->Pads().size(), 1u );
222 BOOST_CHECK_EQUAL( loaded->GetBoard(), nullptr );
223 BOOST_CHECK_EQUAL( loaded->Pads().front()->GetNet(), NETINFO_LIST::OrphanedItem() );
224}
225
226
227// Concurrency regression for the FP_CACHE heap corruption (Sentry 6819786130 / 6322230945 /
228// 7271165487): a writer churns the library while readers rebuild the cache, which races unserialized.
229BOOST_AUTO_TEST_CASE( ConcurrentPluginAccessIsSerialized )
230{
231 // Writable copy so the writer can churn the library and force concurrent cache rebuilds.
232 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_adapter_concurrent" );
233 const std::filesystem::path libPath = tmpLib.CreateChildDir( "kicad_qa_adapter_concurrent.pretty" );
234
235 for( const auto& entry : std::filesystem::directory_iterator(
236 std::filesystem::path( getResistorLibPath().ToStdString() ) ) )
237 {
238 if( entry.is_regular_file() )
239 std::filesystem::copy_file( entry.path(), libPath / entry.path().filename() );
240 }
241
242 LIBRARY_MANAGER manager;
243 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
244
245 const wxString nickname = wxS( "Resistor_SMD" );
246 adapter.SeedLoadedLibrary( nickname, libPath.string() );
247
248 // Readers probe this; the writer only writes scratch names, so it always resolves.
249 const wxString stableFp = wxS( "R_0603_1608Metric" );
250
251 BOOST_REQUIRE( adapter.FootprintExists( nickname, stableFp ) );
252
253 constexpr int readerCount = 6;
254 constexpr int iterations = 40;
255
256 std::atomic<bool> sawMissing{ false };
257 std::atomic<bool> sawNullLoad{ false };
258 std::atomic<int> savedCount{ 0 };
259
260 // Release all threads together so readers and writer overlap deterministically.
261 std::atomic<int> ready{ 0 };
262 std::atomic<bool> go{ false };
263
264 auto waitForStart = [&]()
265 {
266 ready.fetch_add( 1 );
267
268 while( !go.load() )
269 std::this_thread::yield();
270 };
271
272 std::vector<std::thread> workers;
273 workers.reserve( readerCount + 1 );
274
275 for( int t = 0; t < readerCount; ++t )
276 {
277 workers.emplace_back(
278 [&]()
279 {
280 waitForStart();
281
282 for( int i = 0; i < iterations; ++i )
283 {
284 // Base-class path whose guard this change adds.
285 adapter.IsWritable( nickname );
286
287 if( !adapter.FootprintExists( nickname, stableFp ) )
288 sawMissing = true;
289
290 std::unique_ptr<FOOTPRINT> fp{ adapter.LoadFootprint( nickname, stableFp, false ) };
291
292 if( !fp )
293 sawNullLoad = true;
294 }
295 } );
296 }
297
298 workers.emplace_back(
299 [&]()
300 {
301 std::unique_ptr<FOOTPRINT> seed{ adapter.LoadFootprint( nickname, stableFp, false ) };
302
303 if( !seed )
304 {
305 sawNullLoad = true;
306 return;
307 }
308
309 waitForStart();
310
311 for( int i = 0; i < iterations; ++i )
312 {
313 // Each save bumps the library timestamp, forcing the next validateCache() to rebuild.
314 seed->SetFPID( LIB_ID( nickname, wxString::Format( wxS( "scratch_%d" ), i % 4 ) ) );
315
316 try
317 {
318 if( adapter.SaveFootprint( nickname, seed.get(), true ) == FOOTPRINT_LIBRARY_ADAPTER::SAVE_OK )
319 savedCount.fetch_add( 1 );
320 }
321 catch( const IO_ERROR& )
322 {
323 // Transient write failures are fine; a total failure trips savedCount below.
324 }
325 }
326 } );
327
328 while( ready.load() < readerCount + 1 )
329 std::this_thread::yield();
330
331 go.store( true );
332
333 for( std::thread& worker : workers )
334 worker.join();
335
336 BOOST_CHECK( !sawMissing.load() );
337 BOOST_CHECK( !sawNullLoad.load() );
338
339 // Confirm the writer churned the cache, else the readers never raced a rebuild.
340 BOOST_CHECK( savedCount.load() > 0 );
341}
342
343
344BOOST_AUTO_TEST_CASE( RefreshChangedLibrariesPicksUpExternalAddition )
345{
346 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_adapter_stale" );
347 KI_TEST::SCOPED_TEMP_DIR tmpTable( "kicad_qa_adapter_stale_table" );
348
349 const std::filesystem::path libPath = tmpLib.CreateChildDir( "kicad_qa_adapter_stale.pretty" );
350
351 const std::filesystem::path source =
352 std::filesystem::path( getResistorLibPath().ToStdString() ) / "R_0402_1005Metric.kicad_mod";
353
354 std::filesystem::copy_file( source, libPath / "R_0402_1005Metric.kicad_mod" );
355
356 const wxString nickname = wxS( "StaleCheck" );
357
358 {
359 std::ofstream table( tmpTable.Path() / "fp-lib-table" );
360 table << "(fp_lib_table\n (version 7)\n";
361 table << " (lib (name \"" << nickname.ToStdString() << "\")(type \"KiCad\")(uri \""
362 << libPath.string() << "\")(options \"\")(descr \"\"))\n)\n";
363 }
364
365 LIBRARY_MANAGER manager;
366 manager.LoadProjectTables( tmpTable.PathStr(), { LIBRARY_TABLE_TYPE::FOOTPRINT } );
367
368 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
369 adapter.SeedLoadedLibrary( nickname, libPath.string() );
370
371 adapter.RefreshLibraryIfChanged( nickname );
372 BOOST_REQUIRE_EQUAL( adapter.GetFootprints( nickname, true ).size(), 1u );
373
374 std::filesystem::copy_file( source, libPath / "ZZ_PulledFootprint.kicad_mod" );
375
376 adapter.RefreshChangedLibraries();
377
378 bool found = false;
379
380 for( FOOTPRINT* fp : adapter.GetFootprints( nickname, true ) )
381 {
382 if( fp && fp->GetFPID().GetLibItemName().wx_str() == wxS( "ZZ_PulledFootprint" ) )
383 found = true;
384 }
385
386 BOOST_CHECK_MESSAGE( found, "a footprint added to the library on disk is missing from the listing" );
387}
388
389
390BOOST_AUTO_TEST_CASE( RefreshChangedLibrariesSkipsUnchangedLibraries )
391{
392 KI_TEST::SCOPED_TEMP_DIR tmpA( "kicad_qa_adapter_skip_a" );
393 KI_TEST::SCOPED_TEMP_DIR tmpB( "kicad_qa_adapter_skip_b" );
394 KI_TEST::SCOPED_TEMP_DIR tmpTable( "kicad_qa_adapter_skip_table" );
395
396 const std::filesystem::path libPathA = tmpA.CreateChildDir( "kicad_qa_adapter_skip_a.pretty" );
397 const std::filesystem::path libPathB = tmpB.CreateChildDir( "kicad_qa_adapter_skip_b.pretty" );
398
399 const std::filesystem::path source =
400 std::filesystem::path( getResistorLibPath().ToStdString() ) / "R_0402_1005Metric.kicad_mod";
401
402 std::filesystem::copy_file( source, libPathA / "R_0402_1005Metric.kicad_mod" );
403
404 for( int i = 0; i < 8; ++i )
405 {
406 std::filesystem::copy_file( source, libPathB / ( "R_" + std::to_string( i ) + ".kicad_mod" ) );
407 }
408
409 const wxString nickA = wxS( "SkipCheckA" );
410 const wxString nickB = wxS( "SkipCheckB" );
411
412 const std::filesystem::path tablePath = tmpTable.Path() / "fp-lib-table";
413
414 {
415 std::ofstream table( tablePath );
416 table << "(fp_lib_table\n (version 7)\n";
417 table << " (lib (name \"" << nickA.ToStdString() << "\")(type \"KiCad\")(uri \"" << libPathA.string()
418 << "\")(options \"\")(descr \"\"))\n";
419 table << " (lib (name \"" << nickB.ToStdString() << "\")(type \"KiCad\")(uri \"" << libPathB.string()
420 << "\")(options \"\")(descr \"\"))\n)\n";
421 }
422
423 LIBRARY_MANAGER manager;
424 manager.LoadProjectTables( tmpTable.PathStr(), { LIBRARY_TABLE_TYPE::FOOTPRINT } );
425
426 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
427 adapter.SeedLoadedLibrary( nickA, libPathA.string() );
428 adapter.SeedLoadedLibrary( nickB, libPathB.string() );
429
430 adapter.RefreshLibraryIfChanged( nickA );
431 adapter.RefreshLibraryIfChanged( nickB );
432
433 BOOST_REQUIRE_EQUAL( adapter.GetFootprints( nickA, true ).size(), 1u );
434 BOOST_REQUIRE_EQUAL( adapter.GetFootprints( nickB, true ).size(), 8u );
435
436 // Re-enumeration frees every footprint in the library and allocates replacements. A single
437 // address could be reused by chance, a whole vector of them could not.
438 std::vector<FOOTPRINT*> untouched = adapter.GetFootprints( nickB, true );
439
440 std::filesystem::copy_file( source, libPathA / "ZZ_Added.kicad_mod" );
441
442 adapter.RefreshChangedLibraries();
443
444 BOOST_CHECK_EQUAL( adapter.GetFootprints( nickA, true ).size(), 2u );
445 BOOST_CHECK_MESSAGE( adapter.GetFootprints( nickB, true ) == untouched, "an unchanged library was re-enumerated" );
446}
447
448
454BOOST_AUTO_TEST_CASE( EditorRoundTripKeepsFileUuids )
455{
456 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_adapter_rt" );
457 KI_TEST::SCOPED_TEMP_DIR tmpTable( "kicad_qa_adapter_rt_table" );
458
459 const std::filesystem::path libPath = tmpLib.CreateChildDir( "kicad_qa_adapter_rt.pretty" );
460
461 const std::filesystem::path source =
462 std::filesystem::path( getResistorLibPath().ToStdString() ) / "R_0402_1005Metric.kicad_mod";
463 const std::filesystem::path target = libPath / "R_0402_1005Metric.kicad_mod";
464
465 std::filesystem::copy_file( source, target );
466
467 const wxString nickname = wxS( "RoundTrip" );
468 const wxString fpName = wxS( "R_0402_1005Metric" );
469
470 {
471 std::ofstream table( tmpTable.Path() / "fp-lib-table" );
472 table << "(fp_lib_table\n (version 7)\n";
473 table << " (lib (name \"" << nickname.ToStdString() << "\")(type \"KiCad\")(uri \""
474 << libPath.string() << "\")(options \"\")(descr \"\"))\n)\n";
475 }
476
477 auto fileUuids =
478 []( const std::filesystem::path& aPath )
479 {
480 std::set<std::string> ids;
481 std::ifstream in( aPath );
482 std::string line;
483
484 while( std::getline( in, line ) )
485 {
486 size_t pos = line.find( "(uuid \"" );
487
488 if( pos != std::string::npos )
489 ids.insert( line.substr( pos + 7, 36 ) );
490 }
491
492 return ids;
493 };
494
495 const std::set<std::string> before = fileUuids( target );
496
497 LIBRARY_MANAGER manager;
498 manager.LoadProjectTables( tmpTable.PathStr(), { LIBRARY_TABLE_TYPE::FOOTPRINT } );
499
500 TEST_FOOTPRINT_LIBRARY_ADAPTER adapter( manager );
501 adapter.SeedLoadedLibrary( nickname, libPath.string() );
502
503 // Populates the preloaded-footprint cache the editor then loads through
504 adapter.RefreshLibraryIfChanged( nickname );
505
506 std::unique_ptr<FOOTPRINT> edited( adapter.LoadFootprint( nickname, fpName, true ) );
507 BOOST_REQUIRE( edited );
508
509 BOOST_REQUIRE( adapter.SaveFootprint( nickname, edited.get() ) == FOOTPRINT_LIBRARY_ADAPTER::SAVE_OK );
510
511 const std::set<std::string> after = fileUuids( target );
512
513 std::vector<std::string> common;
514 std::set_intersection( before.begin(), before.end(), after.begin(), after.end(),
515 std::back_inserter( common ) );
516
517 // Only the empty "Footprint" property is dropped on write; every other id must survive
518 BOOST_REQUIRE( !before.empty() );
519 BOOST_CHECK_EQUAL( after.size() + 1, before.size() );
520 BOOST_CHECK_MESSAGE( common.size() == after.size(),
521 "a load/save round trip through the editor path rewrote UUIDs in the .kicad_mod" );
522}
523
524
528BOOST_AUTO_TEST_CASE( RemovedLibraryStopsServingPreloadedFootprints )
529{
530 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_adapter_removed_lib" );
531 KI_TEST::SCOPED_TEMP_DIR tmpTable( "kicad_qa_adapter_removed_lib_table" );
532
533 const std::filesystem::path libPath = tmpLib.CreateChildDir( "kicad_qa_adapter_removed_lib.pretty" );
534
535 const std::filesystem::path source =
536 std::filesystem::path( getResistorLibPath().ToStdString() ) / "R_0402_1005Metric.kicad_mod";
537
538 std::filesystem::copy_file( source, libPath / "R_0402_1005Metric.kicad_mod" );
539
540 const wxString nickname = wxS( "RemovedCheck" );
541
542 {
543 std::ofstream table( tmpTable.Path() / "fp-lib-table" );
544 table << "(fp_lib_table\n (version 7)\n";
545 table << " (lib (name \"" << nickname.ToStdString() << "\")(type \"KiCad\")(uri \"" << libPath.string()
546 << "\")(options \"\")(descr \"\"))\n)\n";
547 }
548
549 LIBRARY_MANAGER manager;
550 manager.LoadProjectTables( tmpTable.PathStr(), { LIBRARY_TABLE_TYPE::FOOTPRINT } );
551
553 std::make_unique<TEST_FOOTPRINT_LIBRARY_ADAPTER>( manager ) );
554
555 std::optional<LIBRARY_MANAGER_ADAPTER*> adapterOpt = manager.Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT );
556 BOOST_REQUIRE( adapterOpt.has_value() );
557 TEST_FOOTPRINT_LIBRARY_ADAPTER& adapter = *static_cast<TEST_FOOTPRINT_LIBRARY_ADAPTER*>( *adapterOpt );
558
559 adapter.SeedLoadedLibrary( nickname, libPath.string() );
560 adapter.RefreshLibraryIfChanged( nickname );
561 BOOST_REQUIRE_EQUAL( adapter.GetFootprints( nickname, true ).size(), 1u );
562
563 // Now remove the library from the table and reload the project tables.
564 {
565 std::ofstream table( tmpTable.Path() / "fp-lib-table" );
566 table << "(fp_lib_table\n (version 7)\n)\n";
567 }
568
569 manager.LoadProjectTables( tmpTable.PathStr(), { LIBRARY_TABLE_TYPE::FOOTPRINT } );
570
571 FOOTPRINT* fp = adapter.LoadFootprint( nickname, wxS( "R_0402_1005Metric" ), false );
572 BOOST_CHECK_MESSAGE( !fp, "a library removed from the table must not keep serving preloaded "
573 "footprints" );
574}
575
576/*
577 * Copying a footprint renewed the uuid of every user field, so each save of a footprint with a field
578 * such as Lifecycle rewrote that line and two edits of it always collided in git.
579 */
580BOOST_AUTO_TEST_CASE( SaveKeepsUserFieldUuids )
581{
582 KI_TEST::SCOPED_TEMP_DIR tmpLib( "kicad_qa_user_field_uuid" );
583
584 wxFileName source( getResistorLibPath(), wxS( "R_0402_1005Metric.kicad_mod" ) );
585 source.RemoveLastDir();
586 source.AppendDir( wxS( "Lifecycle_SMD.pretty" ) );
587
588 const std::filesystem::path libPath = tmpLib.CreateChildDir( "Lifecycle_SMD.pretty" );
589 std::filesystem::copy_file( source.GetFullPath().ToStdString(), libPath / "R_0402_1005Metric.kicad_mod" );
590
592 const wxString lib = wxString::FromUTF8( libPath.string() );
593
594 std::unique_ptr<FOOTPRINT> footprint( plugin->FootprintLoad( lib, wxS( "R_0402_1005Metric" ), true ) );
595 BOOST_REQUIRE( footprint );
596
597 const PCB_FIELD* lifecycle = footprint->GetField( wxS( "Lifecycle" ) );
598 BOOST_REQUIRE( lifecycle );
599
600 const KIID uuid = lifecycle->m_Uuid;
601 plugin->FootprintSave( lib, footprint.get() );
602
604 std::unique_ptr<FOOTPRINT> saved( reader->FootprintLoad( lib, wxS( "R_0402_1005Metric" ), true ) );
605 BOOST_REQUIRE( saved && saved->GetField( wxS( "Lifecycle" ) ) );
606 BOOST_CHECK_EQUAL( saved->GetField( wxS( "Lifecycle" ) )->m_Uuid.AsString(), uuid.AsString() );
607}
608
609
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
const KIID m_Uuid
Definition eda_item.h:599
An interface to the global shared library manager that is schematic-specific and linked to one projec...
FOOTPRINT_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:418
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264
wxString PathStr() const
Get the path to the temporary directory as a wxString.
Definition file_utils.h:64
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
Definition file_utils.h:61
std::filesystem::path CreateChildDir(const wxString &aName) const
Create and return the path to a direct child directory.
std::optional< LIBRARY_MANAGER_ADAPTER * > Adapter(LIBRARY_TABLE_TYPE aType) const
void RegisterAdapter(LIBRARY_TABLE_TYPE aType, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > &&aAdapter)
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Handle the data for a net.
Definition netinfo.h:50
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition netinfo.h:289
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a PCB_IO which the caller can use to import, export, save, or load design documents.
static std::string ToStdString(const wxString &aStr)
std::string source
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
@ F_Cu
Definition layer_ids.h:60
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
LIB_STATUS status
std::unique_ptr< IO_BASE > plugin
Never destroyed while holding the map's mutex; a plugin's worker thread may be blocked on it.
const LIBRARY_TABLE_ROW * row
LOAD_STATUS load_status
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
const std::string table
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_CASE(IsFootprintLibWritableHandlesFailedLoad)
Regression test for a null-plugin dereference crash.
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708