KiCad PCB EDA Suite
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 (C) 2019 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
26#include <base_units.h>
27#include <eda_units.h>
28#include <locale_io.h>
29
30#include <algorithm>
31#include <iostream>
32
34{
35};
36
37
41BOOST_FIXTURE_TEST_SUITE( UnitConversion, UnitFixture )
42
43
44
47BOOST_AUTO_TEST_CASE( wxPointUnitFormat )
48{
49 LOCALE_IO toggle;
50
51#ifdef EESCHEMA
52 const EDA_IU_SCALE& iuScale = schIUScale;
53#elif GERBVIEW
54 const EDA_IU_SCALE& iuScale = gerbIUScale;
55#elif PCBNEW
56 const EDA_IU_SCALE& iuScale = pcbIUScale;
57#endif
58
59 std::string str = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, wxPoint( 123456, 52525252 ) );
60 std::string strZero = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, wxPoint( 0, 0 ) );
61 std::string strNeg = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, wxPoint( -123456, -52525252 ) );
62 std::string strOddNeg = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, wxPoint( -350000, -0 ) );
63 std::string strMax = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, wxPoint( std::numeric_limits<int>::min(), std::numeric_limits<int>::max() ) );
64
65 BOOST_CHECK_EQUAL( strZero, "0 0" );
66
67#ifdef EESCHEMA
68 BOOST_CHECK_EQUAL( str, "12.3456 5252.5252" );
69 BOOST_CHECK_EQUAL( strNeg, "-12.3456 -5252.5252" );
70 BOOST_CHECK_EQUAL( strMax, "-214748.3648 214748.3647" );
71 BOOST_CHECK_EQUAL( strOddNeg, "-35 0" );
72#elif GERBVIEW
73 BOOST_CHECK_EQUAL( str, "1.23456 525.25252" );
74 BOOST_CHECK_EQUAL( strNeg, "-1.23456 -525.25252" );
75 BOOST_CHECK_EQUAL( strMax, "-21474.83648 21474.83647" );
76 BOOST_CHECK_EQUAL( strOddNeg, "-3.5 0" );
77#elif PCBNEW
78 BOOST_CHECK_EQUAL( str, "0.123456 52.525252" );
79 BOOST_CHECK_EQUAL( strNeg, "-0.123456 -52.525252" );
80 BOOST_CHECK_EQUAL( strMax, "-2147.483648 2147.483647" );
81 BOOST_CHECK_EQUAL( strOddNeg, "-0.35 0" );
82#endif
83
84}
85
86
87BOOST_AUTO_TEST_SUITE_END()
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:108
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:139
BOOST_AUTO_TEST_CASE(wxPointUnitFormat)
Declares a struct as the Boost test fixture.