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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 */
20
21#include <boost/test/unit_test.hpp>
22
24
25#include <wx/file.h>
26#include <wx/filename.h>
27
28
29BOOST_AUTO_TEST_SUITE( JobsOutputArchive )
30
31
32
37{
38 explicit ScopedTempDir( const wxString& aTag )
39 {
40 wxFileName fn;
41 fn.AssignDir( wxFileName::GetTempDir() );
42 fn.AppendDir( wxString::Format( wxS( "kicad_qa_%s_%p" ), aTag, this ) );
43
44 BOOST_REQUIRE( wxFileName::Mkdir( fn.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
45 path = fn.GetPath();
46 }
47
49 {
50 if( !path.IsEmpty() && wxFileName::DirExists( path ) )
51 wxFileName::Rmdir( path, wxPATH_RMDIR_RECURSIVE );
52 }
53
54 wxString path;
55};
56
57
66BOOST_AUTO_TEST_CASE( NestedDestinationPathCreatesParents )
67{
68 ScopedTempDir base( wxS( "archive_nested" ) );
69
70 // Populate a temp source directory with a single file to be archived.
71 wxString srcDir = base.path + wxFileName::GetPathSeparator() + wxS( "src" );
72 BOOST_REQUIRE( wxFileName::Mkdir( srcDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
73
74 wxString srcFile = srcDir + wxFileName::GetPathSeparator() + wxS( "payload.txt" );
75 {
76 wxFile f;
77 BOOST_REQUIRE( f.Create( srcFile, true ) );
78 f.Write( wxS( "hello" ) );
79 }
80
81 // Destination uses two layers of nesting that do not yet exist.
82 wxString nestedDir = base.path + wxFileName::GetPathSeparator() + wxS( "level1" )
83 + wxFileName::GetPathSeparator() + wxS( "level2" );
84 wxString outPath = nestedDir + wxFileName::GetPathSeparator() + wxS( "archive.zip" );
85
86 BOOST_REQUIRE( !wxFileName::DirExists( nestedDir ) );
87
88 JOBS_OUTPUT_ARCHIVE archive;
89 archive.SetOutputPath( outPath );
90
91 std::vector<wxString> noOverwriteList;
92 std::vector<JOB_OUTPUT> outputs;
93 std::optional<wxString> resolved;
94
95 bool ok = archive.HandleOutputs( srcDir, nullptr, noOverwriteList, outputs, resolved );
96
97 BOOST_CHECK_MESSAGE( ok, "Archive job should succeed with a nested destination path." );
98 BOOST_CHECK_MESSAGE( wxFileName::DirExists( nestedDir ),
99 "Nested parent directory should have been created." );
100 BOOST_REQUIRE( resolved.has_value() );
101 BOOST_CHECK( wxFileName::FileExists( resolved.value() ) );
102}
103
104
109BOOST_AUTO_TEST_CASE( ExistingDestinationStillWorks )
110{
111 ScopedTempDir base( wxS( "archive_existing" ) );
112
113 wxString srcDir = base.path + wxFileName::GetPathSeparator() + wxS( "src" );
114 BOOST_REQUIRE( wxFileName::Mkdir( srcDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
115
116 wxString srcFile = srcDir + wxFileName::GetPathSeparator() + wxS( "payload.txt" );
117 {
118 wxFile f;
119 BOOST_REQUIRE( f.Create( srcFile, true ) );
120 f.Write( wxS( "hello" ) );
121 }
122
123 wxString outPath = base.path + wxFileName::GetPathSeparator() + wxS( "archive.zip" );
124
125 JOBS_OUTPUT_ARCHIVE archive;
126 archive.SetOutputPath( outPath );
127
128 std::vector<wxString> noOverwriteList;
129 std::vector<JOB_OUTPUT> outputs;
130 std::optional<wxString> resolved;
131
132 bool ok = archive.HandleOutputs( srcDir, nullptr, noOverwriteList, outputs, resolved );
133
134 BOOST_CHECK( ok );
135 BOOST_REQUIRE( resolved.has_value() );
136 BOOST_CHECK( wxFileName::FileExists( resolved.value() ) );
137}
138
139
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")