KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24297_http_migrate.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 3
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
28
29#include <boost/test/unit_test.hpp>
30
31#include <cstring>
32
33#include <wx/filename.h>
34#include <wx/wfstream.h>
35
36#include <sch_io/sch_io_mgr.h>
37
38
39BOOST_AUTO_TEST_SUITE( Issue24297HttpMigrate )
40
41
42
48BOOST_AUTO_TEST_CASE( HttpLibraryRejectedByConvertLibrary )
49{
50 wxFileName settings( wxFileName::CreateTempFileName( "kicad_qa_issue24297_" ) );
51 wxRemoveFile( settings.GetFullPath() );
52 settings.SetExt( "kicad_httplib" );
53
54 {
55 wxFFileOutputStream out( settings.GetFullPath() );
56 BOOST_REQUIRE( out.IsOk() );
57 const char* json =
58 "{\n"
59 " \"meta\": { \"version\": 1.0 },\n"
60 " \"name\": \"Test HTTP Library\",\n"
61 " \"source\": {\n"
62 " \"type\": \"REST_API\",\n"
63 " \"api_version\": \"v1\",\n"
64 " \"root_url\": \"http://localhost:1/\",\n"
65 " \"token\": \"\"\n"
66 " }\n"
67 "}\n";
68 out.WriteAll( json, std::strlen( json ) );
69 }
70
71 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( settings.GetFullPath() ),
72 SCH_IO_MGR::SCH_HTTP );
73
74 wxFileName outLib( settings );
75 outLib.SetExt( "kicad_sym" );
76 wxRemoveFile( outLib.GetFullPath() );
77
78 // Previously this returned true and wrote an empty .kicad_sym, clobbering the table entry.
79 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, settings.GetFullPath(),
80 outLib.GetFullPath() ) );
81
82 // And must not have produced an empty replacement file.
83 BOOST_CHECK( !outLib.Exists() );
84
85 wxRemoveFile( settings.GetFullPath() );
86 wxRemoveFile( outLib.GetFullPath() );
87}
88
89
91BOOST_AUTO_TEST_CASE( DatabaseLibraryRejectedByConvertLibrary )
92{
93 wxFileName settings( wxFileName::CreateTempFileName( "kicad_qa_issue24297_db_" ) );
94 wxRemoveFile( settings.GetFullPath() );
95 settings.SetExt( "kicad_dbl" );
96
97 {
98 wxFFileOutputStream out( settings.GetFullPath() );
99 BOOST_REQUIRE( out.IsOk() );
100 const char* json =
101 "{\n"
102 " \"meta\": { \"version\": 0 },\n"
103 " \"name\": \"Test DB\",\n"
104 " \"source\": { \"type\": \"odbc\", \"dsn\": \"\", \"username\": \"\","
105 " \"password\": \"\", \"connection_string\": \"\" },\n"
106 " \"libraries\": []\n"
107 "}\n";
108 out.WriteAll( json, std::strlen( json ) );
109 }
110
111 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( settings.GetFullPath() ),
112 SCH_IO_MGR::SCH_DATABASE );
113
114 wxFileName outLib( settings );
115 outLib.SetExt( "kicad_sym" );
116 wxRemoveFile( outLib.GetFullPath() );
117
118 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, settings.GetFullPath(),
119 outLib.GetFullPath() ) );
120 BOOST_CHECK( !outLib.Exists() );
121
122 wxRemoveFile( settings.GetFullPath() );
123 wxRemoveFile( outLib.GetFullPath() );
124}
125
126
129BOOST_AUTO_TEST_CASE( NestedTableRejectedByConvertLibrary )
130{
131 wxFileName table( wxFileName::CreateTempFileName( "kicad_qa_issue23291_sym_" ) );
132
133 {
134 wxFFileOutputStream out( table.GetFullPath() );
135 BOOST_REQUIRE( out.IsOk() );
136 const char* contents =
137 "(sym_lib_table\n"
138 " (version 7)\n"
139 " (lib (name \"Device\") (type \"KiCad\")"
140 " (uri \"${KICAD9_SYMBOL_DIR}/Device.kicad_sym\") (options \"\") (descr \"\"))\n"
141 ")\n";
142 out.WriteAll( contents, std::strlen( contents ) );
143 }
144
145 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( table.GetFullPath() ),
146 SCH_IO_MGR::SCH_NESTED_TABLE );
147
148 wxFileName outLib( table );
149 outLib.SetExt( "kicad_sym" );
150 wxRemoveFile( outLib.GetFullPath() );
151
152 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, table.GetFullPath(), outLib.GetFullPath() ) );
153 BOOST_CHECK( !outLib.Exists() );
154
155 wxRemoveFile( table.GetFullPath() );
156 wxRemoveFile( outLib.GetFullPath() );
157}
158
159
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilepath)
Convert a schematic symbol library to the latest KiCad format.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
nlohmann::json json
Definition gerbview.cpp:49
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(HttpLibraryRejectedByConvertLibrary)
Test for issue #24297: Migrate http library fails.
std::vector< std::vector< std::string > > table