KiCad PCB EDA Suite
Loading...
Searching...
No Matches
qa_pns_regressions_main.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.
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 2
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/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 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
24#define BOOST_TEST_NO_MAIN
25
26#include <wx/cmdline.h>
27#include <wx/stdstream.h>
28#include <wx/wfstream.h>
29#include <wx/textfile.h>
30
34
35#include "pns_log_file.h"
37
38#include <boost/test/included/unit_test.hpp>
39
40using namespace boost::unit_test;
41
42#if 0
43
44bool runSingleTest( REPORTER* aReporter, wxString name, wxString testDirPath )
45{
46 PNS_LOG_FILE logFile;
47 PNS_LOG_PLAYER player;
48
49
50 wxString fn( testDirPath );
51 fn = fn.Append( "/" );
52 fn = fn.Append( name );
53 fn = fn.Append( "/pns" );
54
55
56 wxFileName fname( fn );
57
58 aReporter->Report( wxString::Format( "Running test '%s' from '%s'", name, fname.GetFullPath() ),
60
61 //fname.A
62
63 if( !logFile.Load( fname, aReporter ) )
64 {
65 aReporter->Report(
66 wxString::Format( "Failed to load test '%s' from '%s'", name, fname.GetFullPath() ),
68 }
69
70 player.SetReporter( aReporter );
71 player.ReplayLog( &logFile, 0 );
72 bool pass = player.CompareResults( &logFile );
73 return pass;
74}
75
76
77int main( int argc, char* argv[] )
78{
79
80
81 int passed = 0, failed = 0;
82
83 for( auto casename : testCases )
84 {
85 if( runSingleTest( &reporter, casename, cl_parser.GetParam( 0 ) ) )
86 passed++;
87 else
88 failed++;
89 }
90
91 reporter.Report(
92 wxString::Format( "SUMMARY: %d/%d tests cases PASSED", passed,
93 (int) testCases.size() ),
95
96
97 return failed ? -1 : 0;
98}
99#endif
100
102{
103 PNS_TEST_CASE( std::string name, std::string path ) : m_name( name ), m_dataPath( path ){};
104
105 std::string GetDataPath() const { return m_dataPath; }
106 std::string GetName() const { return m_name; }
107 std::string m_dataPath;
108 std::string m_name;
109};
110
111
130
131
133{
134public:
135 static void RunTest( PNS_TEST_CASE* aTestData )
136 {
137 // printf( "Run %s\n", aTestData->GetName().c_str() );
138
139 PNS_LOG_FILE logFile;
140 PNS_LOG_PLAYER player;
141
142 if( !logFile.Load( wxString( aTestData->GetDataPath() ), m_logger.m_Reporter ) )
143 {
144 m_logger.m_Reporter->Report( wxString::Format( "Failed to load test '%s' from '%s'",
145 aTestData->GetName(), aTestData->GetDataPath() ),
147 }
148
149 player.SetReporter( m_logger.m_Reporter );
150 player.ReplayLog( &logFile, 0 );
151 bool pass = player.CompareResults( &logFile );
152
153 if( !pass )
154 BOOST_TEST_FAIL( "replay results inconsistent with reference reslts" );
155 }
156
158};
159
160
162
163
164std::vector<PNS_TEST_CASE*> createTestCases()
165{
166 std::string absPath = KI_TEST::GetPcbnewTestDataDir() + std::string( "/pns_regressions/" );
167 std::vector<PNS_TEST_CASE*> testCases;
168
169 wxFileName fnameList( absPath + "tests.lst" );
170 wxTextFile fp( fnameList.GetFullPath() );
171
172 if( !fp.Open() )
173 {
174 wxString str =
175 wxString::Format( "Failed to load test list from '%s'.", fnameList.GetFullPath() );
176 BOOST_TEST_ERROR( str.c_str().AsChar() );
177 return testCases;
178 }
179
180 std::vector<wxString> lines;
181
182 if( !fp.Eof() )
183 {
184 lines.push_back( fp.GetFirstLine() );
185
186 while( !fp.Eof() )
187 {
188 auto l = fp.GetNextLine();
189 if( l.Length() > 0 )
190 {
191 lines.push_back( l );
192 }
193 }
194 }
195
196 fp.Close();
197
198 for( auto l : lines )
199 {
200 wxString fn( absPath );
201 fn = fn.Append( wxT( "/" ) );
202 fn = fn.Append( l );
203 fn = fn.Append( wxT( "/pns" ) );
204
205 testCases.push_back( new PNS_TEST_CASE( l.ToStdString(), fn.ToStdString() ) );
206 }
207
208 wxString str = wxString::Format( "Loaded %d test cases from '%s'.", (int) testCases.size(),
209 fnameList.GetFullPath() );
210
211 BOOST_TEST_MESSAGE( str.c_str().AsChar() );
212
213 return testCases;
214}
215
216static test_suite* init_pns_test_suite( int argc, char* argv[] )
217{
218 test_suite* pnsTestSuite = BOOST_TEST_SUITE( "pns_regressions" );
219
220 auto testCases = createTestCases();
221
222 for( auto& c : testCases )
223 {
224 pnsTestSuite->add(
225 BOOST_TEST_CASE_NAME( std::bind( &PNS_TEST_FIXTURE::RunTest, c ), c->GetName() ) );
226 }
227
228 framework::master_test_suite().add( pnsTestSuite );
229 return 0;
230}
231
232int main( int argc, char* argv[] )
233{
234 return unit_test_main( init_pns_test_suite, argc, argv );
235}
const char * name
General utilities for PCB file IO for QA programs.
KI_TEST::CONSOLE_LOG * m_Log
KI_TEST::CONSOLE_MSG_REPORTER * m_Reporter
bool Load(const wxFileName &logFileName, REPORTER *aRpt)
bool CompareResults(PNS_LOG_FILE *aLog)
void ReplayLog(PNS_LOG_FILE *aLog, int aStartEventIndex=0, int aFrom=0, int aTo=-1, bool aUpdateExpectedResult=false)
void SetReporter(REPORTER *aReporter)
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
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()
static test_suite * init_pns_test_suite(int argc, char *argv[])
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
std::string GetName() const
std::string GetDataPath() const
PNS_TEST_CASE(std::string name, std::string path)
static void RunTest(PNS_TEST_CASE *aTestData)
static FIXTURE_LOGGER m_logger
std::string path
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")