KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_project_file.cpp File Reference

Tests for PROJECT_FILE class. More...

#include <qa_utils/wx_utils/unit_test_utils.h>
#include <project/project_file.h>
#include <settings/settings_manager.h>
#include <wildcards_and_files_ext.h>
#include <wx/filename.h>
#include <filesystem>
#include <fstream>

Go to the source code of this file.

Classes

class  PROJECT_FILE_TEST_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (SaveAsUpdatesTopLevelSheetNames)
 Test that SaveAs updates top-level sheet names when they match the old project name.
 
 BOOST_AUTO_TEST_CASE (LoadFixesStaleTopLevelSheetReferences)
 Test that LoadFromFile fixes stale top_level_sheets references after template copy.
 
 BOOST_AUTO_TEST_CASE (LoadPreservesValidTopLevelSheetReferences)
 Test that LoadFromFile does NOT modify top_level_sheets when references are already valid.
 
 BOOST_AUTO_TEST_CASE (LoadProjectByAbsolutePathIsStable)
 Test that loading a project by an absolute path is idempotent and does not evict (and free) the already-loaded project when the same project is loaded again by its absolute path.
 

Detailed Description

Tests for PROJECT_FILE class.

Definition in file test_project_file.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( LoadFixesStaleTopLevelSheetReferences )

Test that LoadFromFile fixes stale top_level_sheets references after template copy.

When a project is created from a template, files are renamed to match the new project name, but the .kicad_pro content still references the template's filenames. LoadFromFile should detect and correct these stale references.

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/22951

Definition at line 127 of file test_project_file.cpp.

References BOOST_CHECK_EQUAL(), PROJECT_FILE::GetTopLevelSheets(), SETTINGS_MANAGER::LoadProject(), name, SETTINGS_MANAGER::Prj(), and project.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( LoadPreservesValidTopLevelSheetReferences )

Test that LoadFromFile does NOT modify top_level_sheets when references are already valid.

Definition at line 184 of file test_project_file.cpp.

References BOOST_CHECK_EQUAL(), PROJECT_FILE::GetTopLevelSheets(), SETTINGS_MANAGER::LoadProject(), name, SETTINGS_MANAGER::Prj(), and project.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( LoadProjectByAbsolutePathIsStable )

Test that loading a project by an absolute path is idempotent and does not evict (and free) the already-loaded project when the same project is loaded again by its absolute path.

This guards the invariant relied upon by kicad-cli jobset run. The jobset runner loads the project once and holds the resulting PROJECT* across many kiface job calls. Each kiface board loader looks the project up by its absolute path and loads it if not already present. If the jobset runner had loaded the project by a relative path, the two paths would key different map entries, the second (active) load would evict and free the first, and the held PROJECT* would dangle, crashing in JOBS_OUTPUT_ARCHIVE::HandleOutputs.

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24474

Definition at line 248 of file test_project_file.cpp.

References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), SETTINGS_MANAGER::GetProject(), PROJECT::GetProjectFullName(), and SETTINGS_MANAGER::LoadProject().

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( SaveAsUpdatesTopLevelSheetNames )