blob: e71c7dba22fc98135fcc503a4816934736cef815 [file] [log] [blame]
David Majnemer421c89d2014-12-15 01:04:45 +00001//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests ------===//
Hans Wennborgfabf8bf2013-12-19 20:32:44 +00002//
David Majnemer421c89d2014-12-15 01:04:45 +00003// The LLVM Compiler Infrastructure
Hans Wennborgfabf8bf2013-12-19 20:32:44 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Support/ThreadLocal.h"
11#include "gtest/gtest.h"
David Majnemer421c89d2014-12-15 01:04:45 +000012#include <type_traits>
Hans Wennborgfabf8bf2013-12-19 20:32:44 +000013
14using namespace llvm;
15using namespace sys;
16
17namespace {
18
19class ThreadLocalTest : public ::testing::Test {
20};
21
22struct S {
23 int i;
24};
25
26TEST_F(ThreadLocalTest, Basics) {
27 ThreadLocal<const S> x;
28
David Majnemer421c89d2014-12-15 01:04:45 +000029 static_assert(
30 std::is_const<std::remove_pointer<decltype(x.get())>::type>::value,
31 "ThreadLocal::get didn't return a pointer to const object");
32
Craig Topper66f09ad2014-06-08 22:29:17 +000033 EXPECT_EQ(nullptr, x.get());
Hans Wennborgfabf8bf2013-12-19 20:32:44 +000034
35 S s;
36 x.set(&s);
37 EXPECT_EQ(&s, x.get());
38
39 x.erase();
Craig Topper66f09ad2014-06-08 22:29:17 +000040 EXPECT_EQ(nullptr, x.get());
David Majnemer421c89d2014-12-15 01:04:45 +000041
42 ThreadLocal<S> y;
43
44 static_assert(
45 !std::is_const<std::remove_pointer<decltype(y.get())>::type>::value,
46 "ThreadLocal::get returned a pointer to const object");
47
48 EXPECT_EQ(nullptr, y.get());
49
50 y.set(&s);
51 EXPECT_EQ(&s, y.get());
52
53 y.erase();
54 EXPECT_EQ(nullptr, y.get());
Hans Wennborgfabf8bf2013-12-19 20:32:44 +000055}
56
57}