2019-04-23 08:18:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-24 15:57:52 +00:00
|
|
|
* Copyright (C) 2019-2023 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2021-06-10 18:51:46 +00:00
|
|
|
* Test suite for LIB_SYMBOL
|
2019-04-23 08:18:15 +00:00
|
|
|
*/
|
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// Code under test
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <lib_shape.h>
|
2019-11-06 19:15:42 +00:00
|
|
|
#include <lib_pin.h>
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
#include "lib_field_test_utils.h"
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
class TEST_LIB_SYMBOL_FIXTURE
|
2019-04-23 08:18:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-06-10 18:51:46 +00:00
|
|
|
TEST_LIB_SYMBOL_FIXTURE() :
|
2020-02-13 13:39:52 +00:00
|
|
|
m_part_no_data( "part_name", nullptr )
|
2019-04-23 08:18:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-24 15:57:52 +00:00
|
|
|
///< Part with no extra data set
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL m_part_no_data;
|
2019-04-23 08:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare the test suite
|
|
|
|
*/
|
2021-06-10 18:51:46 +00:00
|
|
|
BOOST_FIXTURE_TEST_SUITE( LibPart, TEST_LIB_SYMBOL_FIXTURE )
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that we can get the basic properties out as expected
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( DefaultProperties )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.GetName(), "part_name" );
|
|
|
|
|
|
|
|
// Didn't set a library, so this is empty
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.GetLibraryName(), "" );
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.GetLib(), nullptr );
|
|
|
|
|
|
|
|
// only get the root
|
2019-11-06 19:15:42 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.IsRoot(), true );
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.IsAlias(), false );
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.SharedPtr().use_count(), 2 );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// no sub units
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.GetUnitCount(), 1 );
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.IsMulti(), false );
|
|
|
|
|
|
|
|
// no conversion
|
2024-01-26 16:16:13 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.HasAlternateBodyStyle(), false );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Check the drawings on a "blank" LIB_SYMBOL
|
2019-04-23 08:18:15 +00:00
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( DefaultDrawings )
|
|
|
|
{
|
|
|
|
// default drawings exist
|
2023-06-19 17:08:18 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.GetDrawItems().size(), MANDATORY_FIELDS );
|
2023-01-20 22:12:15 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.GetAllLibPins().size(), 0 );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the default fields are present as expected
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( DefaultFields )
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
std::vector<SCH_FIELD> fields;
|
2019-04-23 08:18:15 +00:00
|
|
|
m_part_no_data.GetFields( fields );
|
|
|
|
|
|
|
|
// Should get the 4 default fields
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) );
|
|
|
|
|
|
|
|
// but no more (we didn't set them)
|
2021-02-28 13:28:23 +00:00
|
|
|
BOOST_CHECK_EQUAL( fields.size(), MANDATORY_FIELD_T::MANDATORY_FIELDS );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// also check the default field accessors
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
|
2021-02-28 13:28:23 +00:00
|
|
|
( m_part_no_data.GetReferenceField() )( "Reference" )( MANDATORY_FIELD_T::REFERENCE_FIELD ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
|
2021-02-28 13:28:23 +00:00
|
|
|
( m_part_no_data.GetValueField() )( "Value" )( MANDATORY_FIELD_T::VALUE_FIELD ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
|
2021-02-28 13:28:23 +00:00
|
|
|
( m_part_no_data.GetFootprintField() )( "Footprint" )( MANDATORY_FIELD_T::FOOTPRINT_FIELD ) );
|
2023-06-19 17:08:18 +00:00
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
|
|
|
|
( m_part_no_data.GetDatasheetField() )( "Datasheet" )( MANDATORY_FIELD_T::DATASHEET_FIELD) );
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
|
|
|
|
( m_part_no_data.GetDescriptionField() )( "Description" )( MANDATORY_FIELD_T::DESCRIPTION_FIELD) );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Test adding fields to a LIB_SYMBOL
|
2019-04-23 08:18:15 +00:00
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( AddedFields )
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
std::vector<SCH_FIELD> fields;
|
2019-04-23 08:18:15 +00:00
|
|
|
m_part_no_data.GetFields( fields );
|
|
|
|
|
|
|
|
// Ctor takes non-const ref (?!)
|
|
|
|
const std::string newFieldName = "new_field";
|
|
|
|
wxString nonConstNewFieldName = newFieldName;
|
2024-04-12 21:00:41 +00:00
|
|
|
fields.push_back( SCH_FIELD( nullptr, 42, nonConstNewFieldName ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// fairly roundabout way to add a field, but it is what it is
|
|
|
|
m_part_no_data.SetFields( fields );
|
|
|
|
|
|
|
|
// Should get the 4 default fields
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) );
|
|
|
|
|
|
|
|
// and our new one
|
2021-02-28 13:28:23 +00:00
|
|
|
BOOST_REQUIRE_EQUAL( fields.size(), MANDATORY_FIELD_T::MANDATORY_FIELDS + 1 );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
|
2021-02-28 13:28:23 +00:00
|
|
|
( fields[MANDATORY_FIELD_T::MANDATORY_FIELDS] )( newFieldName )( 42 ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// Check by-id lookup
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD* gotNewField = m_part_no_data.GetFieldById( 42 );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
BOOST_REQUIRE_NE( gotNewField, nullptr );
|
|
|
|
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, ( *gotNewField )( newFieldName )( 42 ) );
|
|
|
|
|
|
|
|
// Check by-name lookup
|
|
|
|
|
|
|
|
gotNewField = m_part_no_data.FindField( newFieldName );
|
|
|
|
|
|
|
|
BOOST_REQUIRE_NE( gotNewField, nullptr );
|
|
|
|
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, ( *gotNewField )( newFieldName )( 42 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Test adding draw items to a LIB_SYMBOL
|
2019-11-06 19:15:42 +00:00
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( AddedDrawItems )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
struct TEST_LIB_SYMBOL_SUBREF_CASE
|
2019-04-23 08:18:15 +00:00
|
|
|
{
|
|
|
|
int m_index;
|
|
|
|
bool m_addSep;
|
|
|
|
std::string m_expSubRef;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the subreference indexing
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( SubReference )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
const std::vector<TEST_LIB_SYMBOL_SUBREF_CASE> cases = {
|
2019-04-23 08:18:15 +00:00
|
|
|
{
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
"A",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
2,
|
|
|
|
false,
|
|
|
|
"B",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
26,
|
|
|
|
false,
|
|
|
|
"Z",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
27,
|
|
|
|
false,
|
|
|
|
"AA",
|
|
|
|
},
|
2022-10-06 22:03:58 +00:00
|
|
|
{
|
|
|
|
28,
|
|
|
|
false,
|
|
|
|
"AB",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
53,
|
|
|
|
false,
|
|
|
|
"BA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
79,
|
|
|
|
false,
|
|
|
|
"CA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
105,
|
|
|
|
false,
|
|
|
|
"DA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
131,
|
|
|
|
false,
|
|
|
|
"EA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
157,
|
|
|
|
false,
|
|
|
|
"FA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
183,
|
|
|
|
false,
|
|
|
|
"GA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
209,
|
|
|
|
false,
|
|
|
|
"HA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
235,
|
|
|
|
false,
|
|
|
|
"IA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
261,
|
|
|
|
false,
|
|
|
|
"JA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
287,
|
|
|
|
false,
|
|
|
|
"KA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
313,
|
|
|
|
false,
|
|
|
|
"LA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
339,
|
|
|
|
false,
|
|
|
|
"MA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
365,
|
|
|
|
false,
|
|
|
|
"NA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
391,
|
|
|
|
false,
|
|
|
|
"OA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
417,
|
|
|
|
false,
|
|
|
|
"PA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
443,
|
|
|
|
false,
|
|
|
|
"QA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
469,
|
|
|
|
false,
|
|
|
|
"RA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
495,
|
|
|
|
false,
|
|
|
|
"SA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
521,
|
|
|
|
false,
|
|
|
|
"TA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
547,
|
|
|
|
false,
|
|
|
|
"UA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
573,
|
|
|
|
false,
|
|
|
|
"VA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
599,
|
|
|
|
false,
|
|
|
|
"WA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
625,
|
|
|
|
false,
|
|
|
|
"XA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
651,
|
|
|
|
false,
|
|
|
|
"YA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
677,
|
|
|
|
false,
|
|
|
|
"ZA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
702,
|
|
|
|
false,
|
|
|
|
"ZZ",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
703,
|
|
|
|
false,
|
|
|
|
"AAA",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
728,
|
|
|
|
false,
|
|
|
|
"AAZ",
|
|
|
|
},
|
2019-04-23 08:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( const auto& c : cases )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT(
|
|
|
|
"Subref: " << c.m_index << ", " << c.m_addSep << " -> '" << c.m_expSubRef << "'" )
|
|
|
|
{
|
2023-11-12 23:42:36 +00:00
|
|
|
const auto subref = LIB_SYMBOL::LetterSubReference( c.m_index, 'A' );
|
2019-04-23 08:18:15 +00:00
|
|
|
BOOST_CHECK_EQUAL( subref, c.m_expSubRef );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
/**
|
|
|
|
* Check the compare method.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Compare )
|
|
|
|
{
|
|
|
|
// Identical root part to m_part_no_data sans time stamp.
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL testPart( "part_name" );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Self comparison test.
|
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.Compare( m_part_no_data ), 0 );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Test for identical LIB_SYMBOL.
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Test name.
|
|
|
|
testPart.SetName( "tart_name" );
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
|
|
|
|
testPart.SetName( "cart_name" );
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
|
|
|
|
testPart.SetName( "part_name" );
|
|
|
|
|
|
|
|
// LIB_ID comparison tests.
|
|
|
|
LIB_ID id = testPart.GetLibId();
|
|
|
|
id.SetLibItemName( "tart_name" );
|
|
|
|
testPart.SetLibId( id );
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
|
|
|
|
id.SetLibItemName( "cart_name" );
|
|
|
|
testPart.SetLibId( id );
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
|
|
|
|
id.SetLibItemName( "part_name" );
|
|
|
|
testPart.SetLibId( id );
|
|
|
|
|
|
|
|
// Unit count comparison tests.
|
|
|
|
testPart.SetUnitCount( 2 );
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
|
|
|
|
testPart.SetUnitCount( 1 );
|
|
|
|
m_part_no_data.SetUnitCount( 2 );
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
|
|
|
|
m_part_no_data.SetUnitCount( 1 );
|
|
|
|
|
|
|
|
// Options flag comparison tests.
|
|
|
|
testPart.SetPower();
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) < 0 );
|
|
|
|
testPart.SetNormal();
|
|
|
|
m_part_no_data.SetPower();
|
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart ) > 0 );
|
|
|
|
m_part_no_data.SetNormal();
|
|
|
|
|
|
|
|
// Draw item list size comparison tests.
|
2023-07-25 09:05:02 +00:00
|
|
|
testPart.AddDrawItem( new LIB_SHAPE( &testPart, SHAPE_T::RECTANGLE ) );
|
|
|
|
m_part_no_data.AddDrawItem( new LIB_SHAPE( &m_part_no_data, SHAPE_T::RECTANGLE ) );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
|
2023-01-20 22:12:15 +00:00
|
|
|
m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[LIB_SHAPE_T].front() );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2023-01-20 22:12:15 +00:00
|
|
|
testPart.RemoveDrawItem( &testPart.GetDrawItems()[LIB_SHAPE_T].front() );
|
2023-07-25 09:05:02 +00:00
|
|
|
m_part_no_data.AddDrawItem( new LIB_SHAPE( &m_part_no_data, SHAPE_T::RECTANGLE ) );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2023-01-20 22:12:15 +00:00
|
|
|
m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[LIB_SHAPE_T].front() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Draw item list contents comparison tests.
|
2023-07-25 09:05:02 +00:00
|
|
|
testPart.AddDrawItem( new LIB_SHAPE( &testPart, SHAPE_T::RECTANGLE ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
m_part_no_data.AddDrawItem( new LIB_SHAPE( &m_part_no_data, SHAPE_T::ARC ) );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2023-01-20 22:12:15 +00:00
|
|
|
m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[LIB_SHAPE_T].front() );
|
2023-03-09 11:25:32 +00:00
|
|
|
testPart.RemoveDrawItem( &testPart.GetDrawItems()[LIB_SHAPE_T].front() );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.AddDrawItem( new LIB_PIN( &m_part_no_data ) );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2023-01-20 22:12:15 +00:00
|
|
|
m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[LIB_PIN_T].front() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Footprint filter array comparison tests.
|
|
|
|
wxArrayString footPrintFilters;
|
2020-12-14 13:47:32 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetFPFilters() == footPrintFilters );
|
2019-11-06 19:15:42 +00:00
|
|
|
footPrintFilters.Add( "b" );
|
2020-12-14 13:47:32 +00:00
|
|
|
testPart.SetFPFilters( footPrintFilters );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2020-12-14 13:47:32 +00:00
|
|
|
m_part_no_data.SetFPFilters( footPrintFilters );
|
2019-11-06 19:15:42 +00:00
|
|
|
footPrintFilters.Clear();
|
2020-12-14 13:47:32 +00:00
|
|
|
testPart.SetFPFilters( footPrintFilters );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
footPrintFilters.Clear();
|
2020-12-14 13:47:32 +00:00
|
|
|
m_part_no_data.SetFPFilters( footPrintFilters );
|
|
|
|
testPart.SetFPFilters( footPrintFilters );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Description string tests.
|
|
|
|
m_part_no_data.SetDescription( "b" );
|
|
|
|
testPart.SetDescription( "b" );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetDescription( "a" );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetDescription( "c" );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetDescription( wxEmptyString );
|
|
|
|
testPart.SetDescription( wxEmptyString );
|
|
|
|
|
|
|
|
// Key word string tests.
|
|
|
|
m_part_no_data.SetKeyWords( "b" );
|
|
|
|
testPart.SetKeyWords( "b" );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ), 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetKeyWords( "a" );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetKeyWords( "c" );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetKeyWords( wxEmptyString );
|
|
|
|
testPart.SetKeyWords( wxEmptyString );
|
|
|
|
|
|
|
|
// Pin name offset comparison tests.
|
|
|
|
testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
testPart.SetPinNameOffset( testPart.GetPinNameOffset() - 2 );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
testPart.SetPinNameOffset( testPart.GetPinNameOffset() + 1 );
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Units locked flag comparison tests.
|
2019-11-06 19:15:42 +00:00
|
|
|
testPart.LockUnits( true );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
testPart.LockUnits( false );
|
|
|
|
m_part_no_data.LockUnits( true );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.LockUnits( false );
|
|
|
|
|
2020-09-09 13:03:37 +00:00
|
|
|
// Include in BOM support tests.
|
2023-06-25 02:03:06 +00:00
|
|
|
testPart.SetExcludedFromBOM( true );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2023-06-25 02:03:06 +00:00
|
|
|
testPart.SetExcludedFromBOM( false );
|
|
|
|
m_part_no_data.SetExcludedFromBOM( true );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2023-06-25 02:03:06 +00:00
|
|
|
m_part_no_data.SetExcludedFromBOM( false );
|
2020-09-09 13:03:37 +00:00
|
|
|
|
|
|
|
// Include on board support tests.
|
2023-06-25 02:03:06 +00:00
|
|
|
testPart.SetExcludedFromBoard( true );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2023-06-25 02:03:06 +00:00
|
|
|
testPart.SetExcludedFromBoard( false );
|
|
|
|
m_part_no_data.SetExcludedFromBoard( true );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2023-06-25 02:03:06 +00:00
|
|
|
m_part_no_data.SetExcludedFromBoard( false );
|
2020-09-09 13:03:37 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// Show pin names flag comparison tests.
|
|
|
|
m_part_no_data.SetShowPinNames( false );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetShowPinNames( true );
|
|
|
|
testPart.SetShowPinNames( false );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
testPart.SetShowPinNames( true );
|
|
|
|
|
|
|
|
// Show pin numbers flag comparison tests.
|
|
|
|
m_part_no_data.SetShowPinNumbers( false );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) < 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part_no_data.SetShowPinNumbers( true );
|
|
|
|
testPart.SetShowPinNumbers( false );
|
2024-04-06 13:14:44 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
testPart.SetShowPinNumbers( true );
|
|
|
|
|
|
|
|
// Time stamp comparison tests.
|
2021-03-04 22:59:24 +00:00
|
|
|
|
|
|
|
// Check to see if we broke the copy ctor.
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* copy = new LIB_SYMBOL( testPart );
|
2021-03-04 22:59:24 +00:00
|
|
|
BOOST_CHECK( testPart.Compare( *copy ) == 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-13 13:39:52 +00:00
|
|
|
/**
|
|
|
|
* Check the fetch unit items code.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( GetUnitItems )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
// There are no unit draw items in the empty LIB_SYMBOL object.
|
2021-11-02 18:32:39 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
// A single unique unit with 1 pin common to all units and all body styles.
|
|
|
|
LIB_PIN* pin1 = new LIB_PIN( &m_part_no_data );
|
|
|
|
m_part_no_data.AddDrawItem( pin1 );
|
2021-11-02 18:32:39 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 0, 0 ).size() == 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
// A single unique unit with 1 pin in unit 1 and common to all body styles.
|
|
|
|
pin1->SetUnit( 1 );
|
2021-11-02 18:32:39 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 0 ).size() == 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
// A single unique unit with 1 pin in unit 1 and body style 1.
|
2024-01-26 16:16:13 +00:00
|
|
|
pin1->SetBodyStyle( 1 );
|
2021-11-02 18:32:39 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Two unique units with pin 1 assigned to unit 1 and body style 1 and pin 2 assigned to
|
2020-02-13 13:39:52 +00:00
|
|
|
// unit 2 and body style 1.
|
|
|
|
LIB_PIN* pin2 = new LIB_PIN( &m_part_no_data );
|
|
|
|
m_part_no_data.SetUnitCount( 2 );
|
|
|
|
pin2->SetUnit( 2 );
|
2024-01-26 16:16:13 +00:00
|
|
|
pin2->SetBodyStyle( 2 );
|
2020-02-13 13:39:52 +00:00
|
|
|
pin2->SetNumber( "4" );
|
|
|
|
m_part_no_data.AddDrawItem( pin2 );
|
2021-11-02 18:32:39 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 2 ).size() == 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
// Make pin 1 body style common to all units.
|
2024-01-26 16:16:13 +00:00
|
|
|
pin1->SetBodyStyle( 0 );
|
2021-11-02 18:32:39 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 );
|
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 2, 1 ).size() == 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
m_part_no_data.RemoveDrawItem( pin2 );
|
|
|
|
m_part_no_data.RemoveDrawItem( pin1 );
|
2023-01-20 22:12:15 +00:00
|
|
|
m_part_no_data.RemoveDrawItem( &*m_part_no_data.GetDrawItems().begin() );
|
2020-02-13 13:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the fetch unit draw items code.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( GetUnitDrawItems )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
// There are no unit draw items in the empty LIB_SYMBOL object.
|
2020-02-13 13:39:52 +00:00
|
|
|
BOOST_CHECK( m_part_no_data.GetUnitDrawItems().size() == 0 );
|
|
|
|
|
|
|
|
// A single unique unit with 1 pin common to all units and all body styles.
|
|
|
|
LIB_PIN* pin1 = new LIB_PIN( &m_part_no_data );
|
|
|
|
pin1->SetNumber( "1" );
|
|
|
|
m_part_no_data.AddDrawItem( pin1 );
|
2021-11-02 18:32:39 +00:00
|
|
|
std::vector<struct LIB_SYMBOL_UNIT> units = m_part_no_data.GetUnitDrawItems();
|
2020-02-13 13:39:52 +00:00
|
|
|
BOOST_CHECK( units.size() == 1 );
|
|
|
|
BOOST_CHECK( units[0].m_unit == 0 );
|
2024-01-26 16:16:13 +00:00
|
|
|
BOOST_CHECK( units[0].m_bodyStyle == 0 );
|
2020-02-13 13:39:52 +00:00
|
|
|
BOOST_CHECK( units[0].m_items[0] == pin1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
/**
|
|
|
|
* Check inheritance support.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Inheritance )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr<LIB_SYMBOL> parent = std::make_unique<LIB_SYMBOL>( "parent" );
|
2019-11-06 19:15:42 +00:00
|
|
|
BOOST_CHECK( parent->IsRoot() );
|
2023-08-20 16:05:31 +00:00
|
|
|
BOOST_CHECK_EQUAL( parent->GetInheritanceDepth(), 0 );
|
2023-06-13 19:52:42 +00:00
|
|
|
|
|
|
|
std::unique_ptr<LIB_SYMBOL> ref = std::make_unique<LIB_SYMBOL>( *parent );
|
|
|
|
|
|
|
|
std::unique_ptr<LIB_SYMBOL> child = std::make_unique<LIB_SYMBOL>( "child", parent.get() );
|
|
|
|
BOOST_CHECK( child->IsAlias() );
|
2023-08-20 16:05:31 +00:00
|
|
|
BOOST_CHECK_EQUAL( child->GetInheritanceDepth(), 1 );
|
2023-06-13 19:52:42 +00:00
|
|
|
|
|
|
|
std::unique_ptr<LIB_SYMBOL> grandChild = std::make_unique<LIB_SYMBOL>( "grandchild",
|
|
|
|
child.get() );
|
|
|
|
BOOST_CHECK( grandChild->IsAlias() );
|
2023-08-20 16:05:31 +00:00
|
|
|
BOOST_CHECK_EQUAL( grandChild->GetInheritanceDepth(), 2 );
|
|
|
|
|
2023-10-28 17:15:45 +00:00
|
|
|
BOOST_CHECK( parent->GetRootSymbol().get() == parent.get() );
|
|
|
|
BOOST_CHECK( child->GetRootSymbol().get() == parent.get() );
|
|
|
|
BOOST_CHECK( grandChild->GetRootSymbol().get() == parent.get() );
|
2023-06-13 19:52:42 +00:00
|
|
|
|
|
|
|
LIB_SYMBOL_SPTR parentRef = child->GetParent().lock();
|
2019-11-06 19:15:42 +00:00
|
|
|
BOOST_CHECK( parentRef );
|
|
|
|
BOOST_CHECK( parentRef == parent->SharedPtr() );
|
|
|
|
BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 3 );
|
2023-06-13 19:52:42 +00:00
|
|
|
|
|
|
|
LIB_SYMBOL_SPTR childRef = grandChild->GetParent().lock();
|
|
|
|
BOOST_CHECK( childRef );
|
|
|
|
BOOST_CHECK( childRef == child->SharedPtr() );
|
|
|
|
BOOST_CHECK_EQUAL( child->SharedPtr().use_count(), 3 );
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
|
2019-11-06 19:15:42 +00:00
|
|
|
parent->SetUnitCount( 4 );
|
2023-06-13 19:52:42 +00:00
|
|
|
BOOST_CHECK_EQUAL( child->GetUnitCount(), 4 );
|
|
|
|
parent->SetUnitCount( 1 );
|
|
|
|
|
2023-09-14 23:11:57 +00:00
|
|
|
parent->GetDatasheetField().SetText( "https://kicad/resistors.pdf" );
|
|
|
|
ref->GetDatasheetField().SetText( "https://kicad/resistors.pdf" );
|
|
|
|
|
|
|
|
BOOST_CHECK( *parent == *ref );
|
2023-06-13 19:52:42 +00:00
|
|
|
|
|
|
|
ref->SetName( "child" );
|
2024-04-12 21:00:41 +00:00
|
|
|
SCH_FIELD* field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" );
|
2023-09-14 23:11:57 +00:00
|
|
|
field->SetText( "KiCad" );
|
|
|
|
child->AddField( field );
|
2023-10-21 08:39:11 +00:00
|
|
|
field->SetParent( child.get() );
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" );
|
2023-09-14 23:11:57 +00:00
|
|
|
field->SetText( "KiCad" );
|
2023-06-13 19:52:42 +00:00
|
|
|
ref->AddField( field );
|
2023-10-21 08:39:11 +00:00
|
|
|
field->SetParent( ref.get() );
|
|
|
|
|
2023-06-13 19:52:42 +00:00
|
|
|
BOOST_CHECK( *ref == *child->Flatten() );
|
|
|
|
|
|
|
|
ref->SetName( "grandchild" );
|
2024-04-12 21:00:41 +00:00
|
|
|
field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" );
|
2023-06-13 19:52:42 +00:00
|
|
|
field->SetText( "123456" );
|
2023-09-14 23:11:57 +00:00
|
|
|
grandChild->AddField( field );
|
2023-10-21 08:39:11 +00:00
|
|
|
field->SetParent( grandChild.get() );
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" );
|
2023-06-13 19:52:42 +00:00
|
|
|
field->SetText( "123456" );
|
2023-09-14 23:11:57 +00:00
|
|
|
ref->AddField( field );
|
2023-10-21 08:39:11 +00:00
|
|
|
field->SetParent( ref.get() );
|
|
|
|
|
2023-06-13 19:52:42 +00:00
|
|
|
BOOST_CHECK( *ref == *grandChild->Flatten() );
|
|
|
|
|
2023-09-14 23:11:57 +00:00
|
|
|
BOOST_CHECK_EQUAL( grandChild->Flatten()->GetDatasheetField().GetText(),
|
|
|
|
"https://kicad/resistors.pdf" );
|
|
|
|
|
2023-06-13 19:52:42 +00:00
|
|
|
child->SetParent();
|
|
|
|
BOOST_CHECK_EQUAL( child->GetUnitCount(), 1 );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
parentRef.reset();
|
|
|
|
BOOST_CHECK_EQUAL( parent->SharedPtr().use_count(), 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the copy constructor.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( CopyConstructor )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
std::shared_ptr<LIB_SYMBOL> copy = std::make_shared<LIB_SYMBOL>( m_part_no_data );
|
2019-11-06 19:15:42 +00:00
|
|
|
BOOST_CHECK( m_part_no_data == *copy.get() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-20 16:05:31 +00:00
|
|
|
/**
|
|
|
|
* Check the power and legacy power symbol tests.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( IsPowerTest )
|
|
|
|
{
|
|
|
|
std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( "power" );
|
|
|
|
LIB_PIN* pin = new LIB_PIN( symbol.get() );
|
|
|
|
pin->SetNumber( "1" );
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
|
|
|
pin->SetVisible( false );
|
|
|
|
symbol->AddDrawItem( pin );
|
|
|
|
|
|
|
|
BOOST_CHECK( !symbol->IsPower() );
|
|
|
|
BOOST_CHECK( symbol->IsNormal() );
|
|
|
|
|
|
|
|
symbol->SetPower();
|
|
|
|
BOOST_CHECK( symbol->IsPower() );
|
|
|
|
BOOST_CHECK( !symbol->IsNormal() );
|
|
|
|
|
|
|
|
// symbol->SetNormal();
|
|
|
|
// symbol->GetReferenceField().SetText( wxS( "#PWR" ) );
|
|
|
|
// BOOST_CHECK( symbol->IsPower() );
|
|
|
|
|
|
|
|
// Legacy power symbols are limited to a single pin.
|
|
|
|
// pin = new LIB_PIN( symbol.get() );
|
|
|
|
// pin->SetNumber( "2" );
|
|
|
|
// pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
|
|
|
// pin->SetVisible( false );
|
|
|
|
// symbol->AddDrawItem( pin );
|
|
|
|
// BOOST_CHECK( !symbol->IsPower() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|