KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_text_variable_resolution.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
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
32
34#include <boost/test/unit_test.hpp>
35
36#include <board.h>
37#include <pcb_text.h>
38#include <project.h>
40
41
43{
45 {
46 m_settingsMgr.LoadProject( "" );
47 m_board.SetProject( &m_settingsMgr.Prj() );
48 }
49
50 std::map<wxString, wxString>& ProjectVars() { return m_settingsMgr.Prj().GetTextVars(); }
51
54};
55
56
57BOOST_FIXTURE_TEST_SUITE( TextVariableResolution, TEXT_VAR_RESOLUTION_FIXTURE )
58
59
60
65BOOST_AUTO_TEST_CASE( ProjectTextVarsTakePrecedence )
66{
67 ProjectVars()["MYVAR"] = "project_value";
68
69 // A stale snapshot in the board properties simulates the old load behaviour.
70 std::map<wxString, wxString> boardProps;
71 boardProps["MYVAR"] = "cached_board_value";
72 m_board.SetProperties( boardProps );
73
74 wxString token = "MYVAR";
75
76 BOOST_CHECK( m_board.ResolveTextVar( &token, 0 ) );
77 BOOST_CHECK_EQUAL( token, "project_value" );
78}
79
80
84BOOST_AUTO_TEST_CASE( ProjectTextVarsUpdateDynamically )
85{
86 ProjectVars()["MY_REVISION"] = "1.0";
87
88 wxString token = "MY_REVISION";
89
90 BOOST_CHECK( m_board.ResolveTextVar( &token, 0 ) );
91 BOOST_CHECK_EQUAL( token, "1.0" );
92
93 ProjectVars()["MY_REVISION"] = "2.0";
94 token = "MY_REVISION";
95
96 BOOST_CHECK( m_board.ResolveTextVar( &token, 0 ) );
97 BOOST_CHECK_EQUAL( token, "2.0" );
98}
99
100
107BOOST_AUTO_TEST_CASE( TitleBlockVarsTakePrecedence )
108{
109 m_board.GetTitleBlock().SetTitle( "board_title" );
110 ProjectVars()["TITLE"] = "project_title";
111
112 std::map<wxString, wxString> boardProps;
113 boardProps["TITLE"] = "cached_board_value";
114 m_board.SetProperties( boardProps );
115
116 wxString token = "TITLE";
117
118 BOOST_CHECK( m_board.ResolveTextVar( &token, 0 ) );
119 BOOST_CHECK_EQUAL( token, "board_title" );
120}
121
122
127BOOST_AUTO_TEST_CASE( BoardPropertiesFallback )
128{
129 std::map<wxString, wxString> boardProps;
130 boardProps["LEGACY_VAR"] = "legacy_value";
131 m_board.SetProperties( boardProps );
132
133 wxString token = "LEGACY_VAR";
134
135 BOOST_CHECK( m_board.ResolveTextVar( &token, 0 ) );
136 BOOST_CHECK_EQUAL( token, "legacy_value" );
137}
138
139
145BOOST_AUTO_TEST_CASE( PcbTextResolvesProjectVars )
146{
147 ProjectVars()["VERSION"] = "3.5";
148
149 std::map<wxString, wxString> boardProps;
150 boardProps["VERSION"] = "cached_board_value";
151 m_board.SetProperties( boardProps );
152
153 PCB_TEXT text( &m_board );
154 text.SetText( "Version: ${VERSION}" );
155
156 BOOST_CHECK_EQUAL( text.GetShownText( true ), "Version: 3.5" );
157
158 ProjectVars()["VERSION"] = "4.0";
159
160 BOOST_CHECK_EQUAL( text.GetShownText( true ), "Version: 4.0" );
161}
162
163
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
std::map< wxString, wxString > & ProjectVars()
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(ProjectTextVarsTakePrecedence)
Project text variables must win over the board's cached properties so an external edit (schematic,...