summaryrefslogtreecommitdiff
path: root/sdk/sdk_test.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2020-03-10 22:17:04 +0000
committer Paul Duffin <paulduffin@google.com> 2020-03-13 10:47:14 +0000
commitb07fa511964fd68a36295bb7318ebb142a0bc835 (patch)
tree3af76655882625211f1d7bcd0d13671fb8457a57 /sdk/sdk_test.go
parentc097e36172f0346d2fbe8b547c4dc3ea74737cf7 (diff)
Support extracting common values from embedded structures
This change also added support for excluding properties from common value extraction by using a struct tag of `sdk:"keep"` That was needed to prevent the fields in SdkMemberPropertiesBase from having their values cleared. The purpose of this change is to make it easier to share functionality across sdk member types. Bug: 142935992 Test: m nothing Change-Id: Ie5160a8f854056920e411801ca20721eab7c8578
Diffstat (limited to 'sdk/sdk_test.go')
-rw-r--r--sdk/sdk_test.go105
1 files changed, 105 insertions, 0 deletions
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 96837e3dd..fde92307f 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -16,6 +16,8 @@ package sdk
import (
"testing"
+
+ "github.com/google/blueprint/proptools"
)
// Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE.
@@ -222,3 +224,106 @@ func TestSDkInstall(t *testing.T) {
checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`),
)
}
+
+type EmbeddedPropertiesStruct struct {
+ S_Embedded_Common string
+ S_Embedded_Different string
+}
+
+type testPropertiesStruct struct {
+ private string
+ Public_Kept string `sdk:"keep"`
+ S_Common string
+ S_Different string
+ A_Common []string
+ A_Different []string
+ F_Common *bool
+ F_Different *bool
+ EmbeddedPropertiesStruct
+}
+
+func TestCommonValueOptimization(t *testing.T) {
+ common := &testPropertiesStruct{}
+ structs := []*testPropertiesStruct{
+ &testPropertiesStruct{
+ private: "common",
+ Public_Kept: "common",
+ S_Common: "common",
+ S_Different: "upper",
+ A_Common: []string{"first", "second"},
+ A_Different: []string{"alpha", "beta"},
+ F_Common: proptools.BoolPtr(false),
+ F_Different: proptools.BoolPtr(false),
+ EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
+ S_Embedded_Common: "embedded_common",
+ S_Embedded_Different: "embedded_upper",
+ },
+ },
+ &testPropertiesStruct{
+ private: "common",
+ Public_Kept: "common",
+ S_Common: "common",
+ S_Different: "lower",
+ A_Common: []string{"first", "second"},
+ A_Different: []string{"alpha", "delta"},
+ F_Common: proptools.BoolPtr(false),
+ F_Different: proptools.BoolPtr(true),
+ EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
+ S_Embedded_Common: "embedded_common",
+ S_Embedded_Different: "embedded_lower",
+ },
+ },
+ }
+
+ extractor := newCommonValueExtractor(common)
+ extractor.extractCommonProperties(common, structs)
+
+ h := TestHelper{t}
+ h.AssertDeepEquals("common properties not correct", common,
+ &testPropertiesStruct{
+ private: "",
+ Public_Kept: "",
+ S_Common: "common",
+ S_Different: "",
+ A_Common: []string{"first", "second"},
+ A_Different: []string(nil),
+ F_Common: proptools.BoolPtr(false),
+ F_Different: nil,
+ EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
+ S_Embedded_Common: "embedded_common",
+ S_Embedded_Different: "",
+ },
+ })
+
+ h.AssertDeepEquals("updated properties[0] not correct", structs[0],
+ &testPropertiesStruct{
+ private: "common",
+ Public_Kept: "common",
+ S_Common: "",
+ S_Different: "upper",
+ A_Common: nil,
+ A_Different: []string{"alpha", "beta"},
+ F_Common: nil,
+ F_Different: proptools.BoolPtr(false),
+ EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
+ S_Embedded_Common: "",
+ S_Embedded_Different: "embedded_upper",
+ },
+ })
+
+ h.AssertDeepEquals("updated properties[1] not correct", structs[1],
+ &testPropertiesStruct{
+ private: "common",
+ Public_Kept: "common",
+ S_Common: "",
+ S_Different: "lower",
+ A_Common: nil,
+ A_Different: []string{"alpha", "delta"},
+ F_Common: nil,
+ F_Different: proptools.BoolPtr(true),
+ EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
+ S_Embedded_Common: "",
+ S_Embedded_Different: "embedded_lower",
+ },
+ })
+}