Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: base/threading/platform_thread_unittest.cc

Issue 6001010: Move platform_thread to base/threading and put in the base namespace. I left ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/platform_thread_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/platform_thread.h" 5 #include "base/threading/platform_thread.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 typedef testing::Test PlatformThreadTest; 9 namespace base {
10 10
11 // Trivial tests that thread runs and doesn't crash on create and join --------- 11 // Trivial tests that thread runs and doesn't crash on create and join ---------
12 12
13 class TrivialThread : public PlatformThread::Delegate { 13 class TrivialThread : public PlatformThread::Delegate {
14 public: 14 public:
15 TrivialThread() : did_run_(false) {} 15 TrivialThread() : did_run_(false) {}
16 16
17 virtual void ThreadMain() { 17 virtual void ThreadMain() {
18 did_run_ = true; 18 did_run_ = true;
19 } 19 }
20 20
21 bool did_run() const { return did_run_; } 21 bool did_run() const { return did_run_; }
22 22
23 private: 23 private:
24 bool did_run_; 24 bool did_run_;
25 25
26 DISALLOW_COPY_AND_ASSIGN(TrivialThread); 26 DISALLOW_COPY_AND_ASSIGN(TrivialThread);
27 }; 27 };
28 28
29 TEST_F(PlatformThreadTest, Trivial) { 29 TEST(PlatformThreadTest, Trivial) {
30 TrivialThread thread; 30 TrivialThread thread;
31 PlatformThreadHandle handle = kNullThreadHandle; 31 PlatformThreadHandle handle = kNullThreadHandle;
32 32
33 ASSERT_FALSE(thread.did_run()); 33 ASSERT_FALSE(thread.did_run());
34 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); 34 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
35 PlatformThread::Join(handle); 35 PlatformThread::Join(handle);
36 ASSERT_TRUE(thread.did_run()); 36 ASSERT_TRUE(thread.did_run());
37 } 37 }
38 38
39 TEST_F(PlatformThreadTest, TrivialTimesTen) { 39 TEST(PlatformThreadTest, TrivialTimesTen) {
40 TrivialThread thread[10]; 40 TrivialThread thread[10];
41 PlatformThreadHandle handle[arraysize(thread)]; 41 PlatformThreadHandle handle[arraysize(thread)];
42 42
43 for (size_t n = 0; n < arraysize(thread); n++) 43 for (size_t n = 0; n < arraysize(thread); n++)
44 ASSERT_FALSE(thread[n].did_run()); 44 ASSERT_FALSE(thread[n].did_run());
45 for (size_t n = 0; n < arraysize(thread); n++) 45 for (size_t n = 0; n < arraysize(thread); n++)
46 ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); 46 ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n]));
47 for (size_t n = 0; n < arraysize(thread); n++) 47 for (size_t n = 0; n < arraysize(thread); n++)
48 PlatformThread::Join(handle[n]); 48 PlatformThread::Join(handle[n]);
49 for (size_t n = 0; n < arraysize(thread); n++) 49 for (size_t n = 0; n < arraysize(thread); n++)
(...skipping 15 matching lines...) Expand all
65 } 65 }
66 66
67 PlatformThreadId thread_id() const { return thread_id_; } 67 PlatformThreadId thread_id() const { return thread_id_; }
68 68
69 private: 69 private:
70 PlatformThreadId thread_id_; 70 PlatformThreadId thread_id_;
71 71
72 DISALLOW_COPY_AND_ASSIGN(FunctionTestThread); 72 DISALLOW_COPY_AND_ASSIGN(FunctionTestThread);
73 }; 73 };
74 74
75 TEST_F(PlatformThreadTest, Function) { 75 TEST(PlatformThreadTest, Function) {
76 PlatformThreadId main_thread_id = PlatformThread::CurrentId(); 76 PlatformThreadId main_thread_id = PlatformThread::CurrentId();
77 77
78 FunctionTestThread thread; 78 FunctionTestThread thread;
79 PlatformThreadHandle handle = kNullThreadHandle; 79 PlatformThreadHandle handle = kNullThreadHandle;
80 80
81 ASSERT_FALSE(thread.did_run()); 81 ASSERT_FALSE(thread.did_run());
82 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); 82 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
83 PlatformThread::Join(handle); 83 PlatformThread::Join(handle);
84 ASSERT_TRUE(thread.did_run()); 84 ASSERT_TRUE(thread.did_run());
85 EXPECT_NE(thread.thread_id(), main_thread_id); 85 EXPECT_NE(thread.thread_id(), main_thread_id);
86 } 86 }
87 87
88 TEST_F(PlatformThreadTest, FunctionTimesTen) { 88 TEST(PlatformThreadTest, FunctionTimesTen) {
89 PlatformThreadId main_thread_id = PlatformThread::CurrentId(); 89 PlatformThreadId main_thread_id = PlatformThread::CurrentId();
90 90
91 FunctionTestThread thread[10]; 91 FunctionTestThread thread[10];
92 PlatformThreadHandle handle[arraysize(thread)]; 92 PlatformThreadHandle handle[arraysize(thread)];
93 93
94 for (size_t n = 0; n < arraysize(thread); n++) 94 for (size_t n = 0; n < arraysize(thread); n++)
95 ASSERT_FALSE(thread[n].did_run()); 95 ASSERT_FALSE(thread[n].did_run());
96 for (size_t n = 0; n < arraysize(thread); n++) 96 for (size_t n = 0; n < arraysize(thread); n++)
97 ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); 97 ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n]));
98 for (size_t n = 0; n < arraysize(thread); n++) 98 for (size_t n = 0; n < arraysize(thread); n++)
99 PlatformThread::Join(handle[n]); 99 PlatformThread::Join(handle[n]);
100 for (size_t n = 0; n < arraysize(thread); n++) { 100 for (size_t n = 0; n < arraysize(thread); n++) {
101 ASSERT_TRUE(thread[n].did_run()); 101 ASSERT_TRUE(thread[n].did_run());
102 EXPECT_NE(thread[n].thread_id(), main_thread_id); 102 EXPECT_NE(thread[n].thread_id(), main_thread_id);
103 } 103 }
104 } 104 }
105
106 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/platform_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698