2019-04-23 09:18:15 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
|
2019-04-23 09:18:15 +01: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
|
2024-04-12 22:00:41 +01:00
|
|
|
* Test utils (e.g. print helpers and test predicates for SCH_FIELD objects
|
2019-04-23 09:18:15 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
|
|
|
|
#define QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
|
|
|
|
|
2021-02-06 23:20:31 +01:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2019-04-23 09:18:15 +01:00
|
|
|
|
|
|
|
#include <template_fieldnames.h>
|
2024-04-20 10:44:34 +01:00
|
|
|
#include <sch_field.h>
|
2019-04-23 09:18:15 +01:00
|
|
|
|
|
|
|
|
2024-08-13 10:02:08 +01:00
|
|
|
std::ostream& boost_test_print_type( std::ostream& os, SCH_FIELD const& f )
|
2019-04-23 09:18:15 +01:00
|
|
|
{
|
2024-08-13 10:02:08 +01:00
|
|
|
os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
|
|
|
|
return os;
|
|
|
|
}
|
2019-04-23 09:18:15 +01:00
|
|
|
|
2024-08-13 10:02:08 +01:00
|
|
|
std::ostream& boost_test_print_type( std::ostream& os, std::vector<SCH_FIELD> const& f )
|
2019-04-23 09:18:15 +01:00
|
|
|
{
|
2024-08-13 10:02:08 +01:00
|
|
|
os << "SCH_FIELDS[ " << f.size() << " ]";
|
|
|
|
return os;
|
2019-04-23 09:18:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace KI_TEST
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Predicate to check a field name is as expected
|
2024-04-12 22:00:41 +01:00
|
|
|
* @param aField SCH_FIELD to check the name
|
2019-04-23 09:18:15 +01:00
|
|
|
* @param aExpectedName the expected field name
|
|
|
|
* @param aExpectedId the expected field id
|
2024-04-12 22:00:41 +01:00
|
|
|
* @return true if match
|
2019-04-23 09:18:15 +01:00
|
|
|
*/
|
2024-04-12 22:00:41 +01:00
|
|
|
bool FieldNameIdMatches( const SCH_FIELD& aField, const std::string& aExpectedName, int aExpectedId )
|
2019-04-23 09:18:15 +01:00
|
|
|
{
|
|
|
|
bool ok = true;
|
2020-03-26 11:02:59 +00:00
|
|
|
const auto gotName = aField.GetCanonicalName();
|
2019-04-23 09:18:15 +01:00
|
|
|
|
|
|
|
if( gotName != aExpectedName )
|
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
|
2019-04-23 09:18:15 +01:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
2025-02-08 13:45:57 +00:00
|
|
|
const int gotId = (int) aField.GetId();
|
2019-04-23 09:18:15 +01:00
|
|
|
|
|
|
|
if( gotId != aExpectedId )
|
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
|
2019-04-23 09:18:15 +01:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-04-12 22:00:41 +01:00
|
|
|
* Predicate to check that the mandatory fields look sensible
|
2019-04-23 09:18:15 +01:00
|
|
|
*/
|
2024-04-12 22:00:41 +01:00
|
|
|
bool AreDefaultFieldsCorrect( const std::vector<SCH_FIELD>& aFields )
|
2019-04-23 09:18:15 +01:00
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
const unsigned expectedCount = 5;
|
2024-04-12 22:00:41 +01:00
|
|
|
|
2019-04-23 09:18:15 +01:00
|
|
|
if( aFields.size() < expectedCount )
|
|
|
|
{
|
2024-04-12 22:00:41 +01:00
|
|
|
BOOST_TEST_INFO( "Expected at least " << expectedCount << " fields, got " << aFields.size() );
|
2019-04-23 09:18:15 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2025-02-08 13:45:57 +00:00
|
|
|
ok &= FieldNameIdMatches( aFields[0], "Reference", (int) FIELD_T::REFERENCE );
|
|
|
|
ok &= FieldNameIdMatches( aFields[1], "Value", (int) FIELD_T::VALUE );
|
|
|
|
ok &= FieldNameIdMatches( aFields[2], "Footprint", (int) FIELD_T::FOOTPRINT );
|
|
|
|
ok &= FieldNameIdMatches( aFields[3], "Datasheet", (int) FIELD_T::DATASHEET );
|
2019-04-23 09:18:15 +01:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KI_TEST
|
|
|
|
|
2021-02-06 23:20:31 +01:00
|
|
|
#endif // QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
|