blob: 769a85079f22b4562d1ced294eee6d5d8e893a1f [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.commit3f4a7322008-07-27 06:49:38 +09004
5#include "base/basictypes.h"
6#include "base/file_util.h"
7#include "base/logging.h"
8#include "base/path_service.h"
erikkay@google.comf2406842008-08-21 00:59:49 +09009#include "base/platform_test.h"
erikkay@google.com3620e4c2008-08-12 00:38:27 +090010#if defined(OS_WIN)
maruel@google.com15cfc7f2008-08-08 05:23:09 +090011#include "base/win_util.h"
erikkay@google.com3620e4c2008-08-12 00:38:27 +090012#endif
initial.commit3f4a7322008-07-27 06:49:38 +090013#include "testing/gtest/include/gtest/gtest.h"
maruel@google.com15cfc7f2008-08-08 05:23:09 +090014#include "testing/gtest/include/gtest/gtest-spi.h"
initial.commit3f4a7322008-07-27 06:49:38 +090015
16namespace {
initial.commit3f4a7322008-07-27 06:49:38 +090017
18// Returns true if PathService::Get returns true and sets the path parameter
19// to non-empty for the given PathService::DirType enumeration value.
20bool ReturnsValidPath(int dir_type) {
21 std::wstring path;
22 bool result = PathService::Get(dir_type, &path);
maruel@google.com15cfc7f2008-08-08 05:23:09 +090023 return result && !path.empty() && file_util::PathExists(path);
initial.commit3f4a7322008-07-27 06:49:38 +090024}
25
erikkay@google.com3620e4c2008-08-12 00:38:27 +090026#if defined(OS_WIN)
maruel@google.com15cfc7f2008-08-08 05:23:09 +090027// Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails.
maruel@google.com31177672008-08-08 08:59:04 +090028bool ReturnsInvalidPath(int dir_type) {
maruel@google.com15cfc7f2008-08-08 05:23:09 +090029 std::wstring path;
30 bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path);
maruel@google.com31177672008-08-08 08:59:04 +090031 return !result && path.empty();
maruel@google.com15cfc7f2008-08-08 05:23:09 +090032}
erikkay@google.com3620e4c2008-08-12 00:38:27 +090033#endif
maruel@google.com15cfc7f2008-08-08 05:23:09 +090034
35} // namespace
36
erikkay@google.comf2406842008-08-21 00:59:49 +090037// On the Mac this winds up using some autoreleased objects, so we need to
38// be a PlatformTest.
39typedef PlatformTest PathServiceTest;
40
initial.commit3f4a7322008-07-27 06:49:38 +090041// 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.comf2406842008-08-21 00:59:49 +090045TEST_F(PathServiceTest, Get) {
initial.commit3f4a7322008-07-27 06:49:38 +090046 for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
47 EXPECT_PRED1(ReturnsValidPath, key);
48 }
erikkay@google.com1d4507f2008-08-07 01:29:44 +090049#ifdef OS_WIN
50 for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
maruel@google.com15cfc7f2008-08-08 05:23:09 +090051 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.com31177672008-08-08 08:59:04 +090055 EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
maruel@google.com15cfc7f2008-08-08 05:23:09 +090056 } else {
maruel@google.com31177672008-08-08 08:59:04 +090057 EXPECT_TRUE(ReturnsValidPath(key)) << key;
maruel@google.com15cfc7f2008-08-08 05:23:09 +090058 }
erikkay@google.com1d4507f2008-08-07 01:29:44 +090059 }
60#endif
initial.commit3f4a7322008-07-27 06:49:38 +090061}
license.botf003cfe2008-08-24 09:55:55 +090062