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