1 /*
2 * Copyright (C) 2020 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 "linkerconfig/configparser.h"
18
19 #include <android-base/file.h>
20 #include <gtest/gtest.h>
21
22 using android::linkerconfig::modules::ParseLinkerConfig;
23
24 const std::string kBaseDir =
25 android::base::GetExecutableDirectory() + "/modules/tests/data/";
26
TEST(configparser,apex_file_not_exist)27 TEST(configparser, apex_file_not_exist) {
28 auto result = ParseLinkerConfig(kBaseDir + "linker.config.noexist.pb");
29
30 ASSERT_FALSE(result.ok());
31 }
32
TEST(configparser,apex_contents)33 TEST(configparser, apex_contents) {
34 std::vector<std::string> expected_permitted_paths = {
35 "/a",
36 "/b/c",
37 "/d/e/f",
38 };
39
40 auto result = ParseLinkerConfig(kBaseDir + "linker.config.apex.pb");
41
42 ASSERT_TRUE(result.ok());
43 std::vector<std::string> permitted_paths = {result->permittedpaths().begin(),
44 result->permittedpaths().end()};
45 ASSERT_EQ(permitted_paths, expected_permitted_paths);
46 ASSERT_TRUE(result->visible());
47 }
48
TEST(configparser,system_contents)49 TEST(configparser, system_contents) {
50 std::vector<std::string> expected_provide_libs = {
51 "a.so",
52 "b.so",
53 "c.so",
54 };
55 std::vector<std::string> expected_require_libs = {
56 "foo.so",
57 "bar.so",
58 "baz.so",
59 };
60
61 auto result = ParseLinkerConfig(kBaseDir + "linker.config.system.pb");
62
63 ASSERT_TRUE(result.ok());
64 std::vector<std::string> provide_libs = {result->providelibs().begin(),
65 result->providelibs().end()};
66 std::vector<std::string> require_libs = {result->requirelibs().begin(),
67 result->requirelibs().end()};
68 ASSERT_EQ(provide_libs, expected_provide_libs);
69 ASSERT_EQ(require_libs, expected_require_libs);
70 }