OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/environment.h" | 6 #include "base/environment.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 TEST_F(MultiProcessLockTest, BasicCreationTest) { | 71 TEST_F(MultiProcessLockTest, BasicCreationTest) { |
72 // Test basic creation/destruction with no lock taken | 72 // Test basic creation/destruction with no lock taken |
73 std::string name = GenerateLockName(); | 73 std::string name = GenerateLockName(); |
74 scoped_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name)); | 74 scoped_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name)); |
75 ExpectLockIsUnlocked(name); | 75 ExpectLockIsUnlocked(name); |
76 scoped.reset(NULL); | 76 scoped.reset(NULL); |
77 } | 77 } |
78 | 78 |
79 TEST_F(MultiProcessLockTest, LongNameTest) { | 79 TEST_F(MultiProcessLockTest, LongNameTest) { |
80 // Linux has a max path name of 108 characters. | 80 // Every platform has has it's own max path name size, |
81 // http://lxr.linux.no/linux+v2.6.36/include/linux/un.h | 81 // so different checks are needed for them. |
82 // This is enforced on all platforms. | 82 // POSIX: sizeof(address.sun_path) - 2 |
| 83 // Mac OS X: BOOTSTRAP_MAX_NAME_LEN |
| 84 // Windows: MAX_PATH |
83 LOG(INFO) << "Following error log due to long name is expected"; | 85 LOG(INFO) << "Following error log due to long name is expected"; |
| 86 #if defined(OS_MACOSX) |
| 87 std::string name("This is a name that is longer than one hundred and " |
| 88 "twenty-eight characters to make sure that we fail appropriately on " |
| 89 "Mac OS X when we have a path that is too long for Mac OS X to handle"); |
| 90 #elif defined(OS_POSIX) |
84 std::string name("This is a name that is longer than one hundred and eight " | 91 std::string name("This is a name that is longer than one hundred and eight " |
85 "characters to make sure that we fail appropriately on linux when we " | 92 "characters to make sure that we fail appropriately on POSIX systems " |
86 "have a path that is to long for linux to handle"); | 93 "when we have a path that is too long for the system to handle"); |
| 94 #elif defined(OS_WIN) |
| 95 std::string name("This is a name that is longer than two hundred and sixty " |
| 96 "characters to make sure that we fail appropriately on Windows when we " |
| 97 "have a path that is too long for Windows to handle " |
| 98 "This limitation comes from the MAX_PATH definition which is obviously " |
| 99 "defined to be a maximum of two hundred and sixty characters "); |
| 100 #endif |
87 scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); | 101 scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); |
88 EXPECT_FALSE(test_lock->TryLock()); | 102 EXPECT_FALSE(test_lock->TryLock()); |
89 } | 103 } |
90 | 104 |
91 TEST_F(MultiProcessLockTest, SimpleLock) { | 105 TEST_F(MultiProcessLockTest, SimpleLock) { |
92 std::string name = GenerateLockName(); | 106 std::string name = GenerateLockName(); |
93 scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); | 107 scoped_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); |
94 EXPECT_TRUE(test_lock->TryLock()); | 108 EXPECT_TRUE(test_lock->TryLock()); |
95 ExpectLockIsLocked(name); | 109 ExpectLockIsLocked(name); |
96 test_lock->Unlock(); | 110 test_lock->Unlock(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 MULTIPROCESS_TEST_MAIN(MultiProcessLockTrySucceedMain) { | 162 MULTIPROCESS_TEST_MAIN(MultiProcessLockTrySucceedMain) { |
149 std::string name; | 163 std::string name; |
150 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 164 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
151 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName, | 165 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName, |
152 &name)); | 166 &name)); |
153 scoped_ptr<MultiProcessLock> test_lock( | 167 scoped_ptr<MultiProcessLock> test_lock( |
154 MultiProcessLock::Create(name)); | 168 MultiProcessLock::Create(name)); |
155 EXPECT_TRUE(test_lock->TryLock()); | 169 EXPECT_TRUE(test_lock->TryLock()); |
156 return 0; | 170 return 0; |
157 } | 171 } |
OLD | NEW |