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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <sch_textbox.h>
22
23
25{
27
29 m_textbox( LAYER_NOTES, 0, FILL_T::NO_FILL, wxT( "Hello World" ) )
30 {
31 m_textbox.SetTextSize( VECTOR2I( schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 50 ) ) );
32 m_textbox.SetStart( VECTOR2I( 0, 0 ) );
33 m_textbox.SetEnd( VECTOR2I( schIUScale.MilsToIU( 2000 ), schIUScale.MilsToIU( 500 ) ) );
34 }
35};
36
37
38BOOST_FIXTURE_TEST_SUITE( SchTextbox, SCH_TEXTBOX_FIXTURE )
39
40
41
44BOOST_AUTO_TEST_CASE( GetMinSizeReturnsHeightOnly )
45{
46 VECTOR2I minSize = m_textbox.GetMinSize();
47
49 BOOST_CHECK_GT( minSize.y, 0 );
50}
51
52
56BOOST_AUTO_TEST_CASE( GetMinSizeGrowsWithMoreText )
57{
58 VECTOR2I minSizeShort = m_textbox.GetMinSize();
59
60 m_textbox.SetText( wxT( "Hello World\nSecond Line\nThird Line" ) );
61 m_textbox.ClearBoundingBoxCache();
62 m_textbox.ClearRenderCache();
63 VECTOR2I minSizeLong = m_textbox.GetMinSize();
64
65 BOOST_CHECK_GT( minSizeLong.y, minSizeShort.y );
66}
67
68
72BOOST_AUTO_TEST_CASE( GetMinSizeIncludesMargins )
73{
74 m_textbox.SetText( wxT( "A" ) );
75 m_textbox.SetMarginLeft( 0 );
76 m_textbox.SetMarginRight( 0 );
77 m_textbox.SetMarginTop( 0 );
78 m_textbox.SetMarginBottom( 0 );
79 m_textbox.ClearBoundingBoxCache();
80 m_textbox.ClearRenderCache();
81
82 VECTOR2I minSizeNoMargin = m_textbox.GetMinSize();
83
84 int margin = schIUScale.MilsToIU( 100 );
85 m_textbox.SetMarginTop( margin );
86 m_textbox.SetMarginBottom( margin );
87 m_textbox.ClearBoundingBoxCache();
88 m_textbox.ClearRenderCache();
89
90 VECTOR2I minSizeWithMargin = m_textbox.GetMinSize();
91
92 BOOST_CHECK_EQUAL( minSizeNoMargin.x, 0 );
93 BOOST_CHECK_EQUAL( minSizeWithMargin.x, 0 );
94 BOOST_CHECK_GT( minSizeWithMargin.y, minSizeNoMargin.y );
95}
96
97
101BOOST_AUTO_TEST_CASE( GetMinSizeEmptyText )
102{
103 m_textbox.SetText( wxT( "" ) );
104 m_textbox.ClearBoundingBoxCache();
105 m_textbox.ClearRenderCache();
106
107 VECTOR2I minSize = m_textbox.GetMinSize();
108
111}
112
113
117BOOST_AUTO_TEST_CASE( GetMinSizeVerticalText )
118{
119 m_textbox.SetText( wxT( "Test" ) );
120 m_textbox.ClearBoundingBoxCache();
121 m_textbox.ClearRenderCache();
122
123 VECTOR2I minSizeH = m_textbox.GetMinSize();
124
125 m_textbox.SetTextAngle( ANGLE_VERTICAL );
126 m_textbox.ClearBoundingBoxCache();
127 m_textbox.ClearRenderCache();
128
129 VECTOR2I minSizeV = m_textbox.GetMinSize();
130
131 BOOST_CHECK_EQUAL( minSizeH.x, 0 );
132 BOOST_CHECK_GT( minSizeH.y, 0 );
133 BOOST_CHECK_GT( minSizeV.x, 0 );
134 BOOST_CHECK_EQUAL( minSizeV.y, 0 );
135}
136
137
141BOOST_AUTO_TEST_CASE( GetMinSizeAllowsWidthReduction )
142{
143 m_textbox.SetText( wxT( "This is a very long line of text that should exceed the box width" ) );
144 m_textbox.ClearBoundingBoxCache();
145 m_textbox.ClearRenderCache();
146
147 VECTOR2I minSize = m_textbox.GetMinSize();
148
150 BOOST_CHECK_GT( minSize.y, 0 );
151}
152
153
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
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:59
@ NO_FILL
Definition eda_shape.h:60
@ LAYER_NOTES
Definition layer_ids.h:465
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:683