KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_wildcards_and_files_ext.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
27
28
29BOOST_AUTO_TEST_SUITE( WildcardFileExt )
30
31
32
37{
39 std::vector<std::string> m_exts;
40
43
46 std::string m_re_filter;
47};
48
49const static std::vector<ExtWildcardFilterCase> ext_wildcard_cases = {
50 {
51 { "png" },
52 " (*.png)|*.png",
53 " (*.png)|*.[pP][nN][gG]",
54 },
55 {
56 { "png", "gif" },
57 " (*.png; *.gif)|*.png;*.gif",
58 " (*.png; *.gif)|*.[pP][nN][gG];*.[gG][iI][fF]",
59 },
60};
61
62
63static constexpr bool should_use_regex_filters()
64{
65#ifdef __WXGTK__
66 return true;
67#else
68 return false;
69#endif
70}
71
72
73// Structure used to store the extensions to test and the expected comparison result
75{
76 std::string ext;
79};
80
81const static std::vector<std::string> extensionList = { "dxf", "svg", "SCH", "^g.*" };
82const static std::vector<testExtensions> testExtensionList = {
83 {
84 "dxf",
85 true, // Case insensitive comparison result
86 true // Case sensitive comparison result
87 },
88 {
89 "sch",
90 true, // Case insensitive comparison result
91 false // Case sensitive comparison result
92 },
93 {
94 "gbr",
95 true, // Case insensitive comparison result
96 true // Case sensitive comparison result
97 },
98 {
99 "pcb",
100 false, // Case insensitive comparison result
101 false // Case sensitive comparison result
102 }
103};
104
108BOOST_AUTO_TEST_CASE( FileNameComparison )
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}
122
123
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}
139
140static constexpr bool should_use_windows_filters()
141{
142#ifdef __WXMSW__
143 return true;
144#else
145 return false;
146#endif
147}
148
149BOOST_AUTO_TEST_CASE( AllFilesFilter )
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}
157
158BOOST_AUTO_TEST_SUITE_END()
Data used to construct a simple test of one or more extensions and get a filter string for WX dialogs...
std::vector< std::string > m_exts
The list of exts handled.
std::string m_re_filter
Filter for regex-capable environments (case insensitive filter in a case-sensitive environment)
std::string m_filter_case_insenstive
Filter for case-insensitive environments.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static constexpr bool should_use_regex_filters()
static const std::vector< testExtensions > testExtensionList
BOOST_AUTO_TEST_CASE(FileNameComparison)
Check correct comparison of file names.
static const std::vector< std::string > extensionList
static const std::vector< ExtWildcardFilterCase > ext_wildcard_cases
static constexpr bool should_use_windows_filters()
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
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...
Definition of file extensions used in Kicad.