1 /*
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 specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <android-base/file.h>
17 #include <gtest/gtest.h>
18 
19 #include "linkerconfig/librarylistloader.h"
20 
21 using namespace android::linkerconfig::generator;
22 
23 const std::string kLibraryListA = android::base::GetExecutableDirectory() +
24                                   "/generator/tests/data/library_list_a.txt";
25 const std::string kLibraryListB = android::base::GetExecutableDirectory() +
26                                   "/generator/tests/data/library_list_b.txt";
27 const std::string kLibraryListC = android::base::GetExecutableDirectory() +
28                                   "/generator/tests/data/library_list_c.txt";
29 const std::string kLibraryListInvalid =
30     android::base::GetExecutableDirectory() +
31     "/generator/tests/data/library_list_invalid.txt";
32 
33 TEST(linkerconfig_librarylistloader, get_libraries) {
34   const auto& library_list = GetLibrariesString(kLibraryListA);
35   ASSERT_EQ("a.so:b.so:c.so:d.so:e.so:f.so", library_list);
36 
37   const auto& library_list_invalid = GetLibrariesString(kLibraryListInvalid);
38   ASSERT_TRUE(library_list_invalid.empty());
39 
40   const auto& library_list_empty = GetLibrariesString(kLibraryListC);
41   ASSERT_EQ("", library_list_empty);
42 }
43 
44 TEST(linkerconfig_librarylistloader, get_public_libraries) {
45   const auto& public_library_list =
46       GetPublicLibrariesString(kLibraryListA, kLibraryListB);
47   ASSERT_EQ("a.so:b.so:c.so:d.so", public_library_list);
48 
49   const auto& all_private_library_list =
50       GetPublicLibrariesString(kLibraryListA, kLibraryListA);
51   ASSERT_TRUE(all_private_library_list.empty());
52 
53   const auto& invalid_library_list =
54       GetPublicLibrariesString(kLibraryListInvalid, kLibraryListB);
55   ASSERT_TRUE(invalid_library_list.empty());
56 
57   const auto& private_library_invalid_list =
58       GetPublicLibrariesString(kLibraryListA, kLibraryListInvalid);
59   ASSERT_EQ("a.so:b.so:c.so:d.so:e.so:f.so", private_library_invalid_list);
60 
61   const auto& empty_library_list =
62       GetPublicLibrariesString(kLibraryListC, kLibraryListA);
63   ASSERT_EQ("", empty_library_list);
64 }
65 
66 TEST(linkerconfig_librarylistloader, get_private_libraries) {
67   const auto& private_library_list =
68       GetPrivateLibrariesString(kLibraryListA, kLibraryListB);
69   ASSERT_EQ("e.so:f.so", private_library_list);
70 
71   const auto& all_private_library_list =
72       GetPrivateLibrariesString(kLibraryListA, kLibraryListA);
73   ASSERT_EQ("a.so:b.so:c.so:d.so:e.so:f.so", all_private_library_list);
74 
75   const auto& invalid_library_list =
76       GetPrivateLibrariesString(kLibraryListInvalid, kLibraryListB);
77   ASSERT_TRUE(invalid_library_list.empty());
78 
79   const auto& private_library_invalid_list =
80       GetPrivateLibrariesString(kLibraryListA, kLibraryListInvalid);
81   ASSERT_TRUE(private_library_invalid_list.empty());
82 }
83