Paul Duffin | 047fdca | 2020-02-21 16:06:25 +0000 | [diff] [blame] | 1 | // Copyright (C) 2020 The Android Open Source Project |
| 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 | |
| 15 | package sdk |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | type removeFredTransformation struct { |
| 24 | identityTransformation |
| 25 | } |
| 26 | |
| 27 | func (t removeFredTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { |
| 28 | if name == "fred" { |
| 29 | return nil, nil |
| 30 | } |
| 31 | return value, tag |
| 32 | } |
| 33 | |
Paul Duffin | 180a006 | 2020-02-21 16:06:25 +0000 | [diff] [blame^] | 34 | func (t removeFredTransformation) transformPropertySetBeforeContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { |
Paul Duffin | 047fdca | 2020-02-21 16:06:25 +0000 | [diff] [blame] | 35 | if name == "fred" { |
| 36 | return nil, nil |
| 37 | } |
| 38 | return propertySet, tag |
| 39 | } |
| 40 | |
Paul Duffin | 180a006 | 2020-02-21 16:06:25 +0000 | [diff] [blame^] | 41 | func (t removeFredTransformation) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { |
| 42 | if len(propertySet.properties) == 0 { |
| 43 | return nil, nil |
| 44 | } |
| 45 | return propertySet, tag |
| 46 | } |
| 47 | |
Paul Duffin | 047fdca | 2020-02-21 16:06:25 +0000 | [diff] [blame] | 48 | func TestTransformRemoveProperty(t *testing.T) { |
| 49 | |
| 50 | helper := &TestHelper{t} |
| 51 | |
| 52 | set := newPropertySet() |
| 53 | set.AddProperty("name", "name") |
| 54 | set.AddProperty("fred", "12") |
| 55 | |
| 56 | set.transformContents(removeFredTransformation{}) |
| 57 | |
| 58 | contents := &generatedContents{} |
| 59 | outputPropertySet(contents, set) |
| 60 | helper.AssertTrimmedStringEquals("removing property failed", "name: \"name\",\\n", contents.content.String()) |
| 61 | } |
| 62 | |
| 63 | func TestTransformRemovePropertySet(t *testing.T) { |
| 64 | |
| 65 | helper := &TestHelper{t} |
| 66 | |
| 67 | set := newPropertySet() |
| 68 | set.AddProperty("name", "name") |
| 69 | set.AddPropertySet("fred") |
| 70 | |
| 71 | set.transformContents(removeFredTransformation{}) |
| 72 | |
| 73 | contents := &generatedContents{} |
| 74 | outputPropertySet(contents, set) |
| 75 | helper.AssertTrimmedStringEquals("removing property set failed", "name: \"name\",\\n", contents.content.String()) |
| 76 | } |