KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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#include <sch_field.h>
36
37
39{
40template <>
41struct print_log_value<SCH_FIELD>
42{
43 inline void operator()( std::ostream& os, SCH_FIELD const& f )
44 {
45 os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
46 }
47};
48
49template <>
50struct print_log_value<std::vector<SCH_FIELD>>
51{
52 inline void operator()( std::ostream& os, std::vector<SCH_FIELD> const& f )
53 {
54 os << "SCH_FIELDS[ " << f.size() << " ]";
55 }
56};
57}
59
60
61namespace KI_TEST
62{
63
71bool FieldNameIdMatches( const SCH_FIELD& aField, const std::string& aExpectedName, 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
96bool AreDefaultFieldsCorrect( const std::vector<SCH_FIELD>& aFields )
97{
98 const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS;
99
100 if( aFields.size() < expectedCount )
101 {
102 BOOST_TEST_INFO( "Expected at least " << expectedCount << " fields, got " << aFields.size() );
103 return false;
104 }
105
106 bool ok = true;
107
108 ok &= FieldNameIdMatches( aFields[0], "Reference", MANDATORY_FIELD_T::REFERENCE_FIELD );
109 ok &= FieldNameIdMatches( aFields[1], "Value", MANDATORY_FIELD_T::VALUE_FIELD );
110 ok &= FieldNameIdMatches( aFields[2], "Footprint", MANDATORY_FIELD_T::FOOTPRINT_FIELD );
111 ok &= FieldNameIdMatches( aFields[3], "Datasheet", MANDATORY_FIELD_T::DATASHEET_FIELD );
112
113 return ok;
114}
115
116} // namespace KI_TEST
117
118#endif // QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:1174
int GetId() const
Definition: sch_field.h:133
Before Boost 1.64, nullptr_t wasn't handled.
bool AreDefaultFieldsCorrect(const std::vector< SCH_FIELD > &aFields)
Predicate to check that the mandatory fields look sensible.
bool FieldNameIdMatches(const SCH_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
Predicate to check a field name is as expected.
STL namespace.
void operator()(std::ostream &os, std::vector< SCH_FIELD > const &f)
#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...