license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | #include "base/basictypes.h" |
| 6 | #include "base/file_util.h" |
| 7 | #include "base/logging.h" |
| 8 | #include "base/path_service.h" |
erikkay@google.com | f240684 | 2008-08-21 00:59:49 +0900 | [diff] [blame] | 9 | #include "base/platform_test.h" |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 10 | #if defined(OS_WIN) |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 11 | #include "base/win_util.h" |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 12 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 13 | #include "testing/gtest/include/gtest/gtest.h" |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest-spi.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 15 | |
| 16 | namespace { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 17 | |
| 18 | // Returns true if PathService::Get returns true and sets the path parameter |
| 19 | // to non-empty for the given PathService::DirType enumeration value. |
| 20 | bool ReturnsValidPath(int dir_type) { |
| 21 | std::wstring path; |
| 22 | bool result = PathService::Get(dir_type, &path); |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 23 | return result && !path.empty() && file_util::PathExists(path); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 24 | } |
| 25 | |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 26 | #if defined(OS_WIN) |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 27 | // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 28 | bool ReturnsInvalidPath(int dir_type) { |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 29 | std::wstring path; |
| 30 | bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 31 | return !result && path.empty(); |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 32 | } |
erikkay@google.com | 3620e4c | 2008-08-12 00:38:27 +0900 | [diff] [blame] | 33 | #endif |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 34 | |
| 35 | } // namespace |
| 36 | |
erikkay@google.com | f240684 | 2008-08-21 00:59:49 +0900 | [diff] [blame] | 37 | // On the Mac this winds up using some autoreleased objects, so we need to |
| 38 | // be a PlatformTest. |
| 39 | typedef PlatformTest PathServiceTest; |
| 40 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 41 | // Test that all PathService::Get calls return a value and a true result |
| 42 | // in the development environment. (This test was created because a few |
| 43 | // later changes to Get broke the semantics of the function and yielded the |
| 44 | // correct value while returning false.) |
erikkay@google.com | f240684 | 2008-08-21 00:59:49 +0900 | [diff] [blame] | 45 | TEST_F(PathServiceTest, Get) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 46 | for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) { |
| 47 | EXPECT_PRED1(ReturnsValidPath, key); |
| 48 | } |
erikkay@google.com | 1d4507f | 2008-08-07 01:29:44 +0900 | [diff] [blame] | 49 | #ifdef OS_WIN |
| 50 | for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) { |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 51 | if (key == base::DIR_LOCAL_APP_DATA_LOW && |
| 52 | win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { |
| 53 | // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to |
| 54 | // fail. |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 55 | EXPECT_TRUE(ReturnsInvalidPath(key)) << key; |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 56 | } else { |
maruel@google.com | 3117767 | 2008-08-08 08:59:04 +0900 | [diff] [blame] | 57 | EXPECT_TRUE(ReturnsValidPath(key)) << key; |
maruel@google.com | 15cfc7f | 2008-08-08 05:23:09 +0900 | [diff] [blame] | 58 | } |
erikkay@google.com | 1d4507f | 2008-08-07 01:29:44 +0900 | [diff] [blame] | 59 | } |
| 60 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 61 | } |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 62 | |