KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_job_export_sch_plot_path.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
22#include <qa_utils/file_utils.h>
24
25#include <cli/exit_codes.h>
27#include <jobs/job_export_bom.h>
31#include <jobs/job_sch_erc.h>
32#include <kiway.h>
33#include <locale_io.h>
34#include <reporter.h>
35
36#include <wx/filename.h>
37
38#include <filesystem>
39
40
41// A schematic PDF job whose output is a folder names the file after the schematic
42BOOST_AUTO_TEST_CASE( SchPlotJobOutputFolderGetsDefaultName )
43{
45
46 namespace fs = std::filesystem;
47
48 KI_TEST::SCOPED_TEMP_DIR outputDir( wxS( "kicad_sch_plot_folder" ) );
49
50 fs::path schematic = fs::path( KI_TEST::GetTestDataRootDir() ) / "eeschema" / "issue24217" / "issue24217.kicad_sch";
51
53 job.m_filename = wxString::FromUTF8( schematic.string().c_str() );
54
55 // A path such as ${KIPRJMOD}/ resolves to a folder with a trailing separator
56 job.SetConfiguredOutputPath( wxString::FromUTF8( outputDir.Path().string().c_str() )
57 + wxFileName::GetPathSeparator() );
58
59 EESCHEMA_JOBS_HANDLER handler( nullptr );
61 handler.SetReporter( &reporter );
62
64 BOOST_CHECK( fs::is_regular_file( outputDir.Path() / "issue24217.pdf" ) );
65}
66
67
68// ERC asks the kiway for CvPcb and runs without it
69class NO_FACE_KIWAY : public KIWAY
70{
71public:
73
74 KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true ) override { return nullptr; }
75};
76
77
78// Netlist, BOM and ERC jobs whose output is a folder also get their default file name
79BOOST_AUTO_TEST_CASE( SchJobsOutputFolderGetDefaultName )
80{
82
83 namespace fs = std::filesystem;
84
85 KI_TEST::SCOPED_TEMP_DIR outputDir( wxS( "kicad_sch_job_folder" ) );
86
87 fs::path schematic = fs::path( KI_TEST::GetTestDataRootDir() ) / "eeschema" / "issue24217" / "issue24217.kicad_sch";
88 wxString schPath = wxString::FromUTF8( schematic.string().c_str() );
89 wxString folder = wxString::FromUTF8( outputDir.Path().string().c_str() ) + wxFileName::GetPathSeparator();
90
92 JOB_EXPORT_BOM bomJob;
94 JOB_SCH_ERC ercJob;
95
96 netJob.m_filename = schPath;
97 bomJob.m_filename = schPath;
98 pyBomJob.m_filename = schPath;
99 ercJob.m_filename = schPath;
100 ercJob.m_exitCodeViolations = false;
101
102 NO_FACE_KIWAY kiway;
103 EESCHEMA_JOBS_HANDLER handler( &kiway );
105 handler.SetReporter( &reporter );
106
107 using HANDLER_FN = int ( EESCHEMA_JOBS_HANDLER::* )( JOB* );
108
109 std::vector<std::tuple<JOB*, HANDLER_FN, std::string>> cases = {
110 { &netJob, &EESCHEMA_JOBS_HANDLER::JobExportNetlist, "issue24217.net" },
111 { &bomJob, &EESCHEMA_JOBS_HANDLER::JobExportBom, "issue24217.csv" },
112 { &pyBomJob, &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, "issue24217-bom.xml" },
113 { &ercJob, &EESCHEMA_JOBS_HANDLER::JobSchErc, "issue24217-erc.rpt" }
114 };
115
116 for( auto& [job, run, expected] : cases )
117 {
119 {
120 job->SetConfiguredOutputPath( folder );
121
122 BOOST_CHECK_EQUAL( ( handler.*run )( job ), CLI::EXIT_CODES::OK );
123 BOOST_CHECK_MESSAGE( fs::is_regular_file( outputDir.Path() / expected ), reporter.GetMessages() );
124 }
125 }
126}
Handle Eeschema job dispatches.
void SetReporter(REPORTER *aReporter)
wxString m_filename
bool m_exitCodeViolations
Definition job_rc.h:52
wxString m_filename
Definition job_rc.h:47
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:184
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition job.cpp:181
FACE_T
Known KIFACE implementations.
Definition kiway.h:354
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:53
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
Definition file_utils.h:61
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true) override
Return the KIFACE* given a FACE_T.
A wrapper for reporting to a wxString object.
Definition reporter.h:242
#define KFCTL_STANDALONE
Running as a standalone Top.
Definition kiway.h:174
static const int OK
Definition exit_codes.h:30
std::string GetTestDataRootDir()
std::vector< FAB_LAYER_COLOR > dummy
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_AUTO_TEST_CASE(SchPlotJobOutputFolderGetsDefaultName)
IbisParser parser & reporter
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")