KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_doc_property_helpers.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 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <boost/test/unit_test.hpp>
25
27
28
29using namespace KICAD_DIFF;
30
31
32BOOST_AUTO_TEST_SUITE( DocPropertyHelpers )
33
34
35// AppendPaperDeltas ---------------------------------------------------------
36
37BOOST_AUTO_TEST_CASE( AppendPaperDeltas_IdenticalProducesNoDeltas )
38{
39 PAGE_INFO before( PAGE_SIZE_TYPE::A4, /*portrait*/ false );
40 PAGE_INFO after ( PAGE_SIZE_TYPE::A4, /*portrait*/ false );
41
42 std::vector<PROPERTY_DELTA> deltas;
43 AppendPaperDeltas( deltas, before, after );
44
45 BOOST_CHECK( deltas.empty() );
46}
47
48
49BOOST_AUTO_TEST_CASE( AppendPaperDeltas_FormatChangeOnly )
50{
51 PAGE_INFO before( PAGE_SIZE_TYPE::A4, false );
52 PAGE_INFO after ( PAGE_SIZE_TYPE::A3, false );
53
54 std::vector<PROPERTY_DELTA> deltas;
55 AppendPaperDeltas( deltas, before, after );
56
57 BOOST_REQUIRE_EQUAL( deltas.size(), 1u );
58 BOOST_CHECK( deltas[0].name == DOC_PROP_PAGE_FORMAT );
59 // Format is encoded as ENUM with both the int (PAGE_SIZE_TYPE) and the
60 // label string (GetTypeAsString). Pin both halves — a regression that
61 // dropped the label would still pass an int-only check.
62 BOOST_CHECK( deltas[0].before.GetType() == DIFF_VALUE::T::ENUM );
63 BOOST_CHECK( deltas[0].after.GetType() == DIFF_VALUE::T::ENUM );
64 BOOST_CHECK_EQUAL( deltas[0].before.AsEnum().first,
65 static_cast<int>( PAGE_SIZE_TYPE::A4 ) );
66 BOOST_CHECK_EQUAL( deltas[0].after.AsEnum().first,
67 static_cast<int>( PAGE_SIZE_TYPE::A3 ) );
68 BOOST_CHECK_EQUAL( deltas[0].before.AsEnum().second,
69 before.GetTypeAsString().ToStdString() );
70 BOOST_CHECK_EQUAL( deltas[0].after.AsEnum().second,
71 after.GetTypeAsString().ToStdString() );
72}
73
74
75BOOST_AUTO_TEST_CASE( AppendPaperDeltas_OrientationChangeOnly )
76{
77 PAGE_INFO before( PAGE_SIZE_TYPE::A4, /*portrait*/ false );
78 PAGE_INFO after ( PAGE_SIZE_TYPE::A4, /*portrait*/ true );
79
80 std::vector<PROPERTY_DELTA> deltas;
81 AppendPaperDeltas( deltas, before, after );
82
83 BOOST_REQUIRE_EQUAL( deltas.size(), 1u );
84 BOOST_CHECK( deltas[0].name == DOC_PROP_PAGE_ORIENTATION );
85 // Orientation is encoded as BOOL (the IsPortrait flag).
86 BOOST_CHECK( deltas[0].before.GetType() == DIFF_VALUE::T::BOOL );
87 BOOST_CHECK( deltas[0].after.GetType() == DIFF_VALUE::T::BOOL );
88 BOOST_CHECK_EQUAL( deltas[0].before.AsBool(), false );
89 BOOST_CHECK_EQUAL( deltas[0].after.AsBool(), true );
90}
91
92
93BOOST_AUTO_TEST_CASE( AppendPaperDeltas_BothChange_EmitsTwoInDocumentedOrder )
94{
95 // Format delta MUST be appended before orientation delta — downstream
96 // marker rendering expects this stable order, so a refactor that flips
97 // them should trip the test.
98 PAGE_INFO before( PAGE_SIZE_TYPE::A4, false );
99 PAGE_INFO after ( PAGE_SIZE_TYPE::A3, true );
100
101 std::vector<PROPERTY_DELTA> deltas;
102 AppendPaperDeltas( deltas, before, after );
103
104 BOOST_REQUIRE_EQUAL( deltas.size(), 2u );
105 BOOST_CHECK( deltas[0].name == DOC_PROP_PAGE_FORMAT );
106 BOOST_CHECK( deltas[1].name == DOC_PROP_PAGE_ORIENTATION );
107}
108
109
110BOOST_AUTO_TEST_CASE( AppendPaperDeltas_AppendsToExistingVector )
111{
112 // The helper appends; it must not replace caller-seeded entries. The
113 // PCB and SCH callers stage additional document-level deltas (board
114 // thickness, drawing sheet, etc.) in the same vector before/after
115 // calling AppendPaperDeltas.
116 std::vector<PROPERTY_DELTA> deltas;
117 PROPERTY_DELTA preExisting;
118 preExisting.name = wxS( "Sentinel" );
119 deltas.push_back( preExisting );
120
121 PAGE_INFO before( PAGE_SIZE_TYPE::A4, false );
122 PAGE_INFO after ( PAGE_SIZE_TYPE::A3, false );
123 AppendPaperDeltas( deltas, before, after );
124
125 BOOST_REQUIRE_EQUAL( deltas.size(), 2u );
126 BOOST_CHECK( deltas[0].name == wxS( "Sentinel" ) );
127 BOOST_CHECK( deltas[1].name == DOC_PROP_PAGE_FORMAT );
128}
129
130
const char * name
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
wxString GetTypeAsString() const
const PAGE_SIZE_TYPE & GetType() const
Definition page_info.h:98
const wxString DOC_PROP_PAGE_FORMAT
Property-name keys for the synthetic document-level ITEM_CHANGE (empty KIID_PATH).
const wxString DOC_PROP_PAGE_ORIENTATION
void AppendPaperDeltas(std::vector< PROPERTY_DELTA > &aDeltas, const PAGE_INFO &aBefore, const PAGE_INFO &aAfter)
Append DOC_PROP_PAGE_FORMAT and/or DOC_PROP_PAGE_ORIENTATION deltas to aDeltas when the two PAGE_INFO...
Single (name, before, after) triple for one mutated property on an item.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(AppendPaperDeltas_IdenticalProducesNoDeltas)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")