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
11#include <kiplatform/io.h>
13
14#include <filesystem>
15#include <iterator>
16
17#include <wx/ffile.h>
18
19
20BOOST_AUTO_TEST_SUITE( CompatibilityReport )
21
22
23BOOST_AUTO_TEST_CASE( TextReportIncludesTargetAndAllActions )
24{
26 report.Add( DOWNGRADE_BUCKET::BLOCK, wxS( "Pin notation" ), wxS( "Cannot represent this notation." ) );
27 report.Add( DOWNGRADE_BUCKET::DROP, wxS( "Net chains" ), wxS( "Chain constraints are omitted." ), 3 );
28 report.Add( DOWNGRADE_BUCKET::LOWER, wxS( "Ellipses" ), wxS( "Converted to polygons." ), 2 );
29 report.Add( DOWNGRADE_BUCKET::KEEP, wxS( "Supported setting" ), wxS( "Written unchanged." ), 4 );
30
31 const wxString expectedSections = wxS( "\nKeep: 4\n"
32 " Supported setting (4)\n"
33 " Written unchanged.\n"
34 "\nApproximate: 2\n"
35 " Ellipses (2)\n"
36 " Converted to polygons.\n"
37 "\nDrop: 3\n"
38 " Net chains (3)\n"
39 " Chain constraints are omitted.\n"
40 "\nCannot export: 1\n"
41 " Pin notation (1)\n"
42 " Cannot represent this notation.\n" );
43
44 const wxString target = wxS( "KiCad 9.0" );
45 const wxString text = report.ToText( target );
46
47 BOOST_CHECK( text.Contains( target + wxS( "\n\n" ) ) );
48 BOOST_CHECK( text.Contains( expectedSections ) );
49 BOOST_CHECK( report.IsBlocked() );
50 BOOST_CHECK( report.IsLossy() );
51}
52
53
54BOOST_AUTO_TEST_CASE( TextReportIncludesMergedCountsAndDetails )
55{
57 report.Add( DOWNGRADE_BUCKET::LOWER, wxS( "Ellipses" ), wxEmptyString, 2 );
58 report.Add( DOWNGRADE_BUCKET::LOWER, wxS( "Ellipses" ), wxS( "Converted to polygons." ), 3 );
59
60 const wxString target = wxS( "KiCad 10.0" );
61 wxString text = report.ToText( target );
62
63 BOOST_CHECK( text.Contains( target + wxS( "\n\n" ) ) );
64 BOOST_CHECK( text.Contains( wxS( "\nApproximate: 5\n Ellipses (5)\n Converted to polygons.\n" ) ) );
65 BOOST_CHECK( report.IsLossy() );
66 BOOST_CHECK( !report.IsBlocked() );
67 BOOST_REQUIRE_EQUAL( report.Entries().size(), 1 );
69}
70
71
72BOOST_AUTO_TEST_CASE( EmptyTextReportHasZeroCounts )
73{
75 wxString text = report.ToText( wxS( "KiCad 9.0" ) );
76
77 BOOST_CHECK( text.Contains( wxS( "\nKeep: 0\n\nApproximate: 0\n\nDrop: 0\n\nCannot export: 0\n" ) ) );
78 BOOST_CHECK( !report.IsLossy() );
79 BOOST_CHECK( !report.IsBlocked() );
80}
81
82
83BOOST_AUTO_TEST_CASE( KeptFeaturesAppearWithoutLoss )
84{
86 report.Add( DOWNGRADE_BUCKET::KEEP, wxS( "Supported setting" ) );
87
88 wxString text = report.ToText( wxS( "KiCad 10.0" ) );
89
90 BOOST_CHECK( text.Contains( wxS( "\nKeep: 1\n Supported setting (1)\n\nApproximate: 0\n" ) ) );
91 BOOST_CHECK( !report.IsLossy() );
92 BOOST_CHECK( !report.IsBlocked() );
93}
94
95
96BOOST_AUTO_TEST_CASE( DropOnlyTextReportHasNoApproximationEntries )
97{
99 report.Add( DOWNGRADE_BUCKET::DROP, wxS( "Barcodes" ), wxS( "Omitted by the selected export policy." ), 2 );
100
101 wxString text = report.ToText( wxS( "KiCad 9.0" ) );
102
103 BOOST_CHECK( text.Contains( wxS( "\nApproximate: 0\n" ) ) );
104 BOOST_CHECK( text.Contains( wxS( "\nDrop: 2\n Barcodes (2)\n Omitted by the selected export policy.\n" ) ) );
105 BOOST_CHECK( report.IsLossy() );
106 BOOST_CHECK( !report.IsBlocked() );
107}
108
109
110BOOST_AUTO_TEST_CASE( TextReportRetainsUntranslatedFeatureText )
111{
113 const wxString feature = wxString::FromUTF8( "Réglages Ω" );
114 const wxString detail = wxString::FromUTF8( "日本語\nSecond line: 50%" );
115 report.Add( DOWNGRADE_BUCKET::DROP, feature, detail );
116
117 const wxString target = wxS( "Target 100%" );
118 wxString text = report.ToText( target );
119
120 BOOST_CHECK( text.Contains( target + wxS( "\n\n" ) ) );
121 BOOST_CHECK( text.Contains( feature ) );
122 BOOST_CHECK( text.Contains( detail ) );
123}
124
125
126BOOST_AUTO_TEST_CASE( TextReportCanBeSavedAndReplacedAsUtf8 )
127{
128 KI_TEST::TEMPORARY_DIRECTORY dir( "kicad-compatibility-report-" );
129 wxString path = wxString::FromUTF8( ( dir.GetPath() / "report.txt" ).string() );
131 report.Add( DOWNGRADE_BUCKET::DROP, wxString::FromUTF8( "Réglages Ω" ), wxString::FromUTF8( "日本語" ) );
132
133 for( const wxString& target : { wxS( "KiCad 9.0" ), wxS( "KiCad 10.0" ) } )
134 {
135 wxString text = report.ToText( target );
136 wxScopedCharBuffer utf8 = text.ToUTF8();
137 wxString error;
138
139 BOOST_REQUIRE( KIPLATFORM::IO::AtomicWriteFile( path, utf8.data(), utf8.length(), &error ) );
140 BOOST_CHECK( error.IsEmpty() );
141
142 wxFFile file( path, wxS( "rb" ) );
143 BOOST_REQUIRE( file.IsOpened() );
144 wxString saved;
145 BOOST_REQUIRE( file.ReadAll( &saved, wxConvUTF8 ) );
146 BOOST_CHECK_EQUAL( saved, text );
147 BOOST_CHECK_EQUAL( static_cast<size_t>( file.Length() ), utf8.length() );
148 }
149
150 BOOST_CHECK_EQUAL( std::distance( std::filesystem::directory_iterator( dir.GetPath() ),
151 std::filesystem::directory_iterator() ),
152 1 );
153}
154
155
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
A temporary directory deleted when it goes out of scope.
const std::filesystem::path & GetPath() const
@ 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.
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,...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(TextReportIncludesTargetAndAllActions)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_CHECK_EQUAL(result, "25.4")