thread_tests.cpp 671 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <catch.hpp>
#include <pls/internal/base/thread.h>

#include <string>

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

static bool visited;

TEST_CASE( "thread creation and joining", "[internal/base/thread.h]") {
    visited = false;
    auto t1 = thread<int>::start([]() { visited = true; }, 0);
    t1.join();

    REQUIRE(visited);
}

TEST_CASE( "thread state", "[internal/base/thread.h]") {
    auto t1 = thread<int>::start([]() { REQUIRE(thread<int>::get_current()->local_object_ == 1); }, 1);
    auto t2 = thread<string>::start([]() { REQUIRE(thread<string>::get_current()->local_object_ == "Hello"); }, "Hello");
    t1.join();
    t2.join();
}