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, 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
#include <
qa_utils/wx_utils/unit_test_utils.h
>
25
26
#include <
import_gfx/graphics_import_mgr.h
>
27
#include <
import_gfx/graphics_import_plugin.h
>
28
29
#include <regex>
30
34
BOOST_AUTO_TEST_SUITE
( GraphicsImportMgr )
35
36
static
bool
pluginHandlesExt
( const
GRAPHICS_IMPORT_PLUGIN
& aPlugin, const
std
::
string
& aExt )
37
{
38
const
auto
exts = aPlugin.GetFileExtensions();
39
40
for
(
const
auto
& ext : exts )
41
{
42
std::regex ext_reg( ext );
43
44
if
( std::regex_match( aExt, ext_reg ) )
45
return
true
;
46
}
47
48
return
false
;
49
}
50
51
struct
TYPE_TO_EXTS
52
{
53
// The type of the plugin
54
GRAPHICS_IMPORT_MGR::GFX_FILE_T
m_type
;
55
57
std::vector<std::string>
m_exts
;
58
60
std::string
m_name
;
61
};
62
63
const
static
std::vector<TYPE_TO_EXTS>
type_to_ext_cases
= {
64
{
65
GRAPHICS_IMPORT_MGR::GFX_FILE_T::DXF
,
66
{
"dxf"
},
67
"AutoCAD DXF"
,
68
},
69
{
70
GRAPHICS_IMPORT_MGR::GFX_FILE_T::SVG
,
71
{
"svg"
},
72
"Scalable Vector Graphics"
,
73
},
74
};
75
79
BOOST_AUTO_TEST_CASE
( SelectByType )
80
{
81
GRAPHICS_IMPORT_MGR
mgr( {} );
82
83
for
(
const
auto
& c :
type_to_ext_cases
)
84
{
85
auto
plugin = mgr.GetPlugin( c.m_type );
86
87
BOOST_CHECK( !!plugin );
88
89
if
( plugin )
90
{
91
for
(
const
auto
& ext : c.m_exts )
92
{
93
BOOST_CHECK_MESSAGE(
pluginHandlesExt
( *plugin, ext ),
94
"Plugin '"
<< plugin->GetName() <<
"' handles extension: "
<< ext );
95
}
96
}
97
}
98
}
99
103
BOOST_AUTO_TEST_CASE
( SelectByExt )
104
{
105
GRAPHICS_IMPORT_MGR
mgr( {} );
106
107
for
(
const
auto
& c :
type_to_ext_cases
)
108
{
109
for
(
const
auto
& ext : c.m_exts )
110
{
111
auto
plugin = mgr.GetPluginByExt( wxString( ext ) );
112
113
BOOST_CHECK( !!plugin );
114
115
if
( plugin )
116
{
117
// This is an ugly way to check the right plugin,
118
// as we have to keep a list of expected strings (the plugins
119
// don't report any kind of other unique identifier).
120
// But it's quick and dirty and it's good enough!
121
BOOST_CHECK_EQUAL
( c.m_name, plugin->GetName() );
122
}
123
}
124
}
125
}
126
127
BOOST_AUTO_TEST_SUITE_END
()
GRAPHICS_IMPORT_MGR
Manage vector graphics importers.
Definition
graphics_import_mgr.h:40
GRAPHICS_IMPORT_MGR::GFX_FILE_T
GFX_FILE_T
List of handled file types.
Definition
graphics_import_mgr.h:44
GRAPHICS_IMPORT_MGR::SVG
@ SVG
Definition
graphics_import_mgr.h:46
GRAPHICS_IMPORT_MGR::DXF
@ DXF
Definition
graphics_import_mgr.h:45
GRAPHICS_IMPORT_PLUGIN
Interface for vector graphics import plugins.
Definition
graphics_import_plugin.h:40
graphics_import_mgr.h
graphics_import_plugin.h
std
STL namespace.
TYPE_TO_EXTS
Definition
test_graphics_import_mgr.cpp:52
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:57
TYPE_TO_EXTS::m_type
GRAPHICS_IMPORT_MGR::GFX_FILE_T m_type
Definition
test_graphics_import_mgr.cpp:54
TYPE_TO_EXTS::m_name
std::string m_name
The name of the plugin.
Definition
test_graphics_import_mgr.cpp:60
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:79
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:36
type_to_ext_cases
static const std::vector< TYPE_TO_EXTS > type_to_ext_cases
Definition
test_graphics_import_mgr.cpp:63
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
pcbnew
test_graphics_import_mgr.cpp
Generated on Sun Sep 21 2025 01:05:33 for KiCad PCB EDA Suite by
1.13.2