KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_schematic_text_var_reactive.cpp
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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include <algorithm>
22#include <memory>
23
24#include <eeschema_test_utils.h>
25#include <schematic.h>
27#include <sch_screen.h>
28#include <sch_sheet.h>
29#include <sch_symbol.h>
30#include <sch_text.h>
31#include <sch_field.h>
32#include <text_var_dependency.h>
33
34
42BOOST_AUTO_TEST_SUITE( SchematicTextVarReactive )
43
44
45BOOST_AUTO_TEST_CASE( AdapterInstalledOnSchematicConstruction )
46{
47 SCHEMATIC sch( nullptr );
50}
51
52
53BOOST_AUTO_TEST_CASE( SchTextItemRegistersOnAdded )
54{
55 SCHEMATIC sch( nullptr );
57 text.SetText( wxT( "${U1:Value}" ) );
58
59 std::vector<SCH_ITEM*> added{ &text };
60 sch.GetTextVarAdapter()->OnSchItemsAdded( sch, added );
61
64 index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "U1:Value" ) ) ), 1u );
65}
66
67
68BOOST_AUTO_TEST_CASE( SchSymbolFieldsRegisterAsDependents )
69{
70 SCHEMATIC sch( nullptr );
71 SCH_SYMBOL sym;
72
73 // The symbol's own VALUE field has a text-var reference.
74 sym.GetField( FIELD_T::VALUE )->SetText( wxT( "${SHEETNAME}" ) );
75
76 std::vector<SCH_ITEM*> added{ &sym };
77 sch.GetTextVarAdapter()->OnSchItemsAdded( sch, added );
78
81 index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "SHEETNAME" ) ) ), 1u );
82}
83
84
85BOOST_AUTO_TEST_CASE( RemovedItemsAreUnregistered )
86{
87 SCHEMATIC sch( nullptr );
89 text.SetText( wxT( "${X}" ) );
90
91 std::vector<SCH_ITEM*> items{ &text };
92 sch.GetTextVarAdapter()->OnSchItemsAdded( sch, items );
93
95 BOOST_CHECK_EQUAL( index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "X" ) ) ), 1u );
96
97 sch.GetTextVarAdapter()->OnSchItemsRemoved( sch, items );
98 BOOST_CHECK_EQUAL( index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "X" ) ) ), 0u );
99}
100
101
102BOOST_AUTO_TEST_CASE( RetextReRegisters )
103{
104 SCHEMATIC sch( nullptr );
106 text.SetText( wxT( "${OLD}" ) );
107
108 std::vector<SCH_ITEM*> items{ &text };
109 sch.GetTextVarAdapter()->OnSchItemsAdded( sch, items );
110
112 BOOST_CHECK_EQUAL( index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "OLD" ) ) ), 1u );
113
114 // Edit the text and fire a change notification — the adapter must drop
115 // the old edge and register the new one.
116 text.SetText( wxT( "${NEW}" ) );
117 sch.GetTextVarAdapter()->OnSchItemsChanged( sch, items );
118
119 BOOST_CHECK_EQUAL( index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "OLD" ) ) ), 0u );
120 BOOST_CHECK_EQUAL( index.DependentCount( TEXT_VAR_REF_KEY::FromToken( wxT( "NEW" ) ) ), 1u );
121}
122
123
124BOOST_AUTO_TEST_CASE( SpiceOPTokensAreNotRegistered )
125{
126 SCHEMATIC sch( nullptr );
128 text.SetText( wxT( "${OP:port}" ) );
129
130 std::vector<SCH_ITEM*> items{ &text };
131 sch.GetTextVarAdapter()->OnSchItemsAdded( sch, items );
132
134}
135
136
int index
void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aItems) override
void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aItems) override
void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aItems) override
Holds all the data relating to one schematic.
Definition schematic.h:89
class SCHEMATIC_TEXT_VAR_ADAPTER * GetTextVarAdapter() const
Definition schematic.h:633
void SetText(const wxString &aText) override
Schematic symbol object.
Definition sch_symbol.h:76
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Bidirectional index mapping TEXT_VAR_REF_KEY → dependent items and item → keys.
TEXT_VAR_DEPENDENCY_INDEX & Index()
static TEXT_VAR_REF_KEY FromToken(const wxString &aToken)
Parse a raw token (the text between ${ and }) into a key using lexical classification only — no looku...
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(AdapterInstalledOnSchematicConstruction)
SCHEMATIC_TEXT_VAR_ADAPTER exercised at the listener interface.
BOOST_CHECK_EQUAL(result, "25.4")