20#include <boost/test/unit_test.hpp>
27#include <system_error>
40#include <wx/filename.h>
52 explicit TEMP_FILE(
const wxString& aPrefix ) :
53 m_path( std::string( wxFileName::CreateTempFileName( aPrefix ).ToUTF8() ) )
60 std::filesystem::remove( m_path, ec );
63 const std::filesystem::path& Path()
const {
return m_path; }
64 std::string Str()
const {
return m_path.string(); }
67 std::filesystem::path m_path;
71std::string slurp(
const std::filesystem::path& aPath )
73 std::ifstream in( aPath );
80std::unique_ptr<BOARD> loadTestBoard()
82 const std::filesystem::path boardPath =
94int countTraces(
BOARD* aBoard )
108void importSession(
BOARD* aBoard,
const wxString& aSesPath )
111 toolMgr.
SetEnvironment( aBoard,
nullptr,
nullptr,
nullptr,
nullptr );
116 commit.Push( wxT(
"Import Specctra Session" ),
SKIP_UNDO );
132 std::unique_ptr<BOARD> board = loadTestBoard();
135 board->Footprints().front()->SetValue( wxT(
"2x20 pin 0.1\" female header" ) );
137 TEMP_FILE out( wxT(
"kicad_specctra_24946_" ) );
140 const std::string dsn = slurp( out.Path() );
143 BOOST_CHECK( dsn.find(
"0.1\" female" ) == std::string::npos );
144 BOOST_CHECK( dsn.find(
"0.1'' female" ) != std::string::npos );
154 std::unique_ptr<BOARD> board = loadTestBoard();
156 BOOST_REQUIRE_GE( board->Footprints().size(), 5u );
158 board->Footprints()[0]->SetReference( wxEmptyString );
159 board->Footprints()[1]->SetReference( wxEmptyString );
160 board->Footprints()[2]->SetReference( wxT(
"U1" ) );
161 board->Footprints()[3]->SetReference( wxT(
"U1" ) );
162 board->Footprints()[4]->SetReference( wxT(
"u1" ) );
164 TEMP_FILE out( wxT(
"kicad_specctra_24947_" ) );
167 const std::string dsn = slurp( out.Path() );
170 BOOST_CHECK( dsn.find(
"(place REF**_1 " ) != std::string::npos );
171 BOOST_CHECK( dsn.find(
"(place U1 " ) != std::string::npos );
172 BOOST_CHECK( dsn.find(
"(place U1_1 " ) != std::string::npos );
173 BOOST_CHECK( dsn.find(
"(place u1_2 " ) != std::string::npos );
182 std::unique_ptr<BOARD> board = loadTestBoard();
184 TEMP_FILE ses( wxT(
"kicad_specctra_allegro_poly_" ) );
186 const std::string validLayer = std::string( board->GetLayerName(
F_Cu ).ToUTF8() );
188 std::ofstream out( ses.Path() );
189 out <<
"(session test.ses\n"
190 <<
" (base_design test.dsn)\n"
192 <<
" (resolution um 10)\n"
193 <<
" (library_out )\n"
195 <<
" (net \"/ALLPST\"\n"
196 <<
" (wire (path \"" << validLayer <<
"\" 1600 0 0 1000 0)\n"
197 <<
" (type route))\n"
198 <<
" (wire (poly \"" << validLayer <<
"\" 0 0 0 1000 0 1000 1000 0 1000 0 0)\n"
199 <<
" (type normal))\n"
206 BOOST_REQUIRE_NO_THROW( importSession( board.get(), ses.Str() ) );
218 std::unique_ptr<BOARD> board = loadTestBoard();
220 TEMP_FILE ses( wxT(
"kicad_specctra_24948_" ) );
224 const std::string validLayer = std::string( board->GetLayerName(
F_Cu ).ToUTF8() );
226 std::ofstream out( ses.Path() );
227 out <<
"(session test.ses\n"
228 <<
" (base_design test.dsn)\n"
230 <<
" (resolution um 10)\n"
231 <<
" (component test\n"
232 <<
" (place Nonexistent_Ref 0 0 front 0)\n"
236 <<
" (resolution um 10)\n"
237 <<
" (library_out )\n"
239 <<
" (net \"/ALLPST\"\n"
240 <<
" (wire (path \"" << validLayer <<
"\" 1600 0 0 1000 0))\n"
241 <<
" (wire (path Bogus_Missing_Layer 1600 0 0 1000 1000))\n"
248 BOOST_REQUIRE_NO_THROW( importSession( board.get(), ses.Str() ) );
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
const TRACKS & Tracks() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
This source file implements export and import capabilities to the specctra dsn file format.
void ExportBoardToSpecctraFile(BOARD *aBoard, const wxString &aFullFilename)
Helper method to export board to DSN file.
bool ImportSpecctraSession(BOARD *aBoard, const wxString &fullFileName, COMMIT &aCommit)
Helper method to import SES file to a board.
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_CASE(SpecctraExportQuoteInField)
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)