KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_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 <sch_textbox.h>
26
27
29{
31
33 m_textbox( LAYER_NOTES, 0, FILL_T::NO_FILL, wxT( "Hello World" ) )
34 {
35 m_textbox.SetTextSize( VECTOR2I( schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 50 ) ) );
36 m_textbox.SetStart( VECTOR2I( 0, 0 ) );
37 m_textbox.SetEnd( VECTOR2I( schIUScale.MilsToIU( 2000 ), schIUScale.MilsToIU( 500 ) ) );
38 }
39};
40
41
42BOOST_FIXTURE_TEST_SUITE( SchTextbox, SCH_TEXTBOX_FIXTURE )
43
44
45
48BOOST_AUTO_TEST_CASE( GetMinSizeReturnsHeightOnly )
49{
50 VECTOR2I minSize = m_textbox.GetMinSize();
51
53 BOOST_CHECK_GT( minSize.y, 0 );
54}
55
56
60BOOST_AUTO_TEST_CASE( GetMinSizeGrowsWithMoreText )
61{
62 VECTOR2I minSizeShort = m_textbox.GetMinSize();
63
64 m_textbox.SetText( wxT( "Hello World\nSecond Line\nThird Line" ) );
65 m_textbox.ClearBoundingBoxCache();
66 m_textbox.ClearRenderCache();
67 VECTOR2I minSizeLong = m_textbox.GetMinSize();
68
69 BOOST_CHECK_GT( minSizeLong.y, minSizeShort.y );
70}
71
72
76BOOST_AUTO_TEST_CASE( GetMinSizeIncludesMargins )
77{
78 m_textbox.SetText( wxT( "A" ) );
79 m_textbox.SetMarginLeft( 0 );
80 m_textbox.SetMarginRight( 0 );
81 m_textbox.SetMarginTop( 0 );
82 m_textbox.SetMarginBottom( 0 );
83 m_textbox.ClearBoundingBoxCache();
84 m_textbox.ClearRenderCache();
85
86 VECTOR2I minSizeNoMargin = m_textbox.GetMinSize();
87
88 int margin = schIUScale.MilsToIU( 100 );
89 m_textbox.SetMarginTop( margin );
90 m_textbox.SetMarginBottom( margin );
91 m_textbox.ClearBoundingBoxCache();
92 m_textbox.ClearRenderCache();
93
94 VECTOR2I minSizeWithMargin = m_textbox.GetMinSize();
95
96 BOOST_CHECK_EQUAL( minSizeNoMargin.x, 0 );
97 BOOST_CHECK_EQUAL( minSizeWithMargin.x, 0 );
98 BOOST_CHECK_GT( minSizeWithMargin.y, minSizeNoMargin.y );
99}
100
101
105BOOST_AUTO_TEST_CASE( GetMinSizeEmptyText )
106{
107 m_textbox.SetText( wxT( "" ) );
108 m_textbox.ClearBoundingBoxCache();
109 m_textbox.ClearRenderCache();
110
111 VECTOR2I minSize = m_textbox.GetMinSize();
112
115}
116
117
121BOOST_AUTO_TEST_CASE( GetMinSizeVerticalText )
122{
123 m_textbox.SetText( wxT( "Test" ) );
124 m_textbox.ClearBoundingBoxCache();
125 m_textbox.ClearRenderCache();
126
127 VECTOR2I minSizeH = m_textbox.GetMinSize();
128
129 m_textbox.SetTextAngle( ANGLE_VERTICAL );
130 m_textbox.ClearBoundingBoxCache();
131 m_textbox.ClearRenderCache();
132
133 VECTOR2I minSizeV = m_textbox.GetMinSize();
134
135 BOOST_CHECK_EQUAL( minSizeH.x, 0 );
136 BOOST_CHECK_GT( minSizeH.y, 0 );
137 BOOST_CHECK_GT( minSizeV.x, 0 );
138 BOOST_CHECK_EQUAL( minSizeV.y, 0 );
139}
140
141
145BOOST_AUTO_TEST_CASE( GetMinSizeAllowsWidthReduction )
146{
147 m_textbox.SetText( wxT( "This is a very long line of text that should exceed the box width" ) );
148 m_textbox.ClearBoundingBoxCache();
149 m_textbox.ClearRenderCache();
150
151 VECTOR2I minSize = m_textbox.GetMinSize();
152
154 BOOST_CHECK_GT( minSize.y, 0 );
155}
156
157
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
const int minSize
Push and Shove router track width and via size dialog.
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
FILL_T
Definition eda_shape.h:56
@ NO_FILL
Definition eda_shape.h:57
@ LAYER_NOTES
Definition layer_ids.h:467
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