KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew/test_lset.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 2
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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#include <
qa_utils/wx_utils/unit_test_utils.h
>
25
26
#include <
layer_ids.h
>
27
#include <
lset.h
>
28
29
30
BOOST_AUTO_TEST_SUITE
( LSet )
31
32
struct
LSETS_TO_TEST
33
{
34
LSET
lset
;
35
36
std::string
expectedFmtHex
;
37
std::string
expectedFmtBin
;
38
};
39
40
41
const
static
std::vector<LSETS_TO_TEST>
type_to_ext_cases
= {
42
{
LSET
( {
F_Cu
,
F_Fab
} ),
"00000000_00000000_00000008_00000001"
,
43
"0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|"
44
"0000_0000|0000_0000|0000_0000|0000_1000|0000_0000|0000_0000|0000_0000|0000_0001"
},
45
{
LSET
( {
In14_Cu
,
B_Adhes
,
Rescue
} ),
"00000000_00000000_00000020_40000800"
,
46
"0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|0000_0000|"
47
"0000_0000|0000_0000|0000_0000|0010_0000|0100_0000|0000_0000|0000_1000|0000_0000"
}
48
};
49
50
51
BOOST_AUTO_TEST_CASE
( FmtHex )
52
{
53
for
(
const
auto
& c :
type_to_ext_cases
)
54
{
55
BOOST_CHECK_EQUAL
( c.expectedFmtHex, c.lset.FmtHex() );
56
}
57
}
58
59
60
BOOST_AUTO_TEST_CASE
( FmtBin )
61
{
62
for
(
const
auto
& c :
type_to_ext_cases
)
63
{
64
BOOST_CHECK_EQUAL
( c.expectedFmtBin, c.lset.FmtBin() );
65
}
66
}
67
// Utility macro to test layer name
68
#define TEST_LAYER_NAME(layer_id, expected_name) \
69
BOOST_CHECK_EQUAL(LSET::Name(layer_id), wxString(expected_name))
70
71
// Test standard predefined layers
72
BOOST_AUTO_TEST_CASE
(LSETNamePredefinedLayers)
73
{
74
TEST_LAYER_NAME
(
F_Cu
,
"F.Cu"
);
75
TEST_LAYER_NAME
(
B_Cu
,
"B.Cu"
);
76
TEST_LAYER_NAME
(
F_SilkS
,
"F.SilkS"
);
77
TEST_LAYER_NAME
(
B_SilkS
,
"B.SilkS"
);
78
TEST_LAYER_NAME
(
F_Mask
,
"F.Mask"
);
79
TEST_LAYER_NAME
(
B_Mask
,
"B.Mask"
);
80
TEST_LAYER_NAME
(
F_Adhes
,
"F.Adhes"
);
81
TEST_LAYER_NAME
(
B_Adhes
,
"B.Adhes"
);
82
TEST_LAYER_NAME
(
F_Paste
,
"F.Paste"
);
83
TEST_LAYER_NAME
(
B_Paste
,
"B.Paste"
);
84
TEST_LAYER_NAME
(
F_CrtYd
,
"F.CrtYd"
);
85
TEST_LAYER_NAME
(
B_CrtYd
,
"B.CrtYd"
);
86
TEST_LAYER_NAME
(
F_Fab
,
"F.Fab"
);
87
TEST_LAYER_NAME
(
B_Fab
,
"B.Fab"
);
88
TEST_LAYER_NAME
(
Dwgs_User
,
"Dwgs.User"
);
89
TEST_LAYER_NAME
(
Cmts_User
,
"Cmts.User"
);
90
TEST_LAYER_NAME
(
Eco1_User
,
"Eco1.User"
);
91
TEST_LAYER_NAME
(
Eco2_User
,
"Eco2.User"
);
92
TEST_LAYER_NAME
(
Edge_Cuts
,
"Edge.Cuts"
);
93
TEST_LAYER_NAME
(
Margin
,
"Margin"
);
94
TEST_LAYER_NAME
(
Rescue
,
"Rescue"
);
95
}
96
// Test NameToLayer function for internal copper layers
97
BOOST_AUTO_TEST_CASE
(LSETNameToLayerInternalCuLayers)
98
{
99
for
(
int
i = 1; i <= 300; i++)
100
{
101
wxString layerName = wxString::Format(
"In%d.Cu"
, i);
102
PCB_LAYER_ID
expectedLayer =
static_cast<
PCB_LAYER_ID
>
(
In1_Cu
+ (i - 1) * 2);
103
BOOST_CHECK_EQUAL
(
LSET::NameToLayer
(layerName), expectedLayer);
104
}
105
}
106
107
// Test NameToLayer function for user-defined layers
108
BOOST_AUTO_TEST_CASE
(LSETNameToLayerUserDefinedLayers)
109
{
110
for
(
int
i = 1; i <= 300; i++)
111
{
112
wxString layerName = wxString::Format(
"User.%d"
, i);
113
PCB_LAYER_ID
expectedLayer =
static_cast<
PCB_LAYER_ID
>
(
User_1
+ (i - 1) * 2);
114
BOOST_CHECK_EQUAL
(
LSET::NameToLayer
(layerName), expectedLayer);
115
}
116
}
117
118
// Test NameToLayer function for predefined layers
119
BOOST_AUTO_TEST_CASE
(LSETNameToLayerPredefinedLayers)
120
{
121
std::vector<std::pair<wxString, PCB_LAYER_ID>> layerTests = {
122
{
"F.Cu"
,
F_Cu
},
123
{
"B.Cu"
,
B_Cu
},
124
{
"F.SilkS"
,
F_SilkS
},
125
{
"B.SilkS"
,
B_SilkS
},
126
{
"F.Mask"
,
F_Mask
},
127
{
"B.Mask"
,
B_Mask
},
128
{
"F.Adhes"
,
F_Adhes
},
129
{
"B.Adhes"
,
B_Adhes
},
130
{
"F.Paste"
,
F_Paste
},
131
{
"B.Paste"
,
B_Paste
},
132
{
"F.CrtYd"
,
F_CrtYd
},
133
{
"B.CrtYd"
,
B_CrtYd
},
134
{
"F.Fab"
,
F_Fab
},
135
{
"B.Fab"
,
B_Fab
},
136
{
"Dwgs.User"
,
Dwgs_User
},
137
{
"Cmts.User"
,
Cmts_User
},
138
{
"Eco1.User"
,
Eco1_User
},
139
{
"Eco2.User"
,
Eco2_User
},
140
{
"Edge.Cuts"
,
Edge_Cuts
},
141
{
"Margin"
,
Margin
},
142
{
"Rescue"
,
Rescue
}
143
};
144
145
for
(
const
auto
&
test
: layerTests)
146
{
147
wxString layerName =
test
.first;
148
PCB_LAYER_ID
expectedLayer =
test
.second;
149
BOOST_CHECK_EQUAL
(
LSET::NameToLayer
(layerName), expectedLayer);
150
}
151
}
152
153
// Test dynamically generated user-defined layers
154
BOOST_AUTO_TEST_CASE
(LSETNameUserDefinedLayers)
155
{
156
for
(
int
i =
User_1
; i <=
User_9
; i += 2) {
157
wxString expected_name = wxString::Format(
"User.%d"
, (i -
Rescue
) / 2 );
158
wxString actual_name =
LSET::Name
(
static_cast<
PCB_LAYER_ID
>
( i ) );
159
BOOST_CHECK_EQUAL
( expected_name, actual_name );
160
}
161
}
162
163
// Test dynamically generated internal copper layers
164
BOOST_AUTO_TEST_CASE
(LSETNameInternalCuLayers)
165
{
166
for
(
int
i =
In1_Cu
; i <=
In30_Cu
; i += 2) {
167
wxString expected_name = wxString::Format(
"In%d.Cu"
, (i -
B_Cu
) / 2);
168
TEST_LAYER_NAME
(
static_cast<
PCB_LAYER_ID
>
(i), expected_name);
169
}
170
}
171
172
BOOST_AUTO_TEST_SUITE_END
()
LSET
LSET is a set of PCB_LAYER_IDs.
Definition
lset.h:37
LSET::NameToLayer
static int NameToLayer(wxString &aName)
Return the layer number from a layer name.
Definition
lset.cpp:117
LSET::Name
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition
lset.cpp:188
layer_ids.h
PCB_LAYER_ID
PCB_LAYER_ID
A quick note on layer IDs:
Definition
layer_ids.h:60
In30_Cu
@ In30_Cu
Definition
layer_ids.h:95
F_CrtYd
@ F_CrtYd
Definition
layer_ids.h:116
B_Adhes
@ B_Adhes
Definition
layer_ids.h:103
Edge_Cuts
@ Edge_Cuts
Definition
layer_ids.h:112
Dwgs_User
@ Dwgs_User
Definition
layer_ids.h:107
F_Paste
@ F_Paste
Definition
layer_ids.h:104
Cmts_User
@ Cmts_User
Definition
layer_ids.h:108
F_Adhes
@ F_Adhes
Definition
layer_ids.h:102
B_Mask
@ B_Mask
Definition
layer_ids.h:98
B_Cu
@ B_Cu
Definition
layer_ids.h:65
Eco1_User
@ Eco1_User
Definition
layer_ids.h:109
F_Mask
@ F_Mask
Definition
layer_ids.h:97
B_Paste
@ B_Paste
Definition
layer_ids.h:105
User_9
@ User_9
Definition
layer_ids.h:132
F_Fab
@ F_Fab
Definition
layer_ids.h:119
Margin
@ Margin
Definition
layer_ids.h:113
F_SilkS
@ F_SilkS
Definition
layer_ids.h:100
B_CrtYd
@ B_CrtYd
Definition
layer_ids.h:115
Eco2_User
@ Eco2_User
Definition
layer_ids.h:110
In1_Cu
@ In1_Cu
Definition
layer_ids.h:66
Rescue
@ Rescue
Definition
layer_ids.h:121
User_1
@ User_1
Definition
layer_ids.h:124
B_SilkS
@ B_SilkS
Definition
layer_ids.h:101
In14_Cu
@ In14_Cu
Definition
layer_ids.h:79
F_Cu
@ F_Cu
Definition
layer_ids.h:64
B_Fab
@ B_Fab
Definition
layer_ids.h:118
lset.h
test
Definition
drc_test_provider_diff_pair_coupling.cpp:44
TEST_LAYER_NAME
#define TEST_LAYER_NAME(layer_id, expected_name)
Definition
pcbnew/test_lset.cpp:68
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(FmtHex)
Definition
pcbnew/test_lset.cpp:51
LSETS_TO_TEST
Definition
pcbnew/test_lset.cpp:33
LSETS_TO_TEST::expectedFmtBin
std::string expectedFmtBin
Definition
pcbnew/test_lset.cpp:37
LSETS_TO_TEST::lset
LSET lset
Definition
pcbnew/test_lset.cpp:34
LSETS_TO_TEST::expectedFmtHex
std::string expectedFmtHex
Definition
pcbnew/test_lset.cpp:36
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
type_to_ext_cases
static const std::vector< TYPE_TO_EXTS > type_to_ext_cases
Definition
test_graphics_import_mgr.cpp:63
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
pcbnew
test_lset.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2