2014-12-15 02:04:45 +01:00
|
|
|
//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests ------===//
|
2013-12-19 21:32:44 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-12-19 21:32:44 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/ThreadLocal.h"
|
|
|
|
#include "gtest/gtest.h"
|
2014-12-15 02:04:45 +01:00
|
|
|
#include <type_traits>
|
2013-12-19 21:32:44 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace sys;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ThreadLocalTest : public ::testing::Test {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
int i;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ThreadLocalTest, Basics) {
|
|
|
|
ThreadLocal<const S> x;
|
|
|
|
|
2014-12-15 02:04:45 +01:00
|
|
|
static_assert(
|
|
|
|
std::is_const<std::remove_pointer<decltype(x.get())>::type>::value,
|
|
|
|
"ThreadLocal::get didn't return a pointer to const object");
|
|
|
|
|
2014-06-09 00:29:17 +02:00
|
|
|
EXPECT_EQ(nullptr, x.get());
|
2013-12-19 21:32:44 +01:00
|
|
|
|
|
|
|
S s;
|
|
|
|
x.set(&s);
|
|
|
|
EXPECT_EQ(&s, x.get());
|
|
|
|
|
|
|
|
x.erase();
|
2014-06-09 00:29:17 +02:00
|
|
|
EXPECT_EQ(nullptr, x.get());
|
2014-12-15 02:04:45 +01:00
|
|
|
|
|
|
|
ThreadLocal<S> y;
|
|
|
|
|
|
|
|
static_assert(
|
|
|
|
!std::is_const<std::remove_pointer<decltype(y.get())>::type>::value,
|
|
|
|
"ThreadLocal::get returned a pointer to const object");
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, y.get());
|
|
|
|
|
|
|
|
y.set(&s);
|
|
|
|
EXPECT_EQ(&s, y.get());
|
|
|
|
|
|
|
|
y.erase();
|
|
|
|
EXPECT_EQ(nullptr, y.get());
|
2013-12-19 21:32:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|