KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_graphics_import_mgr.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, 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, see <https://www.gnu.org/licenses/>.
18
*/
19
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
22
#include <
import_gfx/graphics_import_mgr.h
>
23
#include <
import_gfx/graphics_import_plugin.h
>
24
25
#include <regex>
26
30
BOOST_AUTO_TEST_SUITE
( GraphicsImportMgr )
31
32
static
bool
pluginHandlesExt
( const
GRAPHICS_IMPORT_PLUGIN
& aPlugin, const
std
::
string
& aExt )
33
{
34
const
auto
exts = aPlugin.GetFileExtensions();
35
36
for
(
const
auto
& ext : exts )
37
{
38
std::regex ext_reg( ext );
39
40
if
( std::regex_match( aExt, ext_reg ) )
41
return
true
;
42
}
43
44
return
false
;
45
}
46
47
struct
TYPE_TO_EXTS
48
{
49
// The type of the plugin
50
GRAPHICS_IMPORT_MGR::GFX_FILE_T
m_type
;
51
53
std::vector<std::string>
m_exts
;
54
56
std::string
m_name
;
57
};
58
59
const
static
std::vector<TYPE_TO_EXTS>
type_to_ext_cases
= {
60
{
61
GRAPHICS_IMPORT_MGR::GFX_FILE_T::DXF
,
62
{
"dxf"
},
63
"AutoCAD DXF"
,
64
},
65
{
66
GRAPHICS_IMPORT_MGR::GFX_FILE_T::SVG
,
67
{
"svg"
},
68
"Scalable Vector Graphics"
,
69
},
70
};
71
75
BOOST_AUTO_TEST_CASE
( SelectByType )
76
{
77
GRAPHICS_IMPORT_MGR
mgr( {} );
78
79
for
(
const
auto
& c :
type_to_ext_cases
)
80
{
81
auto
plugin = mgr.GetPlugin( c.m_type );
82
83
BOOST_CHECK( !!plugin );
84
85
if
( plugin )
86
{
87
for
(
const
auto
& ext : c.m_exts )
88
{
89
BOOST_CHECK_MESSAGE
(
pluginHandlesExt
( *plugin, ext ),
90
"Plugin '"
<< plugin->GetName() <<
"' handles extension: "
<< ext );
91
}
92
}
93
}
94
}
95
99
BOOST_AUTO_TEST_CASE
( SelectByExt )
100
{
101
GRAPHICS_IMPORT_MGR
mgr( {} );
102
103
for
(
const
auto
& c :
type_to_ext_cases
)
104
{
105
for
(
const
auto
& ext : c.m_exts )
106
{
107
auto
plugin = mgr.GetPluginByExt( wxString( ext ) );
108
109
BOOST_CHECK( !!plugin );
110
111
if
( plugin )
112
{
113
// This is an ugly way to check the right plugin,
114
// as we have to keep a list of expected strings (the plugins
115
// don't report any kind of other unique identifier).
116
// But it's quick and dirty and it's good enough!
117
BOOST_CHECK_EQUAL
( c.m_name, plugin->GetName() );
118
}
119
}
120
}
121
}
122
123
BOOST_AUTO_TEST_SUITE_END
()
GRAPHICS_IMPORT_MGR
Manage vector graphics importers.
Definition
graphics_import_mgr.h:36
GRAPHICS_IMPORT_MGR::GFX_FILE_T
GFX_FILE_T
List of handled file types.
Definition
graphics_import_mgr.h:40
GRAPHICS_IMPORT_MGR::SVG
@ SVG
Definition
graphics_import_mgr.h:42
GRAPHICS_IMPORT_MGR::DXF
@ DXF
Definition
graphics_import_mgr.h:41
GRAPHICS_IMPORT_PLUGIN
Interface for vector graphics import plugins.
Definition
graphics_import_plugin.h:36
graphics_import_mgr.h
graphics_import_plugin.h
std
STL namespace.
TYPE_TO_EXTS
Definition
test_graphics_import_mgr.cpp:48
TYPE_TO_EXTS::m_exts
std::vector< std::string > m_exts
The list of extensions we expect this plugin to handle.
Definition
test_graphics_import_mgr.cpp:53
TYPE_TO_EXTS::m_type
GRAPHICS_IMPORT_MGR::GFX_FILE_T m_type
Definition
test_graphics_import_mgr.cpp:50
TYPE_TO_EXTS::m_name
std::string m_name
The name of the plugin.
Definition
test_graphics_import_mgr.cpp:56
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(SelectByType)
Check we can look a plugin up by type and get the right one.
Definition
test_graphics_import_mgr.cpp:75
pluginHandlesExt
static bool pluginHandlesExt(const GRAPHICS_IMPORT_PLUGIN &aPlugin, const std::string &aExt)
Declares a struct as the Boost test fixture.
Definition
test_graphics_import_mgr.cpp:32
type_to_ext_cases
static const std::vector< TYPE_TO_EXTS > type_to_ext_cases
Definition
test_graphics_import_mgr.cpp:59
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
pcbnew
test_graphics_import_mgr.cpp
Generated on Fri Jun 26 2026 00:05:45 for KiCad PCB EDA Suite by
1.13.2