KiCad PCB EDA Suite
test_wildcards_and_files_ext.cpp File Reference

Go to the source code of this file.

Classes

struct  ExtWildcardFilterCase
 Data used to construct a simple test of one or more extensions and get a filter string for WX dialogs out. More...
 
struct  testExtensions
 

Functions

static constexpr bool should_use_regex_filters ()
 
 BOOST_AUTO_TEST_CASE (FileNameComparison)
 Check correct comparison of file names. More...
 
 BOOST_AUTO_TEST_CASE (BasicFilter)
 Check correct handling of filter strings (as used by WX) More...
 
static constexpr bool should_use_windows_filters ()
 
 BOOST_AUTO_TEST_CASE (AllFilesFilter)
 

Variables

static const std::vector< ExtWildcardFilterCaseext_wildcard_cases
 
static const std::vector< std::string > extensionList = { "dxf", "svg", "SCH", "^g.*" }
 
static const std::vector< testExtensionstestExtensionList
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( FileNameComparison  )

Check correct comparison of file names.

Definition at line 108 of file test_wildcards_and_files_ext.cpp.

109 {
110  for( const auto& testExt : testExtensionList )
111  {
112  bool extPresent_insense = compareFileExtensions( testExt.ext, extensionList, false );
113  bool extPresent_sense = compareFileExtensions( testExt.ext, extensionList, true );
114 
115  BOOST_TEST_INFO( "Case insensitive test for extension " + testExt.ext );
116  BOOST_CHECK_EQUAL( extPresent_insense, testExt.insense_result );
117 
118  BOOST_TEST_INFO( "Case sensitive test for extension " + testExt.ext );
119  BOOST_CHECK_EQUAL( extPresent_sense, testExt.sense_result );
120  }
121 }
static const std::vector< std::string > extensionList
static const std::vector< testExtensions > testExtensionList
bool compareFileExtensions(const std::string &aExtension, const std::vector< std::string > &aReference, bool aCaseSensitive)
Compare the given extension against the reference extensions to see if it matches any of the referenc...
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO, compareFileExtensions(), extensionList, and testExtensionList.

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( BasicFilter  )

Check correct handling of filter strings (as used by WX)

Definition at line 127 of file test_wildcards_and_files_ext.cpp.

128 {
129  for( const auto& c : ext_wildcard_cases )
130  {
131  const std::string exp_filter =
132  should_use_regex_filters() ? c.m_re_filter : c.m_filter_case_insenstive;
133 
134  const auto resp = AddFileExtListToFilter( c.m_exts );
135 
136  BOOST_CHECK_EQUAL( resp, exp_filter );
137  }
138 }
static constexpr bool should_use_regex_filters()
static const std::vector< ExtWildcardFilterCase > ext_wildcard_cases
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.

References AddFileExtListToFilter(), ext_wildcard_cases, and should_use_regex_filters().

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( AllFilesFilter  )

Definition at line 149 of file test_wildcards_and_files_ext.cpp.

150 {
151  const auto resp = AddFileExtListToFilter( {} );
152 
153  const std::string exp_filter = should_use_windows_filters() ? " (*.*)|*.*" : " (*)|*";
154 
155  BOOST_CHECK_EQUAL( resp, exp_filter );
156 }
static constexpr bool should_use_windows_filters()
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.

References AddFileExtListToFilter(), and should_use_windows_filters().

◆ should_use_regex_filters()

static constexpr bool should_use_regex_filters ( )
static

Definition at line 63 of file test_wildcards_and_files_ext.cpp.

64 {
65 #ifdef __WXGTK__
66  return true;
67 #else
68  return false;
69 #endif
70 }

Referenced by BOOST_AUTO_TEST_CASE().

◆ should_use_windows_filters()

static constexpr bool should_use_windows_filters ( )
static

Definition at line 140 of file test_wildcards_and_files_ext.cpp.

141 {
142 #ifdef __WXMSW__
143  return true;
144 #else
145  return false;
146 #endif
147 }

Referenced by BOOST_AUTO_TEST_CASE().

Variable Documentation

◆ ext_wildcard_cases

const std::vector<ExtWildcardFilterCase> ext_wildcard_cases
static
Initial value:
= {
{
{ "png" },
" ( *.png)|*.png",
" ( *.png)|*.[pP][nN][gG]",
},
{
{ "png", "gif" },
" ( *.png *.gif)|*.png;*.gif",
" ( *.png *.gif)|*.[pP][nN][gG];*.[gG][iI][fF]",
},
}

Definition at line 49 of file test_wildcards_and_files_ext.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ extensionList

const std::vector<std::string> extensionList = { "dxf", "svg", "SCH", "^g.*" }
static

◆ testExtensionList

const std::vector<testExtensions> testExtensionList
static
Initial value:
= {
{
"dxf",
true,
true
},
{
"sch",
true,
false
},
{
"gbr",
true,
true
},
{
"pcb",
false,
false
}
}

Definition at line 82 of file test_wildcards_and_files_ext.cpp.

Referenced by BOOST_AUTO_TEST_CASE().