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 CHANGELOG.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 <class_libentry.h>
35 #include <template_fieldnames.h>
36 
37 
39 {
40 template <>
41 struct print_log_value<LIB_FIELD>
42 {
43  inline void operator()( std::ostream& os, LIB_FIELD const& f )
44  {
45  os << "LIB_FIELD[ " << f.GetCanonicalName() << " ]";
46  }
47 };
48 
49 template <>
50 struct print_log_value<LIB_FIELDS>
51 {
52  inline void operator()( std::ostream& os, LIB_FIELDS const& f )
53  {
54  os << "LIB_FIELDS[ " << f.size() << " ]";
55  }
56 };
57 }
59 
60 
61 namespace KI_TEST
62 {
63 
71 bool FieldNameIdMatches( const LIB_FIELD& aField, const std::string& aExpectedName,
72  int aExpectedId )
73 {
74  bool ok = true;
75  const auto gotName = aField.GetCanonicalName();
76 
77  if( gotName != aExpectedName )
78  {
79  BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
80  ok = false;
81  }
82 
83  const int gotId = aField.GetId();
84 
85  if( gotId != aExpectedId )
86  {
87  BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
88  ok = false;
89  }
90 
91  return ok;
92 }
93 
99 bool AreDefaultFieldsCorrect( const LIB_FIELDS& aFields )
100 {
101  const unsigned expectedCount = NumFieldType::MANDATORY_FIELDS;
102  if( aFields.size() < expectedCount )
103  {
105  "Expected at least " << expectedCount << " fields, got " << aFields.size() );
106  return false;
107  }
108 
109  bool ok = true;
110 
111  ok &= FieldNameIdMatches( aFields[0], "Reference", NumFieldType::REFERENCE );
112  ok &= FieldNameIdMatches( aFields[1], "Value", NumFieldType::VALUE );
113  ok &= FieldNameIdMatches( aFields[2], "Footprint", NumFieldType::FOOTPRINT );
114  ok &= FieldNameIdMatches( aFields[3], "Datasheet", NumFieldType::DATASHEET );
115 
116  return ok;
117 }
118 
119 } // namespace KI_TEST
120 
121 #endif // QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
Before Boost 1.64, nullptr_t wasn't handled.
name of datasheet
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Field object used in symbol libraries.
Definition: lib_field.h:59
bool AreDefaultFieldsCorrect(const LIB_FIELDS &aFields)
Predicate to check that the mandatory fields in a LIB_FIELDS object look sensible.
int GetId() const
Definition: lib_field.h:138
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE
#define VALUE
Class LIB_PIN definition.
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:375
void operator()(std::ostream &os, LIB_FIELDS const &f)
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
bool FieldNameIdMatches(const LIB_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
Predicate to check a field name is as expected.
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...