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>
65#include <jobs/job_pcb_render.h>
66#include <drc/drc_item.h>
67#include <drc/drc_rule.h>
68#include <padstack.h>
69#include <pcb_dimension.h>
70#include <pcb_track.h>
71#include <plotprint_opts.h>
73#include <zones.h>
74#include <zone_settings.h>
75
76using namespace kiapi::common;
77
78BOOST_AUTO_TEST_SUITE( ApiEnums )
79
84
89
94
99
100BOOST_AUTO_TEST_CASE( KiCadObjectType )
101{
103}
104
109
114
119
124
129
134
139
144
149
151{
152 // VIATYPE::NOT_DEFINED is not mapped
154}
155
160
165
170
175
180
185
190
195
200
205
210
215
220
225
230
235
240
245
250
255
260
265
266BOOST_AUTO_TEST_CASE( ConstraintType )
267{
268 // UNDEFINED is an internal sentinel that is not exposed to the API.
270}
271
276
277BOOST_AUTO_TEST_CASE( DesignRuleType )
278{
279 using ProtoType = kiapi::board::DrcErrorType;
280
351 {
352 ProtoType proto = ToProtoEnum<PCB_DRC_CODE, ProtoType>( value );
353 BOOST_REQUIRE( proto != ProtoType::DRCET_UNKNOWN );
354 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( proto ) == value ) );
355 }
356
357 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( ProtoType::DRCET_UNKNOWN )
358 == static_cast<PCB_DRC_CODE>( 0 ) ) );
359}
360
361BOOST_AUTO_TEST_CASE( CustomRuleConstraintType )
362{
363 using ProtoType = kiapi::board::CustomRuleConstraintType;
364
365 for( DRC_CONSTRAINT_T value : magic_enum::enum_values<DRC_CONSTRAINT_T>() )
366 {
367 if( value == NULL_CONSTRAINT )
368 continue;
369
370 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT_T, ProtoType>( value );
371 BOOST_REQUIRE( proto != ProtoType::CRCT_UNKNOWN );
372 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( proto ) == value ) );
373 }
374
375 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( ProtoType::CRCT_UNKNOWN )
376 == NULL_CONSTRAINT ) );
377}
378
379BOOST_AUTO_TEST_CASE( CustomRuleConstraintOption )
380{
381 using ProtoType = kiapi::board::CustomRuleConstraintOption;
382
383 for( DRC_CONSTRAINT::OPTIONS value : magic_enum::enum_values<DRC_CONSTRAINT::OPTIONS>() )
384 {
386 continue;
387
388 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( value );
389 BOOST_REQUIRE( proto != ProtoType::CRCO_UNKNOWN );
390 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( proto ) == value ) );
391 }
392}
393
394BOOST_AUTO_TEST_CASE( CustomRuleDisallowType )
395{
396 using ProtoType = kiapi::board::CustomRuleDisallowType;
397
404 {
405 ProtoType proto = ToProtoEnum<DRC_DISALLOW_T, ProtoType>( value );
406 BOOST_REQUIRE( proto != ProtoType::CRDT_UNKNOWN );
407 BOOST_CHECK( ( FromProtoEnum<DRC_DISALLOW_T, ProtoType>( proto ) == value ) );
408 }
409}
410
415
420
425
430
435
440
445
446BOOST_AUTO_TEST_CASE( SvgPaginationMode )
447{
448 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
449
451 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
453 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
454
455 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
457 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
459 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
461}
462
463BOOST_AUTO_TEST_CASE( DxfPaginationMode )
464{
465 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
466
468 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
470 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
471
472 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
474 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
476 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
478}
479
484
489
490BOOST_AUTO_TEST_CASE( PsPaginationMode )
491{
492 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
493
495 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
497 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
498
499 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
501 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
503 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
505}
506
511
516
521
526
531
536
541
546
551
556
561
566
573
575{
576 // COUNT marks an unrecognised token and has no API value
578 BOOST_CHECK( FromProtoEnum<JOB_EXPORT_PCB_FAB::DATA_SET>( kiapi::board::jobs::FDS_UNKNOWN )
580 BOOST_CHECK( FromProtoEnum<JOB_EXPORT_PCB_FAB::DATA_SET>( static_cast<kiapi::board::jobs::FabDataSet>( 99 ) )
582}
583
590
597
602
607
612
617
622
627
632
637
642
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.