slan | e7fc725c | 2015-05-29 23:05:43 | [diff] [blame] | 1 | // 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 | |
| 10 | namespace chromecast { |
| 11 | namespace { |
| 12 | const char kTestRelPath[] = "rel/path"; |
| 13 | const char kTestAbsPath[] = "/abs/path/to/dir"; |
| 14 | |
| 15 | std::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 | |
| 23 | TEST(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 | |
| 34 | TEST(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 | |
| 45 | TEST(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 |