20#define BOOST_TEST_NO_MAIN
23#include <wx/cmdline.h>
24#include <wx/stdstream.h>
25#include <wx/wfstream.h>
26#include <wx/textfile.h>
39#include <boost/test/unit_test.hpp>
41using namespace boost::unit_test;
63 m_Log->SetConsoleOutputEnabled( wxGetEnv( wxS(
"KICAD_PNS_VERBOSE" ),
nullptr ) );
90 wxString boardFilename;
92 if( hash.has_value() )
96 boardFilename = it->second;
114 player.
ReplayLog( &logFile, 0, 0, -1,
true );
119 BOOST_TEST_ERROR(
"Failed to save golden file: " << aTestData->
GetDataPath() );
129 bool hasHeads =
expected.m_heads.size() > 0;
137 <<
expected.m_removedIds.size() <<
" removed items and "
138 <<
expected.m_heads.size() <<
" head items." );
140 BOOST_TEST_MESSAGE(
"Test result has " << cstate.m_addedItems.size() <<
" added items, "
141 << cstate.m_removedIds.size() <<
" removed items and "
142 << cstate.m_heads.size() <<
" head items." );
145 bool pass = cstate.Compare(
expected, !hasHeads );
159std::vector<wxString>
scanSubdirs(
const wxString& absPath,
bool aFiles, wxString filespec = wxEmptyString )
161 std::vector<wxString> rv;
163 wxDir dir( absPath );
164 if( !dir.IsOpened() )
166 BOOST_TEST_ERROR(
"Failed to open directory: " << absPath );
172 bool hasFiles = dir.GetFirst( &dirName, filespec, aFiles ? wxDIR_FILES : wxDIR_DIRS );
175 rv.push_back( dirName );
176 hasFiles = dir.GetNext( &dirName );
184 for(
const wxString& brdFile :
scanSubdirs( aPath,
true, wxT(
"*.kicad_pcb") ) )
186 wxFileName
path ( aPath );
187 path.SetName( brdFile );
191 BOOST_TEST_MESSAGE(
"- file: " << std::left << std::setw(50) << brdFile <<
" hash: " << ( *hash ) );
199 std::vector<PNS_TEST_CASE*> testCases;
202 absPath.AppendDir (wxT(
"pns_regressions"));
204 wxFileName boardsPath( absPath );
205 boardsPath.AppendDir(wxT(
"boards"));
209 for(
const wxString& subdir :
scanSubdirs( absPath.GetFullPath(),
false ) )
211 if( !subdir.CmpNoCase( wxT(
"boards") ) )
214 wxFileName
path( absPath );
215 path.AppendDir( subdir );
217 for(
const wxString& logName:
scanSubdirs(
path.GetFullPath(),
true, wxT(
"*.log") ) )
219 wxFileName logPath(
path );
220 logPath.SetName( logName );
224 testCases.push_back(
new PNS_TEST_CASE( subdir, logPath.GetFullPath() ) );
234 test_suite* pnsTestSuite = BOOST_TEST_SUITE(
"pns_regressions" );
238 for(
auto& c : testCases )
244 framework::master_test_suite().p_name.value =
"P&S router regressions";
245 framework::master_test_suite().add( pnsTestSuite );
250int main(
int argc,
char* argv[] )
252 wxApp::SetInstance(
new wxAppConsole );
253 wxInitialize( argc, argv );
255 for(
int i = 1; i < argc; i++ )
257 if( wxString( argv[i] ).Cmp( wxT(
"--update-golden" ) ) == 0 )
General utilities for PCB file IO for QA programs.
KI_TEST::CONSOLE_LOG * m_Log
KI_TEST::CONSOLE_MSG_REPORTER * m_Reporter
const std::optional< wxString > GetLogBoardHash(const wxString &logFileName)
const COMMIT_STATE & GetExpectedResult() const
bool SaveLog(const wxFileName &logFileName, REPORTER *aRpt)
bool Load(const wxFileName &logFileName, REPORTER *aRpt, const wxString boardFileName=wxT(""))
const PNS_LOG_FILE::COMMIT_STATE GetRouterUpdatedItems()
void ReplayLog(PNS_LOG_FILE *aLog, int aStartEventIndex=0, int aFrom=0, int aTo=-1, bool aUpdateExpectedResult=false)
void SetReporter(REPORTER *aReporter)
std::optional< wxString > fileHashMMH3(const wxString &aFilePath)
Calculates an MMH3 hash of a given file.
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::vector< PNS_TEST_CASE * > createTestCases()
void scanAndHashBoards(const wxString &aPath)
std::map< wxString, wxString > g_testBoards
static bool g_updateGolden
bool init_pns_test_suite()
std::vector< wxString > scanSubdirs(const wxString &absPath, bool aFiles, wxString filespec=wxEmptyString)
PNS_TEST_CASE(const wxString &aName, const wxString &aPath)
wxString GetDataPath() const
static bool RunTest(PNS_TEST_CASE *aTestData)
static FIXTURE_LOGGER m_logger
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")