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