OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/lock.h" | 5 #include "base/lock.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/thread.h" | 8 #include "base/thread.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 public: | 30 public: |
31 explicit SleepSome(int msec) : msec_(msec) { | 31 explicit SleepSome(int msec) : msec_(msec) { |
32 } | 32 } |
33 virtual void Run() { | 33 virtual void Run() { |
34 PlatformThread::Sleep(msec_); | 34 PlatformThread::Sleep(msec_); |
35 } | 35 } |
36 private: | 36 private: |
37 int msec_; | 37 int msec_; |
38 }; | 38 }; |
39 | 39 |
| 40 class SleepInsideInitThread : public Thread { |
| 41 public: |
| 42 SleepInsideInitThread() : Thread("none") { init_called_ = false; } |
| 43 virtual ~SleepInsideInitThread() { } |
| 44 |
| 45 virtual void Init() { |
| 46 PlatformThread::Sleep(500); |
| 47 init_called_ = true; |
| 48 } |
| 49 bool InitCalled() { return init_called_; } |
| 50 private: |
| 51 bool init_called_; |
| 52 }; |
| 53 |
40 } // namespace | 54 } // namespace |
41 | 55 |
42 TEST_F(ThreadTest, Restart) { | 56 TEST_F(ThreadTest, Restart) { |
43 Thread a("Restart"); | 57 Thread a("Restart"); |
44 a.Stop(); | 58 a.Stop(); |
45 EXPECT_FALSE(a.message_loop()); | 59 EXPECT_FALSE(a.message_loop()); |
46 EXPECT_TRUE(a.Start()); | 60 EXPECT_TRUE(a.Start()); |
47 EXPECT_TRUE(a.message_loop()); | 61 EXPECT_TRUE(a.message_loop()); |
48 a.Stop(); | 62 a.Stop(); |
49 EXPECT_FALSE(a.message_loop()); | 63 EXPECT_FALSE(a.message_loop()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 a.StopSoon(); | 114 a.StopSoon(); |
101 a.Stop(); | 115 a.Stop(); |
102 EXPECT_FALSE(a.message_loop()); | 116 EXPECT_FALSE(a.message_loop()); |
103 } | 117 } |
104 | 118 |
105 TEST_F(ThreadTest, ThreadName) { | 119 TEST_F(ThreadTest, ThreadName) { |
106 Thread a("ThreadName"); | 120 Thread a("ThreadName"); |
107 EXPECT_TRUE(a.Start()); | 121 EXPECT_TRUE(a.Start()); |
108 EXPECT_EQ("ThreadName", a.thread_name()); | 122 EXPECT_EQ("ThreadName", a.thread_name()); |
109 } | 123 } |
| 124 |
| 125 // Make sure we can't use a thread between Start() and Init(). |
| 126 TEST_F(ThreadTest, SleepInsideInit) { |
| 127 SleepInsideInitThread t; |
| 128 EXPECT_FALSE(t.InitCalled()); |
| 129 t.Start(); |
| 130 EXPECT_TRUE(t.InitCalled()); |
| 131 } |
| 132 |
OLD | NEW |