initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 1 | // Copyright 2008, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | #include "base/basictypes.h" |
| 31 | #include "base/file_util.h" |
| 32 | #include "base/logging.h" |
| 33 | #include "base/path_service.h" |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 34 | #if defined(OS_WIN) |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 35 | #include "base/win_util.h" |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 36 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 37 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 38 | #include "testing/gtest/include/gtest/gtest-spi.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 39 | |
| 40 | namespace { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 41 | |
| 42 | // Returns true if PathService::Get returns true and sets the path parameter |
| 43 | // to non-empty for the given PathService::DirType enumeration value. |
| 44 | bool ReturnsValidPath(int dir_type) { |
| 45 | std::wstring path; |
| 46 | bool result = PathService::Get(dir_type, &path); |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 47 | return result && !path.empty() && file_util::PathExists(path); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 50 | #if defined(OS_WIN) |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 51 | // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. |
[email protected] | 0cfda1e | 2008-08-07 23:59:04 | [diff] [blame] | 52 | bool ReturnsInvalidPath(int dir_type) { |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 53 | std::wstring path; |
| 54 | bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); |
[email protected] | 0cfda1e | 2008-08-07 23:59:04 | [diff] [blame] | 55 | return !result && path.empty(); |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 56 | } |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 57 | #endif |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 58 | |
| 59 | } // namespace |
| 60 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 61 | // Test that all PathService::Get calls return a value and a true result |
| 62 | // in the development environment. (This test was created because a few |
| 63 | // later changes to Get broke the semantics of the function and yielded the |
| 64 | // correct value while returning false.) |
| 65 | TEST(PathServiceTest, Get) { |
| 66 | for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) { |
| 67 | EXPECT_PRED1(ReturnsValidPath, key); |
| 68 | } |
[email protected] | 1010f7d | 2008-08-06 16:29:44 | [diff] [blame] | 69 | #ifdef OS_WIN |
| 70 | for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) { |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 71 | if (key == base::DIR_LOCAL_APP_DATA_LOW && |
| 72 | win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { |
| 73 | // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to |
| 74 | // fail. |
[email protected] | 0cfda1e | 2008-08-07 23:59:04 | [diff] [blame] | 75 | EXPECT_TRUE(ReturnsInvalidPath(key)) << key; |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 76 | } else { |
[email protected] | 0cfda1e | 2008-08-07 23:59:04 | [diff] [blame] | 77 | EXPECT_TRUE(ReturnsValidPath(key)) << key; |
[email protected] | 09ad1e62 | 2008-08-07 20:23:09 | [diff] [blame] | 78 | } |
[email protected] | 1010f7d | 2008-08-06 16:29:44 | [diff] [blame] | 79 | } |
| 80 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 81 | } |