KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_kiway.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
21
22#include <cli/exit_codes.h>
23#include <kiway.h>
24#include <reporter.h>
25
26#include <wx/log.h>
27
28
29namespace
30{
31
32// Stands in for an install that is missing one kiface
33class MISSING_DSO_KIWAY : public KIWAY
34{
35public:
36 MISSING_DSO_KIWAY() :
38 {
39 }
40
41protected:
42 const wxString dso_search_path( FACE_T aFaceId ) override
43 {
44 return wxS( "/nonexistent/_missing.kiface" );
45 }
46};
47
48
49// wxLogBuffer would flush to a message box on some platforms
50class CAPTURE_LOG : public wxLog
51{
52public:
53 wxString m_text;
54
55protected:
56 void DoLogTextAtLevel( wxLogLevel aLevel, const wxString& aMsg ) override { m_text += aMsg; }
57};
58
59} // namespace
60
61
62BOOST_AUTO_TEST_SUITE( KiwayLoad )
63
64
65BOOST_AUTO_TEST_CASE( MissingKifaceIsReportedOnceNotThrown )
66{
67 MISSING_DSO_KIWAY kiway;
68 CAPTURE_LOG log;
70 wxLog* prevLog = wxLog::SetActiveTarget( &log );
71 KIFACE* kiface = nullptr;
72 KIWAY_PLAYER* player = nullptr;
73 wxString loadLog;
74 wxString openLogs[2];
75 int exitCode = CLI::EXIT_CODES::SUCCESS;
76
77 auto takeLog =
78 [&]()
79 {
80 wxString text = log.m_text;
81 log.m_text.clear();
82 return text;
83 };
84
85 BOOST_CHECK_NO_THROW( kiface = kiway.KiFACE( KIWAY::FACE_SCH ) );
86 loadLog = takeLog();
87
88 // Every explicit open answers, unlike the implicit lookup below
89 for( wxString& openLog : openLogs )
90 {
91 player = kiway.Player( FRAME_SCH, true );
92 openLog = takeLog();
93 }
94
95 BOOST_CHECK_NO_THROW( exitCode = kiway.ProcessJob( KIWAY::FACE_SCH, nullptr, &reporter ) );
96
97 wxLog::SetActiveTarget( prevLog );
98
99 BOOST_CHECK( kiface == nullptr );
100 BOOST_CHECK( player == nullptr );
101 BOOST_CHECK( loadLog.Contains( wxS( "Failed to load kiface library" ) ) );
102
103 for( const wxString& openLog : openLogs )
104 BOOST_CHECK_MESSAGE( openLog.Contains( wxS( "Application cannot start" ) ), "open was silent: " << openLog );
105
107 BOOST_CHECK( reporter.GetMessages().Contains( wxS( "_missing.kiface" ) ) );
108 BOOST_CHECK_MESSAGE( log.m_text.IsEmpty(), "second lookup logged again: " << log.m_text );
109}
110
111
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
@ FACE_SCH
eeschema DSO
Definition kiway.h:355
A wrapper for reporting to a wxString object.
Definition reporter.h:242
@ FRAME_SCH
Definition frame_type.h:30
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
Definition kiway.h:175
static const int SUCCESS
Definition exit_codes.h:29
static const int ERR_UNKNOWN
Definition exit_codes.h:32
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
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_SUITE_END()
IbisParser parser & reporter