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 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
23
24
25BOOST_AUTO_TEST_SUITE( WildcardFileExt )
26
27
28
33{
35 std::vector<std::string> m_exts;
36
39
42 std::string m_re_filter;
43};
44
45const static std::vector<ExtWildcardFilterCase> ext_wildcard_cases = {
46 {
47 { "png" },
48 " (*.png)|*.png",
49 " (*.png)|*.[pP][nN][gG]",
50 },
51 {
52 { "png", "gif" },
53 " (*.png; *.gif)|*.png;*.gif",
54 " (*.png; *.gif)|*.[pP][nN][gG];*.[gG][iI][fF]",
55 },
56};
57
58
59static constexpr bool should_use_regex_filters()
60{
61#ifdef __WXGTK__
62 return true;
63#else
64 return false;
65#endif
66}
67
68
69// Structure used to store the extensions to test and the expected comparison result
71{
72 std::string ext;
75};
76
77const static std::vector<std::string> extensionList = { "dxf", "svg", "SCH", "^g.*" };
78const static std::vector<testExtensions> testExtensionList = {
79 {
80 "dxf",
81 true, // Case insensitive comparison result
82 true // Case sensitive comparison result
83 },
84 {
85 "sch",
86 true, // Case insensitive comparison result
87 false // Case sensitive comparison result
88 },
89 {
90 "gbr",
91 true, // Case insensitive comparison result
92 true // Case sensitive comparison result
93 },
94 {
95 "pcb",
96 false, // Case insensitive comparison result
97 false // Case sensitive comparison result
98 }
99};
100
104BOOST_AUTO_TEST_CASE( FileNameComparison )
105{
106 for( const auto& testExt : testExtensionList )
107 {
108 bool extPresent_insense = compareFileExtensions( testExt.ext, extensionList, false );
109 bool extPresent_sense = compareFileExtensions( testExt.ext, extensionList, true );
110
111 BOOST_TEST_INFO( "Case insensitive test for extension " + testExt.ext );
112 BOOST_CHECK_EQUAL( extPresent_insense, testExt.insense_result );
113
114 BOOST_TEST_INFO( "Case sensitive test for extension " + testExt.ext );
115 BOOST_CHECK_EQUAL( extPresent_sense, testExt.sense_result );
116 }
117}
118
119
124{
125 for( const auto& c : ext_wildcard_cases )
126 {
127 const std::string exp_filter =
128 should_use_regex_filters() ? c.m_re_filter : c.m_filter_case_insenstive;
129
130 const auto resp = AddFileExtListToFilter( c.m_exts );
131
132 BOOST_CHECK_EQUAL( resp, exp_filter );
133 }
134}
135
136static constexpr bool should_use_windows_filters()
137{
138#ifdef __WXMSW__
139 return true;
140#else
141 return false;
142#endif
143}
144
145BOOST_AUTO_TEST_CASE( AllFilesFilter )
146{
147 const auto resp = AddFileExtListToFilter( {} );
148
149 const std::string exp_filter = should_use_windows_filters() ? " (*.*)|*.*" : " (*)|*";
150
151 BOOST_CHECK_EQUAL( resp, exp_filter );
152}
153
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)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
BOOST_CHECK_EQUAL(result, "25.4")
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()
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.