1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/core/unittest_util.h"
16 :
17 : #include "base/files/file_path.h"
18 : #include "base/files/file_util.h"
19 : #include "gtest/gtest.h"
20 :
21 : namespace testing {
22 :
23 E : TEST(CoreUnittestUtils, GetRelativePath) {
24 E : const base::FilePath kEmptyPath;
25 E : const base::FilePath kCurrentDir(L".");
26 E : const base::FilePath kPath1(L"C:\\foo\\bar");
27 E : const base::FilePath kPath2(L"c:\\foo\\bar\\sub");
28 E : const base::FilePath kPath3(L"c:\\foo\\other\\file");
29 E : const base::FilePath kPath4(L"D:\\foo\\bar");
30 E : const base::FilePath kRelPath1From2(L"..");
31 E : const base::FilePath kRelPath2From1(L"sub");
32 E : const base::FilePath kRelPath1From3(L"..\\..\\bar");
33 E : const base::FilePath kRelPath3From1(L"..\\other\\file");
34 :
35 E : EXPECT_EQ(kEmptyPath, GetRelativePath(kPath1, kPath4));
36 E : EXPECT_EQ(kCurrentDir, GetRelativePath(kPath1, kPath1));
37 E : EXPECT_EQ(kRelPath1From2, GetRelativePath(kPath1, kPath2));
38 E : EXPECT_EQ(kRelPath2From1, GetRelativePath(kPath2, kPath1));
39 E : EXPECT_EQ(kRelPath1From3, GetRelativePath(kPath1, kPath3));
40 E : EXPECT_EQ(kRelPath3From1, GetRelativePath(kPath3, kPath1));
41 :
42 E : base::FilePath sub_dir;
43 E : ASSERT_TRUE(base::GetCurrentDirectory(&sub_dir));
44 E : EXPECT_EQ(base::FilePath(L"blah"), GetRelativePath(sub_dir.Append(L"blah")));
45 E : }
46 :
47 : } // namespace testing
|