20#include <boost/test/unit_test.hpp>
42#include <wx/filename.h>
43#include <wx/stdpaths.h>
50std::string symbolPayload(
const char* aName )
53 + wxS(
"remote_symbol_lib.kicad_sym" );
55 wxFFile file( libPath, wxS(
"rb" ) );
56 BOOST_REQUIRE_MESSAGE( file.IsOpened(),
"Could not open " << libPath );
61 body.Replace( wxS(
"TestResistor" ), wxString::FromUTF8( aName ) );
63 return std::string( body.ToUTF8() );
67wxString sha256Hex(
const std::string& aPayload )
70 picosha2::hash256_hex_string( aPayload.begin(), aPayload.end(), hashHex );
71 return wxString::FromUTF8( hashHex.c_str() );
77 wxString
path = wxFileName::CreateTempFileName( wxS(
"remote-symbol-import" ) );
89 metadata.
api_base_url = wxString(
"https://provider.example.test/api" );
108 manifest.
part_id = wxString(
"acme-res-10k" );
112 const std::string symbolBlob = symbolPayload(
"R" );
114 symbol.
name = wxString(
"acme-res-10k.kicad_sym" );
115 symbol.
content_type = wxString(
"application/x-kicad-symbol" );
116 symbol.
size_bytes =
static_cast<long long>( symbolBlob.size() );
117 symbol.
sha256 = sha256Hex( symbolBlob );
118 symbol.
download_url = wxString(
"https://provider.example.test/downloads/acme-res-10k.kicad_sym" );
124 footprint.
asset_type = wxString(
"footprint" );
125 footprint.
name = wxString(
"R_0603.pretty" );
126 footprint.
content_type = wxString(
"application/x-kicad-footprint" );
128 footprint.
sha256 = wxString(
"8d8090740282c9ec23541a148af0ae57543e0da581e00e714e066dc4a1adefb0" );
129 footprint.
download_url = wxString(
"https://provider.example.test/downloads/R_0603.pretty" );
132 footprint.
target_name = wxString(
"R_0603_1608Metric" );
134 manifest.
assets = { symbol, footprint };
144 const wxString outputDir = tempDir();
154 wxUnusedVar( aError );
157 if( aUrl.EndsWith( wxString(
"acme-res-10k.kicad_sym" ) ) )
159 aResponse.
content_type = wxString(
"application/x-kicad-symbol" );
160 const std::string payload = symbolPayload(
"R" );
161 aResponse.
payload.assign( payload.begin(), payload.end() );
165 aResponse.
content_type = wxString(
"application/x-kicad-footprint" );
166 const std::string payload =
"(module \"R_0603_1608Metric\" (layer \"F.Cu\"))\n";
167 aResponse.
payload.assign( payload.begin(), payload.end() );
174 BOOST_REQUIRE( job.Import( provider(), importContext(), manifest(),
false, error ) );
176 wxFileName symbolPath( outputDir, wxString() );
177 symbolPath.AppendDir( wxString(
"symbols" ) );
178 symbolPath.SetFullName( wxString(
"testremote_device.kicad_sym" ) );
179 BOOST_CHECK( symbolPath.FileExists() );
181 wxFileName footprintPath( outputDir, wxString() );
182 footprintPath.AppendDir( wxString(
"footprints" ) );
183 footprintPath.AppendDir( wxString(
"testremote_resistor_smd.pretty" ) );
184 footprintPath.SetFullName( wxString(
"R_0603_1608Metric.kicad_mod" ) );
185 BOOST_CHECK( footprintPath.FileExists() );
192 LIB_SYMBOL* loaded = plugin->LoadSymbol( symbolPath.GetFullPath(), wxString(
"R" ) );
195 std::string(
"testremote_resistor_smd:R_0603_1608Metric" ) );
200 const wxString outputDir = tempDir();
210 wxUnusedVar( aError );
213 if( aUrl.EndsWith( wxString(
"acme-res-10k.kicad_sym" ) ) )
215 aResponse.
content_type = wxString(
"application/x-kicad-symbol" );
216 const std::string payload = symbolPayload(
"WrongName" );
217 aResponse.
payload.assign( payload.begin(), payload.end() );
221 aResponse.
content_type = wxString(
"application/x-kicad-footprint" );
222 const std::string payload =
"(module \"R_0603_1608Metric\" (layer \"F.Cu\"))\n";
223 aResponse.
payload.assign( payload.begin(), payload.end() );
230 BOOST_CHECK( !job.Import( provider(), importContext(), manifest(),
false, error ) );
231 BOOST_CHECK( !error.IsEmpty() );
236 const wxString outputDir = tempDir();
244 multiManifest.
part_id = wxString(
"acme-res-10k" );
247 const std::string symbolBlob = symbolPayload(
"R" );
248 symbolAsset.
asset_type = wxString(
"symbol" );
249 symbolAsset.
name = wxString(
"acme-res-10k.kicad_sym" );
250 symbolAsset.
content_type = wxString(
"application/x-kicad-symbol" );
251 symbolAsset.
size_bytes =
static_cast<long long>( symbolBlob.size() );
252 symbolAsset.
sha256 = sha256Hex( symbolBlob );
253 symbolAsset.
download_url = wxString(
"https://provider.example.test/downloads/acme-res-10k.kicad_sym" );
257 const std::string fpBlob0603 =
"(module \"R_0603_1608Metric\" (layer \"F.Cu\"))\n";
258 const std::string fpBlob0805 =
"(module \"R_0805_2012Metric\" (layer \"F.Cu\"))\n";
261 fpPrimary.
asset_type = wxString(
"footprint" );
262 fpPrimary.
name = wxString(
"R_0603.pretty" );
263 fpPrimary.
content_type = wxString(
"application/x-kicad-footprint" );
264 fpPrimary.
size_bytes =
static_cast<long long>( fpBlob0603.size() );
265 fpPrimary.
sha256 = sha256Hex( fpBlob0603 );
266 fpPrimary.
download_url = wxString(
"https://provider.example.test/downloads/R_0603.kicad_mod" );
268 fpPrimary.
target_name = wxString(
"R_0603_1608Metric" );
272 fpAlt.
name = wxString(
"R_0805.pretty" );
273 fpAlt.
content_type = wxString(
"application/x-kicad-footprint" );
274 fpAlt.
size_bytes =
static_cast<long long>( fpBlob0805.size() );
275 fpAlt.
sha256 = sha256Hex( fpBlob0805 );
276 fpAlt.
download_url = wxString(
"https://provider.example.test/downloads/R_0805.kicad_mod" );
278 fpAlt.
target_name = wxString(
"R_0805_2012Metric" );
282 multiManifest.
assets = { symbolAsset, fpPrimary, fpAlt };
287 wxUnusedVar( aError );
290 if( aUrl.EndsWith( wxString(
"acme-res-10k.kicad_sym" ) ) )
292 aResponse.
content_type = wxString(
"application/x-kicad-symbol" );
293 aResponse.
payload.assign( symbolBlob.begin(), symbolBlob.end() );
297 if( aUrl.EndsWith( wxString(
"R_0805.kicad_mod" ) ) )
299 aResponse.
content_type = wxString(
"application/x-kicad-footprint" );
300 aResponse.
payload.assign( fpBlob0805.begin(), fpBlob0805.end() );
304 aResponse.
content_type = wxString(
"application/x-kicad-footprint" );
305 aResponse.
payload.assign( fpBlob0603.begin(), fpBlob0603.end() );
311 BOOST_REQUIRE( job.Import( provider(), importContext(), multiManifest,
false, error ) );
313 wxFileName symbolPath( outputDir, wxString() );
314 symbolPath.AppendDir( wxString(
"symbols" ) );
315 symbolPath.SetFullName( wxString(
"testremote_device.kicad_sym" ) );
321 LIB_SYMBOL* loaded = plugin->LoadSymbol( symbolPath.GetFullPath(), wxString(
"R" ) );
325 std::string(
"testremote_resistor_smd:R_0603_1608Metric" ) );
329 if( filters.GetCount() == 1 )
336 const wxString outputDir = tempDir();
337 wxFileName projectFile( outputDir, wxS(
"remote" ), wxS(
"kicad_pro" ) );
346 const std::string payload = symbolPayload(
"R" );
350 std::vector<uint8_t>( payload.begin(), payload.end() ), wxS(
"R" ), error );
353 const wxString nickname = wxS(
"testremote_device" );
354 wxFileName libFile( outputDir, nickname, wxS(
"kicad_sym" ) );
REMOTE_PROVIDER_SETTINGS m_RemoteSymbol
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
Define a library symbol object.
wxArrayString GetFPFilters() const
wxString GetFootprintProp() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
static std::string ToStdString(const wxString &aStr)
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
PGM_BASE & Pgm()
The global program "get" accessor.
std::unique_ptr< LIB_SYMBOL > LoadRemoteSymbolFromPayload(const std::vector< uint8_t > &aPayload, const wxString &aLibItemName, wxString &aError)
Deserialize a remote-downloaded symbol payload into a LIB_SYMBOL.
bool SaveRemoteSymbolToLibrary(SYMBOL_LIBRARY_ADAPTER &aAdapter, const wxFileName &aLibraryFile, const wxString &aNickname, bool aGlobalTable, std::unique_ptr< LIB_SYMBOL > aSymbol, wxString &aError)
Save a downloaded symbol into the remote symbol library aNickname backed by aLibraryFile.
T * GetAppSettings(const char *aFilename)
std::vector< REMOTE_PROVIDER_PART_ASSET > assets
std::vector< uint8_t > payload
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(ImportWritesDownloadedAssets)
BOOST_CHECK_EQUAL(result, "25.4")