blob: b75ab7e64c26c57e177cc6f4b22f9207511a8840 [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]09ad1e622008-08-07 20:23:0934#include "base/win_util.h"
initial.commitd7cae122008-07-26 21:49:3835#include "testing/gtest/include/gtest/gtest.h"
[email protected]09ad1e622008-08-07 20:23:0936#include "testing/gtest/include/gtest/gtest-spi.h"
initial.commitd7cae122008-07-26 21:49:3837
38namespace {
initial.commitd7cae122008-07-26 21:49:3839
40// Returns true if PathService::Get returns true and sets the path parameter
41// to non-empty for the given PathService::DirType enumeration value.
42bool ReturnsValidPath(int dir_type) {
43 std::wstring path;
44 bool result = PathService::Get(dir_type, &path);
[email protected]09ad1e622008-08-07 20:23:0945 return result && !path.empty() && file_util::PathExists(path);
initial.commitd7cae122008-07-26 21:49:3846}
47
[email protected]09ad1e622008-08-07 20:23:0948// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
[email protected]0cfda1e2008-08-07 23:59:0449bool ReturnsInvalidPath(int dir_type) {
[email protected]09ad1e622008-08-07 20:23:0950 std::wstring path;
51 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
[email protected]0cfda1e2008-08-07 23:59:0452 return !result && path.empty();
[email protected]09ad1e622008-08-07 20:23:0953}
54
55} // namespace
56
initial.commitd7cae122008-07-26 21:49:3857// Test that all PathService::Get calls return a value and a true result
58// in the development environment. (This test was created because a few
59// later changes to Get broke the semantics of the function and yielded the
60// correct value while returning false.)
61TEST(PathServiceTest, Get) {
62 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
63 EXPECT_PRED1(ReturnsValidPath, key);
64 }
[email protected]1010f7d2008-08-06 16:29:4465#ifdef OS_WIN
66 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
[email protected]09ad1e622008-08-07 20:23:0967 if (key == base::DIR_LOCAL_APP_DATA_LOW &&
68 win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
69 // DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to
70 // fail.
[email protected]0cfda1e2008-08-07 23:59:0471 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0972 } else {
[email protected]0cfda1e2008-08-07 23:59:0473 EXPECT_TRUE(ReturnsValidPath(key)) << key;
[email protected]09ad1e622008-08-07 20:23:0974 }
[email protected]1010f7d2008-08-06 16:29:4475 }
76#endif
initial.commitd7cae122008-07-26 21:49:3877}