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 
17 #include <gtest/gtest.h>
18 
19 #include "linkerconfig/configwriter.h"
20 #include "linkerconfig/link.h"
21 
22 constexpr const char* kSharedLibsExpectedResult =
23     "namespace.originalNamespace.link.targetNamespace.shared_libs = "
24     "lib1.so:lib2.so:lib3.so\n";
25 
TEST(linkerconfig_link,link_with_all_shared_libs)26 TEST(linkerconfig_link, link_with_all_shared_libs) {
27   android::linkerconfig::modules::ConfigWriter writer;
28 
29   auto link = std::make_shared<android::linkerconfig::modules::Link>(
30       "originalNamespace", "targetNamespace");
31   link->AllowAllSharedLibs();
32 
33   link->WriteConfig(writer);
34   auto config_text = writer.ToString();
35 
36   ASSERT_EQ(config_text,
37             "namespace.originalNamespace.link.targetNamespace.allow_all_shared_"
38             "libs = true\n");
39 }
40 
TEST(linkerconfig_link,link_with_shared_libs)41 TEST(linkerconfig_link, link_with_shared_libs) {
42   android::linkerconfig::modules::ConfigWriter writer;
43   auto link = std::make_shared<android::linkerconfig::modules::Link>(
44       "originalNamespace", "targetNamespace");
45   link->AddSharedLib("lib1.so", "lib2.so", "lib3.so");
46 
47   link->WriteConfig(writer);
48   auto config_text = writer.ToString();
49 
50   ASSERT_EQ(config_text, kSharedLibsExpectedResult);
51 }
52