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
>
27
#include <
qa_utils/wx_utils/wx_assert.h
>
28
#include <
widgets/unit_binder.h
>
29
30
BOOST_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.
35
BOOST_AUTO_TEST_CASE
( RangeBoundDistance )
36
{
37
UNIT_BINDER::RANGE_BOUND
bound =
UNIT_BINDER::ConvertRangeBound
(
38
pcbIUScale
,
EDA_UNITS::MM
, 4.0,
EDA_UNITS::MM
,
EDA_DATA_TYPE::DISTANCE
);
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.
47
BOOST_AUTO_TEST_CASE
( RangeBoundArea )
48
{
49
UNIT_BINDER::RANGE_BOUND
bound =
UNIT_BINDER::ConvertRangeBound
(
50
pcbIUScale
,
EDA_UNITS::MM
, 4.0,
EDA_UNITS::MM
,
EDA_DATA_TYPE::AREA
);
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.
58
BOOST_AUTO_TEST_CASE
( RangeBoundVolume )
59
{
60
UNIT_BINDER::RANGE_BOUND
bound =
UNIT_BINDER::ConvertRangeBound
(
61
pcbIUScale
,
EDA_UNITS::MM
, 2.0,
EDA_UNITS::MM
,
EDA_DATA_TYPE::VOLUME
);
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.
71
BOOST_AUTO_TEST_CASE
( RangeBoundUnitless )
72
{
73
UNIT_BINDER::RANGE_BOUND
bound{};
74
75
BOOST_CHECK_NO_THROW( bound =
UNIT_BINDER::ConvertRangeBound
(
pcbIUScale
,
EDA_UNITS::UNSCALED
,
76
5.0,
EDA_UNITS::UNSCALED
,
77
EDA_DATA_TYPE::UNITLESS
) );
78
79
BOOST_CHECK_CLOSE( bound.internalUnits, 5.0, 1e-9 );
80
BOOST_CHECK_EQUAL
( bound.displayText, wxString::FromUTF8(
"5"
) );
81
}
82
83
84
BOOST_AUTO_TEST_SUITE_END
()
base_units.h
PCB_IU_PER_MM
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition
base_units.h:68
pcbIUScale
constexpr EDA_IU_SCALE pcbIUScale
Definition
base_units.h:128
UNIT_BINDER::ConvertRangeBound
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.
Definition
unit_binder.cpp:385
eda_units.h
EDA_DATA_TYPE::AREA
@ AREA
Definition
eda_units.h:36
EDA_DATA_TYPE::VOLUME
@ VOLUME
Definition
eda_units.h:37
EDA_DATA_TYPE::DISTANCE
@ DISTANCE
Definition
eda_units.h:35
EDA_DATA_TYPE::UNITLESS
@ UNITLESS
Definition
eda_units.h:38
EDA_UNITS::MM
@ MM
Definition
eda_units.h:47
EDA_UNITS::UNSCALED
@ UNSCALED
Definition
eda_units.h:48
UNIT_BINDER::RANGE_BOUND
A range bound converted to internal units together with its user-facing display string.
Definition
unit_binder.h:188
UNIT_BINDER::RANGE_BOUND::internalUnits
double internalUnits
Definition
unit_binder.h:189
UNIT_BINDER::RANGE_BOUND::displayText
wxString displayText
Definition
unit_binder.h:190
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:80
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(RangeBoundDistance)
Definition
test_unit_binder.cpp:35
unit_binder.h
wx_assert.h
src
qa
tests
common
test_unit_binder.cpp
Generated on Tue Nov 17 2026 00:06:29 for KiCad PCB EDA Suite by
1.13.2