KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_layer_range.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 along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
21
#define BOOST_TEST_NO_MAIN
22
#include <boost/test/unit_test.hpp>
23
#include <
layer_range.h
>
24
#include <vector>
25
26
BOOST_AUTO_TEST_SUITE
(LayerRangeTests)
27
28
BOOST_AUTO_TEST_CASE
( ForwardIterationTwoLayers )
29
{
30
LAYER_RANGE
range(
F_Cu
,
B_Cu
, 2 );
31
std::vector<PCB_LAYER_ID>
expected
= {
F_Cu
,
B_Cu
};
32
std::vector<PCB_LAYER_ID>
result
;
33
34
for
(
auto
layer : range )
35
{
36
result
.push_back( layer );
37
}
38
39
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
40
}
41
42
BOOST_AUTO_TEST_CASE
( ForwardIterationFourLayers )
43
{
44
LAYER_RANGE
range(
F_Cu
,
B_Cu
, 4 );
45
std::vector<PCB_LAYER_ID>
expected
= {
F_Cu
,
In1_Cu
,
In2_Cu
,
B_Cu
};
46
std::vector<PCB_LAYER_ID>
result
;
47
48
for
(
auto
layer : range )
49
{
50
result
.push_back( layer );
51
}
52
53
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
54
}
55
56
BOOST_AUTO_TEST_CASE
( ReverseIterationFourLayers )
57
{
58
LAYER_RANGE
range(
B_Cu
,
F_Cu
, 4 );
59
std::vector<PCB_LAYER_ID>
expected
= {
B_Cu
,
In2_Cu
,
In1_Cu
,
F_Cu
};
60
std::vector<PCB_LAYER_ID>
result
;
61
62
for
(
auto
layer : range )
63
{
64
result
.push_back( layer );
65
}
66
67
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
68
}
69
70
BOOST_AUTO_TEST_CASE
( PartialRangeForward )
71
{
72
LAYER_RANGE
range(
In1_Cu
,
B_Cu
, 6 );
73
std::vector<PCB_LAYER_ID>
expected
= {
In1_Cu
,
In2_Cu
,
In3_Cu
,
In4_Cu
,
B_Cu
};
74
std::vector<PCB_LAYER_ID>
result
;
75
76
for
(
auto
layer : range )
77
{
78
result
.push_back( layer );
79
}
80
81
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
82
}
83
84
BOOST_AUTO_TEST_CASE
( PartialRangeReverse )
85
{
86
LAYER_RANGE
range(
In3_Cu
,
F_Cu
, 6 );
87
std::vector<PCB_LAYER_ID>
expected
= {
In3_Cu
,
In2_Cu
,
In1_Cu
,
F_Cu
};
88
std::vector<PCB_LAYER_ID>
result
;
89
90
for
(
auto
layer : range )
91
{
92
result
.push_back( layer );
93
}
94
95
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
96
}
97
98
BOOST_AUTO_TEST_CASE
( InvalidLayerThrowsException )
99
{
100
BOOST_CHECK_THROW(
LAYER_RANGE
(
F_Mask
,
B_Cu
, 4 ), std::invalid_argument );
101
BOOST_CHECK_THROW(
LAYER_RANGE
(
F_Cu
,
B_Mask
, 4 ), std::invalid_argument );
102
}
103
104
BOOST_AUTO_TEST_CASE
( SingleLayerRange )
105
{
106
LAYER_RANGE
range(
In2_Cu
,
In2_Cu
, 6 );
107
std::vector<PCB_LAYER_ID>
expected
= {
In2_Cu
};
108
std::vector<PCB_LAYER_ID>
result
;
109
110
for
(
auto
layer : range )
111
{
112
result
.push_back( layer );
113
}
114
115
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
116
}
117
118
BOOST_AUTO_TEST_CASE
( MaxLayerCount )
119
{
120
LAYER_RANGE
range(
F_Cu
,
B_Cu
,
PCB_LAYER_ID_COUNT
);
121
std::vector<PCB_LAYER_ID>
expected
= {
F_Cu
};
122
123
124
for
(
int
i =
In1_Cu
; i < 2 *
PCB_LAYER_ID_COUNT
; i += 2 )
125
{
126
expected
.push_back(
static_cast<
PCB_LAYER_ID
>
( i ) );
127
}
128
expected
.push_back(
B_Cu
);
129
130
std::vector<PCB_LAYER_ID>
result
;
131
for
(
auto
layer : range )
132
{
133
result
.push_back( layer );
134
}
135
136
BOOST_CHECK_EQUAL_COLLECTIONS(
result
.begin(),
result
.end(),
expected
.begin(),
expected
.end() );
137
}
138
139
BOOST_AUTO_TEST_SUITE_END
()
LAYER_RANGE
Definition
layer_range.h:27
PCB_LAYER_ID
PCB_LAYER_ID
A quick note on layer IDs:
Definition
layer_ids.h:60
B_Mask
@ B_Mask
Definition
layer_ids.h:98
B_Cu
@ B_Cu
Definition
layer_ids.h:65
F_Mask
@ F_Mask
Definition
layer_ids.h:97
In2_Cu
@ In2_Cu
Definition
layer_ids.h:67
In4_Cu
@ In4_Cu
Definition
layer_ids.h:69
In1_Cu
@ In1_Cu
Definition
layer_ids.h:66
PCB_LAYER_ID_COUNT
@ PCB_LAYER_ID_COUNT
Definition
layer_ids.h:171
In3_Cu
@ In3_Cu
Definition
layer_ids.h:68
F_Cu
@ F_Cu
Definition
layer_ids.h:64
layer_range.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:134
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(ForwardIterationTwoLayers)
Definition
test_layer_range.cpp:28
expected
VECTOR3I expected(15, 30, 45)
result
wxString result
Test unit parsing edge cases and error handling.
Definition
test_text_eval_numeric_compat.cpp:602
src
qa
tests
common
test_layer_range.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2