diff options
author | 2024-01-12 12:12:26 -0800 | |
---|---|---|
committer | 2024-01-12 14:28:53 -0800 | |
commit | a03ac3a75a31247383956870a7f8f16f1280a314 (patch) | |
tree | e42f929533b467b8a02817f8f8e5d7f66501c3be /android/soongconfig/modules_test.go | |
parent | 744a2a6b7d89e044b8fdc438e329be131e1e93dd (diff) |
Allow value variables to set pointer properties
Non-null pointers were always leading to an "unsupported property type"
error due to not updating the kind field.
Bug: 319897584
Test: Presubmits
Change-Id: I058ab8d153d9507f9037d699acf6e1fe4f08f538
Diffstat (limited to 'android/soongconfig/modules_test.go')
-rw-r--r-- | android/soongconfig/modules_test.go | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/android/soongconfig/modules_test.go b/android/soongconfig/modules_test.go index 00e8b785a..db2c83ccb 100644 --- a/android/soongconfig/modules_test.go +++ b/android/soongconfig/modules_test.go @@ -299,7 +299,7 @@ type boolVarProps struct { Conditions_default *properties } -type soongConfigVars struct { +type boolSoongConfigVars struct { Bool_var interface{} } @@ -307,7 +307,11 @@ type stringSoongConfigVars struct { String_var interface{} } -func Test_PropertiesToApply(t *testing.T) { +type valueSoongConfigVars struct { + My_value_var interface{} +} + +func Test_PropertiesToApply_Bool(t *testing.T) { mt, _ := newModuleType(&ModuleTypeProperties{ Module_type: "foo", Config_namespace: "bar", @@ -323,9 +327,9 @@ func Test_PropertiesToApply(t *testing.T) { B: false, } actualProps := &struct { - Soong_config_variables soongConfigVars + Soong_config_variables boolSoongConfigVars }{ - Soong_config_variables: soongConfigVars{ + Soong_config_variables: boolSoongConfigVars{ Bool_var: &boolVarProps{ A: boolVarPositive.A, B: boolVarPositive.B, @@ -369,6 +373,62 @@ func Test_PropertiesToApply(t *testing.T) { } } +func Test_PropertiesToApply_Value(t *testing.T) { + mt, _ := newModuleType(&ModuleTypeProperties{ + Module_type: "foo", + Config_namespace: "bar", + Value_variables: []string{"my_value_var"}, + Properties: []string{"a", "b"}, + }) + conditionsDefault := &properties{ + A: proptools.StringPtr("default"), + B: false, + } + actualProps := &struct { + Soong_config_variables valueSoongConfigVars + }{ + Soong_config_variables: valueSoongConfigVars{ + My_value_var: &boolVarProps{ + A: proptools.StringPtr("A=%s"), + B: true, + Conditions_default: conditionsDefault, + }, + }, + } + props := reflect.ValueOf(actualProps) + + testCases := []struct { + name string + config SoongConfig + wantProps []interface{} + }{ + { + name: "no_vendor_config", + config: Config(map[string]string{}), + wantProps: []interface{}{conditionsDefault}, + }, + { + name: "value_var_set", + config: Config(map[string]string{"my_value_var": "Hello"}), + wantProps: []interface{}{&properties{ + A: proptools.StringPtr("A=Hello"), + B: true, + }}, + }, + } + + for _, tc := range testCases { + gotProps, err := PropertiesToApply(mt, props, tc.config) + if err != nil { + t.Errorf("%s: Unexpected error in PropertiesToApply: %s", tc.name, err) + } + + if !reflect.DeepEqual(gotProps, tc.wantProps) { + t.Errorf("%s: Expected %s, got %s", tc.name, tc.wantProps, gotProps) + } + } +} + func Test_PropertiesToApply_String_Error(t *testing.T) { mt, _ := newModuleType(&ModuleTypeProperties{ Module_type: "foo", |