• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
23 using ::testing::Eq;
24 using ::testing::IsNull;
25 using ::testing::NotNull;
26 
27 namespace android {
TEST(ApkParsingTest,ValidArm64Path)28 TEST(ApkParsingTest, ValidArm64Path) {
29   const char* path = "lib/arm64-v8a/library.so";
30   auto lastSlash = util::ValidLibraryPathLastSlash(path, false);
31   ASSERT_THAT(lastSlash, NotNull());
32   ASSERT_THAT(lastSlash, Eq(path + 13));
33 }
34 
TEST(ApkParsingTest,ValidArm64PathButSuppressed)35 TEST(ApkParsingTest, ValidArm64PathButSuppressed) {
36   const char* path = "lib/arm64-v8a/library.so";
37   auto lastSlash = util::ValidLibraryPathLastSlash(path, true);
38   ASSERT_THAT(lastSlash, IsNull());
39 }
40 
TEST(ApkParsingTest,ValidArm32Path)41 TEST(ApkParsingTest, ValidArm32Path) {
42   const char* path = "lib/armeabi-v7a/library.so";
43   auto lastSlash = util::ValidLibraryPathLastSlash(path, false);
44   ASSERT_THAT(lastSlash, NotNull());
45   ASSERT_THAT(lastSlash, Eq(path + 15));
46 }
47 
TEST(ApkParsingTest,InvalidCharacter)48 TEST(ApkParsingTest, InvalidCharacter) {
49   const char* path = "lib/arm64-v8a/lib#.so";
50   auto lastSlash = util::ValidLibraryPathLastSlash(path, false);
51   ASSERT_THAT(lastSlash, IsNull());
52 }
53 
TEST(ApkParsingTest,InvalidSubdirectories)54 TEST(ApkParsingTest, InvalidSubdirectories) {
55   const char* path = "lib/arm64-v8a/anything/library.so";
56   auto lastSlash = util::ValidLibraryPathLastSlash(path, false);
57   ASSERT_THAT(lastSlash, IsNull());
58 }
59 
TEST(ApkParsingTest,InvalidFileAtRoot)60 TEST(ApkParsingTest, InvalidFileAtRoot) {
61   const char* path = "lib/library.so";
62   auto lastSlash = util::ValidLibraryPathLastSlash(path, false);
63   ASSERT_THAT(lastSlash, IsNull());
64 }
65 
TEST(ApkParsingTest,InvalidPrefix)66 TEST(ApkParsingTest, InvalidPrefix) {
67   const char* path = "assets/libhello.so";
68   auto lastSlash = util::ValidLibraryPathLastSlash(path, false);
69   ASSERT_THAT(lastSlash, IsNull());
70 }
71 }