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
38std::ostream& boost_test_print_type( std::ostream& os, SCH_FIELD const& f )
39{
40 os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
41 return os;
42}
43
44std::ostream& boost_test_print_type( std::ostream& os, std::vector<SCH_FIELD> const& f )
45{
46 os << "SCH_FIELDS[ " << f.size() << " ]";
47 return os;
48}
49
50
51namespace KI_TEST
52{
53
61bool FieldNameIdMatches( const SCH_FIELD& aField, const std::string& aExpectedName, int aExpectedId )
62{
63 bool ok = true;
64 const auto gotName = aField.GetCanonicalName();
65
66 if( gotName != aExpectedName )
67 {
68 BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
69 ok = false;
70 }
71
72 const int gotId = aField.GetId();
73
74 if( gotId != aExpectedId )
75 {
76 BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
77 ok = false;
78 }
79
80 return ok;
81}
82
86bool AreDefaultFieldsCorrect( const std::vector<SCH_FIELD>& aFields )
87{
88 const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS;
89
90 if( aFields.size() < expectedCount )
91 {
92 BOOST_TEST_INFO( "Expected at least " << expectedCount << " fields, got " << aFields.size() );
93 return false;
94 }
95
96 bool ok = true;
97
98 ok &= FieldNameIdMatches( aFields[0], "Reference", MANDATORY_FIELD_T::REFERENCE_FIELD );
99 ok &= FieldNameIdMatches( aFields[1], "Value", MANDATORY_FIELD_T::VALUE_FIELD );
100 ok &= FieldNameIdMatches( aFields[2], "Footprint", MANDATORY_FIELD_T::FOOTPRINT_FIELD );
101 ok &= FieldNameIdMatches( aFields[3], "Datasheet", MANDATORY_FIELD_T::DATASHEET_FIELD );
102
103 return ok;
104}
105
106} // namespace KI_TEST
107
108#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:1252
int GetId() const
Definition: sch_field.h:133
std::ostream & boost_test_print_type(std::ostream &os, SCH_FIELD const &f)
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.