Fix the SCH_PINs test to be more reflective of the codebase.
This commit is contained in:
parent
c9fa46ace8
commit
e6f4e156b6
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
* Copyright (C) 2019-2020 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
|
||||
|
@ -21,20 +21,12 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test suite for SCH_PIM
|
||||
*/
|
||||
|
||||
#include <unit_test_utils/geometry.h>
|
||||
#include <unit_test_utils/unit_test_utils.h>
|
||||
#include <unit_test_utils/wx_assert.h>
|
||||
|
||||
// Code under test
|
||||
#include <sch_pin.h>
|
||||
|
||||
#include <sch_component.h>
|
||||
|
||||
#include <eda_rect.h>
|
||||
|
||||
|
||||
|
@ -42,25 +34,38 @@ class TEST_SCH_PIN_FIXTURE
|
|||
{
|
||||
public:
|
||||
TEST_SCH_PIN_FIXTURE()
|
||||
: m_parent_part( "parent_part", nullptr ),
|
||||
m_lib_pin( &m_parent_part ),
|
||||
m_parent_comp( wxPoint( 0, 0 ), nullptr ),
|
||||
m_sch_pin( &m_lib_pin, &m_parent_comp )
|
||||
{
|
||||
m_parent_part = new LIB_PART( "parent_part", nullptr );
|
||||
|
||||
m_lib_pin = new LIB_PIN( m_parent_part );
|
||||
m_parent_part->AddDrawItem( m_lib_pin );
|
||||
|
||||
// give the pin some kind of data we can use to test
|
||||
m_lib_pin.SetNumber( "42" );
|
||||
m_lib_pin.SetName( "pinname" );
|
||||
m_lib_pin.SetType( ELECTRICAL_PINTYPE::PT_INPUT );
|
||||
m_lib_pin->SetNumber( "42" );
|
||||
m_lib_pin->SetName( "pinname" );
|
||||
m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
|
||||
m_lib_pin->SetPosition( wxPoint( 1, -2 ) ); // local coord system is upside-down
|
||||
|
||||
SCH_SHEET_PATH path;
|
||||
m_parent_comp.SetRef( &path, "U2" );
|
||||
m_parent_comp = new SCH_COMPONENT( *m_parent_part, m_parent_part->GetLibId(),
|
||||
&path, 0, 0, wxPoint( 1, 2 ) );
|
||||
m_parent_comp->SetRef( &path, "U2" );
|
||||
m_parent_comp->UpdatePins();
|
||||
|
||||
m_sch_pin = m_parent_comp->GetPins( &path )[0];
|
||||
}
|
||||
|
||||
LIB_PART m_parent_part;
|
||||
LIB_PIN m_lib_pin;
|
||||
~TEST_SCH_PIN_FIXTURE()
|
||||
{
|
||||
delete m_parent_comp;
|
||||
delete m_parent_part;
|
||||
}
|
||||
|
||||
SCH_COMPONENT m_parent_comp;
|
||||
SCH_PIN m_sch_pin;
|
||||
LIB_PART* m_parent_part;
|
||||
LIB_PIN* m_lib_pin;
|
||||
|
||||
SCH_COMPONENT* m_parent_comp;
|
||||
SCH_PIN* m_sch_pin; // owned by m_parent_comp, not us
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,20 +79,19 @@ BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
|
|||
*/
|
||||
BOOST_AUTO_TEST_CASE( DefaultProperties )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.GetParentComponent(), &m_parent_comp );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.GetLibPin(), &m_lib_pin );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->GetParentComponent(), m_parent_comp );
|
||||
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.GetLocalPosition(), wxPoint( 0, 0 ) );
|
||||
// Note: local coord system is upside-down; schematic coord system is not.
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->GetLocalPosition(), wxPoint( 1, -2 ) );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->GetPosition(), wxPoint( 2, 4 ) );
|
||||
|
||||
// These just forward to LIB_PIN for now, so this isn't very interesting
|
||||
// but later we will want to test these functions for SCH_PIN's own functionality
|
||||
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() );
|
||||
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() );
|
||||
|
||||
BOOST_CHECK( ( m_sch_pin.GetType() == m_lib_pin.GetType() ) );
|
||||
BOOST_CHECK( ( m_sch_pin->GetType() == m_lib_pin->GetType() ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.IsPowerConnection(), m_lib_pin.IsPowerConnection() );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->IsPowerConnection(), m_lib_pin->IsPowerConnection() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,9 +99,10 @@ BOOST_AUTO_TEST_CASE( DefaultProperties )
|
|||
*/
|
||||
BOOST_AUTO_TEST_CASE( Assign )
|
||||
{
|
||||
SCH_PIN assigned = m_sch_pin;
|
||||
SCH_PIN assigned = *m_sch_pin;
|
||||
|
||||
BOOST_CHECK_EQUAL( assigned.GetParentComponent(), &m_parent_comp );
|
||||
BOOST_CHECK_EQUAL( assigned.GetParentComponent(), m_parent_comp );
|
||||
BOOST_CHECK_EQUAL( assigned.GetNumber(), m_lib_pin->GetNumber() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,9 +110,10 @@ BOOST_AUTO_TEST_CASE( Assign )
|
|||
*/
|
||||
BOOST_AUTO_TEST_CASE( Copy )
|
||||
{
|
||||
SCH_PIN copied( m_sch_pin );
|
||||
SCH_PIN copied( *m_sch_pin );
|
||||
|
||||
BOOST_CHECK_EQUAL( copied.GetParentComponent(), &m_parent_comp );
|
||||
BOOST_CHECK_EQUAL( copied.GetParentComponent(), m_parent_comp );
|
||||
BOOST_CHECK_EQUAL( copied.GetNumber(), m_lib_pin->GetNumber() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,15 +122,15 @@ BOOST_AUTO_TEST_CASE( Copy )
|
|||
BOOST_AUTO_TEST_CASE( PinDangling )
|
||||
{
|
||||
// dangles by default
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.IsDangling(), true );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
|
||||
|
||||
// all you have to do to un-dangle is say so
|
||||
m_sch_pin.SetIsDangling( false );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.IsDangling(), false );
|
||||
m_sch_pin->SetIsDangling( false );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), false );
|
||||
|
||||
// and the same to re-dangle
|
||||
m_sch_pin.SetIsDangling( true );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin.IsDangling(), true );
|
||||
m_sch_pin->SetIsDangling( true );
|
||||
BOOST_CHECK_EQUAL( m_sch_pin->IsDangling(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,12 +140,12 @@ BOOST_AUTO_TEST_CASE( PinNumbering )
|
|||
{
|
||||
SCH_SHEET_PATH path;
|
||||
|
||||
const wxString name = m_sch_pin.GetDefaultNetName( path );
|
||||
const wxString name = m_sch_pin->GetDefaultNetName( path );
|
||||
BOOST_CHECK_EQUAL( name, "Net-(U2-Pad42)" );
|
||||
|
||||
// do it again: this should now (transparently) go though the net name map
|
||||
// can't really check directly, but coverage tools should see this
|
||||
const wxString map_name = m_sch_pin.GetDefaultNetName( path );
|
||||
const wxString map_name = m_sch_pin->GetDefaultNetName( path );
|
||||
BOOST_CHECK_EQUAL( map_name, name );
|
||||
}
|
||||
|
||||
|
@ -148,13 +154,22 @@ BOOST_AUTO_TEST_CASE( PinNumbering )
|
|||
*/
|
||||
BOOST_AUTO_TEST_CASE( PinNumberingPower )
|
||||
{
|
||||
// but if we set is power...
|
||||
m_lib_pin.SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
||||
m_parent_part.SetPower();
|
||||
// but if we set isPower...
|
||||
m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
||||
m_parent_part->SetPower();
|
||||
|
||||
// the name is just the pin name
|
||||
// and update component from library...
|
||||
SCH_SHEET_PATH path;
|
||||
const wxString pwr_name = m_sch_pin.GetDefaultNetName( path );
|
||||
delete m_parent_comp;
|
||||
m_parent_comp = new SCH_COMPONENT( *m_parent_part, m_parent_part->GetLibId(),
|
||||
&path, 0, 0, wxPoint( 1, 2 ) );
|
||||
m_parent_comp->SetRef( &path, "U2" );
|
||||
m_parent_comp->UpdatePins();
|
||||
|
||||
m_sch_pin = m_parent_comp->GetPins( &path )[0];
|
||||
|
||||
// ... then the name is just the pin name
|
||||
const wxString pwr_name = m_sch_pin->GetDefaultNetName( path );
|
||||
BOOST_CHECK_EQUAL( pwr_name, "pinname" );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue