|
KiCad PCB EDA Suite
|
Tests for NESTED_SETTINGS and ReleaseNestedSettings behavior. More...
#include <qa_utils/wx_utils/unit_test_utils.h>#include <settings/nested_settings.h>#include <settings/parameters.h>#include <settings/settings_manager.h>#include <settings/json_settings_internals.h>#include <wx/filename.h>#include <wx/stdpaths.h>#include <wx/utils.h>#include <fstream>Go to the source code of this file.
Classes | |
| class | TEST_JSON_SETTINGS |
| A test-accessible JSON_SETTINGS subclass that exposes the protected m_modified flag. More... | |
| class | TEST_NESTED_SETTINGS |
| A minimal nested settings subclass for testing. More... | |
| class | NESTED_SETTINGS_TEST_FIXTURE |
| class | MIGRATING_NESTED_SETTINGS |
| A nested settings subclass that migrates a v0 block to v1 by writing a key directly into the JSON, without any registered param reflecting the change. More... | |
| class | DISK_SETTINGS |
| Verify that SaveToFile does not rewrite the on-disk file when its serialized contents match what already exists. More... | |
| class | DISK_PARENT_SETTINGS |
| A disk-backed parent that carries a nested setting, mirroring the project file / nested board or ERC settings relationship. More... | |
Functions | |
| BOOST_AUTO_TEST_CASE (ReleaseDoesNotMarkParentModified) | |
| Verify that releasing nested settings does not mark the parent as modified. | |
| BOOST_AUTO_TEST_CASE (ExplicitSaveDetectsModifications) | |
| Verify that explicitly saving while the nested settings are alive correctly detects modifications. | |
| BOOST_AUTO_TEST_CASE (ReleaseFlushesDataToParent) | |
| Verify that releasing nested settings still flushes the data to the parent JSON. | |
| BOOST_AUTO_TEST_CASE (AbsentDefaultIsModifiedWhenNotResetIfMissing) | |
| When missing keys are not reset to their defaults on load (as for board design settings), an absent param holding the default value is NOT a faithful round-trip of the file, so it must count as modified and be flushed. | |
| BOOST_AUTO_TEST_CASE (MigrationFlushesToParent) | |
| A migration that mutates only the JSON (not a registered param) must still flush to the parent, otherwise the upgraded content is silently lost. | |
| BOOST_AUTO_TEST_CASE (SaveToFileSkipsWriteWhenContentsMatch) | |
| BOOST_AUTO_TEST_CASE (ReleasedNestedChangePersistsToDisk) | |
| Verify that a genuine change to a nested setting survives the release-then-save sequence that happens on editor close. | |
| BOOST_AUTO_TEST_CASE (DefaultFillDoesNotChurnExistingFile) | |
| Reproduce issue #24402 class 1 directly: an older project file is missing a newly-introduced nested default param. | |
Tests for NESTED_SETTINGS and ReleaseNestedSettings behavior.
Definition in file test_nested_settings.cpp.
| BOOST_AUTO_TEST_CASE | ( | AbsentDefaultIsModifiedWhenNotResetIfMissing | ) |
When missing keys are not reset to their defaults on load (as for board design settings), an absent param holding the default value is NOT a faithful round-trip of the file, so it must count as modified and be flushed.
Otherwise a user reset-to-default could be silently dropped.
Definition at line 229 of file test_nested_settings.cpp.
References BOOST_CHECK_EQUAL().
| BOOST_AUTO_TEST_CASE | ( | DefaultFillDoesNotChurnExistingFile | ) |
Reproduce issue #24402 class 1 directly: an older project file is missing a newly-introduced nested default param.
Opening and closing the editor (load + release the nested settings with no user change) must not materialize that default into the parent and must not rewrite the file.
Definition at line 469 of file test_nested_settings.cpp.
References BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), JSON_SETTINGS::Internals(), JSON_SETTINGS::ReleaseNestedSettings(), JSON_SETTINGS::SaveToFile(), and JSON_SETTINGS::SetManager().
| BOOST_AUTO_TEST_CASE | ( | ExplicitSaveDetectsModifications | ) |
Verify that explicitly saving while the nested settings are alive correctly detects modifications.
This ensures the fix doesn't break the normal save path.
Definition at line 161 of file test_nested_settings.cpp.
References BOOST_CHECK_EQUAL().
| BOOST_AUTO_TEST_CASE | ( | MigrationFlushesToParent | ) |
A migration that mutates only the JSON (not a registered param) must still flush to the parent, otherwise the upgraded content is silently lost.
Guards against detecting nested changes solely through param Store() (see #24402 review).
Definition at line 289 of file test_nested_settings.cpp.
References BOOST_CHECK_EQUAL().
| BOOST_AUTO_TEST_CASE | ( | ReleasedNestedChangePersistsToDisk | ) |
Verify that a genuine change to a nested setting survives the release-then-save sequence that happens on editor close.
The nested object flushes its change into the parent's in-memory JSON and is then released; a subsequent parent save must still write that change to disk even though the parent's modified heuristic is not set by the release. Regression guard for the data-loss risk that accompanies suppressing the project rewrite in #24402.
Definition at line 422 of file test_nested_settings.cpp.
References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), JSON_SETTINGS::ReleaseNestedSettings(), JSON_SETTINGS::SaveToFile(), and JSON_SETTINGS::SetManager().
| BOOST_AUTO_TEST_CASE | ( | ReleaseDoesNotMarkParentModified | ) |
Verify that releasing nested settings does not mark the parent as modified.
This is the core regression test for https://gitlab.com/kicad/code/kicad/-/issues/22972 and https://gitlab.com/kicad/code/kicad/-/issues/24402. When a nested settings object is destroyed during editor close, round-trip serialization differences (such as new default params not present in the project file) would falsely mark the parent project file as modified, causing the .kicad_pro timestamp to update even when the user discarded changes.
Definition at line 122 of file test_nested_settings.cpp.
References BOOST_AUTO_TEST_CASE(), BOOST_CHECK_EQUAL(), and BOOST_CHECK_MESSAGE().
| BOOST_AUTO_TEST_CASE | ( | ReleaseFlushesDataToParent | ) |
Verify that releasing nested settings still flushes the data to the parent JSON.
Even though the parent is not marked modified, the in-memory state should be updated.
Definition at line 197 of file test_nested_settings.cpp.
References BOOST_CHECK_EQUAL().
| BOOST_AUTO_TEST_CASE | ( | SaveToFileSkipsWriteWhenContentsMatch | ) |
Definition at line 340 of file test_nested_settings.cpp.
References BOOST_CHECK_MESSAGE(), BOOST_REQUIRE(), DISK_SETTINGS::ForceModified(), DISK_SETTINGS::m_value, result, JSON_SETTINGS::SaveToFile(), and JSON_SETTINGS::SetManager().