| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. | 
|  | 2 | // | 
|  | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | // you may not use this file except in compliance with the License. | 
|  | 5 | // You may obtain a copy of the License at | 
|  | 6 | // | 
|  | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | // | 
|  | 9 | // Unless required by applicable law or agreed to in writing, software | 
|  | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | // See the License for the specific language governing permissions and | 
|  | 13 | // limitations under the License. | 
|  | 14 |  | 
| Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 15 | package aconfig | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "strings" | 
|  | 19 | "testing" | 
|  | 20 |  | 
|  | 21 | "android/soong/android" | 
|  | 22 | ) | 
|  | 23 |  | 
| Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 24 | func TestAconfigDeclarations(t *testing.T) { | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 25 | bp := ` | 
| Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 26 | aconfig_declarations { | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 27 | name: "module_name", | 
| Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 28 | package: "com.example.package", | 
| Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 29 | container: "com.android.foo", | 
| Zi Wang | 0e5d16c | 2024-02-08 06:19:34 +0000 | [diff] [blame] | 30 | exportable: true, | 
| Zhi Dou | 8a35a6f | 2023-07-19 18:04:24 +0000 | [diff] [blame] | 31 | srcs: [ | 
|  | 32 | "foo.aconfig", | 
|  | 33 | "bar.aconfig", | 
|  | 34 | ], | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 35 | } | 
|  | 36 | ` | 
|  | 37 | result := runTest(t, android.FixtureExpectsNoErrors, bp) | 
|  | 38 |  | 
| Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 39 | module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule) | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 40 |  | 
|  | 41 | // Check that the provider has the right contents | 
| LaMont Jones | aa005ae | 2023-12-19 19:01:57 +0000 | [diff] [blame] | 42 | depData, _ := android.SingletonModuleProvider(result, module, android.AconfigDeclarationsProviderKey) | 
| Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 43 | android.AssertStringEquals(t, "package", depData.Package, "com.example.package") | 
| Yu Liu | eae7b36 | 2023-11-16 17:05:47 -0800 | [diff] [blame] | 44 | android.AssertStringEquals(t, "container", depData.Container, "com.android.foo") | 
| Zi Wang | 0e5d16c | 2024-02-08 06:19:34 +0000 | [diff] [blame] | 45 | android.AssertBoolEquals(t, "exportable", depData.Exportable, true) | 
| Jihoon Kang | cca3e0c | 2023-11-29 19:35:29 +0000 | [diff] [blame] | 46 | if !strings.HasSuffix(depData.IntermediateCacheOutputPath.String(), "/intermediate.pb") { | 
|  | 47 | t.Errorf("Missing intermediates proto path in provider: %s", depData.IntermediateCacheOutputPath.String()) | 
|  | 48 | } | 
|  | 49 | if !strings.HasSuffix(depData.IntermediateDumpOutputPath.String(), "/intermediate.txt") { | 
|  | 50 | t.Errorf("Missing intermediates text path in provider: %s", depData.IntermediateDumpOutputPath.String()) | 
| Joe Onorato | 175073c | 2023-06-01 14:42:59 -0700 | [diff] [blame] | 51 | } | 
|  | 52 | } | 
| Zi Wang | 0e5d16c | 2024-02-08 06:19:34 +0000 | [diff] [blame] | 53 |  | 
|  | 54 | func TestAconfigDeclarationsWithExportableUnset(t *testing.T) { | 
|  | 55 | bp := ` | 
|  | 56 | aconfig_declarations { | 
|  | 57 | name: "module_name", | 
|  | 58 | package: "com.example.package", | 
|  | 59 | container: "com.android.foo", | 
|  | 60 | srcs: [ | 
|  | 61 | "foo.aconfig", | 
|  | 62 | "bar.aconfig", | 
|  | 63 | ], | 
|  | 64 | } | 
|  | 65 | ` | 
|  | 66 | result := runTest(t, android.FixtureExpectsNoErrors, bp) | 
|  | 67 |  | 
|  | 68 | module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule) | 
|  | 69 | depData, _ := android.SingletonModuleProvider(result, module, android.AconfigDeclarationsProviderKey) | 
|  | 70 | android.AssertBoolEquals(t, "exportable", depData.Exportable, false) | 
|  | 71 | } | 
| Yu Liu | eeff222 | 2024-03-19 23:07:34 +0000 | [diff] [blame] | 72 |  | 
|  | 73 | func TestAconfigDeclarationsWithContainer(t *testing.T) { | 
|  | 74 | bp := ` | 
|  | 75 | aconfig_declarations { | 
|  | 76 | name: "module_name", | 
|  | 77 | package: "com.example.package", | 
|  | 78 | container: "com.android.foo", | 
|  | 79 | srcs: [ | 
|  | 80 | "foo.aconfig", | 
|  | 81 | ], | 
|  | 82 | } | 
|  | 83 | ` | 
|  | 84 | result := runTest(t, android.FixtureExpectsNoErrors, bp) | 
|  | 85 |  | 
|  | 86 | module := result.ModuleForTests("module_name", "") | 
|  | 87 | rule := module.Rule("aconfig") | 
|  | 88 | android.AssertStringEquals(t, "rule must contain container", rule.Args["container"], "--container com.android.foo") | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | func TestAconfigDeclarationsWithoutContainer(t *testing.T) { | 
|  | 92 | bp := ` | 
|  | 93 | aconfig_declarations { | 
|  | 94 | name: "module_name", | 
|  | 95 | package: "com.example.package", | 
|  | 96 | srcs: [ | 
|  | 97 | "foo.aconfig", | 
|  | 98 | ], | 
|  | 99 | } | 
|  | 100 | ` | 
|  | 101 | result := runTest(t, android.FixtureExpectsNoErrors, bp) | 
|  | 102 |  | 
|  | 103 | module := result.ModuleForTests("module_name", "") | 
|  | 104 | rule := module.Rule("aconfig") | 
|  | 105 | android.AssertIntEquals(t, "rule must not contain container", len(rule.Args["container"]), 0) | 
|  | 106 | } |