KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_format_units.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
22#include <base_units.h>
23#include <eda_units.h>
24#include <locale_io.h>
25
26#include <algorithm>
27#include <iostream>
28
30{
31};
32
33
37BOOST_FIXTURE_TEST_SUITE( UnitConversion, UnitFixture )
38
39
40
43BOOST_AUTO_TEST_CASE( VECTOR2IUnitFormat )
44{
45 LOCALE_IO toggle;
46
47#ifdef EESCHEMA
48 const EDA_IU_SCALE& iuScale = schIUScale;
49#elif GERBVIEW
50 const EDA_IU_SCALE& iuScale = gerbIUScale;
51#elif PCBNEW
52 const EDA_IU_SCALE& iuScale = pcbIUScale;
53#endif
54
55 std::string str = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( 123456, 52525252 ) );
56 std::string strZero = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( 0, 0 ) );
57 std::string strNeg = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( -123456, -52525252 ) );
58 std::string strOddNeg = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( -350000, -0 ) );
59 std::string strMax = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::max() ) );
60
61 BOOST_CHECK_EQUAL( strZero, "0 0" );
62
63#ifdef EESCHEMA
64 BOOST_CHECK_EQUAL( str, "12.3456 5252.5252" );
65 BOOST_CHECK_EQUAL( strNeg, "-12.3456 -5252.5252" );
66 BOOST_CHECK_EQUAL( strMax, "-214748.3648 214748.3647" );
67 BOOST_CHECK_EQUAL( strOddNeg, "-35 0" );
68#elif GERBVIEW
69 BOOST_CHECK_EQUAL( str, "1.23456 525.25252" );
70 BOOST_CHECK_EQUAL( strNeg, "-1.23456 -525.25252" );
71 BOOST_CHECK_EQUAL( strMax, "-21474.83648 21474.83647" );
72 BOOST_CHECK_EQUAL( strOddNeg, "-3.5 0" );
73#elif PCBNEW
74 BOOST_CHECK_EQUAL( str, "0.123456 52.525252" );
75 BOOST_CHECK_EQUAL( strNeg, "-0.123456 -52.525252" );
76 BOOST_CHECK_EQUAL( strMax, "-2147.483648 2147.483647" );
77 BOOST_CHECK_EQUAL( strOddNeg, "-0.35 0" );
78#endif
79
80}
81
82
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:120
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683