KiCad PCB EDA Suite
lib_field_test_utils.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
29#ifndef QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
30#define QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
31
33
34#include <template_fieldnames.h>
35
36
38{
39template <>
40struct print_log_value<LIB_FIELD>
41{
42 inline void operator()( std::ostream& os, LIB_FIELD const& f )
43 {
44 os << "LIB_FIELD[ " << f.GetCanonicalName() << " ]";
45 }
46};
47
48template <>
49struct print_log_value<std::vector<LIB_FIELD>>
50{
51 inline void operator()( std::ostream& os, std::vector<LIB_FIELD> const& f )
52 {
53 os << "LIB_FIELDS[ " << f.size() << " ]";
54 }
55};
56}
58
59
60namespace KI_TEST
61{
62
70bool FieldNameIdMatches( const LIB_FIELD& aField, const std::string& aExpectedName,
71 int aExpectedId )
72{
73 bool ok = true;
74 const auto gotName = aField.GetCanonicalName();
75
76 if( gotName != aExpectedName )
77 {
78 BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
79 ok = false;
80 }
81
82 const int gotId = aField.GetId();
83
84 if( gotId != aExpectedId )
85 {
86 BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
87 ok = false;
88 }
89
90 return ok;
91}
92
98bool AreDefaultFieldsCorrect( const std::vector<LIB_FIELD>& aFields )
99{
100 const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS;
101 if( aFields.size() < expectedCount )
102 {
104 "Expected at least " << expectedCount << " fields, got " << aFields.size() );
105 return false;
106 }
107
108 bool ok = true;
109
110 ok &= FieldNameIdMatches( aFields[0], "Reference", MANDATORY_FIELD_T::REFERENCE_FIELD );
111 ok &= FieldNameIdMatches( aFields[1], "Value", MANDATORY_FIELD_T::VALUE_FIELD );
112 ok &= FieldNameIdMatches( aFields[2], "Footprint", MANDATORY_FIELD_T::FOOTPRINT_FIELD );
113 ok &= FieldNameIdMatches( aFields[3], "Datasheet", MANDATORY_FIELD_T::DATASHEET_FIELD );
114
115 return ok;
116}
117
118} // namespace KI_TEST
119
120#endif // QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
Field object used in symbol libraries.
Definition: lib_field.h:60
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:424
int GetId() const
Definition: lib_field.h:115
Before Boost 1.64, nullptr_t wasn't handled.
bool AreDefaultFieldsCorrect(const std::vector< LIB_FIELD > &aFields)
Predicate to check that the mandatory fields in a LIB_FIELDS object look sensible.
bool FieldNameIdMatches(const LIB_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
Predicate to check a field name is as expected.
Definition: bitmap.cpp:64
void operator()(std::ostream &os, std::vector< LIB_FIELD > const &f)
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...