KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_altium_project_variants.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
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, see <https://www.gnu.org/licenses/>.
18 */
19
21
23
24#include <wx/filefn.h>
25#include <wx/filename.h>
26
27
28BOOST_AUTO_TEST_SUITE( AltiumProjectVariants )
29
30
31BOOST_AUTO_TEST_CASE( ParseVariationFields )
32{
34 wxS( "Designator=R1|UniqueId=ROOT\\SHEET\\ABCDEFGH|Kind=0|AlternatePart=RES_ALT|Comment=10k" ) );
35
36 BOOST_CHECK_EQUAL( entry.designator, wxS( "R1" ) );
37
38 // Only the final backslash-delimited path segment is the component's own unique id
39 BOOST_CHECK_EQUAL( entry.uniqueId, wxS( "ABCDEFGH" ) );
40 BOOST_CHECK_EQUAL( entry.kind, 0 );
41 BOOST_CHECK_EQUAL( entry.alternateFields[wxS( "LibReference" )], wxS( "RES_ALT" ) );
42 BOOST_CHECK_EQUAL( entry.alternateFields[wxS( "Comment" )], wxS( "10k" ) );
43}
44
45
46BOOST_AUTO_TEST_CASE( ParseVariationBackslashBeforeSeparator )
47{
48 // A UniqueId path ending in a backslash sits right before the '|', so wxSplit's default
49 // escape eats the separator and Kind is swallowed, leaving the entry read back as fitted
51 ParseVariationString( wxS( "Designator=R1|UniqueId=ROOT\\SHEET\\|Kind=1" ) );
52
53 BOOST_CHECK_EQUAL( entry.designator, wxS( "R1" ) );
54 BOOST_CHECK_EQUAL( entry.kind, 1 );
55 BOOST_CHECK_EQUAL( entry.uniqueId, wxS( "" ) );
56}
57
58
59BOOST_AUTO_TEST_CASE( ParseParametersFromRelativePath )
60{
61 wxFileName projectFile( wxString::FromUTF8( KI_TEST::GetTestDataRootDir() )
62 + wxS( "pcbnew/plugins/altium/issue24456/Fastino_Ground_Isolator.PrjPcb" ) );
63
64 const wxString previousCwd = wxGetCwd();
65
66 BOOST_REQUIRE( wxSetWorkingDirectory( projectFile.GetPath() ) );
67
68 // wxFileConfig anchors a relative name at the home directory, so an unanchored name reaches
69 // it as a path that does not exist and every section goes missing without an error
70 std::map<wxString, wxString> parameters =
71 ParseAltiumProjectParameters( projectFile.GetFullName() );
72
73 wxSetWorkingDirectory( previousCwd );
74
75 BOOST_CHECK_EQUAL( parameters[wxS( "PCB_REVISION" )], wxS( "A" ) );
76}
77
78
std::map< wxString, wxString > ParseAltiumProjectParameters(const wxString &aPrjPcbPath)
Parse all [ParameterN] sections from an Altium .PrjPcb project file.
ALTIUM_VARIANT_ENTRY ParseVariationString(const wxString &aValue)
Parse a single pipe-delimited Altium "Variation" string into its component entry.
std::string GetTestDataRootDir()
A single component variation within an Altium project variant.
int kind
wxString uniqueId
wxString designator
std::map< wxString, wxString > alternateFields
BOOST_AUTO_TEST_CASE(ParseVariationFields)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")