1 /*
<lambda>null2  * Copyright 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 package androidx.build.clang
18 
19 import com.google.common.truth.Truth.assertThat
20 import org.gradle.testfixtures.ProjectBuilder
21 import org.junit.Rule
22 import org.junit.Test
23 import org.junit.rules.TemporaryFolder
24 
25 class CreateDefFileWithLibraryPathTaskTest {
26     @get:Rule
27     val tmpFolder = TemporaryFolder()
28 
29     @Test
30     fun buildDefFile() {
31         val testDir = tmpFolder.newFolder()
32         val project = ProjectBuilder.builder().withProjectDir(
33             testDir.resolve("project")
34         ).build()
35         val inputFile = tmpFolder.newFile("input.def").apply {
36             writeText(
37                 """
38                 package=foo.bar
39                 headers=foo.h
40                 """.trimIndent()
41             )
42         }
43         val soFile = testDir.resolve("soFiles/myso.so").apply {
44             parentFile.mkdirs()
45             writeText("this is some so file contents")
46         }
47         val outputFile = project.layout.buildDirectory.file("output.def")
48         val task = project.tasks.register(
49             "testTask",
50             CreateDefFileWithLibraryPathTask::class.java
51         ) { task ->
52             task.original.set(inputFile)
53             task.objectFile.set(soFile)
54             task.target.set(outputFile)
55             task.projectDir.set(project.layout.projectDirectory)
56         }
57         task.get().createPlatformSpecificDefFile()
58         // make sure the libraryPaths is relative to the projectDir for maximum cacheability since
59         // the contents of this file will be a task input for cinterop task.
60         assertThat(
61             outputFile.get().asFile.readText()
62         ).contains(
63             """
64             package=foo.bar
65             headers=foo.h
66             libraryPaths="../soFiles"
67             staticLibraries=myso.so
68             """.trimIndent()
69         )
70     }
71 }
72