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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21#include <local_history.h>
22#include <pgm_base.h>
23#include <sch_screen.h>
24#include <sch_sheet.h>
25#include <schematic.h>
29
30#include <vector>
31
32#include <wx/filename.h>
33#include <wx/stdpaths.h>
34
35BOOST_AUTO_TEST_SUITE( SchHistoryAutosave )
36
37template <typename T>
39{
40 SCOPED_SETTING_OVERRIDE( T& aRef, T aValue ) : m_ref( aRef ), m_original( aRef ) { aRef = aValue; }
42
45};
46
47
49{
51 {
52 wxString tempDir = wxStandardPaths::Get().GetTempDir();
53 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxT( "legacy_autosave.kicad_pro" );
54
55 m_settingsManager.LoadProject( projectPath.ToStdString() );
56 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
57 m_schematic->SetProject( &m_settingsManager.Prj() );
58 m_schematic->CreateDefaultScreens();
59 }
60
62 {
63 // Clean up the entire .history directory under the project
64 wxString historyPath = m_settingsManager.Prj().GetProjectPath() + wxS( ".history" );
65 wxFileName::Rmdir( historyPath, wxPATH_RMDIR_RECURSIVE );
66 }
67
69 std::unique_ptr<SCHEMATIC> m_schematic;
70};
71
72BOOST_FIXTURE_TEST_CASE( SavesLegacySheetIntoHistoryPath, HISTORY_AUTOSAVE_FIXTURE )
73{
74 std::vector<SCH_SHEET*> sheets = m_schematic->GetTopLevelSheets();
75 BOOST_REQUIRE( !sheets.empty() );
76
77 SCH_SHEET* sheet = sheets[0];
78 BOOST_REQUIRE( sheet->GetScreen() != nullptr );
79
80 sheet->SetFileName( wxS( "legacy/legacy.sch" ) );
81 sheet->GetScreen()->SetFileName( wxS( "legacy/legacy.sch" ) );
82
83 std::vector<HISTORY_FILE_DATA> fileData;
84 m_schematic->SaveToHistory( m_settingsManager.Prj().GetProjectPath(), fileData );
85
86 BOOST_REQUIRE_EQUAL( fileData.size(), 1 );
87
88 // SaveToHistory now emits project-relative paths -- the dispatcher joins them with
89 // the storage root (.history/ or the user data dir) at write time.
90 wxFileName saved( fileData[0].relativePath );
92 BOOST_CHECK( saved.GetPath().Contains( wxS( "legacy" ) ) );
93 BOOST_CHECK( !wxFileName( fileData[0].relativePath ).IsAbsolute() );
94 BOOST_CHECK( !fileData[0].content.empty() );
95 BOOST_CHECK( fileData[0].prettify );
96}
97
98// A clean sheet must still be captured while local history is active (backups on, format
99// incremental). The manual-save flow clears the dirty flag before the saver runs, so
100// filtering on it here would drop the whole snapshot -- the regression that left .history
101// stale for users on the Zip backup format (issue 24773).
102BOOST_FIXTURE_TEST_CASE( CleanSheetStillSavedWhenLocalHistoryEnabled, HISTORY_AUTOSAVE_FIXTURE )
103{
105 BOOST_REQUIRE( cs );
106
107 SCOPED_SETTING_OVERRIDE<bool> backupOn( cs->m_Backup.enabled, true );
110
111 std::vector<SCH_SHEET*> sheets = m_schematic->GetTopLevelSheets();
112 BOOST_REQUIRE( !sheets.empty() );
113
114 SCH_SHEET* sheet = sheets[0];
115 BOOST_REQUIRE( sheet->GetScreen() != nullptr );
116
117 sheet->SetFileName( wxS( "clean/clean.kicad_sch" ) );
118 sheet->GetScreen()->SetFileName( wxS( "clean/clean.kicad_sch" ) );
119 sheet->GetScreen()->SetContentModified( false );
120
121 std::vector<HISTORY_FILE_DATA> fileData;
122 m_schematic->SaveToHistory( m_settingsManager.Prj().GetProjectPath(), fileData );
123
124 BOOST_CHECK_EQUAL( fileData.size(), 1 );
125}
126
void SetContentModified(bool aModified=true)
Definition base_screen.h:55
AUTO_BACKUP m_Backup
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:562
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:44
void SetFileName(const wxString &aFilename)
Definition sch_sheet.h:376
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:139
@ INCREMENTAL
Git-based local history (default)
static const std::string LegacySchematicFileExtension
static wxString historyPath(const wxString &aProjectPath)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
BACKUP_FORMAT format
Backup format (incremental git history vs zip archives)
bool enabled
Automatically back up the project when files are saved.
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.