43 void SeedLoadedLibrary(
const wxString& aNickname,
const wxString& aUri )
45 LIBRARY_TABLE_ROW* row = m_rows.emplace_back( std::make_unique<LIBRARY_TABLE_ROW>() ).get();
50 LIB_DATA& data = m_libraries[aNickname];
52 data.
plugin = std::make_unique<DESIGN_BLOCK_IO>();
57 std::vector<std::unique_ptr<LIBRARY_TABLE_ROW>> m_rows;
61std::filesystem::path makeBlockLibrary(
const std::string& aDirName,
const std::string& aBlockName,
62 const std::string& aJson )
65 std::filesystem::path lib = std::filesystem::temp_directory_path( ec ) / aDirName;
67 std::filesystem::remove_all( lib, ec );
69 std::filesystem::path block = lib / ( aBlockName +
".kicad_block" );
70 std::filesystem::create_directories( block, ec );
72 std::ofstream
json( block / ( aBlockName +
".json" ) );
81 explicit SCOPED_LIBRARY(
const std::filesystem::path& aPath ) :
89 std::filesystem::remove_all( path, ec );
92 std::filesystem::path path;
103 SCOPED_LIBRARY lib( makeBlockLibrary(
"kicad_qa_db_absent_item",
"Amp",
"{}" ) );
110 std::unique_ptr<DESIGN_BLOCK> loaded( io.
DesignBlockLoad( lib.path.string(), wxS(
"Missing" ) ) );
111 BOOST_FAIL(
"loading a design block that does not exist must throw" );
118 BOOST_CHECK_MESSAGE( what.Contains( wxS(
"Missing" ) ) && !what.Contains( wxS(
".kicad_block" ) ),
119 "the message must name the design block, not the assembled path, got: " + what );
131 SCOPED_LIBRARY lib( makeBlockLibrary(
"kicad_qa_db_bad_metadata",
"Amp",
"{ \"description\":" ) );
134 TEST_DESIGN_BLOCK_LIBRARY_ADAPTER adapter( manager );
136 adapter.SeedLoadedLibrary( wxS(
"blocks" ), lib.path.string() );
139 std::unique_ptr<DESIGN_BLOCK> block( adapter.LoadDesignBlock( wxS(
"blocks" ), wxS(
"Amp" ),
false, &error ) );
141 BOOST_REQUIRE_MESSAGE( !block,
"a design block with unreadable metadata must not load" );
142 BOOST_CHECK_MESSAGE( error.Contains( wxS(
"Amp.json" ) ),
"the reason must name the metadata file, got: " + error );
149 TEST_DESIGN_BLOCK_LIBRARY_ADAPTER adapter( manager );
152 std::unique_ptr<DESIGN_BLOCK> block( adapter.LoadDesignBlock( wxS(
"nope" ), wxS(
"Amp" ),
false, &error ) );
155 BOOST_CHECK_MESSAGE( error.Contains( wxS(
"nope" ) ),
"the reason must name the missing library, got: " + error );
DESIGN_BLOCK * DesignBlockLoad(const wxString &aLibraryPath, const wxString &aDesignBlockName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr)
DESIGN_BLOCK_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
std::unique_ptr< IO_BASE > plugin
const LIBRARY_TABLE_ROW * row
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(LoadNamesTheBlockNotThePath)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()