KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_database_value.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#include <boost/test/unit_test.hpp>
21
23
24BOOST_AUTO_TEST_SUITE( DatabaseValue )
25
26
27BOOST_AUTO_TEST_CASE( DoublesRoundTrip )
28{
29 BOOST_CHECK_EQUAL( DatabaseValueToString( 4700000.0 ), "4700000" );
30 BOOST_CHECK_EQUAL( DatabaseValueToString( 10012345.0 ), "10012345" );
31 BOOST_CHECK_EQUAL( DatabaseValueToString( 1234.5678 ), "1234.5678" );
34}
35
36
37BOOST_AUTO_TEST_CASE( DecimalTextTrimmed )
38{
39 BOOST_CHECK_EQUAL( NormalizeDecimalText( "4700000.0000" ), "4700000" );
40 BOOST_CHECK_EQUAL( NormalizeDecimalText( "1.2300" ), "1.23" );
41 BOOST_CHECK_EQUAL( NormalizeDecimalText( "-0.500" ), "-0.5" );
43 BOOST_CHECK_EQUAL( NormalizeDecimalText( "0.000" ), "0" );
46 BOOST_CHECK_EQUAL( NormalizeDecimalText( ".5000" ), "0.5" );
47 BOOST_CHECK_EQUAL( NormalizeDecimalText( "-.25" ), "-0.25" );
48 BOOST_CHECK_EQUAL( NormalizeDecimalText( ".0000" ), "0" );
50 BOOST_CHECK_EQUAL( NormalizeDecimalText( "+1.50" ), "+1.5" );
51 BOOST_CHECK_EQUAL( NormalizeDecimalText( "1.2.300" ), "1.2.300" );
52 BOOST_CHECK_EQUAL( NormalizeDecimalText( "1-2.00" ), "1-2.00" );
54}
55
56
58{
59 BOOST_CHECK_EQUAL( DatabaseValueToString( std::monostate() ), "" );
62 BOOST_CHECK_EQUAL( DatabaseValueToString( int64_t( 9007199254740993 ) ), "9007199254740993" );
63 BOOST_CHECK_EQUAL( DatabaseValueToString( std::string( "1.2300" ) ), "1.2300" );
64}
65
66
std::string NormalizeDecimalText(const std::string &aText)
Trim redundant trailing zeros and a dangling decimal point from decimal text, for example "4700000....
std::string DatabaseValueToString(const DB_VALUE &aValue)
Convert a database value to the text KiCad stores for it.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_AUTO_TEST_CASE(DoublesRoundTrip)
BOOST_AUTO_TEST_SUITE_END()