blob: d76a89c6fce60fc7e86c4867783fd34af2c4b7f8 [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
Alessio Balsini2a79da02021-12-02 20:09:05 +000023namespace mediaprovider::fuse {
Corina633099b2020-06-17 21:55:33 +010024
25TEST(FuseUtilsTest, testContainsMount_isTrueForAndroidDataObb) {
Martijn Coenen35b44892021-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 Coenen35b44892021-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/"));
Corina633099b2020-06-17 21:55:33 +010042}
43
Corina762bb252020-07-09 10:30:33 +010044TEST(FuseUtilsTest, testContainsMount_isCaseInsensitive) {
Martijn Coenen35b44892021-09-24 10:14:16 +020045 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"));
Corina633099b2020-06-17 21:55:33 +010050}
51
52TEST(FuseUtilsTest, testContainsMount_isFalseForPathWithAdditionalSlash) {
Martijn Coenen35b44892021-09-24 10:14:16 +020053 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/"));
Corina633099b2020-06-17 21:55:33 +010056
Martijn Coenen35b44892021-09-24 10:14:16 +020057 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"));
Corina633099b2020-06-17 21:55:33 +010060}
Alessio Balsini2a79da02021-12-02 20:09:05 +000061
62} // namespace mediaprovider::fuse