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
21
24
25#include <regex>
26
30BOOST_AUTO_TEST_SUITE( GraphicsImportMgr )
31
32static 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
48{
49 // The type of the plugin
51
53 std::vector<std::string> m_exts;
54
56 std::string m_name;
57};
58
59const static std::vector<TYPE_TO_EXTS> type_to_ext_cases = {
60 {
62 { "dxf" },
63 "AutoCAD DXF",
64 },
65 {
67 { "svg" },
68 "Scalable Vector Graphics",
69 },
70};
71
75BOOST_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 {
90 "Plugin '" << plugin->GetName() << "' handles extension: " << ext );
91 }
92 }
93 }
94}
95
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
Manage vector graphics importers.
GFX_FILE_T
List of handled file types.
Interface for vector graphics import plugins.
STL namespace.
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_AUTO_TEST_SUITE(CadstarPartParser)
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
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")