blob: dede692bd7811f1bd381f55aa7a5c08c6fa63d0e [file] [log] [blame]
Corina633099b2020-06-17 21:55:33 +01001/*
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
23using namespace mediaprovider::fuse;
24
25TEST(FuseUtilsTest, testContainsMount_isTrueForAndroidDataObb) {
Martijn Coenenfc41bbf2021-09-24 10:14:16 +020026 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"));
Corina633099b2020-06-17 21:55:33 +010032}
33
34TEST(FuseUtilsTest, testContainsMount) {
Martijn Coenenfc41bbf2021-09-24 10:14:16 +020035 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/"));
Corina633099b2020-06-17 21:55:33 +010043}
44
Corina762bb252020-07-09 10:30:33 +010045TEST(FuseUtilsTest, testContainsMount_isCaseInsensitive) {
Martijn Coenenfc41bbf2021-09-24 10:14:16 +020046 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"));
Corina633099b2020-06-17 21:55:33 +010051}
52
53TEST(FuseUtilsTest, testContainsMount_isFalseForPathWithAdditionalSlash) {
Martijn Coenenfc41bbf2021-09-24 10:14:16 +020054 EXPECT_FALSE(containsMount("/storage/emulated//Android/data"));
Corina633099b2020-06-17 21:55:33 +010055
Martijn Coenenfc41bbf2021-09-24 10:14:16 +020056 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/"));
Corina633099b2020-06-17 21:55:33 +010059
Martijn Coenenfc41bbf2021-09-24 10:14:16 +020060 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"));
Corina633099b2020-06-17 21:55:33 +010063}