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 std::set<wxString> firstNames;
77
78 for( LIB_SYMBOL* symbol : first )
79 {
80 firstNames.insert( symbol->GetName() );
81 delete symbol;
82 }
83
84 for( LIB_SYMBOL* symbol : second )
85 {
86 BOOST_CHECK( firstNames.count( symbol->GetName() ) );
87 delete symbol;
88 }
89}
90
91
102BOOST_AUTO_TEST_CASE( FieldMappedDescriptionMatchesShownDescription )
103{
104 const std::string dblPath =
105 KI_TEST::GetTestDataRootDir() + "dblib/qa_dblib_field_description.kicad_dbl";
106
107 LIBRARY_MANAGER manager;
108 SYMBOL_LIBRARY_ADAPTER adapter( manager );
109
110 SCH_IO_DATABASE plugin;
111 plugin.SetLibraryManagerAdapter( &adapter );
112
113 LIB_SYMBOL* symbol = nullptr;
114
115 try
116 {
117 symbol = plugin.LoadSymbol( dblPath, wxS( "RES-001" ), nullptr );
118 }
119 catch( const IO_ERROR& ioe )
120 {
121 // The database connection needs a working ODBC SQLite driver; skip when it is unavailable
122 // so the test does not fail spuriously on minimal CI images.
123 BOOST_TEST_MESSAGE( "Skipping: database library unavailable: " + ioe.What().ToStdString() );
124 return;
125 }
126
127 BOOST_REQUIRE( symbol );
128
129 std::unique_ptr<LIB_SYMBOL> owned( symbol );
130
131 const wxString liveDescription = owned->GetField( FIELD_T::DESCRIPTION )->GetShownText( FOR_GUI );
132
133 // The database row for RES-001 carries a non-empty Description.
134 BOOST_REQUIRE( !liveDescription.IsEmpty() );
135
136 // The chooser tree / search path must agree with the live field the details panel shows.
137 BOOST_CHECK_EQUAL( owned->GetShownDescription( FOR_GUI ), liveDescription );
138 BOOST_CHECK_EQUAL( owned->GetDesc(), liveDescription );
139
140 // The search-term cache feeds chooser filtering and is built from the shown description, so it
141 // must reflect the database value too.
142 const std::vector<SEARCH_TERM>& terms = owned->GetSearchTerms();
143 bool descriptionTermPresent = std::any_of( terms.begin(), terms.end(),
144 [&]( const SEARCH_TERM& aTerm )
145 {
146 return aTerm.Text == liveDescription;
147 } );
148
149 BOOST_CHECK( descriptionTermPresent );
150}
151
152
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:119
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...
@ FOR_GUI
Definition common.h:89
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_AUTO_TEST_CASE(UnchangedDataReusesCache)
SCH_IO_DATABASE::cacheLib() must not rebuild its materialized LIB_SYMBOL cache when a re-query return...
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")