KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_remote_symbol_load_from_payload.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,
12 * but 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
28
30
31#include <lib_symbol.h>
33#include <sch_io/sch_io_mgr.h>
34
35#include <wx/filename.h>
36
37
38namespace
39{
40// LoadSymbol only reads, so the library is used in place from qa/data
41wxString symbolLibPath()
42{
43 return wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() )
44 + wxS( "remote_symbol_lib.kicad_sym" );
45}
46} // namespace
47
48
49BOOST_AUTO_TEST_SUITE( RemoteSymbolLoadFromPayload )
50
51
52BOOST_AUTO_TEST_CASE( CopiedSymbolSurvivesPluginDestruction )
53{
54 const wxString libPath = symbolLibPath();
55 std::unique_ptr<LIB_SYMBOL> symbol;
56
57 {
58 IO_RELEASER<SCH_IO> plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
59 BOOST_REQUIRE( plugin );
60
61 LIB_SYMBOL* loaded = plugin->LoadSymbol( libPath, wxS( "TestResistor" ) );
62 BOOST_REQUIRE( loaded );
63
64 // The fix for #23286: copy the symbol so it is independent of the
65 // plugin's cache, which is destroyed when the plugin goes out of scope.
66 symbol = std::make_unique<LIB_SYMBOL>( *loaded );
67 }
68
69 // Plugin and its cache have been destroyed. The copied symbol must still
70 // be valid and accessible without triggering a use-after-free.
71 BOOST_CHECK( symbol );
72 BOOST_CHECK( symbol->GetName() == wxS( "TestResistor" ) );
73}
74
75
76BOOST_AUTO_TEST_CASE( LoadSymbolReturnsNullForMissingName )
77{
78 const wxString libPath = symbolLibPath();
79
80 IO_RELEASER<SCH_IO> plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
81 BOOST_REQUIRE( plugin );
82
83 LIB_SYMBOL* loaded = plugin->LoadSymbol( libPath, wxS( "NonExistentSymbol" ) );
84 BOOST_CHECK( loaded == nullptr );
85}
86
87
Define a library symbol object.
Definition lib_symbol.h:114
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CopiedSymbolSurvivesPluginDestruction)