KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
test_sch_screen.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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
26#include "eeschema_test_utils.h"
27
28#include <schematic.h>
30
31// Code under test
32#include <sch_screen.h>
33
36
38{
39protected:
40 wxFileName GetSchematicPath( const wxString& aRelativePath ) override;
41};
42
43
44wxFileName TEST_SCH_SCREEN_FIXTURE::GetSchematicPath( const wxString& aRelativePath )
45{
46 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
47
48 wxString path = fn.GetFullPath();
49 path += aRelativePath + wxT( "." ) + FILEEXT::KiCadSchematicFileExtension;
50
51 return wxFileName( path );
52}
53
54
58BOOST_FIXTURE_TEST_SUITE( SchScreen, TEST_SCH_SCREEN_FIXTURE )
59
60
61
64BOOST_AUTO_TEST_CASE( TestInProjectPath )
65{
66 LoadSchematic( "schematic_object_tests/not_shared_by_multiple_projects/"
67 "not_shared_by_multiple_projects" );
68
69 SCH_SCREEN testScreen( &m_schematic );
70 wxFileName testFn( m_schematic.RootScreen()->GetFileName() );
71
72 // File is in same folder as project.
73 testFn.SetName( "test" );
74 testScreen.SetFileName( testFn.GetFullPath() );
75 BOOST_CHECK( testScreen.InProjectPath() );
76
77 // File is in a sub-folder inside project.
78 testFn.AppendDir( "sch" );
79 testScreen.SetFileName( testFn.GetFullPath() );
80 BOOST_CHECK( testScreen.InProjectPath() );
81
82 // File is one folder below poject folder.
83 testFn.RemoveLastDir();
84 testFn.RemoveLastDir();
85 testScreen.SetFileName( testFn.GetFullPath() );
86 BOOST_CHECK( !testScreen.InProjectPath() );
87
88 // File is in a completely different path with the same folder depth.
89 testFn.SetPath( "/home/foo/kicad" );
90
91 wxFileName projectFn( m_schematic.Prj().GetProjectFullName() );
92
93 // Just in case someone has a build path with no subfolders.
94 BOOST_CHECK( testFn.GetDirCount() < projectFn.GetDirCount() );
95
96 int subDirCount = 1;
97
98 while( projectFn.GetDirCount() != testFn.GetDirCount() )
99 {
100 testFn.AppendDir( wxString::Format( wxS( "subdir%d" ), subDirCount ) );
101 subDirCount += 1;
102 }
103
104 testScreen.SetFileName( testFn.GetFullPath() );
105 BOOST_CHECK( !testScreen.InProjectPath() );
106}
107
108
112BOOST_AUTO_TEST_CASE( TestSharedByMultipleProjects )
113{
114 LoadSchematic( "schematic_object_tests/not_shared_by_multiple_projects/"
115 "not_shared_by_multiple_projects" );
116
117 const SCH_SCREEN* rootScreen = m_schematic.RootScreen();
118 BOOST_CHECK( !rootScreen->HasInstanceDataFromOtherProjects() );
119 BOOST_CHECK( rootScreen->InProjectPath() );
120}
121
122
A generic fixture for loading schematics and associated settings for qa tests.
bool HasInstanceDataFromOtherProjects() const
Check symbols for instance data from other projects.
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:120
bool InProjectPath() const
Check if the schematic file is in the current project path.
wxFileName GetSchematicPath(const wxString &aRelativePath) override
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(TestInProjectPath)
Declare the test suite.
Test utilities for timestamps.
Definition of file extensions used in Kicad.