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
GRAPHICS_IMPORT_MGR::GFX_FILE_T::BITMAP
,
72
{
"png"
,
"jpg"
,
"jpeg"
,
"bmp"
,
"gif"
},
73
"Bitmap image"
,
74
},
75
};
76
80
BOOST_AUTO_TEST_CASE
( SelectByType )
81
{
82
GRAPHICS_IMPORT_MGR
mgr( {} );
83
84
for
(
const
auto
& c :
type_to_ext_cases
)
85
{
86
auto
plugin = mgr.GetPlugin( c.m_type );
87
88
BOOST_CHECK( !!plugin );
89
90
if
( plugin )
91
{
92
for
(
const
auto
& ext : c.m_exts )
93
{
94
BOOST_CHECK_MESSAGE(
pluginHandlesExt
( *plugin, ext ),
95
"Plugin '"
<< plugin->GetName() <<
"' handles extension: "
<< ext );
96
}
97
}
98
}
99
}
100
104
BOOST_AUTO_TEST_CASE
( SelectByExt )
105
{
106
GRAPHICS_IMPORT_MGR
mgr( {} );
107
108
for
(
const
auto
& c :
type_to_ext_cases
)
109
{
110
for
(
const
auto
& ext : c.m_exts )
111
{
112
auto
plugin = mgr.GetPluginByExt( wxString( ext ) );
113
114
BOOST_CHECK( !!plugin );
115
116
if
( plugin )
117
{
118
// This is an ugly way to check the right plugin,
119
// as we have to keep a list of expected strings (the plugins
120
// don't report any kind of other unique identifier).
121
// But it's quick and dirty and it's good enough!
122
BOOST_CHECK_EQUAL
( c.m_name, plugin->GetName() );
123
}
124
}
125
}
126
}
127
128
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_MGR::BITMAP
@ BITMAP
Definition
graphics_import_mgr.h:43
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:80
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_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
pcbnew
test_graphics_import_mgr.cpp
Generated on Tue Oct 27 2026 00:06:46 for KiCad PCB EDA Suite by
1.13.2