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 <map>
29#include <memory>
30#include <mutex>
31#include <functional>
32#include <optional>
33#include <string>
34
35#include <wx/string.h>
36
37#include <reporter.h>
38#include <core/typeinfo.h>
39#include <tool/tool_manager.h>
40
41class BOARD;
42class BOARD_ITEM;
43class FOOTPRINT;
44class KIID;
45class PCB_TEXT;
46class PCB_SHAPE;
47class ZONE;
48class PAD;
49class SHAPE_POLY_SET;
51
52namespace KI_TEST
53{
54class DUMMY_TOOL : public TOOL_BASE
55{
56public:
58 TOOL_BASE( BATCH, TOOL_MANAGER::MakeToolId( "" ), "testframework.dummytool" )
59 {};
60
61 void Reset( RESET_REASON aReason ) override {}
62};
63
64
77{
78public:
80
81 void DumpBoardToFile( BOARD& aBoard, const std::string& aName ) const;
82
83 const bool m_dump_boards;
84};
85
86
88{
89public:
90 enum COLOR
91 {
92 RED = 0,
95 };
96
98
99 void PrintProgress( const wxString& aMessage )
100 {
103
104 printf( "%s", (const char*) aMessage.c_str() );
105 fflush( stdout );
106
108 }
109
110
111 void Print( const wxString& aMessage )
112 {
115
116 printf( "%s", (const char*) aMessage.c_str() );
117 fflush( stdout );
118
120 }
121
122
124 {
125 std::map<COLOR, wxString> colorMap = { { RED, "\033[0;31m" },
126 { GREEN, "\033[0;32m" },
127 { DEFAULT, "\033[0;37m" } };
128
129 printf( "%s", (const char*) colorMap[color].c_str() );
130 fflush( stdout );
131 }
132
133
134private:
136 {
137 printf( "\r\033[K" );
138 fflush( stdout );
139 }
140
142 std::mutex m_lock;
143};
144
145
147{
148public:
151
152
153 virtual REPORTER& Report( const wxString& aText,
154 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
155 {
156 switch( aSeverity )
157 {
160 m_log->Print( "ERROR | " );
161 break;
162
163 default: m_log->SetColor( CONSOLE_LOG::DEFAULT ); m_log->Print( " | " );
164 }
165
167 m_log->Print( aText + "\n" );
168 return *this;
169 }
170
171 virtual bool HasMessage() const override { return true; }
172
173private:
175};
176
177
178void LoadBoard( SETTINGS_MANAGER& aSettingsManager, const wxString& aRelPath,
179 std::unique_ptr<BOARD>& aBoard );
180
191BOARD_ITEM& RequireBoardItemWithTypeAndId( const BOARD& aBoard, KICAD_T aItemType,
192 const KIID& aID );
193
205void LoadAndTestBoardFile( const wxString aRelativePath, bool aRoundtrip,
206 std::function<void( BOARD& )> aBoardTestFunction,
207 std::optional<int> aExpectedBoardVersion = std::nullopt );
208
209void FillZones( BOARD* m_board );
210
211
215void CheckFootprint( const FOOTPRINT* expected, const FOOTPRINT* fp );
216
217void CheckFpPad( const PAD* expected, const PAD* pad );
218
219void CheckFpText( const PCB_TEXT* expected, const PCB_TEXT* text );
220
221void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape );
222
223void CheckFpZone( const ZONE* expected, const ZONE* zone );
224
225void CheckShapePolySet( const SHAPE_POLY_SET* expected, const SHAPE_POLY_SET* polyset );
226
227} // namespace KI_TEST
228
229#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:282
Definition: kiid.h:49
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:53
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:62
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 LoadAndTestBoardFile(const wxString aRelativePath, bool aRoundtrip, std::function< void(BOARD &)> aBoardTestFunction, std::optional< int > aExpectedBoardVersion)
Perform "some test" on a board file loaded from the path, then optionally save and reload and run the...
void CheckShapePolySet(const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
BOARD_ITEM & RequireBoardItemWithTypeAndId(const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
Get an item from the given board with a certain type and UUID.
SEVERITY
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
VECTOR3I expected(15, 30, 45)
@ BATCH
Definition: tool_base.h:52
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78