KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pcb_textbox.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
25#include <board.h>
26#include <pcb_textbox.h>
27
28
30{
33
35 m_board(),
37 {
38 m_textbox.SetText( wxT( "Hello World" ) );
39 m_textbox.SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
40 m_textbox.SetStart( VECTOR2I( 0, 0 ) );
41 m_textbox.SetEnd( VECTOR2I( pcbIUScale.mmToIU( 20.0 ), pcbIUScale.mmToIU( 5.0 ) ) );
42 }
43};
44
45
46BOOST_FIXTURE_TEST_SUITE( PcbTextbox, PCB_TEXTBOX_FIXTURE )
47
48
49
53BOOST_AUTO_TEST_CASE( GetMinSizeReturnsHeightOnly )
54{
55 VECTOR2I minSize = m_textbox.GetMinSize();
56
58 BOOST_CHECK_GT( minSize.y, 0 );
59}
60
61
65BOOST_AUTO_TEST_CASE( GetMinSizeGrowsWithMoreText )
66{
67 VECTOR2I minSizeShort = m_textbox.GetMinSize();
68
69 m_textbox.SetText( wxT( "Hello World\nSecond Line\nThird Line" ) );
70 m_textbox.ClearBoundingBoxCache();
71 m_textbox.ClearRenderCache();
72 VECTOR2I minSizeLong = m_textbox.GetMinSize();
73
74 BOOST_CHECK_GT( minSizeLong.y, minSizeShort.y );
75}
76
77
81BOOST_AUTO_TEST_CASE( GetMinSizeIncludesMargins )
82{
83 m_textbox.SetText( wxT( "A" ) );
84 m_textbox.SetMarginLeft( 0 );
85 m_textbox.SetMarginRight( 0 );
86 m_textbox.SetMarginTop( 0 );
87 m_textbox.SetMarginBottom( 0 );
88 m_textbox.ClearBoundingBoxCache();
89 m_textbox.ClearRenderCache();
90
91 VECTOR2I minSizeNoMargin = m_textbox.GetMinSize();
92
93 int margin = pcbIUScale.mmToIU( 1.0 );
94 m_textbox.SetMarginTop( margin );
95 m_textbox.SetMarginBottom( margin );
96 m_textbox.ClearBoundingBoxCache();
97 m_textbox.ClearRenderCache();
98
99 VECTOR2I minSizeWithMargin = m_textbox.GetMinSize();
100
101 BOOST_CHECK_EQUAL( minSizeNoMargin.x, 0 );
102 BOOST_CHECK_EQUAL( minSizeWithMargin.x, 0 );
103 BOOST_CHECK_GT( minSizeWithMargin.y, minSizeNoMargin.y );
104}
105
106
110BOOST_AUTO_TEST_CASE( GetMinSizeHeightAtLeastTextHeight )
111{
112 m_textbox.SetText( wxT( "A" ) );
113 m_textbox.ClearBoundingBoxCache();
114 m_textbox.ClearRenderCache();
115 VECTOR2I minSize = m_textbox.GetMinSize();
116
117 BOOST_CHECK_GE( minSize.y, m_textbox.GetTextSize().y );
118}
119
120
124BOOST_AUTO_TEST_CASE( GetMinSizeEmptyText )
125{
126 m_textbox.SetText( wxT( "" ) );
127 m_textbox.ClearBoundingBoxCache();
128 m_textbox.ClearRenderCache();
129
130 VECTOR2I minSize = m_textbox.GetMinSize();
131
134}
135
136
141BOOST_AUTO_TEST_CASE( GetMinSizeRotated90 )
142{
143 m_textbox.SetText( wxT( "Wide Text" ) );
144 m_textbox.ClearBoundingBoxCache();
145 m_textbox.ClearRenderCache();
146
147 VECTOR2I minSize0 = m_textbox.GetMinSize();
148
149 m_textbox.SetTextAngle( EDA_ANGLE( 90.0, DEGREES_T ) );
150 m_textbox.ClearBoundingBoxCache();
151 m_textbox.ClearRenderCache();
152
153 VECTOR2I minSize90 = m_textbox.GetMinSize();
154
155 BOOST_CHECK_EQUAL( minSize0.x, 0 );
156 BOOST_CHECK_GT( minSize0.y, 0 );
157 BOOST_CHECK_GT( minSize90.x, 0 );
158 BOOST_CHECK_EQUAL( minSize90.y, 0 );
159}
160
161
165BOOST_AUTO_TEST_CASE( GetMinSizeAllowsWidthReduction )
166{
167 m_textbox.SetText( wxT( "This is a very long line of text that should exceed the box width" ) );
168 m_textbox.ClearBoundingBoxCache();
169 m_textbox.ClearRenderCache();
170
171 VECTOR2I minSize = m_textbox.GetMinSize();
172
174 BOOST_CHECK_GT( minSize.y, 0 );
175}
176
177
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const int minSize
Push and Shove router track width and via size dialog.
@ DEGREES_T
Definition eda_angle.h:31
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(GetMinSizeReturnsHeightOnly)
Verify that GetMinSize() returns height-only constraint for non-empty text.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695