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 
24 #include <qa_utils/wx_utils/unit_test_utils.h>
25 
26 #include <base_units.h>
27 #include <locale_io.h>
28 
29 #include <algorithm>
30 #include <iostream>
31 
32 struct UnitFixture
33 {
34 };
35 
36 
37 /**
38  * Declares a struct as the Boost test fixture.
39  */
BOOST_FIXTURE_TEST_SUITE(UnitConversion,UnitFixture)40 BOOST_FIXTURE_TEST_SUITE( UnitConversion, UnitFixture )
41 
42 
43 /**
44  * Check formatting the point
45  */
46 BOOST_AUTO_TEST_CASE( wxPointUnitFormat )
47 {
48     LOCALE_IO toggle;
49     std::string str = FormatInternalUnits( wxPoint( 123456, 52525252 ) );
50     std::string strZero = FormatInternalUnits( wxPoint( 0, 0 ) );
51     std::string strNeg = FormatInternalUnits( wxPoint( -123456, -52525252 ) );
52     std::string strOddNeg = FormatInternalUnits( wxPoint( -350000, -0 ) );
53 
54     std::string strMax = FormatInternalUnits( wxPoint( std::numeric_limits<int>::min(),
55             std::numeric_limits<int>::max() ) );
56 
57     BOOST_CHECK_EQUAL( strZero, "0 0" );
58 
59 #ifdef EESCHEMA
60     BOOST_CHECK_EQUAL( str, "12.3456 5252.5252" );
61     BOOST_CHECK_EQUAL( strNeg, "-12.3456 -5252.5252" );
62     BOOST_CHECK_EQUAL( strMax, "-214748.3648 214748.3647" );
63     BOOST_CHECK_EQUAL( strOddNeg, "-35 0" );
64 #elif GERBVIEW
65     BOOST_CHECK_EQUAL( str, "1.23456 525.25252" );
66     BOOST_CHECK_EQUAL( strNeg, "-1.23456 -525.25252" );
67     BOOST_CHECK_EQUAL( strMax, "-21474.83648 21474.83647" );
68     BOOST_CHECK_EQUAL( strOddNeg, "-3.5 0" );
69 #elif PCBNEW
70     BOOST_CHECK_EQUAL( str, "0.123456 52.525252" );
71     BOOST_CHECK_EQUAL( strNeg, "-0.123456 -52.525252" );
72     BOOST_CHECK_EQUAL( strMax, "-2147.483648 2147.483647" );
73     BOOST_CHECK_EQUAL( strOddNeg, "-0.35 0" );
74 #endif
75 
76 }
77 
78 
79 BOOST_AUTO_TEST_SUITE_END()
80