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>
22#include <nlohmann/json.hpp>
23
24
25BOOST_AUTO_TEST_SUITE( JobExportSchBom )
26
27
28BOOST_AUTO_TEST_CASE( VariantRoundTrip )
29{
31 job.SetSelectedVariant( wxS( "VAR A" ) );
32
33 nlohmann::json j;
34 job.ToJson( j );
35
36 JOB_EXPORT_SCH_BOM loaded;
37 loaded.FromJson( j );
38
39 BOOST_CHECK( loaded.GetSelectedVariant() == wxS( "VAR A" ) );
40}
41
42
43BOOST_AUTO_TEST_CASE( EmptyVariantRoundTrip )
44{
46
47 nlohmann::json j;
48 job.ToJson( j );
49
50 JOB_EXPORT_SCH_BOM loaded;
51 loaded.FromJson( j );
52
53 BOOST_CHECK( loaded.GetSelectedVariant().IsEmpty() );
54}
55
56
57// Issue #23932: saving a job used to append the choice every time, so the list grew
58// without bound. Setting the selection must replace the list, never grow it.
59BOOST_AUTO_TEST_CASE( VariantNoAccumulation )
60{
62 job.SetSelectedVariant( wxS( "VAR A" ) );
63 job.SetSelectedVariant( wxS( "VAR A" ) );
64 job.SetSelectedVariant( wxS( "VAR B" ) );
65
66 BOOST_CHECK_EQUAL( job.m_variantNames.size(), 1u );
67 BOOST_CHECK( job.GetSelectedVariant() == wxS( "VAR B" ) );
68}
69
70
71// Selecting the default variant leaves the list empty.
72BOOST_AUTO_TEST_CASE( DefaultVariantClearsList )
73{
75 job.SetSelectedVariant( wxS( "VAR A" ) );
76 job.SetSelectedVariant( wxEmptyString );
77
78 BOOST_CHECK( job.m_variantNames.empty() );
79 BOOST_CHECK( job.GetSelectedVariant().IsEmpty() );
80}
81
82
83// A CLI multi-variant list is reported through its first entry.
84BOOST_AUTO_TEST_CASE( VariantFromList )
85{
86 nlohmann::json j = { { "variant_names", { "VAR A", "VAR B" } } };
87
88 JOB_EXPORT_SCH_BOM loaded;
89 loaded.FromJson( j );
90
91 BOOST_CHECK( loaded.GetSelectedVariant() == wxS( "VAR A" ) );
92}
93
94
void SetSelectedVariant(const wxString &aVariant)
std::vector< wxString > m_variantNames
wxString GetSelectedVariant() const
virtual void FromJson(const nlohmann::json &j)
Definition job.cpp:60
virtual void ToJson(nlohmann::json &j) const
Definition job.cpp:67
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(VariantRoundTrip)
BOOST_CHECK_EQUAL(result, "25.4")