KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_priority_thread_pool_task.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 3
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
20
#include <boost/test/unit_test.hpp>
21
22
#include <atomic>
23
#include <stdexcept>
24
#include <vector>
25
26
#include <
priority_thread_pool_task.h
>
27
28
29
namespace
30
{
31
36
class
COUNTING_TASK :
public
PRIORITY_THREAD_POOL_TASK
<std::vector<int>>
37
{
38
public
:
39
std::atomic<int> m_processed{ 0 };
40
41
private
:
42
int
computePriorityKey(
const
int
& aItem )
const override
{
return
aItem; }
43
44
size_t
task(
int
& aItem )
override
45
{
46
if
( aItem < 0 )
47
throw
std::runtime_error(
"negative item"
);
48
49
++m_processed;
50
return
1;
51
}
52
};
53
54
}
// namespace
55
56
57
BOOST_AUTO_TEST_SUITE
( PriorityThreadPoolTask )
58
59
60
BOOST_AUTO_TEST_CASE
( AllItemsProcessed )
61
{
62
COUNTING_TASK task;
63
std::vector<int> items = { 5, 3, 8, 1, 9 };
64
65
BOOST_CHECK_NO_THROW( task.Execute( items ) );
66
67
// All items should have been processed by now
68
BOOST_CHECK_EQUAL
( task.m_processed.load(), (
int
) items.size() );
69
}
70
71
72
BOOST_AUTO_TEST_CASE
( ExceptionPropagates )
73
{
74
COUNTING_TASK task;
75
std::vector<int> items = { 5, 3, -1, 1, 9 };
76
77
BOOST_CHECK_THROW( task.Execute( items ), std::runtime_error );
78
}
79
80
81
BOOST_AUTO_TEST_SUITE_END
()
PRIORITY_THREAD_POOL_TASK
A helper class to execute tasks on a thread pool in priority order, with progress reporting.
Definition
priority_thread_pool_task.h:31
priority_thread_pool_task.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:79
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(AllItemsProcessed)
Definition
test_priority_thread_pool_task.cpp:60
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
src
qa
tests
common
test_priority_thread_pool_task.cpp
Generated on Thu Sep 17 2026 00:06:24 for KiCad PCB EDA Suite by
1.13.2