Fixes C++0x compatibility problems.

This commit is contained in:
vladlosev
2011-09-26 17:52:19 +00:00
parent 2ca4d21500
commit 1b2e509958
3 changed files with 488 additions and 165 deletions

View File

@@ -968,23 +968,23 @@ TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) {
}
TEST(ThreadLocalTest, GetAndPointerReturnSameValue) {
ThreadLocal<String> thread_local;
ThreadLocal<String> thread_local_string;
EXPECT_EQ(thread_local.pointer(), &(thread_local.get()));
EXPECT_EQ(thread_local_string.pointer(), &(thread_local_string.get()));
// Verifies the condition still holds after calling set.
thread_local.set("foo");
EXPECT_EQ(thread_local.pointer(), &(thread_local.get()));
thread_local_string.set("foo");
EXPECT_EQ(thread_local_string.pointer(), &(thread_local_string.get()));
}
TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) {
ThreadLocal<String> thread_local;
const ThreadLocal<String>& const_thread_local = thread_local;
ThreadLocal<String> thread_local_string;
const ThreadLocal<String>& const_thread_local_string = thread_local_string;
EXPECT_EQ(thread_local.pointer(), const_thread_local.pointer());
EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer());
thread_local.set("foo");
EXPECT_EQ(thread_local.pointer(), const_thread_local.pointer());
thread_local_string.set("foo");
EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer());
}
#if GTEST_IS_THREADSAFE
@@ -1094,14 +1094,15 @@ void RetrieveThreadLocalValue(pair<ThreadLocal<String>*, String*> param) {
}
TEST(ThreadLocalTest, ParameterizedConstructorSetsDefault) {
ThreadLocal<String> thread_local("foo");
EXPECT_STREQ("foo", thread_local.get().c_str());
ThreadLocal<String> thread_local_string("foo");
EXPECT_STREQ("foo", thread_local_string.get().c_str());
thread_local.set("bar");
EXPECT_STREQ("bar", thread_local.get().c_str());
thread_local_string.set("bar");
EXPECT_STREQ("bar", thread_local_string.get().c_str());
String result;
RunFromThread(&RetrieveThreadLocalValue, make_pair(&thread_local, &result));
RunFromThread(&RetrieveThreadLocalValue,
make_pair(&thread_local_string, &result));
EXPECT_STREQ("foo", result.c_str());
}
@@ -1130,8 +1131,8 @@ class DestructorTracker {
typedef ThreadLocal<DestructorTracker>* ThreadParam;
void CallThreadLocalGet(ThreadParam thread_local) {
thread_local->get();
void CallThreadLocalGet(ThreadParam thread_local_param) {
thread_local_param->get();
}
// Tests that when a ThreadLocal object dies in a thread, it destroys
@@ -1141,19 +1142,19 @@ TEST(ThreadLocalTest, DestroysManagedObjectForOwnThreadWhenDying) {
{
// The next line default constructs a DestructorTracker object as
// the default value of objects managed by thread_local.
ThreadLocal<DestructorTracker> thread_local;
// the default value of objects managed by thread_local_tracker.
ThreadLocal<DestructorTracker> thread_local_tracker;
ASSERT_EQ(1U, g_destroyed.size());
ASSERT_FALSE(g_destroyed[0]);
// This creates another DestructorTracker object for the main thread.
thread_local.get();
thread_local_tracker.get();
ASSERT_EQ(2U, g_destroyed.size());
ASSERT_FALSE(g_destroyed[0]);
ASSERT_FALSE(g_destroyed[1]);
}
// Now thread_local has died. It should have destroyed both the
// Now thread_local_tracker has died. It should have destroyed both the
// default value shared by all threads and the value for the main
// thread.
ASSERT_EQ(2U, g_destroyed.size());
@@ -1170,14 +1171,14 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
{
// The next line default constructs a DestructorTracker object as
// the default value of objects managed by thread_local.
ThreadLocal<DestructorTracker> thread_local;
// the default value of objects managed by thread_local_tracker.
ThreadLocal<DestructorTracker> thread_local_tracker;
ASSERT_EQ(1U, g_destroyed.size());
ASSERT_FALSE(g_destroyed[0]);
// This creates another DestructorTracker object in the new thread.
ThreadWithParam<ThreadParam> thread(
&CallThreadLocalGet, &thread_local, NULL);
&CallThreadLocalGet, &thread_local_tracker, NULL);
thread.Join();
// Now the new thread has exited. The per-thread object for it
@@ -1187,7 +1188,7 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
ASSERT_TRUE(g_destroyed[1]);
}
// Now thread_local has died. The default value should have been
// Now thread_local_tracker has died. The default value should have been
// destroyed too.
ASSERT_EQ(2U, g_destroyed.size());
EXPECT_TRUE(g_destroyed[0]);
@@ -1197,12 +1198,13 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
}
TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) {
ThreadLocal<String> thread_local;
thread_local.set("Foo");
EXPECT_STREQ("Foo", thread_local.get().c_str());
ThreadLocal<String> thread_local_string;
thread_local_string.set("Foo");
EXPECT_STREQ("Foo", thread_local_string.get().c_str());
String result;
RunFromThread(&RetrieveThreadLocalValue, make_pair(&thread_local, &result));
RunFromThread(&RetrieveThreadLocalValue,
make_pair(&thread_local_string, &result));
EXPECT_TRUE(result.c_str() == NULL);
}