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

Side by Side Diff: base/shared_memory_unittest.cc

Issue 3828009: Move scoped_nsdisable_screen_update from base to app/mac... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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/scoped_nsdisable_screen_updates.h ('k') | base/test/test_suite.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) 2006-2008 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/mac/scoped_nsautorelease_pool.h"
6 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
7 #include "base/scoped_nsautorelease_pool.h"
8 #include "base/shared_memory.h" 8 #include "base/shared_memory.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/test/multiprocess_test.h" 10 #include "base/test/multiprocess_test.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/multiprocess_func_list.h" 12 #include "testing/multiprocess_func_list.h"
13 13
14 static const int kNumThreads = 5; 14 static const int kNumThreads = 5;
15 static const int kNumTasks = 5; 15 static const int kNumTasks = 5;
16 16
17 namespace base { 17 namespace base {
18 18
19 namespace { 19 namespace {
20 20
21 // Each thread will open the shared memory. Each thread will take a different 4 21 // Each thread will open the shared memory. Each thread will take a different 4
22 // byte int pointer, and keep changing it, with some small pauses in between. 22 // byte int pointer, and keep changing it, with some small pauses in between.
23 // Verify that each thread's value in the shared memory is always correct. 23 // Verify that each thread's value in the shared memory is always correct.
24 class MultipleThreadMain : public PlatformThread::Delegate { 24 class MultipleThreadMain : public PlatformThread::Delegate {
25 public: 25 public:
26 explicit MultipleThreadMain(int16 id) : id_(id) {} 26 explicit MultipleThreadMain(int16 id) : id_(id) {}
27 ~MultipleThreadMain() {} 27 ~MultipleThreadMain() {}
28 28
29 static void CleanUp() { 29 static void CleanUp() {
30 SharedMemory memory; 30 SharedMemory memory;
31 memory.Delete(s_test_name_); 31 memory.Delete(s_test_name_);
32 } 32 }
33 33
34 // PlatformThread::Delegate interface. 34 // PlatformThread::Delegate interface.
35 void ThreadMain() { 35 void ThreadMain() {
36 ScopedNSAutoreleasePool pool; // noop if not OSX 36 mac::ScopedNSAutoreleasePool pool; // noop if not OSX
37 const uint32 kDataSize = 1024; 37 const uint32 kDataSize = 1024;
38 SharedMemory memory; 38 SharedMemory memory;
39 bool rv = memory.Create(s_test_name_, false, true, kDataSize); 39 bool rv = memory.Create(s_test_name_, false, true, kDataSize);
40 EXPECT_TRUE(rv); 40 EXPECT_TRUE(rv);
41 rv = memory.Map(kDataSize); 41 rv = memory.Map(kDataSize);
42 EXPECT_TRUE(rv); 42 EXPECT_TRUE(rv);
43 int *ptr = static_cast<int*>(memory.memory()) + id_; 43 int *ptr = static_cast<int*>(memory.memory()) + id_;
44 EXPECT_EQ(*ptr, 0); 44 EXPECT_EQ(*ptr, 0);
45 45
46 for (int idx = 0; idx < 100; idx++) { 46 for (int idx = 0; idx < 100; idx++) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 class SharedMemoryProcessTest : public base::MultiProcessTest { 279 class SharedMemoryProcessTest : public base::MultiProcessTest {
280 public: 280 public:
281 281
282 static void CleanUp() { 282 static void CleanUp() {
283 SharedMemory memory; 283 SharedMemory memory;
284 memory.Delete(s_test_name_); 284 memory.Delete(s_test_name_);
285 } 285 }
286 286
287 static int TaskTestMain() { 287 static int TaskTestMain() {
288 int errors = 0; 288 int errors = 0;
289 ScopedNSAutoreleasePool pool; // noop if not OSX 289 mac::ScopedNSAutoreleasePool pool; // noop if not OSX
290 const uint32 kDataSize = 1024; 290 const uint32 kDataSize = 1024;
291 SharedMemory memory; 291 SharedMemory memory;
292 bool rv = memory.Create(s_test_name_, false, true, kDataSize); 292 bool rv = memory.Create(s_test_name_, false, true, kDataSize);
293 EXPECT_TRUE(rv); 293 EXPECT_TRUE(rv);
294 if (rv != true) 294 if (rv != true)
295 errors++; 295 errors++;
296 rv = memory.Map(kDataSize); 296 rv = memory.Map(kDataSize);
297 EXPECT_TRUE(rv); 297 EXPECT_TRUE(rv);
298 if (rv != true) 298 if (rv != true)
299 errors++; 299 errors++;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 335 }
336 336
337 SharedMemoryProcessTest::CleanUp(); 337 SharedMemoryProcessTest::CleanUp();
338 } 338 }
339 339
340 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 340 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
341 return SharedMemoryProcessTest::TaskTestMain(); 341 return SharedMemoryProcessTest::TaskTestMain();
342 } 342 }
343 343
344 } // namespace base 344 } // namespace base
OLDNEW
« no previous file with comments | « base/scoped_nsdisable_screen_updates.h ('k') | base/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698