KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_env_paths.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
22#include <env_paths.h>
23
24#include <wx/filename.h>
25
26
27BOOST_AUTO_TEST_SUITE( EnvPaths )
28
29
30BOOST_AUTO_TEST_CASE( MakeRelativePathToProject )
31{
32#ifdef __WINDOWS__
33 const wxString root = wxS( "C:\\" );
34#else
35 const wxString root = wxS( "/" );
36#endif
37
38 const wxString project = root + wxS( "work/board/" );
39
40 BOOST_CHECK_EQUAL( MakeRelativePath( root + wxS( "work/board/out/fab.zip" ), project ), wxS( "out/fab.zip" ) );
41 BOOST_CHECK_EQUAL( MakeRelativePath( root + wxS( "work/board/out/" ), project ), wxS( "out/" ) );
42 BOOST_CHECK_EQUAL( MakeRelativePath( root + wxS( "work/sheets/a4.kicad_wks" ), project ),
43 wxS( "../sheets/a4.kicad_wks" ) );
44 BOOST_CHECK_EQUAL( MakeRelativePath( root + wxS( "work/board" ), project ), wxS( "." ) );
45 BOOST_CHECK_EQUAL( MakeRelativePath( wxS( "out/fab.zip" ), project ), wxS( "out/fab.zip" ) );
46 BOOST_CHECK_EQUAL( MakeRelativePath( root + wxS( "work/board/out/" ), wxEmptyString ),
47 root + wxS( "work/board/out/" ) );
48
49#ifdef __WINDOWS__
50 BOOST_CHECK_EQUAL( MakeRelativePath( wxS( "D:\\out\\fab.zip" ), project ), wxS( "D:\\out\\fab.zip" ) );
51#endif
52}
53
54
55BOOST_AUTO_TEST_CASE( NormalizePathForProjectPrecedence )
56{
57 wxFileName tempDir = wxFileName::DirName( wxFileName::GetTempDir() );
58 tempDir.Normalize( wxPATH_NORM_ALL & ~wxPATH_NORM_CASE );
59
60 const wxString temp = tempDir.GetPathWithSep();
61 const wxString sheet = temp + wxS( "sheets" ) + wxFileName::GetPathSeparator() + wxS( "a4.kicad_wks" );
62 const wxString project = temp + wxS( "board" );
63 const ENV_VAR_MAP envVars = { { wxS( "SHARED" ), ENV_VAR_ITEM( temp ) } };
64
65 BOOST_CHECK_EQUAL( NormalizePathForProject( project + wxS( "/out/fab.zip" ), &envVars, project, false ),
66 wxS( "out/fab.zip" ) );
67 BOOST_CHECK_EQUAL( NormalizePathForProject( sheet, &envVars, project, true ),
68 wxS( "${SHARED}/sheets/a4.kicad_wks" ) );
69 BOOST_CHECK_EQUAL( NormalizePathForProject( sheet, nullptr, project, false ), sheet );
70 BOOST_CHECK_EQUAL( NormalizePathForProject( sheet, nullptr, project, true ), wxS( "../sheets/a4.kicad_wks" ) );
71}
72
73
KiCad uses environment variables internally for determining the base paths for libraries,...
wxString MakeRelativePath(const wxString &aPath, const wxString &aBaseDir)
Express an absolute path relative to a base directory, stepping out with ".." when needed.
wxString NormalizePathForProject(const wxString &aPath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath, bool aAllowParentDirs)
Choose how to store a path the user picked for a project.
Helper functions to substitute paths with environmental variables.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(MakeRelativePathToProject)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")