KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_unit_binder.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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#define BOOST_TEST_NO_MAIN
21#include <boost/test/unit_test.hpp>
22
23#include <wx/debug.h>
24
25#include <base_units.h>
26#include <eda_units.h>
28#include <widgets/unit_binder.h>
29
30BOOST_AUTO_TEST_SUITE( UnitBinder )
31
32
33// A distance bound must convert and format exactly as it always has (single unit conversion,
34// bare units label), guarding the generalized code against DISTANCE regressions.
35BOOST_AUTO_TEST_CASE( RangeBoundDistance )
36{
39
40 BOOST_CHECK_CLOSE( bound.internalUnits, 4.0 * PCB_IU_PER_MM, 1e-9 );
41 BOOST_CHECK_EQUAL( bound.displayText, wxString::FromUTF8( "4 mm" ) );
42}
43
44
45// An area bound scales by the square of the unit factor and its label carries the ² exponent.
46// The pre-fix code single-converted and formatted as DISTANCE, so both checks failed.
47BOOST_AUTO_TEST_CASE( RangeBoundArea )
48{
51
52 BOOST_CHECK_CLOSE( bound.internalUnits, 4.0 * PCB_IU_PER_MM * PCB_IU_PER_MM, 1e-9 );
53 BOOST_CHECK_EQUAL( bound.displayText, wxString::FromUTF8( "4 mm\xC2\xB2" ) );
54}
55
56
57// A volume bound scales by the cube of the unit factor and its label carries the ³ exponent.
58BOOST_AUTO_TEST_CASE( RangeBoundVolume )
59{
62
63 BOOST_CHECK_CLOSE( bound.internalUnits, 2.0 * PCB_IU_PER_MM * PCB_IU_PER_MM * PCB_IU_PER_MM,
64 1e-9 );
65 BOOST_CHECK_EQUAL( bound.displayText, wxString::FromUTF8( "2 mm\xC2\xB3" ) );
66}
67
68
69// A unitless bound converts nothing and must not carry a units label; requesting one trips
70// GetText's UNIMPLEMENTED_FOR assertion. qa_common does not install the assert thrower
71// globally, so arm it here or a regression would assert silently and the string checks
72// would still pass.
73BOOST_AUTO_TEST_CASE( RangeBoundUnitless )
74{
75 wxAssertHandler_t prevHandler = wxSetAssertHandler( &KI_TEST::wxAssertThrower );
76
78
82
83 wxSetAssertHandler( prevHandler );
84
85 BOOST_CHECK_CLOSE( bound.internalUnits, 5.0, 1e-9 );
86 BOOST_CHECK_EQUAL( bound.displayText, wxString::FromUTF8( "5" ) );
87}
88
89
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition base_units.h:68
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
static RANGE_BOUND ConvertRangeBound(const EDA_IU_SCALE &aIuScale, EDA_UNITS aBoundUnits, double aBound, EDA_UNITS aDisplayUnits, EDA_DATA_TYPE aDataType)
Convert a range bound and format its display string honoring aDataType.
void wxAssertThrower(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Definition wx_assert.h:67
A range bound converted to internal units together with its user-facing display string.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(RangeBoundDistance)