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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 */
20
29
30#include <boost/test/unit_test.hpp>
31
32#include <cstring>
33
34#include <wx/filename.h>
35#include <wx/wfstream.h>
36
37#include <sch_io/sch_io_mgr.h>
38
39
40BOOST_AUTO_TEST_SUITE( Issue24297HttpMigrate )
41
42
43
49BOOST_AUTO_TEST_CASE( HttpLibraryRejectedByConvertLibrary )
50{
51 wxFileName settings( wxFileName::CreateTempFileName( "kicad_qa_issue24297_" ) );
52 wxRemoveFile( settings.GetFullPath() );
53 settings.SetExt( "kicad_httplib" );
54
55 {
56 wxFFileOutputStream out( settings.GetFullPath() );
57 BOOST_REQUIRE( out.IsOk() );
58 const char* json =
59 "{\n"
60 " \"meta\": { \"version\": 1.0 },\n"
61 " \"name\": \"Test HTTP Library\",\n"
62 " \"source\": {\n"
63 " \"type\": \"REST_API\",\n"
64 " \"api_version\": \"v1\",\n"
65 " \"root_url\": \"http://localhost:1/\",\n"
66 " \"token\": \"\"\n"
67 " }\n"
68 "}\n";
69 out.WriteAll( json, std::strlen( json ) );
70 }
71
72 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( settings.GetFullPath() ),
73 SCH_IO_MGR::SCH_HTTP );
74
75 wxFileName outLib( settings );
76 outLib.SetExt( "kicad_sym" );
77 wxRemoveFile( outLib.GetFullPath() );
78
79 // Previously this returned true and wrote an empty .kicad_sym, clobbering the table entry.
80 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, settings.GetFullPath(),
81 outLib.GetFullPath() ) );
82
83 // And must not have produced an empty replacement file.
84 BOOST_CHECK( !outLib.Exists() );
85
86 wxRemoveFile( settings.GetFullPath() );
87 wxRemoveFile( outLib.GetFullPath() );
88}
89
90
92BOOST_AUTO_TEST_CASE( DatabaseLibraryRejectedByConvertLibrary )
93{
94 wxFileName settings( wxFileName::CreateTempFileName( "kicad_qa_issue24297_db_" ) );
95 wxRemoveFile( settings.GetFullPath() );
96 settings.SetExt( "kicad_dbl" );
97
98 {
99 wxFFileOutputStream out( settings.GetFullPath() );
100 BOOST_REQUIRE( out.IsOk() );
101 const char* json =
102 "{\n"
103 " \"meta\": { \"version\": 0 },\n"
104 " \"name\": \"Test DB\",\n"
105 " \"source\": { \"type\": \"odbc\", \"dsn\": \"\", \"username\": \"\","
106 " \"password\": \"\", \"connection_string\": \"\" },\n"
107 " \"libraries\": []\n"
108 "}\n";
109 out.WriteAll( json, std::strlen( json ) );
110 }
111
112 BOOST_REQUIRE_EQUAL( SCH_IO_MGR::GuessPluginTypeFromLibPath( settings.GetFullPath() ),
113 SCH_IO_MGR::SCH_DATABASE );
114
115 wxFileName outLib( settings );
116 outLib.SetExt( "kicad_sym" );
117 wxRemoveFile( outLib.GetFullPath() );
118
119 BOOST_CHECK( !SCH_IO_MGR::ConvertLibrary( nullptr, settings.GetFullPath(),
120 outLib.GetFullPath() ) );
121 BOOST_CHECK( !outLib.Exists() );
122
123 wxRemoveFile( settings.GetFullPath() );
124 wxRemoveFile( outLib.GetFullPath() );
125}
126
127
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:53
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.