KiCad PCB EDA Suite
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 (C) 2018 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
25
28
29#include <regex>
30
34BOOST_AUTO_TEST_SUITE( GraphicsImportMgr )
35
36static 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
52{
53 // The type of the plugin
55
57 std::vector<std::string> m_exts;
58
60 std::string m_name;
61};
62
63const 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
79BOOST_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
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
127BOOST_AUTO_TEST_SUITE_END()
Manage vector graphics importers.
GFX_FILE_T
< List of handled file types.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > GetPluginByExt(const wxString &aExtension) const
Returns a plugin instance for a specific file type.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > GetPlugin(GFX_FILE_T aType) const
Interface for vector graphics import plugins.
Definition: bitmap.cpp:64
std::vector< std::string > m_exts
The list of extensions we expect this plugin to handle.
GRAPHICS_IMPORT_MGR::GFX_FILE_T m_type
std::string m_name
The name of the plugin.
BOOST_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
BOOST_AUTO_TEST_CASE(SelectByType)
Check we can look a plugin up by type and get the right one.
static bool pluginHandlesExt(const GRAPHICS_IMPORT_PLUGIN &aPlugin, const std::string &aExt)
Declares a struct as the Boost test fixture.
static const std::vector< TYPE_TO_EXTS > type_to_ext_cases