blob: 618bb0f3e4b2141a0addd5f2fffd4db6c236c566 [file] [log] [blame]
slane7fc725c2015-05-29 23:05:431// Copyright 2015 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.
4
5#include "base/files/file_path.h"
6#include "base/path_service.h"
7#include "chromecast/base/path_utils.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace chromecast {
11namespace {
12const char kTestRelPath[] = "rel/path";
13const char kTestAbsPath[] = "/abs/path/to/dir";
14
15std::string GetTestString(int base_dir_key) {
16 base::FilePath basedir;
17 EXPECT_TRUE(PathService::Get(base_dir_key, &basedir));
18 return basedir.value() + "/" + kTestRelPath;
19}
20
21} // namespace
22
23TEST(PathUtilsTest, GetHomePath) {
24 // Test with relative path.
25 std::string expected = GetTestString(base::DIR_HOME);
26 base::FilePath actual = GetHomePath(base::FilePath(kTestRelPath));
27 EXPECT_EQ(expected, actual.value());
28
29 // Test with absolute path.
30 actual = GetHomePath(base::FilePath(kTestAbsPath));
31 EXPECT_EQ(kTestAbsPath, actual.value());
32}
33
34TEST(PathUtilsTest, GetBinPath) {
35 // Test with relative path.
36 std::string expected = GetTestString(base::DIR_EXE);
37 base::FilePath actual = GetBinPath(base::FilePath(kTestRelPath));
38 EXPECT_EQ(expected, actual.value());
39
40 // Test with absolute path.
41 actual = GetBinPath(base::FilePath(kTestAbsPath));
42 EXPECT_EQ(kTestAbsPath, actual.value());
43}
44
45TEST(PathUtilsTest, GetTmpPath) {
46 // Test with relative path.
47 std::string expected = GetTestString(base::DIR_TEMP);
48 base::FilePath actual = GetTmpPath(base::FilePath(kTestRelPath));
49 EXPECT_EQ(expected, actual.value());
50
51 // Test with absolute path.
52 actual = GetTmpPath(base::FilePath(kTestAbsPath));
53 EXPECT_EQ(kTestAbsPath, actual.value());
54}
55
56} // chromecast