KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_easyeda_sch_import.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
20#include <boost/test/unit_test.hpp>
22
23#include <json_common.h>
24#include <lib_symbol.h>
26
27#include <wx/filename.h>
28
29#include <fstream>
30
31
32BOOST_AUTO_TEST_SUITE( EasyedaSchImport )
33
34
35BOOST_AUTO_TEST_CASE( WrappedSingleSheetEnumeratesItsSymbols )
36{
37 const wxString source = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() )
38 + wxS( "../pcbnew/plugins/easyeda/SCH_ESP32-PICO-D4 smart watch_2023-09-02.json" );
39
40 std::ifstream in( source.ToStdString() );
41 nlohmann::json doc = nlohmann::json::parse( in, nullptr, false );
42
43 BOOST_REQUIRE( !doc.is_discarded() );
44
45 // The server wraps a lone sheet in an envelope that carries the sheet under dataStr
46 nlohmann::json wrapped = { { "docType", "1" },
47 { "title", "sheet" },
48 { "dataStr", doc["schematics"][0]["dataStr"] } };
49
50 wxFileName path( wxFileName::CreateTempFileName( wxS( "kicad_easyeda_wrapped_" ) ) );
51 wxFileName jsonPath( path );
52 jsonPath.SetExt( wxS( "json" ) );
53
54 {
55 std::ofstream out( jsonPath.GetFullPath().ToStdString() );
56 out << wrapped.dump();
57 }
58
59 SCH_IO_EASYEDA plugin;
60 wxArrayString names;
61
62 plugin.EnumerateSymbolLib( names, jsonPath.GetFullPath() );
63
64 wxRemoveFile( jsonPath.GetFullPath() );
65 wxRemoveFile( path.GetFullPath() );
66
67 BOOST_CHECK( !names.IsEmpty() );
68}
69
70
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.
std::string source
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
std::string path