blob: 4aab0a146ecfea29b96126e646073356df91b2e1 [file] [log] [blame]
Jeremy Meyer5fd34ea2022-12-15 18:43:36 +00001/*
2 * Copyright (C) 2023 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 "androidfw/ApkParsing.h"
18
19#include "android-base/test_utils.h"
20
21#include "TestHelpers.h"
22
23using ::testing::Eq;
24using ::testing::IsNull;
25using ::testing::NotNull;
26
27namespace android {
28TEST(ApkParsingTest, ValidArm64Path) {
29 const char* path = "lib/arm64-v8a/library.so";
30 auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
31 ASSERT_THAT(lastSlash, NotNull());
32 ASSERT_THAT(lastSlash, Eq(path + 13));
33}
34
35TEST(ApkParsingTest, ValidArm64PathButSuppressed) {
36 const char* path = "lib/arm64-v8a/library.so";
37 auto lastSlash = util::ValidLibraryPathLastSlash(path, true, false);
38 ASSERT_THAT(lastSlash, IsNull());
39}
40
41TEST(ApkParsingTest, ValidArm32Path) {
42 const char* path = "lib/armeabi-v7a/library.so";
43 auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
44 ASSERT_THAT(lastSlash, NotNull());
45 ASSERT_THAT(lastSlash, Eq(path + 15));
46}
47
48TEST(ApkParsingTest, InvalidMustStartWithLib) {
49 const char* path = "lib/arm64-v8a/random.so";
50 auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
51 ASSERT_THAT(lastSlash, IsNull());
52}
53
54TEST(ApkParsingTest, InvalidMustEndInSo) {
55 const char* path = "lib/arm64-v8a/library.txt";
56 auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
57 ASSERT_THAT(lastSlash, IsNull());
58}
59
60TEST(ApkParsingTest, InvalidCharacter) {
61 const char* path = "lib/arm64-v8a/lib#.so";
62 auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
63 ASSERT_THAT(lastSlash, IsNull());
64}
65
66TEST(ApkParsingTest, InvalidSubdirectories) {
67 const char* path = "lib/arm64-v8a/anything/library.so";
68 auto lastSlash = util::ValidLibraryPathLastSlash(path, false, false);
69 ASSERT_THAT(lastSlash, IsNull());
70}
71}