2019-01-25 16:00:29 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file test_array_pad_name_provider.cpp
|
|
|
|
* Test suite for the #ARRAY_PAD_NAME_PROVIDER class
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unit_test_utils/unit_test_utils.h>
|
|
|
|
|
|
|
|
#include <array_pad_name_provider.h> // UUT
|
|
|
|
|
|
|
|
#include <common.h> // make_unique
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
2019-01-25 16:00:29 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-14 21:21:54 +00:00
|
|
|
* Make a footprint with a given list of named pads
|
2019-01-25 16:00:29 +00:00
|
|
|
*/
|
2020-11-14 21:21:54 +00:00
|
|
|
static std::unique_ptr<FOOTPRINT> FootprintWithPads( const std::vector<wxString> aNames )
|
2019-01-25 16:00:29 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( nullptr );
|
2019-01-25 16:00:29 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( const wxString& name : aNames )
|
2019-01-25 16:00:29 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( footprint.get() );
|
2019-01-25 16:00:29 +00:00
|
|
|
|
|
|
|
pad->SetName( name );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Add( pad.release() );
|
2019-01-25 16:00:29 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
return footprint;
|
2019-01-25 16:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare the test suite
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_SUITE( ArrayPadNameProv )
|
|
|
|
|
|
|
|
|
|
|
|
struct APNP_CASE
|
|
|
|
{
|
|
|
|
std::string m_case_name;
|
2020-11-14 21:21:54 +00:00
|
|
|
bool m_using_footprint;
|
2019-01-25 16:00:29 +00:00
|
|
|
std::vector<wxString> m_existing_pads;
|
|
|
|
std::unique_ptr<ARRAY_OPTIONS> m_arr_opts;
|
|
|
|
std::vector<wxString> m_exp_arr_names;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
/**
|
2020-11-14 21:21:54 +00:00
|
|
|
* Get Array Pad Name Provider cases when a footprint is looked at to determine what names
|
|
|
|
* are available.
|
2019-02-07 12:33:29 +00:00
|
|
|
*/
|
2020-11-14 21:21:54 +00:00
|
|
|
std::vector<APNP_CASE> GetFootprintAPNPCases()
|
2019-01-25 16:00:29 +00:00
|
|
|
{
|
|
|
|
std::vector<APNP_CASE> cases;
|
|
|
|
|
|
|
|
auto opts = std::make_unique<ARRAY_GRID_OPTIONS>();
|
|
|
|
|
|
|
|
// simple linear numbering
|
|
|
|
opts->m_2dArrayNumbering = false;
|
2019-05-15 10:47:45 +00:00
|
|
|
opts->m_pri_axis.SetOffset( 1 );
|
|
|
|
opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
|
2019-01-25 16:00:29 +00:00
|
|
|
|
|
|
|
cases.push_back( {
|
|
|
|
"Simple linear, skip some",
|
2019-02-07 12:33:29 +00:00
|
|
|
true,
|
2019-01-25 16:00:29 +00:00
|
|
|
{ "1", "3" },
|
|
|
|
std::move( opts ),
|
|
|
|
{ "2", "4", "5", "6", "7" },
|
|
|
|
} );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
// one without a footprint
|
2019-01-25 16:00:29 +00:00
|
|
|
opts = std::make_unique<ARRAY_GRID_OPTIONS>();
|
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
// simple linear numbering (again)
|
|
|
|
opts->m_2dArrayNumbering = false;
|
2019-05-15 10:47:45 +00:00
|
|
|
opts->m_pri_axis.SetOffset( 1 );
|
|
|
|
opts->m_pri_axis.SetAxisType( ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC );
|
2019-02-07 12:33:29 +00:00
|
|
|
|
|
|
|
cases.push_back( {
|
2020-11-14 21:21:54 +00:00
|
|
|
"Simple linear, no footprint",
|
2019-02-07 12:33:29 +00:00
|
|
|
false,
|
|
|
|
{}, // not used
|
|
|
|
std::move( opts ),
|
|
|
|
{ "1", "2", "3", "4", "5" },
|
|
|
|
} );
|
|
|
|
|
2019-01-25 16:00:29 +00:00
|
|
|
// Grid numberings with skips don't make a lot of sense, there is
|
|
|
|
// no particular contract made for them
|
|
|
|
|
|
|
|
return cases;
|
|
|
|
}
|
|
|
|
|
2019-02-07 12:33:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that an #ARRAY_PAD_NAME_PROVIDER provides the right names
|
|
|
|
* @param aProvider the provider
|
|
|
|
* @param aExpNames ordered list of expected names
|
|
|
|
*/
|
|
|
|
void CheckPadNameProvider( ARRAY_PAD_NAME_PROVIDER& aProvider, std::vector<wxString> aExpNames )
|
2019-01-25 16:00:29 +00:00
|
|
|
{
|
2019-02-07 12:33:29 +00:00
|
|
|
std::vector<wxString> got_names;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < aExpNames.size(); ++i )
|
2019-01-25 16:00:29 +00:00
|
|
|
{
|
2019-02-07 12:33:29 +00:00
|
|
|
got_names.push_back( aProvider.GetNextPadName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
|
|
|
aExpNames.begin(), aExpNames.end(), got_names.begin(), got_names.end() );
|
|
|
|
}
|
2019-01-25 16:00:29 +00:00
|
|
|
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
BOOST_AUTO_TEST_CASE( FootprintCases )
|
2019-02-07 12:33:29 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
for( const auto& c : GetFootprintAPNPCases() )
|
2019-02-07 12:33:29 +00:00
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( c.m_case_name )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> footprint;
|
2019-01-25 16:00:29 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( c.m_using_footprint )
|
|
|
|
footprint = FootprintWithPads( c.m_existing_pads );
|
2019-01-25 16:00:29 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
ARRAY_PAD_NAME_PROVIDER apnp( footprint.get(), *c.m_arr_opts );
|
2019-02-07 12:33:29 +00:00
|
|
|
|
|
|
|
CheckPadNameProvider( apnp, c.m_exp_arr_names );
|
2019-01-25 16:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|