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 | |
Alessio Balsini | 2a79da0 | 2021-12-02 20:09:05 +0000 | [diff] [blame] | 23 | namespace mediaprovider::fuse { |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 24 | |
| 25 | TEST(FuseUtilsTest, testContainsMount_isTrueForAndroidDataObb) { |
Martijn Coenen | 35b4489 | 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 | 35b4489 | 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/")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Corina | 762bb25 | 2020-07-09 10:30:33 +0100 | [diff] [blame] | 44 | TEST(FuseUtilsTest, testContainsMount_isCaseInsensitive) { |
Martijn Coenen | 35b4489 | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 45 | EXPECT_TRUE(containsMount("/storage/emulated/1234/android")); |
| 46 | EXPECT_TRUE(containsMount("/storage/emulated/1234/Android/Data")); |
| 47 | EXPECT_TRUE(containsMount("/storage/emulated/1234/ANDroid/dATa")); |
| 48 | EXPECT_TRUE(containsMount("/storage/emulated/1234/ANDROID/OBB")); |
| 49 | EXPECT_TRUE(containsMount("/Storage/EMULATED/1234/Android/obb")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | TEST(FuseUtilsTest, testContainsMount_isFalseForPathWithAdditionalSlash) { |
Martijn Coenen | 35b4489 | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 53 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/")); |
| 54 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/data/")); |
| 55 | EXPECT_FALSE(containsMount("/storage/emulated/1234/Android/obb/")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 56 | |
Martijn Coenen | 35b4489 | 2021-09-24 10:14:16 +0200 | [diff] [blame] | 57 | EXPECT_FALSE(containsMount("//storage/emulated/1234/Android")); |
| 58 | EXPECT_FALSE(containsMount("/storage/emulated//1234/Android/data")); |
| 59 | EXPECT_FALSE(containsMount("/storage/emulated/1234//Android/data")); |
Corina | 633099b | 2020-06-17 21:55:33 +0100 | [diff] [blame] | 60 | } |
Alessio Balsini | 2a79da0 | 2021-12-02 20:09:05 +0000 | [diff] [blame] | 61 | |
| 62 | } // namespace mediaprovider::fuse |