KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_jobs_output_archive.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 2
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
23
24#include <wx/file.h>
25#include <wx/filename.h>
26
27
28BOOST_AUTO_TEST_SUITE( JobsOutputArchive )
29
30
31
36{
37 explicit ScopedTempDir( const wxString& aTag )
38 {
39 wxFileName fn;
40 fn.AssignDir( wxFileName::GetTempDir() );
41 fn.AppendDir( wxString::Format( wxS( "kicad_qa_%s_%p" ), aTag, this ) );
42
43 BOOST_REQUIRE( wxFileName::Mkdir( fn.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
44 path = fn.GetPath();
45 }
46
48 {
49 if( !path.IsEmpty() && wxFileName::DirExists( path ) )
50 wxFileName::Rmdir( path, wxPATH_RMDIR_RECURSIVE );
51 }
52
53 wxString path;
54};
55
56
65BOOST_AUTO_TEST_CASE( NestedDestinationPathCreatesParents )
66{
67 ScopedTempDir base( wxS( "archive_nested" ) );
68
69 // Populate a temp source directory with a single file to be archived.
70 wxString srcDir = base.path + wxFileName::GetPathSeparator() + wxS( "src" );
71 BOOST_REQUIRE( wxFileName::Mkdir( srcDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
72
73 wxString srcFile = srcDir + wxFileName::GetPathSeparator() + wxS( "payload.txt" );
74 {
75 wxFile f;
76 BOOST_REQUIRE( f.Create( srcFile, true ) );
77 f.Write( wxS( "hello" ) );
78 }
79
80 // Destination uses two layers of nesting that do not yet exist.
81 wxString nestedDir = base.path + wxFileName::GetPathSeparator() + wxS( "level1" )
82 + wxFileName::GetPathSeparator() + wxS( "level2" );
83 wxString outPath = nestedDir + wxFileName::GetPathSeparator() + wxS( "archive.zip" );
84
85 BOOST_REQUIRE( !wxFileName::DirExists( nestedDir ) );
86
87 JOBS_OUTPUT_ARCHIVE archive;
88 archive.SetOutputPath( outPath );
89
90 std::vector<wxString> noOverwriteList;
91 std::vector<JOB_OUTPUT> outputs;
92 std::optional<wxString> resolved;
93
94 bool ok = archive.HandleOutputs( srcDir, nullptr, noOverwriteList, outputs, resolved );
95
96 BOOST_CHECK_MESSAGE( ok, "Archive job should succeed with a nested destination path." );
97 BOOST_CHECK_MESSAGE( wxFileName::DirExists( nestedDir ),
98 "Nested parent directory should have been created." );
99 BOOST_REQUIRE( resolved.has_value() );
100 BOOST_CHECK( wxFileName::FileExists( resolved.value() ) );
101}
102
103
108BOOST_AUTO_TEST_CASE( ExistingDestinationStillWorks )
109{
110 ScopedTempDir base( wxS( "archive_existing" ) );
111
112 wxString srcDir = base.path + wxFileName::GetPathSeparator() + wxS( "src" );
113 BOOST_REQUIRE( wxFileName::Mkdir( srcDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
114
115 wxString srcFile = srcDir + wxFileName::GetPathSeparator() + wxS( "payload.txt" );
116 {
117 wxFile f;
118 BOOST_REQUIRE( f.Create( srcFile, true ) );
119 f.Write( wxS( "hello" ) );
120 }
121
122 wxString outPath = base.path + wxFileName::GetPathSeparator() + wxS( "archive.zip" );
123
124 JOBS_OUTPUT_ARCHIVE archive;
125 archive.SetOutputPath( outPath );
126
127 std::vector<wxString> noOverwriteList;
128 std::vector<JOB_OUTPUT> outputs;
129 std::optional<wxString> resolved;
130
131 bool ok = archive.HandleOutputs( srcDir, nullptr, noOverwriteList, outputs, resolved );
132
133 BOOST_CHECK( ok );
134 BOOST_REQUIRE( resolved.has_value() );
135 BOOST_CHECK( wxFileName::FileExists( resolved.value() ) );
136}
137
138
bool HandleOutputs(const wxString &aBaseTempPath, PROJECT *aProject, const std::vector< wxString > &aPathsWithOverwriteDisallowed, const std::vector< JOB_OUTPUT > &aOutputsToHandle, std::optional< wxString > &aResolvedOutputPath) override
void SetOutputPath(const wxString &aPath)
Definition jobs_output.h:56
Scoped temporary directory used by the tests below.
ScopedTempDir(const wxString &aTag)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(NestedDestinationPathCreatesParents)
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24162.
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")