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
352 {
353 ProtoType proto = ToProtoEnum<PCB_DRC_CODE, ProtoType>( value );
354 BOOST_REQUIRE( proto != ProtoType::DRCET_UNKNOWN );
355 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( proto ) == value ) );
356 }
357
358 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( ProtoType::DRCET_UNKNOWN )
359 == static_cast<PCB_DRC_CODE>( 0 ) ) );
360}
361
362BOOST_AUTO_TEST_CASE( CustomRuleConstraintType )
363{
364 using ProtoType = kiapi::board::CustomRuleConstraintType;
365
366 for( DRC_CONSTRAINT_T value : magic_enum::enum_values<DRC_CONSTRAINT_T>() )
367 {
368 if( value == NULL_CONSTRAINT )
369 continue;
370
371 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT_T, ProtoType>( value );
372 BOOST_REQUIRE( proto != ProtoType::CRCT_UNKNOWN );
373 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( proto ) == value ) );
374 }
375
376 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( ProtoType::CRCT_UNKNOWN )
377 == NULL_CONSTRAINT ) );
378}
379
380BOOST_AUTO_TEST_CASE( CustomRuleConstraintOption )
381{
382 using ProtoType = kiapi::board::CustomRuleConstraintOption;
383
384 for( DRC_CONSTRAINT::OPTIONS value : magic_enum::enum_values<DRC_CONSTRAINT::OPTIONS>() )
385 {
387 continue;
388
389 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( value );
390 BOOST_REQUIRE( proto != ProtoType::CRCO_UNKNOWN );
391 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( proto ) == value ) );
392 }
393}
394
395BOOST_AUTO_TEST_CASE( CustomRuleDisallowType )
396{
397 using ProtoType = kiapi::board::CustomRuleDisallowType;
398
405 {
406 ProtoType proto = ToProtoEnum<DRC_DISALLOW_T, ProtoType>( value );
407 BOOST_REQUIRE( proto != ProtoType::CRDT_UNKNOWN );
408 BOOST_CHECK( ( FromProtoEnum<DRC_DISALLOW_T, ProtoType>( proto ) == value ) );
409 }
410}
411
416
421
426
431
436
441
446
447BOOST_AUTO_TEST_CASE( SvgPaginationMode )
448{
449 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
450
452 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
454 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
455
456 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
458 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
460 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
462}
463
464BOOST_AUTO_TEST_CASE( DxfPaginationMode )
465{
466 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
467
469 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
471 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
472
473 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
475 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
477 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
479}
480
485
490
491BOOST_AUTO_TEST_CASE( PsPaginationMode )
492{
493 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
494
496 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
498 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
499
500 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
502 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
504 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
506}
507
512
517
522
527
532
537
542
547
552
557
562
567
574
576{
577 // COUNT marks an unrecognised token and has no API value
579 BOOST_CHECK( FromProtoEnum<JOB_EXPORT_PCB_FAB::DATA_SET>( kiapi::board::jobs::FDS_UNKNOWN )
581 BOOST_CHECK( FromProtoEnum<JOB_EXPORT_PCB_FAB::DATA_SET>( static_cast<kiapi::board::jobs::FabDataSet>( 99 ) )
583}
584
591
598
603
608
613
618
623
628
633
638
643
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.
@ DRC_DISALLOW_PADS
@ DRC_DISALLOW_BURIED_VIAS
@ DRC_DISALLOW_BLIND_VIAS
@ DRC_DISALLOW_TEXTS
@ DRC_DISALLOW_ZONES
@ DRC_DISALLOW_HOLES
@ DRC_DISALLOW_GRAPHICS
@ DRC_DISALLOW_THROUGH_VIAS
@ DRC_DISALLOW_FOOTPRINTS
@ DRC_DISALLOW_TRACKS
@ DRC_DISALLOW_MICRO_VIAS
@ NULL_CONSTRAINT
PCB_DRC_CODE
Definition drc_item.h:46
@ DRCE_DISABLED_LAYER_ITEM
Definition drc_item.h:85
@ DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG
Definition drc_item.h:125
@ DRCE_SKEW_OUT_OF_RANGE
Definition drc_item.h:122
@ DRCE_CREEPAGE
Definition drc_item.h:53
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:63
@ DRCE_MICROVIA_STACK_DEPTH
Definition drc_item.h:76
@ DRCE_SILK_EDGE_CLEARANCE
Definition drc_item.h:113
@ DRCE_FOOTPRINT_FILTERS
Definition drc_item.h:93
@ DRCE_SILK_MASK_CLEARANCE
Definition drc_item.h:111
@ DRCE_VIA_DIAMETER
Definition drc_item.h:70
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:48
@ DRCE_DP_GAP_OUT_OF_RANGE
Definition drc_item.h:124
@ DRCE_TRACK_WIDTH
Definition drc_item.h:64
@ DRCE_PADSTACK
Definition drc_item.h:71
@ DRCE_MIRRORED_TEXT_ON_FRONT_LAYER
Definition drc_item.h:127
@ DRCE_HOLE_ASPECT_RATIO
Definition drc_item.h:77
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:96
@ DRCE_MICROVIA_CROSSES_CORE
Definition drc_item.h:78
@ DRCE_OVERLAPPING_FOOTPRINTS
Definition drc_item.h:79
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:86
@ DRCE_TRACK_ON_POST_MACHINED_LAYER
Definition drc_item.h:133
@ DRCE_TEXT_ON_EDGECUTS
Definition drc_item.h:51
@ DRCE_MALFORMED_MICROVIA_STACK_SPAN
Definition drc_item.h:74
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:69
@ DRCE_EDGE_CLEARANCE
Definition drc_item.h:55
@ DRCE_STARVED_THERMAL
Definition drc_item.h:58
@ DRCE_TRACK_SEGMENT_LENGTH
Definition drc_item.h:66
@ DRCE_SCHEMATIC_FIELDS_PARITY
Definition drc_item.h:137
@ DRCE_MISSING_COURTYARD
Definition drc_item.h:80
@ DRCE_MICROVIA_STACK_NOT_FILLED
Definition drc_item.h:75
@ DRCE_TRACK_ANGLE
Definition drc_item.h:65
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:135
@ DRCE_COPPER_OUTSIDE_BOARD
Definition drc_item.h:142
@ DRCE_CLEARANCE
Definition drc_item.h:52
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:57
@ DRCE_GENERIC_ERROR
Definition drc_item.h:105
@ DRCE_MISSING_TUNING_PROFILE
Definition drc_item.h:130
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:61
@ DRCE_ALLOWED_ITEMS
Definition drc_item.h:50
@ DRCE_COPPER_SLIVER
Definition drc_item.h:107
@ DRCE_PTH_IN_COURTYARD
Definition drc_item.h:83
@ DRCE_MICROVIA_DRILL_OUT_OF_RANGE
Definition drc_item.h:73
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:49
@ DRCE_MALFORMED_COURTYARD
Definition drc_item.h:81
@ DRCE_DANGLING_VIA
Definition drc_item.h:59
@ DRCE_PADSTACK_INVALID
Definition drc_item.h:72
@ DRCE_UNRESOLVED_VARIABLE
Definition drc_item.h:102
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition drc_item.h:95
@ DRCE_DUPLICATE_FOOTPRINT
Definition drc_item.h:89
@ DRCE_DANGLING_TRACK
Definition drc_item.h:60
@ DRCE_TEXT_HEIGHT
Definition drc_item.h:115
@ DRCE_ASSERTION_FAILURE
Definition drc_item.h:103
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:108
@ DRCE_DRILLED_HOLES_COLOCATED
Definition drc_item.h:62
@ DRCE_EXTRA_FOOTPRINT
Definition drc_item.h:90
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:114
@ DRCE_LENGTH_OUT_OF_RANGE
Definition drc_item.h:118
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:97
@ DRCE_NET_CONFLICT
Definition drc_item.h:91
@ DRCE_MISSING_FOOTPRINT
Definition drc_item.h:88
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition drc_item.h:98
@ DRCE_FOOTPRINT
Definition drc_item.h:99
@ DRCE_UNMIRRORED_TEXT_ON_BACK_LAYER
Definition drc_item.h:128
@ DRCE_GENERIC_WARNING
Definition drc_item.h:104
@ DRCE_TEXT_THICKNESS
Definition drc_item.h:116
@ DRCE_NPTH_IN_COURTYARD
Definition drc_item.h:84
@ DRCE_CONNECTION_WIDTH
Definition drc_item.h:68
@ DRCE_SCHEMATIC_PARITY
Definition drc_item.h:92
@ DRCE_TRACKS_CROSSING
Definition drc_item.h:54
@ DRCE_VIA_COUNT_OUT_OF_RANGE
Definition drc_item.h:123
@ DRCE_ANNULAR_WIDTH
Definition drc_item.h:67
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.