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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
24
25#ifndef QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
26#define QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
27
29
30#include <template_fieldnames.h>
31#include <sch_field.h>
32
33
34std::ostream& boost_test_print_type( std::ostream& os, SCH_FIELD const& f )
35{
36 os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
37 return os;
38}
39
40std::ostream& boost_test_print_type( std::ostream& os, std::vector<SCH_FIELD> const& f )
41{
42 os << "SCH_FIELDS[ " << f.size() << " ]";
43 return os;
44}
45
46
47namespace KI_TEST
48{
49
57bool FieldNameIdMatches( const SCH_FIELD& aField, const std::string& aExpectedName, int aExpectedId )
58{
59 bool ok = true;
60 const auto gotName = aField.GetCanonicalName();
61
62 if( gotName != aExpectedName )
63 {
64 BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
65 ok = false;
66 }
67
68 const int gotId = (int) aField.GetId();
69
70 if( gotId != aExpectedId )
71 {
72 BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
73 ok = false;
74 }
75
76 return ok;
77}
78
82bool AreDefaultFieldsCorrect( const std::vector<SCH_FIELD>& aFields )
83{
84 const unsigned expectedCount = 5;
85
86 if( aFields.size() < expectedCount )
87 {
88 BOOST_TEST_INFO( "Expected at least " << expectedCount << " fields, got " << aFields.size() );
89 return false;
90 }
91
92 bool ok = true;
93
94 ok &= FieldNameIdMatches( aFields[0], "Reference", (int) FIELD_T::REFERENCE );
95 ok &= FieldNameIdMatches( aFields[1], "Value", (int) FIELD_T::VALUE );
96 ok &= FieldNameIdMatches( aFields[2], "Footprint", (int) FIELD_T::FOOTPRINT );
97 ok &= FieldNameIdMatches( aFields[3], "Datasheet", (int) FIELD_T::DATASHEET );
98
99 return ok;
100}
101
102} // namespace KI_TEST
103
104#endif // QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
FIELD_T GetId() const
Definition sch_field.h:132
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
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.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)