KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_test_utils.h
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 (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
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
25#ifndef QA_PCBNEW_BOARD_TEST_UTILS__H
26#define QA_PCBNEW_BOARD_TEST_UTILS__H
27
28#include <memory>
29#include <string>
30#include <wx/string.h>
31#include <mutex>
32#include <map>
33#include <reporter.h>
34#include <tool/tool_manager.h>
35
36class BOARD;
37class BOARD_ITEM;
38class FOOTPRINT;
39class PCB_TEXT;
40class PCB_SHAPE;
41class ZONE;
42class PAD;
43class SHAPE_POLY_SET;
45
46
47namespace KI_TEST
48{
49class DUMMY_TOOL : public TOOL_BASE
50{
51public:
53 TOOL_BASE( BATCH, TOOL_MANAGER::MakeToolId( "" ), "testframework.dummytool" )
54 {};
55
56 void Reset( RESET_REASON aReason ) override {}
57};
58
59
72{
73public:
75
76 void DumpBoardToFile( BOARD& aBoard, const std::string& aName ) const;
77
78 const bool m_dump_boards;
79};
80
81
83{
84public:
85 enum COLOR
86 {
87 RED = 0,
90 };
91
93
94 void PrintProgress( const wxString& aMessage )
95 {
98
99 printf( "%s", (const char*) aMessage.c_str() );
100 fflush( stdout );
101
103 }
104
105
106 void Print( const wxString& aMessage )
107 {
110
111 printf( "%s", (const char*) aMessage.c_str() );
112 fflush( stdout );
113
115 }
116
117
119 {
120 std::map<COLOR, wxString> colorMap = { { RED, "\033[0;31m" },
121 { GREEN, "\033[0;32m" },
122 { DEFAULT, "\033[0;37m" } };
123
124 printf( "%s", (const char*) colorMap[color].c_str() );
125 fflush( stdout );
126 }
127
128
129private:
131 {
132 printf( "\r\033[K" );
133 fflush( stdout );
134 }
135
137 std::mutex m_lock;
138};
139
140
142{
143public:
146
147
148 virtual REPORTER& Report( const wxString& aText,
149 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
150 {
151 switch( aSeverity )
152 {
155 m_log->Print( "ERROR | " );
156 break;
157
158 default: m_log->SetColor( CONSOLE_LOG::DEFAULT ); m_log->Print( " | " );
159 }
160
162 m_log->Print( aText + "\n" );
163 return *this;
164 }
165
166 virtual bool HasMessage() const override { return true; }
167
168private:
170};
171
172
173void LoadBoard( SETTINGS_MANAGER& aSettingsManager, const wxString& aRelPath,
174 std::unique_ptr<BOARD>& aBoard );
175
176void FillZones( BOARD* m_board );
177
178
182void CheckFootprint( const FOOTPRINT* expected, const FOOTPRINT* fp );
183
184void CheckFpPad( const PAD* expected, const PAD* pad );
185
186void CheckFpText( const PCB_TEXT* expected, const PCB_TEXT* text );
187
188void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape );
189
190void CheckFpZone( const ZONE* expected, const ZONE* zone );
191
192void CheckShapePolySet( const SHAPE_POLY_SET* expected, const SHAPE_POLY_SET* polyset );
193
194} // namespace KI_TEST
195
196#endif // QA_PCBNEW_BOARD_TEST_UTILS__H
int color
Definition: DXF_plotter.cpp:58
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
A helper that contains logic to assist in dumping boards to disk depending on some environment variab...
void DumpBoardToFile(BOARD &aBoard, const std::string &aName) const
void PrintProgress(const wxString &aMessage)
void SetColor(COLOR color)
void Print(const wxString &aMessage)
virtual bool HasMessage() const override
Returns true if the reporter client is non-empty.
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition: pad.h:58
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
Represent a set of closed polygons.
Base abstract interface for all kinds of tools.
Definition: tool_base.h:66
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Master controller class:
Definition: tool_manager.h:57
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void CheckFootprint(const FOOTPRINT *expected, const FOOTPRINT *fp)
Helper method to check if two footprints are semantically the same.
void FillZones(BOARD *m_board)
void CheckFpShape(const PCB_SHAPE *expected, const PCB_SHAPE *shape)
void CheckFpPad(const PAD *expected, const PAD *pad)
void CheckFpZone(const ZONE *expected, const ZONE *zone)
void CheckFpText(const PCB_TEXT *expected, const PCB_TEXT *text)
void CheckShapePolySet(const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
SEVERITY
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
VECTOR3I expected(15, 30, 45)
@ BATCH
Definition: tool_base.h:52