blob: 970ea0c97473a6870caabeab3a67affaf68fcd25 [file] [log] [blame]
initial.commitd7cae122008-07-26 21:49:381// 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]6723f832008-08-11 15:38:2734#if defined(OS_WIN)
[email protected]09ad1e622008-08-07 20:23:0935#include "base/win_util.h"
[email protected]6723f832008-08-11 15:38:2736#endif
initial.commitd7cae122008-07-26 21:49:3837#include "testing/gtest/include/gtest/gtest.h"
[email protected]09ad1e622008-08-07 20:23:0938#include "testing/gtest/include/gtest/gtest-spi.h"
initial.commitd7cae122008-07-26 21:49:3839
40namespace {
initial.commitd7cae122008-07-26 21:49:3841
42// Returns true if PathService::Get returns true and sets the path parameter
43// to non-empty for the given PathService::DirType enumeration value.
44bool ReturnsValidPath(int dir_type) {
45 std::wstring path;
46 bool result = PathService::Get(dir_type, &path);
[email protected]09ad1e622008-08-07 20:23:0947 return result && !path.empty() && file_util::PathExists(path);
initial.commitd7cae122008-07-26 21:49:3848}
49
[email protected]6723f832008-08-11 15:38:2750#if defined(OS_WIN)
[email protected]09ad1e622008-08-07 20:23:0951// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
[email protected]0cfda1e2008-08-07 23:59:0452bool ReturnsInvalidPath(int dir_type) {
[email protected]09ad1e622008-08-07 20:23:0953 std::wstring path;
54 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
[email protected]0cfda1e2008-08-07 23:59:0455 return !result && path.empty();
[email protected]09ad1e622008-08-07 20:23:0956}
[email protected]6723f832008-08-11 15:38:2757#endif
[email protected]09ad1e622008-08-07 20:23:0958
59} // namespace
60
initial.commitd7cae122008-07-26 21:49:3861// 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.)
65TEST(PathServiceTest, Get) {
66 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
67 EXPECT_PRED1(ReturnsValidPath, key);
68 }
[email protected]1010f7d2008-08-06 16:29:4469#ifdef OS_WIN
70 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
[email protected]09ad1e622008-08-07 20:23:0971 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]0cfda1e2008-08-07 23:59:0475 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0976 } else {
[email protected]0cfda1e2008-08-07 23:59:0477 EXPECT_TRUE(ReturnsValidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0978 }
[email protected]1010f7d2008-08-06 16:29:4479 }
80#endif
initial.commitd7cae122008-07-26 21:49:3881}