KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_api_enums.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 <magic_enum.hpp>
22#include <import_export.h>
25
26// Common
27#include <api/api_enums.h>
28#include <api/board/board.pb.h>
29#include <api/board/board_rules.pb.h>
30#include <api/common/types/enums.pb.h>
31#include <api/common/types/library_types.pb.h>
32#include <eda_shape.h>
33#include <core/mirror.h>
34#include <core/typeinfo.h>
36#include <layer_ids.h>
39#include <pin_type.h>
40#include <stroke_params.h>
42
43// Board-specific
44#include <api/board/board_types.pb.h>
45#include <api/board/board_commands.pb.h>
46#include <api/board/board_jobs.pb.h>
47#include <api/schematic/schematic_jobs.pb.h>
48#include <api/common/types/embedded_files.pb.h>
49#include <embedded_files.h>
64#include <jobs/job_pcb_render.h>
65#include <drc/drc_item.h>
66#include <drc/drc_rule.h>
67#include <padstack.h>
68#include <pcb_dimension.h>
69#include <pcb_track.h>
70#include <plotprint_opts.h>
72#include <zones.h>
73#include <zone_settings.h>
74
75using namespace kiapi::common;
76
77BOOST_AUTO_TEST_SUITE( ApiEnums )
78
83
88
93
98
99BOOST_AUTO_TEST_CASE( KiCadObjectType )
100{
102}
103
108
113
118
123
128
133
138
143
148
150{
151 // VIATYPE::NOT_DEFINED is not mapped
153}
154
159
164
169
174
179
184
189
194
199
204
209
214
219
224
229
234
239
244
249
254
259
264
265BOOST_AUTO_TEST_CASE( ConstraintType )
266{
267 // UNDEFINED is an internal sentinel that is not exposed to the API.
269}
270
275
276BOOST_AUTO_TEST_CASE( DesignRuleType )
277{
278 using ProtoType = kiapi::board::DrcErrorType;
279
350 {
351 ProtoType proto = ToProtoEnum<PCB_DRC_CODE, ProtoType>( value );
352 BOOST_REQUIRE( proto != ProtoType::DRCET_UNKNOWN );
353 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( proto ) == value ) );
354 }
355
356 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( ProtoType::DRCET_UNKNOWN )
357 == static_cast<PCB_DRC_CODE>( 0 ) ) );
358}
359
360BOOST_AUTO_TEST_CASE( CustomRuleConstraintType )
361{
362 using ProtoType = kiapi::board::CustomRuleConstraintType;
363
364 for( DRC_CONSTRAINT_T value : magic_enum::enum_values<DRC_CONSTRAINT_T>() )
365 {
366 if( value == NULL_CONSTRAINT )
367 continue;
368
369 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT_T, ProtoType>( value );
370 BOOST_REQUIRE( proto != ProtoType::CRCT_UNKNOWN );
371 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( proto ) == value ) );
372 }
373
374 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( ProtoType::CRCT_UNKNOWN )
375 == NULL_CONSTRAINT ) );
376}
377
378BOOST_AUTO_TEST_CASE( CustomRuleConstraintOption )
379{
380 using ProtoType = kiapi::board::CustomRuleConstraintOption;
381
382 for( DRC_CONSTRAINT::OPTIONS value : magic_enum::enum_values<DRC_CONSTRAINT::OPTIONS>() )
383 {
385 continue;
386
387 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( value );
388 BOOST_REQUIRE( proto != ProtoType::CRCO_UNKNOWN );
389 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( proto ) == value ) );
390 }
391}
392
393BOOST_AUTO_TEST_CASE( CustomRuleDisallowType )
394{
395 using ProtoType = kiapi::board::CustomRuleDisallowType;
396
403 {
404 ProtoType proto = ToProtoEnum<DRC_DISALLOW_T, ProtoType>( value );
405 BOOST_REQUIRE( proto != ProtoType::CRDT_UNKNOWN );
406 BOOST_CHECK( ( FromProtoEnum<DRC_DISALLOW_T, ProtoType>( proto ) == value ) );
407 }
408}
409
414
419
424
429
434
439
444
445BOOST_AUTO_TEST_CASE( SvgPaginationMode )
446{
447 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
448
450 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
452 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
453
454 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
456 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
458 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
460}
461
462BOOST_AUTO_TEST_CASE( DxfPaginationMode )
463{
464 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
465
467 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
469 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
470
471 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
473 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
475 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
477}
478
483
488
489BOOST_AUTO_TEST_CASE( PsPaginationMode )
490{
491 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
492
494 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
496 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
497
498 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
500 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
502 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
504}
505
510
515
520
525
530
535
540
545
550
555
560
565
570
575
580
585
590
595
600
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:55
void testEnums(bool aPartiallyMapped=false, std::optional< KiCadEnum > aNullMapping=std::nullopt)
Checks if a KiCad enum has been properly mapped to a Protobuf enum.
PCB_DRC_CODE
Definition drc_item.h:35
@ DRCE_DISABLED_LAYER_ITEM
Definition drc_item.h:74
@ DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG
Definition drc_item.h:114
@ DRCE_SKEW_OUT_OF_RANGE
Definition drc_item.h:111
@ DRCE_CREEPAGE
Definition drc_item.h:42
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:52
@ DRCE_MICROVIA_STACK_DEPTH
Definition drc_item.h:65
@ DRCE_SILK_EDGE_CLEARANCE
Definition drc_item.h:102
@ DRCE_FOOTPRINT_FILTERS
Definition drc_item.h:82
@ DRCE_SILK_MASK_CLEARANCE
Definition drc_item.h:100
@ DRCE_VIA_DIAMETER
Definition drc_item.h:59
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:37
@ DRCE_DP_GAP_OUT_OF_RANGE
Definition drc_item.h:113
@ DRCE_TRACK_WIDTH
Definition drc_item.h:53
@ DRCE_PADSTACK
Definition drc_item.h:60
@ DRCE_MIRRORED_TEXT_ON_FRONT_LAYER
Definition drc_item.h:116
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:85
@ DRCE_MICROVIA_CROSSES_CORE
Definition drc_item.h:67
@ DRCE_OVERLAPPING_FOOTPRINTS
Definition drc_item.h:68
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:75
@ DRCE_TRACK_ON_POST_MACHINED_LAYER
Definition drc_item.h:122
@ DRCE_TEXT_ON_EDGECUTS
Definition drc_item.h:40
@ DRCE_MALFORMED_MICROVIA_STACK_SPAN
Definition drc_item.h:63
@ DRCE_MICROVIA_ASPECT_RATIO
Definition drc_item.h:66
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:58
@ DRCE_EDGE_CLEARANCE
Definition drc_item.h:44
@ DRCE_STARVED_THERMAL
Definition drc_item.h:47
@ DRCE_TRACK_SEGMENT_LENGTH
Definition drc_item.h:55
@ DRCE_SCHEMATIC_FIELDS_PARITY
Definition drc_item.h:126
@ DRCE_MISSING_COURTYARD
Definition drc_item.h:69
@ DRCE_MICROVIA_STACK_NOT_FILLED
Definition drc_item.h:64
@ DRCE_TRACK_ANGLE
Definition drc_item.h:54
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:124
@ DRCE_CLEARANCE
Definition drc_item.h:41
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:46
@ DRCE_GENERIC_ERROR
Definition drc_item.h:94
@ DRCE_MISSING_TUNING_PROFILE
Definition drc_item.h:119
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:50
@ DRCE_ALLOWED_ITEMS
Definition drc_item.h:39
@ DRCE_COPPER_SLIVER
Definition drc_item.h:96
@ DRCE_PTH_IN_COURTYARD
Definition drc_item.h:72
@ DRCE_MICROVIA_DRILL_OUT_OF_RANGE
Definition drc_item.h:62
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:38
@ DRCE_MALFORMED_COURTYARD
Definition drc_item.h:70
@ DRCE_DANGLING_VIA
Definition drc_item.h:48
@ DRCE_PADSTACK_INVALID
Definition drc_item.h:61
@ DRCE_UNRESOLVED_VARIABLE
Definition drc_item.h:91
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition drc_item.h:84
@ DRCE_DUPLICATE_FOOTPRINT
Definition drc_item.h:78
@ DRCE_DANGLING_TRACK
Definition drc_item.h:49
@ DRCE_TEXT_HEIGHT
Definition drc_item.h:104
@ DRCE_ASSERTION_FAILURE
Definition drc_item.h:92
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:97
@ DRCE_DRILLED_HOLES_COLOCATED
Definition drc_item.h:51
@ DRCE_EXTRA_FOOTPRINT
Definition drc_item.h:79
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:103
@ DRCE_LENGTH_OUT_OF_RANGE
Definition drc_item.h:107
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:86
@ DRCE_NET_CONFLICT
Definition drc_item.h:80
@ DRCE_MISSING_FOOTPRINT
Definition drc_item.h:77
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition drc_item.h:87
@ DRCE_FOOTPRINT
Definition drc_item.h:88
@ DRCE_UNMIRRORED_TEXT_ON_BACK_LAYER
Definition drc_item.h:117
@ DRCE_GENERIC_WARNING
Definition drc_item.h:93
@ DRCE_TEXT_THICKNESS
Definition drc_item.h:105
@ DRCE_NPTH_IN_COURTYARD
Definition drc_item.h:73
@ DRCE_CONNECTION_WIDTH
Definition drc_item.h:57
@ DRCE_SCHEMATIC_PARITY
Definition drc_item.h:81
@ DRCE_TRACKS_CROSSING
Definition drc_item.h:43
@ DRCE_VIA_COUNT_OUT_OF_RANGE
Definition drc_item.h:112
@ DRCE_ANNULAR_WIDTH
Definition drc_item.h:56
DRC_DISALLOW_T
Definition drc_rule.h:96
@ DRC_DISALLOW_PADS
Definition drc_rule.h:102
@ DRC_DISALLOW_BURIED_VIAS
Definition drc_rule.h:100
@ DRC_DISALLOW_BLIND_VIAS
Definition drc_rule.h:99
@ DRC_DISALLOW_TEXTS
Definition drc_rule.h:104
@ DRC_DISALLOW_ZONES
Definition drc_rule.h:103
@ DRC_DISALLOW_HOLES
Definition drc_rule.h:106
@ DRC_DISALLOW_GRAPHICS
Definition drc_rule.h:105
@ DRC_DISALLOW_THROUGH_VIAS
Definition drc_rule.h:97
@ DRC_DISALLOW_FOOTPRINTS
Definition drc_rule.h:107
@ DRC_DISALLOW_TRACKS
Definition drc_rule.h:101
@ DRC_DISALLOW_MICRO_VIAS
Definition drc_rule.h:98
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ NULL_CONSTRAINT
Definition drc_rule.h:50
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
Class ZONE_SETTINGS used to handle zones parameters in dialogs.