KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_io_database.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 <algorithm>
21#include <memory>
22#include <set>
23#include <vector>
24
26
28#include <eda_pattern_match.h>
29#include <ki_exception.h>
30#include <lib_symbol.h>
34
35
36BOOST_AUTO_TEST_SUITE( SchIoDatabase )
37
38
39
53BOOST_AUTO_TEST_CASE( UnchangedDataReusesCache )
54{
55 LIBRARY_MANAGER manager;
56 SYMBOL_LIBRARY_ADAPTER adapter( manager );
57
58 SCH_IO_DATABASE plugin;
59 plugin.SetLibraryManagerAdapter( &adapter );
60
61 wxString libPath( QA_DBLIB_SETTINGS_PATH );
62
63 std::vector<LIB_SYMBOL*> first;
64 BOOST_REQUIRE_NO_THROW( plugin.EnumerateSymbolLib( first, libPath ) );
65 BOOST_REQUIRE( !first.empty() );
66
67 // Defeat the age throttle so the next call actually re-queries and compares signatures rather
68 // than short-circuiting on the cache timestamp.
69 plugin.Settings()->m_Cache.max_age = 0;
70
71 std::vector<LIB_SYMBOL*> second;
72 BOOST_REQUIRE_NO_THROW( plugin.EnumerateSymbolLib( second, libPath ) );
73
74 BOOST_REQUIRE_EQUAL( first.size(), second.size() );
75
76 // Identical data must yield the same materialized symbols. Pointer identity proves the cache
77 // was reused; a rebuild would hand back freshly allocated LIB_SYMBOLs.
78 std::set<LIB_SYMBOL*> firstSet( first.begin(), first.end() );
79
80 for( LIB_SYMBOL* symbol : second )
81 BOOST_CHECK( firstSet.count( symbol ) );
82}
83
84
95BOOST_AUTO_TEST_CASE( FieldMappedDescriptionMatchesShownDescription )
96{
97 const std::string dblPath =
98 KI_TEST::GetTestDataRootDir() + "dblib/qa_dblib_field_description.kicad_dbl";
99
100 LIBRARY_MANAGER manager;
101 SYMBOL_LIBRARY_ADAPTER adapter( manager );
102
103 SCH_IO_DATABASE plugin;
104 plugin.SetLibraryManagerAdapter( &adapter );
105
106 LIB_SYMBOL* symbol = nullptr;
107
108 try
109 {
110 symbol = plugin.LoadSymbol( dblPath, wxS( "RES-001" ), nullptr );
111 }
112 catch( const IO_ERROR& ioe )
113 {
114 // The database connection needs a working ODBC SQLite driver; skip when it is unavailable
115 // so the test does not fail spuriously on minimal CI images.
116 BOOST_TEST_MESSAGE( "Skipping: database library unavailable: " + ioe.What().ToStdString() );
117 return;
118 }
119
120 BOOST_REQUIRE( symbol );
121
122 std::unique_ptr<LIB_SYMBOL> owned( symbol );
123
124 const wxString liveDescription = owned->GetField( FIELD_T::DESCRIPTION )->GetShownText( false );
125
126 // The database row for RES-001 carries a non-empty Description.
127 BOOST_REQUIRE( !liveDescription.IsEmpty() );
128
129 // The chooser tree / search path must agree with the live field the details panel shows.
130 BOOST_CHECK_EQUAL( owned->GetShownDescription(), liveDescription );
131 BOOST_CHECK_EQUAL( owned->GetDesc(), liveDescription );
132
133 // The search-term cache feeds chooser filtering and is built from the shown description, so it
134 // must reflect the database value too.
135 const std::vector<SEARCH_TERM>& terms = owned->GetSearchTerms();
136 bool descriptionTermPresent = std::any_of( terms.begin(), terms.end(),
137 [&]( const SEARCH_TERM& aTerm )
138 {
139 return aTerm.Text == liveDescription;
140 } );
141
142 BOOST_CHECK( descriptionTermPresent );
143}
144
145
DATABASE_CACHE_SETTINGS m_Cache
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Define a library symbol object.
Definition lib_symbol.h:79
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins on ...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
DATABASE_LIB_SETTINGS * Settings() const
void SetLibraryManagerAdapter(SYMBOL_LIBRARY_ADAPTER *aAdapter) override
Some library plugins need to interface with other loaded libraries.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Abstract pattern-matching tool and implementations.
std::string GetTestDataRootDir()
int max_age
Max age of cached rows before they expire, in seconds.
A structure for storing weighted search terms.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
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_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_AUTO_TEST_CASE(UnchangedDataReusesCache)
SCH_IO_DATABASE::cacheLib() must not rebuild its materialized LIB_SYMBOL cache when a re-query return...
BOOST_CHECK_EQUAL(result, "25.4")