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_sch_bom.h
>
22
#include <nlohmann/json.hpp>
23
24
25
BOOST_AUTO_TEST_SUITE
( JobExportSchBom )
26
27
28
BOOST_AUTO_TEST_CASE
( VariantRoundTrip )
29
{
30
JOB_EXPORT_SCH_BOM
job;
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
43
BOOST_AUTO_TEST_CASE
( EmptyVariantRoundTrip )
44
{
45
JOB_EXPORT_SCH_BOM
job;
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.
59
BOOST_AUTO_TEST_CASE
( VariantNoAccumulation )
60
{
61
JOB_EXPORT_SCH_BOM
job;
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.
72
BOOST_AUTO_TEST_CASE
( DefaultVariantClearsList )
73
{
74
JOB_EXPORT_SCH_BOM
job;
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.
84
BOOST_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
95
BOOST_AUTO_TEST_SUITE_END
()
JOB_EXPORT_SCH_BOM
Definition
job_export_sch_bom.h:29
JOB_EXPORT_SCH_BOM::SetSelectedVariant
void SetSelectedVariant(const wxString &aVariant)
Definition
job_export_sch_bom.cpp:100
JOB_EXPORT_SCH_BOM::m_variantNames
std::vector< wxString > m_variantNames
Definition
job_export_sch_bom.h:67
JOB_EXPORT_SCH_BOM::GetSelectedVariant
wxString GetSelectedVariant() const
Definition
job_export_sch_bom.cpp:91
JOB::FromJson
virtual void FromJson(const nlohmann::json &j)
Definition
job.cpp:60
JOB::ToJson
virtual void ToJson(nlohmann::json &j) const
Definition
job.cpp:67
job_export_sch_bom.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(VariantRoundTrip)
Definition
test_job_export_sch_bom.cpp:28
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
src
qa
tests
common
test_job_export_sch_bom.cpp
Generated on Tue Jul 7 2026 00:07:26 for KiCad PCB EDA Suite by
1.13.2