KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_backup_settings.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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25
27
28#include <pgm_base.h>
32
33#include <json_common.h>
34#include <wx/filename.h>
35
36
37BOOST_AUTO_TEST_SUITE( BackupSettings )
38
39
40// Verify the new auto_backup.format and auto_backup.location parameters round-trip
41// through the JSON_SETTINGS persistence layer. PARAM_ENUM serializes enums as
42// integers; this test exercises both directions.
43BOOST_AUTO_TEST_CASE( BackupFormatLocationRoundTrip )
44{
46
47 // Set non-default values.
48 cs.m_Backup.format = BACKUP_FORMAT::ZIP;
49 cs.m_Backup.location = BACKUP_LOCATION::USER_DIR;
50
51 // Force the parameters to write through to the in-memory JSON.
52 cs.Store();
53
54 // Mutate the struct, then load back from JSON to confirm values were persisted.
55 cs.m_Backup.format = BACKUP_FORMAT::INCREMENTAL;
56 cs.m_Backup.location = BACKUP_LOCATION::PROJECT_DIR;
57
58 cs.Load();
59
60 BOOST_CHECK( cs.m_Backup.format == BACKUP_FORMAT::ZIP );
61 BOOST_CHECK( cs.m_Backup.location == BACKUP_LOCATION::USER_DIR );
62}
63
64
65// Fresh-install defaults: new users get the new INCREMENTAL/PROJECT_DIR behavior.
66// Existing users are handled by the schema-5 -> schema-6 migration test below.
67BOOST_AUTO_TEST_CASE( BackupFormatLocationDefaults )
68{
70
71 cs.ResetToDefaults();
72
73 BOOST_CHECK( cs.m_Backup.format == BACKUP_FORMAT::INCREMENTAL );
74 BOOST_CHECK( cs.m_Backup.location == BACKUP_LOCATION::PROJECT_DIR );
75}
76
77
78// Pre-schema-6 configs unconditionally produced timestamped ZIP archives whenever a
79// save was eligible for backup. The migration must therefore write ZIP into upgraded
80// configs that lack auto_backup.format -- otherwise existing users with backups
81// enabled would silently lose archive creation after the upgrade because the new
82// PARAM_ENUM default (INCREMENTAL) causes TriggerBackupIfNeeded() to short-circuit.
83BOOST_AUTO_TEST_CASE( SchemaFiveToSixPreservesArchiveBehavior )
84{
86
87 // Persist the in-memory params to the JSON tree so meta.version exists, then
88 // simulate a schema-5 config: drop the auto_backup subtree entirely (matching what
89 // a real pre-schema-6 file would contain) and rewind meta.version.
90 cs.Store();
91
92 JSON_SETTINGS_INTERNALS* internals = cs.Internals();
93
94 if( internals->contains( nlohmann::json::json_pointer( "/auto_backup" ) ) )
95 internals->erase( "auto_backup" );
96
97 cs.Set<int>( "meta.version", 5 );
98
99 BOOST_REQUIRE( cs.Migrate() );
100
101 // Re-load params from the migrated JSON so m_Backup reflects what the migration wrote.
102 cs.Load();
103
104 BOOST_CHECK( cs.m_Backup.format == BACKUP_FORMAT::ZIP );
105 BOOST_CHECK( cs.m_Backup.location == BACKUP_LOCATION::PROJECT_DIR );
106}
107
108
109// If a schema-5 config somehow already has an auto_backup.format key, the migration
110// must respect it rather than overwriting the user's choice.
111BOOST_AUTO_TEST_CASE( SchemaFiveToSixRespectsExistingFormat )
112{
114
115 cs.Store();
116
117 cs.Set<int>( "auto_backup.format", static_cast<int>( BACKUP_FORMAT::INCREMENTAL ) );
118 cs.Set<int>( "meta.version", 5 );
119
120 BOOST_REQUIRE( cs.Migrate() );
121
122 cs.Load();
123
124 BOOST_CHECK( cs.m_Backup.format == BACKUP_FORMAT::INCREMENTAL );
125}
126
127
@ ZIP
Zip archive snapshots; autosave uses recovery files.
@ INCREMENTAL
Git-based local history (default)
@ USER_DIR
Under the KiCad user data directory.
@ PROJECT_DIR
Inside the project directory (default)
see class PGM_BASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(BackupFormatLocationRoundTrip)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
struct DROP_TABLE cs
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()