QA: unit tests for file ext filters
This adds a unit test for the recent AddFileExtListToFilter to demonstrate how to use it and the expected output. The unit tests are a bit clunky, as the vararg approach cannot work winth strings passed at runtime.
This commit is contained in:
parent
1ca3b2c768
commit
f86d953c80
|
@ -37,10 +37,11 @@ set( common_srcs
|
||||||
../../common/observable.cpp
|
../../common/observable.cpp
|
||||||
|
|
||||||
test_color4d.cpp
|
test_color4d.cpp
|
||||||
|
test_format_units.cpp
|
||||||
test_hotkey_store.cpp
|
test_hotkey_store.cpp
|
||||||
test_title_block.cpp
|
test_title_block.cpp
|
||||||
test_utf8.cpp
|
test_utf8.cpp
|
||||||
test_format_units.cpp
|
test_wildcards_and_files_ext.cpp
|
||||||
|
|
||||||
libeval/test_numeric_evaluator.cpp
|
libeval/test_numeric_evaluator.cpp
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, you may find one here:
|
||||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||||
|
* or you may write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unit_test_utils/unit_test_utils.h>
|
||||||
|
|
||||||
|
#include <wildcards_and_files_ext.h>
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE( WildcardFileExt )
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data used to construct a simple test of one or more extensions
|
||||||
|
* and get a filter string for WX dialogs out
|
||||||
|
*/
|
||||||
|
struct ExtWildcardFilterCase
|
||||||
|
{
|
||||||
|
/// The list of exts handled
|
||||||
|
std::vector<std::string> m_exts;
|
||||||
|
|
||||||
|
/// Filter for case-insensitive environments
|
||||||
|
std::string m_filter_case_insenstive;
|
||||||
|
|
||||||
|
/// Filter for regex-capable environments (case insensitive filter in a
|
||||||
|
/// case-sensitive environment)
|
||||||
|
std::string m_re_filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
const static std::vector<ExtWildcardFilterCase> ext_wildcard_cases = {
|
||||||
|
{
|
||||||
|
{ "png" },
|
||||||
|
" ( *.png)|*.png",
|
||||||
|
" ( *.png)|*.[pP][nN][gG]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ "png", "gif" },
|
||||||
|
" ( *.png *.gif)|*.png;*.gif",
|
||||||
|
" ( *.png *.gif)|*.[pP][nN][gG];*.[gG][iI][fF]",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static constexpr bool should_use_regex_filters()
|
||||||
|
{
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check correct handling of filter strings (as used by WX)
|
||||||
|
*/
|
||||||
|
BOOST_AUTO_TEST_CASE( SingleFilter )
|
||||||
|
{
|
||||||
|
const auto& c = ext_wildcard_cases[0];
|
||||||
|
const std::string exp_filter =
|
||||||
|
should_use_regex_filters() ? c.m_re_filter : c.m_filter_case_insenstive;
|
||||||
|
|
||||||
|
const auto resp = AddFileExtListToFilter( 1, "png" );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( resp, exp_filter );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( MultipleFilter )
|
||||||
|
{
|
||||||
|
const auto& c = ext_wildcard_cases[1];
|
||||||
|
const std::string exp_filter =
|
||||||
|
should_use_regex_filters() ? c.m_re_filter : c.m_filter_case_insenstive;
|
||||||
|
|
||||||
|
const auto resp = AddFileExtListToFilter( 2, "png", "gif" );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( resp, exp_filter );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in New Issue