KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue23023_http_fields.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, see <https://www.gnu.org/licenses/>.
18
*/
19
32
33
#include <boost/test/unit_test.hpp>
34
35
#include <algorithm>
36
#include <tuple>
37
38
#include <wx/arrstr.h>
// for MSVC to see std::vector<wxString> is exported from wx
39
40
#include <
json_common.h
>
41
#include <
http_lib/http_lib_connection.h
>
42
#include <
http_lib/http_lib_settings.h
>
43
44
45
BOOST_AUTO_TEST_SUITE
( Issue23023HttpFields )
46
47
48
static const
HTTP_LIB_PART
::field_type*
findField
( const
HTTP_LIB_PART
& aPart, const
std
::
string
& aName )
49
{
50
for
(
const
auto
& [
name
, properties] : aPart.fields )
51
{
52
if( name == aName )
53
return &properties;
54
}
55
56
return
nullptr
;
57
}
58
59
61
BOOST_AUTO_TEST_CASE
( DetailRecordPopulatesFields )
62
{
63
const
nlohmann::json
detail
= R
"({
64
"id": "1",
65
"name": "RC0603FR-0710KL",
66
"symbolIdStr": "Device:R",
67
"exclude_from_bom": "False",
68
"exclude_from_board": "False",
69
"exclude_from_sim": "True",
70
"fields": {
71
"footprint": { "value": "Resistor_SMD:R_0603_1608Metric", "visible": "False" },
72
"datasheet": { "value": "www.kicad.org", "visible": "False" },
73
"value": { "value": "10k" },
74
"reference": { "value": "R" }
75
}
76
})"_json;
77
78
HTTP_LIB_PART
part;
79
80
BOOST_CHECK(
setPartExtendedData
(
detail
, part ) );
81
82
BOOST_CHECK_EQUAL
( part.
symbolIdStr
,
"Device:R"
);
83
BOOST_CHECK_EQUAL
( part.
exclude_from_sim
,
true
);
84
BOOST_CHECK_EQUAL
( part.
exclude_from_bom
,
false
);
85
86
BOOST_REQUIRE_EQUAL( part.
fields
.size(), 4u );
87
88
const
HTTP_LIB_PART::field_type
* value =
findField
( part,
"value"
);
89
BOOST_REQUIRE
( value );
90
BOOST_CHECK_EQUAL
( std::get<0>( *value ),
"10k"
);
91
92
// A field with no explicit "visible" key must default to visible.
93
BOOST_CHECK_EQUAL
( std::get<1>( *value ),
true
);
94
95
const
HTTP_LIB_PART::field_type
* footprint =
findField
( part,
"footprint"
);
96
BOOST_REQUIRE
( footprint );
97
BOOST_CHECK_EQUAL
( std::get<0>( *footprint ),
"Resistor_SMD:R_0603_1608Metric"
);
98
BOOST_CHECK_EQUAL
( std::get<1>( *footprint ),
false
);
99
}
100
101
104
BOOST_AUTO_TEST_CASE
( ListingRecordReportsNotDetailed )
105
{
106
const
nlohmann::json listing = R
"({
107
"id": "1",
108
"name": "RC0603FR-0710KL",
109
"description": "10 kOhms resistor"
110
})"_json;
111
112
HTTP_LIB_PART
part;
113
114
BOOST_CHECK( !
setPartExtendedData
( listing, part ) );
115
BOOST_CHECK( part.
fields
.empty() );
116
}
117
118
121
BOOST_AUTO_TEST_CASE
( NativeBooleanFlagsAreAccepted )
122
{
123
const
nlohmann::json
detail
= R
"({
124
"id": "1",
125
"symbolIdStr": "Device:R",
126
"exclude_from_bom": true,
127
"fields": {
128
"mpn": { "value": "RC0603FR-0710KL", "visible": false }
129
}
130
})"_json;
131
132
HTTP_LIB_PART
part;
133
134
BOOST_CHECK_NO_THROW(
setPartExtendedData
(
detail
, part ) );
135
BOOST_CHECK_EQUAL
( part.
exclude_from_bom
,
true
);
136
137
const
HTTP_LIB_PART::field_type
* mpn =
findField
( part,
"mpn"
);
138
BOOST_REQUIRE
( mpn );
139
BOOST_CHECK_EQUAL
( std::get<1>( *mpn ),
false
);
140
}
141
142
143
BOOST_AUTO_TEST_SUITE_END
()
name
const char * name
Definition
DXF_plotter.cpp:61
setPartExtendedData
bool setPartExtendedData(const nlohmann::json &aPartJson, HTTP_LIB_PART &aPart)
Parse the exclusion flags and field content from a part's JSON record into aPart.
Definition
http_lib_connection.cpp:236
http_lib_connection.h
http_lib_settings.h
json_common.h
detail
Definition
json_serializers.h:29
std
STL namespace.
HTTP_LIB_PART
Definition
http_lib_settings.h:50
HTTP_LIB_PART::exclude_from_bom
bool exclude_from_bom
Definition
http_lib_settings.h:55
HTTP_LIB_PART::symbolIdStr
std::string symbolIdStr
Definition
http_lib_settings.h:53
HTTP_LIB_PART::exclude_from_sim
bool exclude_from_sim
Definition
http_lib_settings.h:57
HTTP_LIB_PART::field_type
std::tuple< std::string, bool > field_type
Field content keyed by name, holding the text value and its schematic visibility.
Definition
http_lib_settings.h:68
HTTP_LIB_PART::fields
std::vector< std::pair< std::string, field_type > > fields
Definition
http_lib_settings.h:70
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
findField
static const HTTP_LIB_PART::field_type * findField(const HTTP_LIB_PART &aPart, const std::string &aName)
Issue #23023.
Definition
test_issue23023_http_fields.cpp:48
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(DetailRecordPopulatesFields)
A detail record with a fields object populates every field and reports itself as detailed.
Definition
test_issue23023_http_fields.cpp:61
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
src
qa
tests
eeschema
test_issue23023_http_fields.cpp
Generated on Tue Jul 7 2026 00:07:27 for KiCad PCB EDA Suite by
1.13.2