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/common/types/enums.pb.h>
30#include <eda_shape.h>
31#include <core/typeinfo.h>
33#include <layer_ids.h>
34#include <pin_type.h>
35#include <stroke_params.h>
37
38// Board-specific
39#include <api/board/board_types.pb.h>
40#include <api/board/board_commands.pb.h>
41#include <api/board/board_jobs.pb.h>
42#include <api/schematic/schematic_jobs.pb.h>
57#include <jobs/job_pcb_render.h>
58#include <drc/drc_item.h>
59#include <drc/drc_rule.h>
60#include <padstack.h>
61#include <pcb_dimension.h>
62#include <pcb_track.h>
63#include <plotprint_opts.h>
65#include <zones.h>
66#include <zone_settings.h>
67
68using namespace kiapi::common;
69
70BOOST_AUTO_TEST_SUITE( ApiEnums )
71
76
81
86
91
96
101
106
111
116
121
126
131
136
138{
139 // VIATYPE::NOT_DEFINED is not mapped
141}
142
147
152
157
162
167
172
177
182
187
192
197
202
207
212
217
222
227
232
233BOOST_AUTO_TEST_CASE( ConstraintType )
234{
235 // UNDEFINED is an internal sentinel that is not exposed to the API.
237}
238
243
244BOOST_AUTO_TEST_CASE( DesignRuleType )
245{
246 using ProtoType = kiapi::board::DrcErrorType;
247
313 {
314 ProtoType proto = ToProtoEnum<PCB_DRC_CODE, ProtoType>( value );
315 BOOST_REQUIRE( proto != ProtoType::DRCET_UNKNOWN );
316 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( proto ) == value ) );
317 }
318
319 BOOST_CHECK( ( FromProtoEnum<PCB_DRC_CODE, ProtoType>( ProtoType::DRCET_UNKNOWN )
320 == static_cast<PCB_DRC_CODE>( 0 ) ) );
321}
322
323BOOST_AUTO_TEST_CASE( CustomRuleConstraintType )
324{
325 using ProtoType = kiapi::board::CustomRuleConstraintType;
326
327 for( DRC_CONSTRAINT_T value : magic_enum::enum_values<DRC_CONSTRAINT_T>() )
328 {
329 if( value == NULL_CONSTRAINT )
330 continue;
331
332 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT_T, ProtoType>( value );
333 BOOST_REQUIRE( proto != ProtoType::CRCT_UNKNOWN );
334 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( proto ) == value ) );
335 }
336
337 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT_T, ProtoType>( ProtoType::CRCT_UNKNOWN )
338 == NULL_CONSTRAINT ) );
339}
340
341BOOST_AUTO_TEST_CASE( CustomRuleConstraintOption )
342{
343 using ProtoType = kiapi::board::CustomRuleConstraintOption;
344
345 for( DRC_CONSTRAINT::OPTIONS value : magic_enum::enum_values<DRC_CONSTRAINT::OPTIONS>() )
346 {
348 continue;
349
350 ProtoType proto = ToProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( value );
351 BOOST_REQUIRE( proto != ProtoType::CRCO_UNKNOWN );
352 BOOST_CHECK( ( FromProtoEnum<DRC_CONSTRAINT::OPTIONS, ProtoType>( proto ) == value ) );
353 }
354}
355
356BOOST_AUTO_TEST_CASE( CustomRuleDisallowType )
357{
358 using ProtoType = kiapi::board::CustomRuleDisallowType;
359
366 {
367 ProtoType proto = ToProtoEnum<DRC_DISALLOW_T, ProtoType>( value );
368 BOOST_REQUIRE( proto != ProtoType::CRDT_UNKNOWN );
369 BOOST_CHECK( ( FromProtoEnum<DRC_DISALLOW_T, ProtoType>( proto ) == value ) );
370 }
371}
372
377
382
387
392
397
402
407
408BOOST_AUTO_TEST_CASE( SvgPaginationMode )
409{
410 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
411
413 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
415 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
416
417 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
419 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
421 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_SVG::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
423}
424
425BOOST_AUTO_TEST_CASE( DxfPaginationMode )
426{
427 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
428
430 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
432 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
433
434 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
436 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
438 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_DXF::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
440}
441
446
451
452BOOST_AUTO_TEST_CASE( PsPaginationMode )
453{
454 using Mode = kiapi::board::jobs::BoardJobPaginationMode;
455
457 == Mode::BJPM_ALL_LAYERS_ONE_PAGE ) );
459 == Mode::BJPM_EACH_LAYER_OWN_FILE ) );
460
461 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_ALL_LAYERS_ONE_PAGE )
463 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_FILE )
465 BOOST_CHECK( ( FromProtoEnum<JOB_EXPORT_PCB_PS::GEN_MODE, Mode>( Mode::BJPM_EACH_LAYER_OWN_PAGE )
467}
468
473
478
483
488
493
498
503
508
513
518
523
528
533
538
543
548
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:47
void testEnums(bool aPartiallyMapped=false)
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:69
@ DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG
Definition drc_item.h:109
@ DRCE_SKEW_OUT_OF_RANGE
Definition drc_item.h:106
@ DRCE_CREEPAGE
Definition drc_item.h:42
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:52
@ DRCE_SILK_EDGE_CLEARANCE
Definition drc_item.h:97
@ DRCE_FOOTPRINT_FILTERS
Definition drc_item.h:77
@ DRCE_SILK_MASK_CLEARANCE
Definition drc_item.h:95
@ 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:108
@ 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:111
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:80
@ DRCE_OVERLAPPING_FOOTPRINTS
Definition drc_item.h:63
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:70
@ DRCE_TRACK_ON_POST_MACHINED_LAYER
Definition drc_item.h:117
@ DRCE_TEXT_ON_EDGECUTS
Definition drc_item.h:40
@ 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:121
@ DRCE_MISSING_COURTYARD
Definition drc_item.h:64
@ DRCE_TRACK_ANGLE
Definition drc_item.h:54
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:119
@ DRCE_CLEARANCE
Definition drc_item.h:41
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:46
@ DRCE_GENERIC_ERROR
Definition drc_item.h:89
@ DRCE_MISSING_TUNING_PROFILE
Definition drc_item.h:114
@ 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:91
@ DRCE_PTH_IN_COURTYARD
Definition drc_item.h:67
@ 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:65
@ DRCE_DANGLING_VIA
Definition drc_item.h:48
@ DRCE_PADSTACK_INVALID
Definition drc_item.h:61
@ DRCE_UNRESOLVED_VARIABLE
Definition drc_item.h:86
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition drc_item.h:79
@ DRCE_DUPLICATE_FOOTPRINT
Definition drc_item.h:73
@ DRCE_DANGLING_TRACK
Definition drc_item.h:49
@ DRCE_TEXT_HEIGHT
Definition drc_item.h:99
@ DRCE_ASSERTION_FAILURE
Definition drc_item.h:87
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:92
@ DRCE_DRILLED_HOLES_COLOCATED
Definition drc_item.h:51
@ DRCE_EXTRA_FOOTPRINT
Definition drc_item.h:74
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:98
@ DRCE_LENGTH_OUT_OF_RANGE
Definition drc_item.h:102
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:81
@ DRCE_NET_CONFLICT
Definition drc_item.h:75
@ DRCE_MISSING_FOOTPRINT
Definition drc_item.h:72
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition drc_item.h:82
@ DRCE_FOOTPRINT
Definition drc_item.h:83
@ DRCE_UNMIRRORED_TEXT_ON_BACK_LAYER
Definition drc_item.h:112
@ DRCE_GENERIC_WARNING
Definition drc_item.h:88
@ DRCE_TEXT_THICKNESS
Definition drc_item.h:100
@ DRCE_NPTH_IN_COURTYARD
Definition drc_item.h:68
@ DRCE_CONNECTION_WIDTH
Definition drc_item.h:57
@ DRCE_SCHEMATIC_PARITY
Definition drc_item.h:76
@ DRCE_TRACKS_CROSSING
Definition drc_item.h:43
@ DRCE_VIA_COUNT_OUT_OF_RANGE
Definition drc_item.h:107
@ DRCE_ANNULAR_WIDTH
Definition drc_item.h:56
DRC_DISALLOW_T
Definition drc_rule.h:94
@ DRC_DISALLOW_PADS
Definition drc_rule.h:100
@ DRC_DISALLOW_BURIED_VIAS
Definition drc_rule.h:98
@ DRC_DISALLOW_BLIND_VIAS
Definition drc_rule.h:97
@ DRC_DISALLOW_TEXTS
Definition drc_rule.h:102
@ DRC_DISALLOW_ZONES
Definition drc_rule.h:101
@ DRC_DISALLOW_HOLES
Definition drc_rule.h:104
@ DRC_DISALLOW_GRAPHICS
Definition drc_rule.h:103
@ DRC_DISALLOW_THROUGH_VIAS
Definition drc_rule.h:95
@ DRC_DISALLOW_FOOTPRINTS
Definition drc_rule.h:105
@ DRC_DISALLOW_TRACKS
Definition drc_rule.h:99
@ DRC_DISALLOW_MICRO_VIAS
Definition drc_rule.h:96
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.