2019-04-23 08:18:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-02-24 13:48:02 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-23 08:18:15 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
|
|
|
#include <qa_utils/wx_utils/wx_assert.h>
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// Code under test
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <lib_symbol.h>
|
2019-04-23 08:18:15 +00:00
|
|
|
#include <sch_pin.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TEST_SCH_PIN_FIXTURE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_SCH_PIN_FIXTURE()
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
m_parent_part = new LIB_SYMBOL( "parent_part", nullptr );
|
2021-02-24 13:48:02 +00:00
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
m_lib_pin = new SCH_PIN( m_parent_part );
|
2020-08-31 23:01:20 +00:00
|
|
|
m_parent_part->AddDrawItem( m_lib_pin );
|
2021-02-24 13:48:02 +00:00
|
|
|
|
2019-04-23 08:18:15 +00:00
|
|
|
// give the pin some kind of data we can use to test
|
2020-08-31 23:01:20 +00:00
|
|
|
m_lib_pin->SetNumber( "42" );
|
|
|
|
m_lib_pin->SetName( "pinname" );
|
|
|
|
m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
|
2024-04-27 12:47:56 +00:00
|
|
|
m_lib_pin->SetPosition( VECTOR2I( 1, 2 ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
SCH_SHEET_PATH path;
|
2023-02-19 03:40:07 +00:00
|
|
|
m_parent_symbol = new SCH_SYMBOL( *m_parent_part, m_parent_part->GetLibId(), &path, 0, 0,
|
|
|
|
VECTOR2I( 1, 2 ) );
|
2020-11-15 13:58:21 +00:00
|
|
|
m_parent_symbol->SetRef( &path, "U2" );
|
|
|
|
m_parent_symbol->UpdatePins();
|
2021-02-24 13:48:02 +00:00
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
m_sch_pin = m_parent_symbol->GetPins( &path )[0];
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 23:01:20 +00:00
|
|
|
~TEST_SCH_PIN_FIXTURE()
|
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
delete m_parent_symbol;
|
2020-08-31 23:01:20 +00:00
|
|
|
delete m_parent_part;
|
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* m_parent_part;
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* m_lib_pin;
|
2019-04-23 08:18:15 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* m_parent_symbol;
|
|
|
|
SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
|
2019-04-23 08:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare the test suite
|
|
|
|
*/
|
|
|
|
BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check basic properties of an un-modified SCH_PIN object
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( DefaultProperties )
|
|
|
|
{
|
2020-11-15 13:58:21 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->GetParentSymbol(), m_parent_symbol );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
2024-04-27 12:47:56 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->GetLocalPosition(), VECTOR2I( 1, 2 ) );
|
2023-02-19 03:40:07 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->GetPosition(), VECTOR2I( 2, 4 ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
2020-08-31 23:01:20 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->IsVisible(), m_lib_pin->IsVisible() );
|
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->GetName(), m_lib_pin->GetName() );
|
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->GetNumber(), m_lib_pin->GetNumber() );
|
2020-01-18 20:51:28 +00:00
|
|
|
|
2020-08-31 23:01:20 +00:00
|
|
|
BOOST_CHECK( ( m_sch_pin->GetType() == m_lib_pin->GetType() ) );
|
2020-01-18 20:51:28 +00:00
|
|
|
|
2023-01-18 15:06:46 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->IsGlobalPower(), m_lib_pin->IsGlobalPower() );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the assignment operator
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Assign )
|
|
|
|
{
|
2020-08-31 23:01:20 +00:00
|
|
|
SCH_PIN assigned = *m_sch_pin;
|
2019-04-23 08:18:15 +00:00
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
BOOST_CHECK_EQUAL( assigned.GetParentSymbol(), m_parent_symbol );
|
2020-08-31 23:01:20 +00:00
|
|
|
BOOST_CHECK_EQUAL( assigned.GetNumber(), m_lib_pin->GetNumber() );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the copy ctor
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Copy )
|
|
|
|
{
|
2020-08-31 23:01:20 +00:00
|
|
|
SCH_PIN copied( *m_sch_pin );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
BOOST_CHECK_EQUAL( copied.GetParentSymbol(), m_parent_symbol );
|
2020-08-31 23:01:20 +00:00
|
|
|
BOOST_CHECK_EQUAL( copied.GetNumber(), m_lib_pin->GetNumber() );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the pin dangling flag
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( PinDangling )
|
|
|
|
{
|
|
|
|
// dangles by default
|
2020-08-31 23:01:20 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// all you have to do to un-dangle is say so
|
2020-08-31 23:01:20 +00:00
|
|
|
m_sch_pin->SetIsDangling( false );
|
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), false );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// and the same to re-dangle
|
2020-08-31 23:01:20 +00:00
|
|
|
m_sch_pin->SetIsDangling( true );
|
|
|
|
BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the pin labelling
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( PinNumbering )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH path;
|
|
|
|
|
2020-08-31 23:01:20 +00:00
|
|
|
const wxString name = m_sch_pin->GetDefaultNetName( path );
|
2022-01-01 01:17:00 +00:00
|
|
|
BOOST_CHECK_EQUAL( name, "Net-(U2-pinname)" );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// do it again: this should now (transparently) go though the net name map
|
|
|
|
// can't really check directly, but coverage tools should see this
|
2020-08-31 23:01:20 +00:00
|
|
|
const wxString map_name = m_sch_pin->GetDefaultNetName( path );
|
2019-04-23 08:18:15 +00:00
|
|
|
BOOST_CHECK_EQUAL( map_name, name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the pin labelling when it's a power pin
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( PinNumberingPower )
|
|
|
|
{
|
2020-08-31 23:01:20 +00:00
|
|
|
// but if we set isPower...
|
|
|
|
m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
|
|
|
m_parent_part->SetPower();
|
2023-01-18 17:49:58 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_lib_pin->IsGlobalPower(), true );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
// and update symbol from library...
|
2019-04-23 08:18:15 +00:00
|
|
|
SCH_SHEET_PATH path;
|
2020-11-15 13:58:21 +00:00
|
|
|
delete m_parent_symbol;
|
2023-02-19 03:40:07 +00:00
|
|
|
m_parent_symbol = new SCH_SYMBOL( *m_parent_part, m_parent_part->GetLibId(), &path, 0, 0,
|
|
|
|
VECTOR2I( 1, 2 ) );
|
2020-11-15 13:58:21 +00:00
|
|
|
m_parent_symbol->SetRef( &path, "U2" );
|
2023-01-18 17:49:58 +00:00
|
|
|
m_parent_symbol->SetValueFieldText( "voltage_value" );
|
2020-11-15 13:58:21 +00:00
|
|
|
m_parent_symbol->UpdatePins();
|
2020-08-31 23:01:20 +00:00
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
m_sch_pin = m_parent_symbol->GetPins( &path )[0];
|
2020-08-31 23:01:20 +00:00
|
|
|
|
|
|
|
// ... then the name is just the pin name
|
|
|
|
const wxString pwr_name = m_sch_pin->GetDefaultNetName( path );
|
2023-01-18 17:49:58 +00:00
|
|
|
BOOST_CHECK_EQUAL( pwr_name, "voltage_value" );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 13:48:02 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|