KiCad PCB EDA Suite
test_altium_parser_sch.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) 2021 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
30
32
33// Function declarations of private methods to test
34int ReadKiCadUnitFrac( const std::map<wxString, wxString>& aProps,
35 const wxString& aKey );
36
37
39{
41};
42
43
47BOOST_FIXTURE_TEST_SUITE( AltiumParserSch, ALTIUM_PARSER_SCH_FIXTURE )
48
50{
51 wxString input;
52 wxString input_frac;
54};
55
59static const std::vector<ALTIUM_TO_KICAD_UNIT_FRAC_CASE> altium_to_kicad_unit_frac = {
60 // Some simple values
61 { "0", "0", 0 },
62 { "1", "0", 2540 },
63 { "2", "0", 5080 },
64 { "-1", "0", -2540 },
65 { "-2", "0", -5080 },
66 // Decimal Places
67 { "0", "1", 0 },
68 { "0", "10", 0 },
69 { "0", "100", 0 },
70 { "0", "1000", 30 },
71 { "0", "10000", 250 },
72 { "1", "10000", 2790 },
73 { "0", "-1", 0 },
74 { "0", "-10", 0 },
75 { "0", "-100", 0 },
76 { "0", "-1000", -30 },
77 { "0", "-10000", -250 },
78 { "-1", "-10000", -2790 },
79 // Edge Cases
80 // Clamp bigger values
81 // imperial rounded units as input
82 // metric rounded units as input
83};
84
88BOOST_AUTO_TEST_CASE( PropertiesReadKiCadUnitFracConversation )
89{
90 for( const auto& c : altium_to_kicad_unit_frac )
91 {
93 wxString::Format( wxT( "%s FRAC %s -> %i" ), c.input, c.input_frac, c.exp_result ) )
94 {
95 std::map<wxString, wxString> properties = { { "TEST", c.input },
96 { "TEST_FRAC", c.input_frac } };
97
98 int result = ReadKiCadUnitFrac( properties, "TEST" );
99
100 // These are all valid
101 BOOST_CHECK_EQUAL( result, c.exp_result );
102 }
103 }
104}
105
106
107BOOST_AUTO_TEST_SUITE_END()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Declares the struct as the Boost test fixture.
static const std::vector< ALTIUM_TO_KICAD_UNIT_FRAC_CASE > altium_to_kicad_unit_frac
A list of valid internal unit conversation factors.
int ReadKiCadUnitFrac(const std::map< wxString, wxString > &aProps, const wxString &aKey)
BOOST_AUTO_TEST_CASE(PropertiesReadKiCadUnitFracConversation)
Test conversation from Altium internal units into KiCad internal units using properties with FRAC.
#define BOOST_TEST_CONTEXT(A)