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

4
#include <vector>
5 6 7 8 9 10 11 12

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

static bool visited;

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

    REQUIRE(visited);
}

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