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
39namespace
40{
41
42void removeIfPresent( const wxFileName& aFile )
43{
44 if( aFile.FileExists() )
45 wxRemoveFile( aFile.GetFullPath() );
46}
47
48} // namespace
49
50
51BOOST_AUTO_TEST_SUITE( Issue24297HttpMigrate )
52
53
54
60BOOST_AUTO_TEST_CASE( HttpLibraryRejectedByConvertLibrary )
61{
62 wxFileName settings( wxFileName::CreateTempFileName( "kicad_qa_issue24297_" ) );
63 wxRemoveFile( settings.GetFullPath() );
64 settings.SetExt( "kicad_httplib" );
65
66 {
67 wxFFileOutputStream out( settings.GetFullPath() );
68 BOOST_REQUIRE( out.IsOk() );
69 const char* json =
70 "{\n"
71 " \"meta\": { \"version\": 1.0 },\n"
72 " \"name\": \"Test HTTP Library\",\n"
73 " \"source\": {\n"
74 " \"type\": \"REST_API\",\n"
75 " \"api_version\": \"v1\",\n"
76 " \"root_url\": \"http://localhost:1/\",\n"
77 " \"token\": \"\"\n"
78 " }\n"
79 "}\n";
80 out.WriteAll( json, std::strlen( json ) );
81 }
82
83 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( settings.GetFullPath() ),
84 SCH_IO_MGR::SCH_HTTP );
85
86 wxFileName outLib( settings );
87 outLib.SetExt( "kicad_sym" );
88 removeIfPresent( outLib );
89
90 // Previously this returned true and wrote an empty .kicad_sym, clobbering the table entry.
91 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, settings.GetFullPath(),
92 outLib.GetFullPath() ) );
93
94 // And must not have produced an empty replacement file.
95 BOOST_CHECK( !outLib.Exists() );
96
97 wxRemoveFile( settings.GetFullPath() );
98 removeIfPresent( outLib );
99}
100
101
103BOOST_AUTO_TEST_CASE( DatabaseLibraryRejectedByConvertLibrary )
104{
105 wxFileName settings( wxFileName::CreateTempFileName( "kicad_qa_issue24297_db_" ) );
106 wxRemoveFile( settings.GetFullPath() );
107 settings.SetExt( "kicad_dbl" );
108
109 {
110 wxFFileOutputStream out( settings.GetFullPath() );
111 BOOST_REQUIRE( out.IsOk() );
112 const char* json =
113 "{\n"
114 " \"meta\": { \"version\": 0 },\n"
115 " \"name\": \"Test DB\",\n"
116 " \"source\": { \"type\": \"odbc\", \"dsn\": \"\", \"username\": \"\","
117 " \"password\": \"\", \"connection_string\": \"\" },\n"
118 " \"libraries\": []\n"
119 "}\n";
120 out.WriteAll( json, std::strlen( json ) );
121 }
122
123 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( settings.GetFullPath() ),
124 SCH_IO_MGR::SCH_DATABASE );
125
126 wxFileName outLib( settings );
127 outLib.SetExt( "kicad_sym" );
128 removeIfPresent( outLib );
129
130 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, settings.GetFullPath(),
131 outLib.GetFullPath() ) );
132 BOOST_CHECK( !outLib.Exists() );
133
134 wxRemoveFile( settings.GetFullPath() );
135 removeIfPresent( outLib );
136}
137
138
141BOOST_AUTO_TEST_CASE( NestedTableRejectedByConvertLibrary )
142{
143 wxFileName table( wxFileName::CreateTempFileName( "kicad_qa_issue23291_sym_" ) );
144
145 {
146 wxFFileOutputStream out( table.GetFullPath() );
147 BOOST_REQUIRE( out.IsOk() );
148 const char* contents =
149 "(sym_lib_table\n"
150 " (version 7)\n"
151 " (lib (name \"Device\") (type \"KiCad\")"
152 " (uri \"${KICAD9_SYMBOL_DIR}/Device.kicad_sym\") (options \"\") (descr \"\"))\n"
153 ")\n";
154 out.WriteAll( contents, std::strlen( contents ) );
155 }
156
157 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( table.GetFullPath() ),
158 SCH_IO_MGR::SCH_NESTED_TABLE );
159
160 wxFileName outLib( table );
161 outLib.SetExt( "kicad_sym" );
162 removeIfPresent( outLib );
163
164 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, table.GetFullPath(), outLib.GetFullPath() ) );
165 BOOST_CHECK( !outLib.Exists() );
166
167 wxRemoveFile( table.GetFullPath() );
168 removeIfPresent( outLib );
169}
170
171
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilepath, REPORTER *aReporter=nullptr)
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:50
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)
A .kicad_httplib config (HTTP source) is not migratable to a .kicad_sym snapshot.