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

Unified Diff: base/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 10 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/platform_thread_posix.cc ('k') | base/platform_thread_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_thread_unittest.cc
===================================================================
--- base/platform_thread_unittest.cc (revision 70328)
+++ base/platform_thread_unittest.cc (working copy)
@@ -1,104 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/platform_thread.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-typedef testing::Test PlatformThreadTest;
-
-// Trivial tests that thread runs and doesn't crash on create and join ---------
-
-class TrivialThread : public PlatformThread::Delegate {
- public:
- TrivialThread() : did_run_(false) {}
-
- virtual void ThreadMain() {
- did_run_ = true;
- }
-
- bool did_run() const { return did_run_; }
-
- private:
- bool did_run_;
-
- DISALLOW_COPY_AND_ASSIGN(TrivialThread);
-};
-
-TEST_F(PlatformThreadTest, Trivial) {
- TrivialThread thread;
- PlatformThreadHandle handle = kNullThreadHandle;
-
- ASSERT_FALSE(thread.did_run());
- ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
- PlatformThread::Join(handle);
- ASSERT_TRUE(thread.did_run());
-}
-
-TEST_F(PlatformThreadTest, TrivialTimesTen) {
- TrivialThread thread[10];
- PlatformThreadHandle handle[arraysize(thread)];
-
- for (size_t n = 0; n < arraysize(thread); n++)
- ASSERT_FALSE(thread[n].did_run());
- for (size_t n = 0; n < arraysize(thread); n++)
- ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n]));
- for (size_t n = 0; n < arraysize(thread); n++)
- PlatformThread::Join(handle[n]);
- for (size_t n = 0; n < arraysize(thread); n++)
- ASSERT_TRUE(thread[n].did_run());
-}
-
-// Tests of basic thread functions ---------------------------------------------
-
-class FunctionTestThread : public TrivialThread {
- public:
- FunctionTestThread() : thread_id_(0) {}
-
- virtual void ThreadMain() {
- thread_id_ = PlatformThread::CurrentId();
- PlatformThread::YieldCurrentThread();
- PlatformThread::Sleep(50);
-
- TrivialThread::ThreadMain();
- }
-
- PlatformThreadId thread_id() const { return thread_id_; }
-
- private:
- PlatformThreadId thread_id_;
-
- DISALLOW_COPY_AND_ASSIGN(FunctionTestThread);
-};
-
-TEST_F(PlatformThreadTest, Function) {
- PlatformThreadId main_thread_id = PlatformThread::CurrentId();
-
- FunctionTestThread thread;
- PlatformThreadHandle handle = kNullThreadHandle;
-
- ASSERT_FALSE(thread.did_run());
- ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
- PlatformThread::Join(handle);
- ASSERT_TRUE(thread.did_run());
- EXPECT_NE(thread.thread_id(), main_thread_id);
-}
-
-TEST_F(PlatformThreadTest, FunctionTimesTen) {
- PlatformThreadId main_thread_id = PlatformThread::CurrentId();
-
- FunctionTestThread thread[10];
- PlatformThreadHandle handle[arraysize(thread)];
-
- for (size_t n = 0; n < arraysize(thread); n++)
- ASSERT_FALSE(thread[n].did_run());
- for (size_t n = 0; n < arraysize(thread); n++)
- ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n]));
- for (size_t n = 0; n < arraysize(thread); n++)
- PlatformThread::Join(handle[n]);
- for (size_t n = 0; n < arraysize(thread); n++) {
- ASSERT_TRUE(thread[n].did_run());
- EXPECT_NE(thread[n].thread_id(), main_thread_id);
- }
-}
« no previous file with comments | « base/platform_thread_posix.cc ('k') | base/platform_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698