thread_tests.cpp 843 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
    auto t1 = start_thread([]() { visited = true; });
16 17 18 19 20 21
    t1.join();

    REQUIRE(visited);
}

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

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