KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_compatibility_report.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 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#include <boost/test/unit_test.hpp>
9
16#include <kiplatform/io.h>
17#include <qa_utils/file_utils.h>
18
19#include <filesystem>
20#include <iterator>
21
22#include <wx/ffile.h>
23
24
25BOOST_AUTO_TEST_SUITE( CompatibilityReport )
26
27
28BOOST_AUTO_TEST_CASE( TextReportIncludesTargetAndAllActions )
29{
31 report.Add( DOWNGRADE_BUCKET::BLOCK, wxS( "Pin notation" ), wxS( "Cannot represent this notation." ) );
32 report.Add( DOWNGRADE_BUCKET::DROP, wxS( "Net chains" ), wxS( "Chain constraints are omitted." ), 3 );
33 report.Add( DOWNGRADE_BUCKET::LOWER, wxS( "Ellipses" ), wxS( "Converted to polygons." ), 2 );
34 report.Add( DOWNGRADE_BUCKET::KEEP, wxS( "Supported setting" ), wxS( "Written unchanged." ), 4 );
35
36 const wxString expectedSections = wxS( "\nKeep: 4\n"
37 " Supported setting (4)\n"
38 " Written unchanged.\n"
39 "\nApproximate: 2\n"
40 " Ellipses (2)\n"
41 " Converted to polygons.\n"
42 "\nDrop: 3\n"
43 " Net chains (3)\n"
44 " Chain constraints are omitted.\n"
45 "\nCannot export: 1\n"
46 " Pin notation (1)\n"
47 " Cannot represent this notation.\n" );
48
49 const wxString target = wxS( "KiCad 9.0" );
50 const wxString text = report.ToText( target );
51
52 BOOST_CHECK( text.Contains( target + wxS( "\n\n" ) ) );
53 BOOST_CHECK( text.Contains( expectedSections ) );
54 BOOST_CHECK( report.IsBlocked() );
55 BOOST_CHECK( report.IsLossy() );
56}
57
58
59BOOST_AUTO_TEST_CASE( TextReportIncludesMergedCountsAndDetails )
60{
62 report.Add( DOWNGRADE_BUCKET::LOWER, wxS( "Ellipses" ), wxEmptyString, 2 );
63 report.Add( DOWNGRADE_BUCKET::LOWER, wxS( "Ellipses" ), wxS( "Converted to polygons." ), 3 );
64
65 const wxString target = wxS( "KiCad 10.0" );
66 wxString text = report.ToText( target );
67
68 BOOST_CHECK( text.Contains( target + wxS( "\n\n" ) ) );
69 BOOST_CHECK( text.Contains( wxS( "\nApproximate: 5\n Ellipses (5)\n Converted to polygons.\n" ) ) );
70 BOOST_CHECK( report.IsLossy() );
71 BOOST_CHECK( !report.IsBlocked() );
72 BOOST_REQUIRE_EQUAL( report.Entries().size(), 1 );
74}
75
76
77BOOST_AUTO_TEST_CASE( EmptyTextReportHasZeroCounts )
78{
80 wxString text = report.ToText( wxS( "KiCad 9.0" ) );
81
82 BOOST_CHECK( text.Contains( wxS( "\nKeep: 0\n\nApproximate: 0\n\nDrop: 0\n\nCannot export: 0\n" ) ) );
83 BOOST_CHECK( !report.IsLossy() );
84 BOOST_CHECK( !report.IsBlocked() );
85}
86
87
88BOOST_AUTO_TEST_CASE( KeptFeaturesAppearWithoutLoss )
89{
91 report.Add( DOWNGRADE_BUCKET::KEEP, wxS( "Supported setting" ) );
92
93 wxString text = report.ToText( wxS( "KiCad 10.0" ) );
94
95 BOOST_CHECK( text.Contains( wxS( "\nKeep: 1\n Supported setting (1)\n\nApproximate: 0\n" ) ) );
96 BOOST_CHECK( !report.IsLossy() );
97 BOOST_CHECK( !report.IsBlocked() );
98}
99
100
101BOOST_AUTO_TEST_CASE( DropOnlyTextReportHasNoApproximationEntries )
102{
104 report.Add( DOWNGRADE_BUCKET::DROP, wxS( "Barcodes" ), wxS( "Omitted by the selected export policy." ), 2 );
105
106 wxString text = report.ToText( wxS( "KiCad 9.0" ) );
107
108 BOOST_CHECK( text.Contains( wxS( "\nApproximate: 0\n" ) ) );
109 BOOST_CHECK( text.Contains( wxS( "\nDrop: 2\n Barcodes (2)\n Omitted by the selected export policy.\n" ) ) );
110 BOOST_CHECK( report.IsLossy() );
111 BOOST_CHECK( !report.IsBlocked() );
112}
113
114
115BOOST_AUTO_TEST_CASE( TextReportRetainsUntranslatedFeatureText )
116{
118 const wxString feature = wxString::FromUTF8( "Réglages Ω" );
119 const wxString detail = wxString::FromUTF8( "日本語\nSecond line: 50%" );
120 report.Add( DOWNGRADE_BUCKET::DROP, feature, detail );
121
122 const wxString target = wxS( "Target 100%" );
123 wxString text = report.ToText( target );
124
125 BOOST_CHECK( text.Contains( target + wxS( "\n\n" ) ) );
126 BOOST_CHECK( text.Contains( feature ) );
127 BOOST_CHECK( text.Contains( detail ) );
128}
129
130
131BOOST_AUTO_TEST_CASE( TextReportCanBeSavedAndReplacedAsUtf8 )
132{
133 KI_TEST::SCOPED_TEMP_DIR dir( "kicad-compatibility-report-" );
134 wxString path = wxString::FromUTF8( ( dir.Path() / "report.txt" ).string() );
136 report.Add( DOWNGRADE_BUCKET::DROP, wxString::FromUTF8( "Réglages Ω" ), wxString::FromUTF8( "日本語" ) );
137
138 for( const wxString& target : { wxS( "KiCad 9.0" ), wxS( "KiCad 10.0" ) } )
139 {
140 wxString text = report.ToText( target );
141 wxScopedCharBuffer utf8 = text.ToUTF8();
142 wxString error;
143
144 BOOST_REQUIRE( KIPLATFORM::IO::AtomicWriteFile( path, utf8.data(), utf8.length(), &error ) );
145 BOOST_CHECK( error.IsEmpty() );
146
147 wxFFile file( path, wxS( "rb" ) );
148 BOOST_REQUIRE( file.IsOpened() );
149 wxString saved;
150 BOOST_REQUIRE( file.ReadAll( &saved, wxConvUTF8 ) );
151 BOOST_CHECK_EQUAL( saved, text );
152 BOOST_CHECK_EQUAL( static_cast<size_t>( file.Length() ), utf8.length() );
153 }
154
156 std::distance( std::filesystem::directory_iterator( dir.Path() ), std::filesystem::directory_iterator() ),
157 1 );
158}
159
160
161// A schema bump stops project export working until the downgrade has been checked against it.
162// If this fails, see what the bump changed, fix the downgrade if it needs it, then update
163// PROJECT_SCHEMAS_REVIEWED.
164//
165// ERC and board design settings are not checked. They live in eeschema and pcbnew, which this
166// binary does not link.
167BOOST_AUTO_TEST_CASE( ReviewedSchemasMatchTheLiveOnes )
168{
169 // Params only reach the json through a store, and meta.version is one of them
170 auto live = []( JSON_SETTINGS& aSettings ) -> int
171 {
172 aSettings.Store();
173
174 std::optional<int> value = aSettings.Get<int>( "meta.version" );
175 BOOST_REQUIRE( value.has_value() );
176 return *value;
177 };
178
179 const PROJECT_SCHEMAS_REVIEWED reviewed;
180
181 PROJECT_FILE project( wxT( "schema_probe.kicad_pro" ) );
182 NET_SETTINGS nets( nullptr, "net_settings" );
183 TUNING_PROFILES tuning( nullptr, "tuning_profiles" );
184 COMPONENT_CLASS_SETTINGS classes( nullptr, "component_class_settings" );
185
186 BOOST_CHECK_EQUAL( live( project ), reviewed.m_Project );
187 BOOST_CHECK_EQUAL( live( nets ), reviewed.m_NetSettings );
188 BOOST_CHECK_EQUAL( live( tuning ), reviewed.m_TuningProfiles );
189 BOOST_CHECK_EQUAL( live( classes ), reviewed.m_ComponentClasses );
190}
191
192
What an export to a given target will keep, approximate, drop, or block.
wxString ToText(const wxString &aTargetName) const
A readable preview of the classified export, including counts and feature details.
void Add(DOWNGRADE_BUCKET aBucket, const wxString &aFeature, const wxString &aDetail=wxEmptyString, int aCount=1)
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
int Count(DOWNGRADE_BUCKET aBucket) const
const std::vector< COMPAT_ENTRY > & Entries() const
COMPONENT_CLASS_SETTINGS stores data for component classes, including rules for automatic generation ...
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
Definition file_utils.h:61
NET_SETTINGS stores various net-related settings in a project context.
The backing store for a PROJECT, in JSON format.
TUNING_PROFILES stores the configuration for impedance / delay tuning profiles.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ KEEP
Exists in the target, written unchanged.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
std::string utf8(const wxString &aText)
bool AtomicWriteFile(const wxString &aTargetPath, const void *aData, size_t aSize, wxString *aError=nullptr)
Writes aData to aTargetPath via a sibling temp file, fsyncs the data and directory,...
The settings schemas the project downgrade rules were written against.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(TextReportIncludesTargetAndAllActions)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
std::string path