Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "../path.h" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | using namespace std::literals; |
| 22 | |
| 23 | namespace android::incremental::path { |
| 24 | |
| 25 | TEST(Path, Normalize) { |
| 26 | EXPECT_STREQ("", normalize("").c_str()); |
| 27 | EXPECT_STREQ("/data/app/com.snapchat.android-evzhnJDgPOq8VcxwEkSY5g==/base.apk", |
| 28 | normalize("/data/app/com.snapchat.android-evzhnJDgPOq8VcxwEkSY5g==/base.apk") |
| 29 | .c_str()); |
| 30 | EXPECT_STREQ("/a/b", normalize("/a/c/../b").c_str()); |
| 31 | } |
| 32 | |
| 33 | TEST(Path, Comparator) { |
| 34 | EXPECT_TRUE(PathLess()("/a", "/aa")); |
| 35 | EXPECT_TRUE(PathLess()("/a/b", "/aa/b")); |
| 36 | EXPECT_TRUE(PathLess()("/a", "/a/b")); |
| 37 | EXPECT_TRUE(PathLess()("/a/b"sv, "/a\0"sv)); |
| 38 | EXPECT_TRUE(!PathLess()("/aa/b", "/a/b")); |
| 39 | EXPECT_TRUE(!PathLess()("/a/b", "/a/b")); |
| 40 | EXPECT_TRUE(!PathLess()("/a/b", "/a")); |
| 41 | } |
| 42 | |
Yurii Zubrytskyi | fe807fd | 2021-03-23 12:11:11 -0700 | [diff] [blame^] | 43 | TEST(Path, Join) { |
| 44 | EXPECT_STREQ("", path::join("", "").c_str()); |
| 45 | |
| 46 | EXPECT_STREQ("/", path::join("", "/").c_str()); |
| 47 | EXPECT_STREQ("/", path::join("/", "").c_str()); |
| 48 | EXPECT_STREQ("/", path::join("/", "/").c_str()); |
| 49 | EXPECT_STREQ("/", path::join("/"s, "/").c_str()); |
| 50 | EXPECT_STREQ("/", path::join("/"sv, "/").c_str()); |
| 51 | EXPECT_STREQ("/", path::join("/", "/", "/", "/", "/", "/", "/", "/", "/", "/").c_str()); |
| 52 | |
| 53 | EXPECT_STREQ("/a/b/c/d", path::join("/a/b/"s, "c", "d").c_str()); |
| 54 | EXPECT_STREQ("/a/b/c/d", path::join("/a/b/", "c", "d").c_str()); |
| 55 | EXPECT_STREQ("/a/b/c/d", path::join("/", "a/b/", "c", "d").c_str()); |
| 56 | EXPECT_STREQ("/a/b/c/d", path::join("/", "a/b", "c", "d").c_str()); |
| 57 | EXPECT_STREQ("/a/b/c/d", path::join("/", "//a/b//", "c", "d").c_str()); |
| 58 | EXPECT_STREQ("/a/b/c/d", path::join("", "", "/", "//a/b//", "c", "d").c_str()); |
| 59 | EXPECT_STREQ("/a/b/c/d", path::join(""s, "", "/", "//a/b//", "c", "d").c_str()); |
| 60 | EXPECT_STREQ("/a/b/c/d", path::join("/a/b", "", "", "/", "", "/", "/", "/c", "d").c_str()); |
| 61 | } |
| 62 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 63 | } // namespace android::incremental::path |