Corina | 633099b | 2020-06-17 21:55:33 +0100 | [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 specic language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "FuseUtilsTest" |
| 18 | |
| 19 | #include "libfuse_jni/FuseUtils.h" |
| 20 | |
| 21 | #include <gtest/gtest.h> |
| 22 | |
| 23 | using namespace mediaprovider::fuse; |
| 24 | |
| 25 | TEST(FuseUtilsTest, testContainsMount_isTrueForAndroidDataObb) { |
Martijn Coenen | fc41bbf | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 26 | EXPECT_TRUE(containsMount("/storage/emulated/1234/Android")); |
| 27 | EXPECT_TRUE(containsMount("/storage/emulated/5678/Android")); |
| 28 | EXPECT_TRUE(containsMount("/storage/emulated/1234/Android/data")); |
| 29 | EXPECT_TRUE(containsMount("/storage/emulated/5678/Android/obb")); |
| 30 | EXPECT_TRUE(containsMount("/storage/emulated/1234/Android/obb")); |
| 31 | EXPECT_TRUE(containsMount("/storage/emulated/5678/Android/obb")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | TEST(FuseUtilsTest, testContainsMount) { |
Martijn Coenen | fc41bbf | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 35 | EXPECT_FALSE(containsMount("/random/path")); |
| 36 | EXPECT_FALSE(containsMount("/storage/abc-123")); |
| 37 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/data/and/more")); |
| 38 | EXPECT_FALSE(containsMount("/storage/emulated")); |
| 39 | EXPECT_FALSE(containsMount("/storage/emulated/")); |
| 40 | EXPECT_FALSE(containsMount("/storage/emulated//")); |
| 41 | EXPECT_FALSE(containsMount("/storage/emulated/0/")); |
| 42 | EXPECT_FALSE(containsMount("/storage/emulated/1234/")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Corina | 762bb25 | 2020-07-09 10:30:33 +0100 | [diff] [blame] | 45 | TEST(FuseUtilsTest, testContainsMount_isCaseInsensitive) { |
Martijn Coenen | fc41bbf | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 46 | EXPECT_TRUE(containsMount("/storage/emulated/1234/android")); |
| 47 | EXPECT_TRUE(containsMount("/storage/emulated/1234/Android/Data")); |
| 48 | EXPECT_TRUE(containsMount("/storage/emulated/1234/ANDroid/dATa")); |
| 49 | EXPECT_TRUE(containsMount("/storage/emulated/1234/ANDROID/OBB")); |
| 50 | EXPECT_TRUE(containsMount("/Storage/EMULATED/1234/Android/obb")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | TEST(FuseUtilsTest, testContainsMount_isFalseForPathWithAdditionalSlash) { |
Martijn Coenen | fc41bbf | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 54 | EXPECT_FALSE(containsMount("/storage/emulated//Android/data")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 55 | |
Martijn Coenen | fc41bbf | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 56 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/")); |
| 57 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/data/")); |
| 58 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/obb/")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 59 | |
Martijn Coenen | fc41bbf | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 60 | EXPECT_FALSE(containsMount("//storage/emulated/1234/Android")); |
| 61 | EXPECT_FALSE(containsMount("/storage/emulated//1234/Android/data")); |
| 62 | EXPECT_FALSE(containsMount("/storage/emulated/1234//Android/data")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 63 | } |