KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_history_autosave_legacy.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 3
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/gpl-3.0.html
19 */
20
21#include <boost/test/unit_test.hpp>
22#include <sch_screen.h>
23#include <sch_sheet.h>
24#include <schematic.h>
27
28#include <vector>
29
30#include <wx/filename.h>
31#include <wx/stdpaths.h>
32
33BOOST_AUTO_TEST_SUITE( SchHistoryAutosave )
34
36{
38 {
39 wxString tempDir = wxStandardPaths::Get().GetTempDir();
40 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxT( "legacy_autosave.kicad_pro" );
41
42 m_settingsManager.LoadProject( projectPath.ToStdString() );
43 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
44 m_schematic->SetProject( &m_settingsManager.Prj() );
45 m_schematic->CreateDefaultScreens();
46 }
47
49 {
50 // Clean up the entire .history directory under the project
51 wxString historyPath = m_settingsManager.Prj().GetProjectPath() + wxS( ".history" );
52 wxFileName::Rmdir( historyPath, wxPATH_RMDIR_RECURSIVE );
53 }
54
56 std::unique_ptr<SCHEMATIC> m_schematic;
57};
58
59BOOST_FIXTURE_TEST_CASE( SavesLegacySheetIntoHistoryPath, HISTORY_AUTOSAVE_FIXTURE )
60{
61 std::vector<SCH_SHEET*> sheets = m_schematic->GetTopLevelSheets();
62 BOOST_REQUIRE( !sheets.empty() );
63
64 SCH_SHEET* sheet = sheets[0];
65 BOOST_REQUIRE( sheet->GetScreen() != nullptr );
66
67 sheet->SetFileName( wxS( "legacy/legacy.sch" ) );
68 sheet->GetScreen()->SetFileName( wxS( "legacy/legacy.sch" ) );
69
70 std::vector<wxString> savedFiles;
71 m_schematic->SaveToHistory( m_settingsManager.Prj().GetProjectPath(), savedFiles );
72
73 BOOST_REQUIRE_EQUAL( savedFiles.size(), 1 );
74
75 wxFileName saved( savedFiles[0] );
76 BOOST_CHECK( saved.FileExists() );
78 BOOST_CHECK( saved.GetPath().Contains( wxS( "legacy" ) ) );
79}
80
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void SetFileName(const wxString &aFilename)
Definition sch_sheet.h:382
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:145
static const std::string LegacySchematicFileExtension
static wxString historyPath(const wxString &aProjectPath)
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(SavesLegacySheetIntoHistoryPath, HISTORY_AUTOSAVE_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")
Definition of file extensions used in Kicad.