KiCad PCB EDA Suite
test_format_units.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <base_units.h>
#include <eda_units.h>
#include <locale_io.h>
#include <algorithm>
#include <iostream>

Go to the source code of this file.

Classes

struct  UnitFixture
 

Functions

 BOOST_AUTO_TEST_CASE (VECTOR2IUnitFormat)
 Declares a struct as the Boost test fixture. More...
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( VECTOR2IUnitFormat  )

Declares a struct as the Boost test fixture.

Check formatting the point

Definition at line 47 of file test_format_units.cpp.

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, VECTOR2I( 123456, 52525252 ) );
60 std::string strZero = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( 0, 0 ) );
61 std::string strNeg = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( -123456, -52525252 ) );
62 std::string strOddNeg = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( -350000, -0 ) );
63 std::string strMax = EDA_UNIT_UTILS::FormatInternalUnits( iuScale, VECTOR2I( 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}
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:142
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References EDA_UNIT_UTILS::FormatInternalUnits(), gerbIUScale, pcbIUScale, and schIUScale.