KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_job_export_sch_bom.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 2
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
20#include <boost/test/unit_test.hpp>
21#include <jobs/job_export_bom.h>
22#include <nlohmann/json.hpp>
24
25
26BOOST_AUTO_TEST_SUITE( JobExportSchBom )
27
28
29BOOST_AUTO_TEST_CASE( ByteOrderMarkFormatPresetRoundTripAndLegacyDefault )
30{
32 preset.includeByteOrderMark = true;
33
34 BOM_FMT_PRESET withoutByteOrderMark = preset;
35 withoutByteOrderMark.includeByteOrderMark = false;
36 BOOST_CHECK( preset != withoutByteOrderMark );
37
38 nlohmann::json j = preset;
39
40 BOOST_REQUIRE( j.contains( "include_byte_order_mark" ) );
41 BOOST_CHECK( j.at( "include_byte_order_mark" ).get<bool>() );
42
43 BOM_FMT_PRESET loaded = j.get<BOM_FMT_PRESET>();
44 BOOST_CHECK( loaded.includeByteOrderMark );
45
46 j.erase( "include_byte_order_mark" );
47 loaded.includeByteOrderMark = true;
48 from_json( j, loaded );
49 BOOST_CHECK( !loaded.includeByteOrderMark );
50}
51
52
53BOOST_AUTO_TEST_CASE( VariantRoundTrip )
54{
56 job.SetSelectedVariant( wxS( "VAR A" ) );
57 job.m_includeByteOrderMark = true;
58
59 nlohmann::json j;
60 job.ToJson( j );
61
62 JOB_EXPORT_BOM loaded;
63 loaded.FromJson( j );
64
65 BOOST_CHECK( loaded.GetSelectedVariant() == wxS( "VAR A" ) );
66 BOOST_CHECK( loaded.m_includeByteOrderMark );
67}
68
69
70BOOST_AUTO_TEST_CASE( EmptyVariantRoundTrip )
71{
73
74 nlohmann::json j;
75 job.ToJson( j );
76
77 JOB_EXPORT_BOM loaded;
78 loaded.FromJson( j );
79
80 BOOST_CHECK( loaded.GetSelectedVariant().IsEmpty() );
81}
82
83
84// Issue #23932: saving a job used to append the choice every time, so the list grew
85// without bound. Setting the selection must replace the list, never grow it.
86BOOST_AUTO_TEST_CASE( VariantNoAccumulation )
87{
89 job.SetSelectedVariant( wxS( "VAR A" ) );
90 job.SetSelectedVariant( wxS( "VAR A" ) );
91 job.SetSelectedVariant( wxS( "VAR B" ) );
92
93 BOOST_CHECK_EQUAL( job.m_variantNames.size(), 1u );
94 BOOST_CHECK( job.GetSelectedVariant() == wxS( "VAR B" ) );
95}
96
97
98// Selecting the default variant leaves the list empty.
99BOOST_AUTO_TEST_CASE( DefaultVariantClearsList )
100{
101 JOB_EXPORT_BOM job;
102 job.SetSelectedVariant( wxS( "VAR A" ) );
103 job.SetSelectedVariant( wxEmptyString );
104
105 BOOST_CHECK( job.m_variantNames.empty() );
106 BOOST_CHECK( job.GetSelectedVariant().IsEmpty() );
107}
108
109
110// A CLI multi-variant list is reported through its first entry.
111BOOST_AUTO_TEST_CASE( VariantFromList )
112{
113 nlohmann::json j = { { "variant_names", { "VAR A", "VAR B" } } };
114
115 JOB_EXPORT_BOM loaded;
116 loaded.m_includeByteOrderMark = true;
117 loaded.FromJson( j );
118
119 BOOST_CHECK( loaded.GetSelectedVariant() == wxS( "VAR A" ) );
120 BOOST_CHECK( !loaded.m_includeByteOrderMark );
121}
122
123
wxString GetSelectedVariant() const
std::vector< wxString > m_variantNames
bool m_includeByteOrderMark
void SetSelectedVariant(const wxString &aVariant)
virtual void FromJson(const nlohmann::json &j)
Definition job.cpp:60
virtual void ToJson(nlohmann::json &j) const
Definition job.cpp:67
KICOMMON_API void from_json(const nlohmann::json &j, JOB &f)
Definition job.cpp:173
bool includeByteOrderMark
static BOM_FMT_PRESET CSV()
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(ByteOrderMarkFormatPresetRoundTripAndLegacyDefault)
BOOST_CHECK_EQUAL(result, "25.4")