thread_tests.cpp 834 Bytes
Newer Older
1 2 3
#include <catch.hpp>
#include <pls/internal/base/thread.h>

4
#include <vector>
5 6 7 8 9

using namespace pls::internal::base;
using namespace std;

static bool visited;
10 11
static int local_value_1;
static vector<int> local_value_two;
12 13 14

TEST_CASE( "thread creation and joining", "[internal/base/thread.h]") {
    visited = false;
15 16
    auto t1 = create_thread([]() { visited = true; }, 0);
    t1.start();
17 18 19 20 21 22
    t1.join();

    REQUIRE(visited);
}

TEST_CASE( "thread state", "[internal/base/thread.h]") {
23 24
    auto t1 = create_thread([]() { local_value_1 = *this_thread::state<int>(); }, 1);
    auto t2 = create_thread([]() { local_value_two = *this_thread::state<vector<int>>(); }, vector<int>{1, 2});
25 26
    t1.start();
    t2.start();
27 28
    t1.join();
    t2.join();
29 30 31

    REQUIRE(local_value_1 == 1);
    REQUIRE(local_value_two == vector<int>{1, 2});
32
}