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

Side by Side Diff: base/thread_unittest.cc

Issue 18546: Implementation of Pipeline and FilterHost interfaces. This is a large change... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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/thread.cc ('k') | media/base/factory.h » ('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) 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 private: 50 private:
51 bool init_called_; 51 bool init_called_;
52 }; 52 };
53 53
54 } // namespace 54 } // namespace
55 55
56 TEST_F(ThreadTest, Restart) { 56 TEST_F(ThreadTest, Restart) {
57 Thread a("Restart"); 57 Thread a("Restart");
58 a.Stop(); 58 a.Stop();
59 EXPECT_FALSE(a.message_loop()); 59 EXPECT_FALSE(a.message_loop());
60 EXPECT_FALSE(a.IsRunning());
60 EXPECT_TRUE(a.Start()); 61 EXPECT_TRUE(a.Start());
61 EXPECT_TRUE(a.message_loop()); 62 EXPECT_TRUE(a.message_loop());
63 EXPECT_TRUE(a.IsRunning());
62 a.Stop(); 64 a.Stop();
63 EXPECT_FALSE(a.message_loop()); 65 EXPECT_FALSE(a.message_loop());
66 EXPECT_FALSE(a.IsRunning());
64 EXPECT_TRUE(a.Start()); 67 EXPECT_TRUE(a.Start());
65 EXPECT_TRUE(a.message_loop()); 68 EXPECT_TRUE(a.message_loop());
69 EXPECT_TRUE(a.IsRunning());
66 a.Stop(); 70 a.Stop();
67 EXPECT_FALSE(a.message_loop()); 71 EXPECT_FALSE(a.message_loop());
72 EXPECT_FALSE(a.IsRunning());
68 a.Stop(); 73 a.Stop();
69 EXPECT_FALSE(a.message_loop()); 74 EXPECT_FALSE(a.message_loop());
75 EXPECT_FALSE(a.IsRunning());
70 } 76 }
71 77
72 TEST_F(ThreadTest, StartWithOptions_StackSize) { 78 TEST_F(ThreadTest, StartWithOptions_StackSize) {
73 Thread a("StartWithStackSize"); 79 Thread a("StartWithStackSize");
74 // Ensure that the thread can work with only 12 kb and still process a 80 // Ensure that the thread can work with only 12 kb and still process a
75 // message. 81 // message.
76 Thread::Options options; 82 Thread::Options options;
77 options.stack_size = 12*1024; 83 options.stack_size = 12*1024;
78 EXPECT_TRUE(a.StartWithOptions(options)); 84 EXPECT_TRUE(a.StartWithOptions(options));
79 EXPECT_TRUE(a.message_loop()); 85 EXPECT_TRUE(a.message_loop());
86 EXPECT_TRUE(a.IsRunning());
80 87
81 bool was_invoked = false; 88 bool was_invoked = false;
82 a.message_loop()->PostTask(FROM_HERE, new ToggleValue(&was_invoked)); 89 a.message_loop()->PostTask(FROM_HERE, new ToggleValue(&was_invoked));
83 90
84 // wait for the task to run (we could use a kernel event here 91 // wait for the task to run (we could use a kernel event here
85 // instead to avoid busy waiting, but this is sufficient for 92 // instead to avoid busy waiting, but this is sufficient for
86 // testing purposes). 93 // testing purposes).
87 for (int i = 100; i >= 0 && !was_invoked; --i) { 94 for (int i = 100; i >= 0 && !was_invoked; --i) {
88 PlatformThread::Sleep(10); 95 PlatformThread::Sleep(10);
89 } 96 }
(...skipping 13 matching lines...) Expand all
103 a.message_loop()->PostTask(FROM_HERE, new SleepSome(20)); 110 a.message_loop()->PostTask(FROM_HERE, new SleepSome(20));
104 a.message_loop()->PostTask(FROM_HERE, new ToggleValue(&was_invoked)); 111 a.message_loop()->PostTask(FROM_HERE, new ToggleValue(&was_invoked));
105 } 112 }
106 EXPECT_TRUE(was_invoked); 113 EXPECT_TRUE(was_invoked);
107 } 114 }
108 115
109 TEST_F(ThreadTest, StopSoon) { 116 TEST_F(ThreadTest, StopSoon) {
110 Thread a("StopSoon"); 117 Thread a("StopSoon");
111 EXPECT_TRUE(a.Start()); 118 EXPECT_TRUE(a.Start());
112 EXPECT_TRUE(a.message_loop()); 119 EXPECT_TRUE(a.message_loop());
120 EXPECT_TRUE(a.IsRunning());
113 a.StopSoon(); 121 a.StopSoon();
114 a.StopSoon(); 122 a.StopSoon();
115 a.Stop(); 123 a.Stop();
116 EXPECT_FALSE(a.message_loop()); 124 EXPECT_FALSE(a.message_loop());
125 EXPECT_FALSE(a.IsRunning());
117 } 126 }
118 127
119 TEST_F(ThreadTest, ThreadName) { 128 TEST_F(ThreadTest, ThreadName) {
120 Thread a("ThreadName"); 129 Thread a("ThreadName");
121 EXPECT_TRUE(a.Start()); 130 EXPECT_TRUE(a.Start());
122 EXPECT_EQ("ThreadName", a.thread_name()); 131 EXPECT_EQ("ThreadName", a.thread_name());
123 } 132 }
124 133
125 // Make sure we can't use a thread between Start() and Init(). 134 // Make sure we can't use a thread between Start() and Init().
126 TEST_F(ThreadTest, SleepInsideInit) { 135 TEST_F(ThreadTest, SleepInsideInit) {
127 SleepInsideInitThread t; 136 SleepInsideInitThread t;
128 EXPECT_FALSE(t.InitCalled()); 137 EXPECT_FALSE(t.InitCalled());
129 t.Start(); 138 t.Start();
130 EXPECT_TRUE(t.InitCalled()); 139 EXPECT_TRUE(t.InitCalled());
131 } 140 }
132 141
OLDNEW
« no previous file with comments | « base/thread.cc ('k') | media/base/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698