KiCad PCB EDA Suite
test_graphics_import_mgr.cpp File Reference

Go to the source code of this file.

Classes

struct  TYPE_TO_EXTS
 

Functions

static bool pluginHandlesExt (const GRAPHICS_IMPORT_PLUGIN &aPlugin, const std::string &aExt)
 Declares a struct as the Boost test fixture. More...
 
 BOOST_AUTO_TEST_CASE (SelectByType)
 Check we can look a plugin up by type and get the right one. More...
 
 BOOST_AUTO_TEST_CASE (SelectByExt)
 Check we can look a plugin up by ext and get the right one. More...
 

Variables

static const std::vector< TYPE_TO_EXTStype_to_ext_cases
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( SelectByExt  )

Check we can look a plugin up by ext and get the right one.

Definition at line 103 of file test_graphics_import_mgr.cpp.

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}
Manage vector graphics importers.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > GetPluginByExt(const wxString &aExtension) const
Returns a plugin instance for a specific file type.
BOOST_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
static const std::vector< TYPE_TO_EXTS > type_to_ext_cases

References BOOST_CHECK(), GRAPHICS_IMPORT_MGR::GetPluginByExt(), and type_to_ext_cases.

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( SelectByType  )

Check we can look a plugin up by type and get the right one.

Definition at line 79 of file test_graphics_import_mgr.cpp.

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}
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > GetPlugin(GFX_FILE_T aType) const
static bool pluginHandlesExt(const GRAPHICS_IMPORT_PLUGIN &aPlugin, const std::string &aExt)
Declares a struct as the Boost test fixture.

References BOOST_CHECK(), GRAPHICS_IMPORT_MGR::GetPlugin(), pluginHandlesExt(), and type_to_ext_cases.

◆ pluginHandlesExt()

static bool pluginHandlesExt ( const GRAPHICS_IMPORT_PLUGIN aPlugin,
const std::string &  aExt 
)
static

Declares a struct as the Boost test fixture.

Definition at line 36 of file test_graphics_import_mgr.cpp.

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}
virtual const std::vector< std::string > GetFileExtensions() const =0
Return a vector of the file extensions handled by this plugin.

Referenced by BOOST_AUTO_TEST_CASE().

Variable Documentation

◆ type_to_ext_cases

const std::vector<TYPE_TO_EXTS> type_to_ext_cases
static
Initial value:
= {
{
GRAPHICS_IMPORT_MGR::GFX_FILE_T::DXF,
{ "dxf" },
"AutoCAD DXF",
},
{
GRAPHICS_IMPORT_MGR::GFX_FILE_T::SVG,
{ "svg" },
"Scalable Vector Graphics",
},
}

Definition at line 63 of file test_graphics_import_mgr.cpp.

Referenced by BOOST_AUTO_TEST_CASE().