2023-06-01 23:42:59 +02:00
|
|
|
// Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2023-06-22 00:16:23 +02:00
|
|
|
package aconfig
|
2023-06-01 23:42:59 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
2023-06-22 00:16:23 +02:00
|
|
|
func TestAconfigDeclarations(t *testing.T) {
|
2023-06-01 23:42:59 +02:00
|
|
|
bp := `
|
2023-06-22 00:16:23 +02:00
|
|
|
aconfig_declarations {
|
2023-06-01 23:42:59 +02:00
|
|
|
name: "module_name",
|
2023-06-21 22:49:37 +02:00
|
|
|
package: "com.example.package",
|
2023-11-17 02:05:47 +01:00
|
|
|
container: "com.android.foo",
|
2024-02-08 07:19:34 +01:00
|
|
|
exportable: true,
|
2023-07-19 20:04:24 +02:00
|
|
|
srcs: [
|
|
|
|
"foo.aconfig",
|
|
|
|
"bar.aconfig",
|
|
|
|
],
|
2023-06-01 23:42:59 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
result := runTest(t, android.FixtureExpectsNoErrors, bp)
|
|
|
|
|
2023-06-22 00:16:23 +02:00
|
|
|
module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule)
|
2023-06-01 23:42:59 +02:00
|
|
|
|
|
|
|
// Check that the provider has the right contents
|
2023-12-19 20:01:57 +01:00
|
|
|
depData, _ := android.SingletonModuleProvider(result, module, android.AconfigDeclarationsProviderKey)
|
2023-06-21 22:49:37 +02:00
|
|
|
android.AssertStringEquals(t, "package", depData.Package, "com.example.package")
|
2023-11-17 02:05:47 +01:00
|
|
|
android.AssertStringEquals(t, "container", depData.Container, "com.android.foo")
|
2024-02-08 07:19:34 +01:00
|
|
|
android.AssertBoolEquals(t, "exportable", depData.Exportable, true)
|
2023-11-29 20:35:29 +01:00
|
|
|
if !strings.HasSuffix(depData.IntermediateCacheOutputPath.String(), "/intermediate.pb") {
|
|
|
|
t.Errorf("Missing intermediates proto path in provider: %s", depData.IntermediateCacheOutputPath.String())
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(depData.IntermediateDumpOutputPath.String(), "/intermediate.txt") {
|
|
|
|
t.Errorf("Missing intermediates text path in provider: %s", depData.IntermediateDumpOutputPath.String())
|
2023-06-01 23:42:59 +02:00
|
|
|
}
|
|
|
|
}
|
2024-02-08 07:19:34 +01:00
|
|
|
|
|
|
|
func TestAconfigDeclarationsWithExportableUnset(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "module_name",
|
|
|
|
package: "com.example.package",
|
|
|
|
container: "com.android.foo",
|
|
|
|
srcs: [
|
|
|
|
"foo.aconfig",
|
|
|
|
"bar.aconfig",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
result := runTest(t, android.FixtureExpectsNoErrors, bp)
|
|
|
|
|
|
|
|
module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule)
|
|
|
|
depData, _ := android.SingletonModuleProvider(result, module, android.AconfigDeclarationsProviderKey)
|
|
|
|
android.AssertBoolEquals(t, "exportable", depData.Exportable, false)
|
|
|
|
}
|
2024-03-20 00:07:34 +01:00
|
|
|
|
|
|
|
func TestAconfigDeclarationsWithContainer(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "module_name",
|
|
|
|
package: "com.example.package",
|
|
|
|
container: "com.android.foo",
|
|
|
|
srcs: [
|
|
|
|
"foo.aconfig",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
result := runTest(t, android.FixtureExpectsNoErrors, bp)
|
|
|
|
|
|
|
|
module := result.ModuleForTests("module_name", "")
|
|
|
|
rule := module.Rule("aconfig")
|
|
|
|
android.AssertStringEquals(t, "rule must contain container", rule.Args["container"], "--container com.android.foo")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAconfigDeclarationsWithoutContainer(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "module_name",
|
|
|
|
package: "com.example.package",
|
|
|
|
srcs: [
|
|
|
|
"foo.aconfig",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
result := runTest(t, android.FixtureExpectsNoErrors, bp)
|
|
|
|
|
|
|
|
module := result.ModuleForTests("module_name", "")
|
|
|
|
rule := module.Rule("aconfig")
|
|
|
|
android.AssertIntEquals(t, "rule must not contain container", len(rule.Args["container"]), 0)
|
|
|
|
}
|