| Sasha Smundak | ff36da0 | 2019-02-12 17:12:08 -0800 | [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 |  | 
 | 15 | package android | 
 | 16 |  | 
 | 17 | import ( | 
 | 18 | 	"io/ioutil" | 
 | 19 | 	"os" | 
 | 20 | 	"testing" | 
 | 21 | ) | 
 | 22 |  | 
 | 23 | func testVtsConfig(test *testing.T, bpFileContents string) *TestContext { | 
 | 24 | 	buildDir, err := ioutil.TempDir("", "soong_vts_config_test") | 
 | 25 | 	if err != nil { | 
 | 26 | 		test.Fatal(err) | 
 | 27 | 	} | 
 | 28 |  | 
 | 29 | 	config := TestArchConfig(buildDir, nil) | 
 | 30 | 	defer func() { os.RemoveAll(buildDir) }() | 
 | 31 |  | 
 | 32 | 	ctx := NewTestArchContext() | 
 | 33 | 	ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory)) | 
 | 34 | 	ctx.Register() | 
 | 35 | 	mockFiles := map[string][]byte{ | 
 | 36 | 		"Android.bp": []byte(bpFileContents), | 
 | 37 | 	} | 
 | 38 | 	ctx.MockFileSystem(mockFiles) | 
 | 39 | 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"}) | 
 | 40 | 	FailIfErrored(test, errs) | 
 | 41 | 	_, errs = ctx.PrepareBuildActions(config) | 
 | 42 | 	FailIfErrored(test, errs) | 
 | 43 | 	return ctx | 
 | 44 | } | 
 | 45 |  | 
 | 46 | func TestVtsConfig(t *testing.T) { | 
 | 47 | 	ctx := testVtsConfig(t, ` | 
 | 48 | vts_config { name: "plain"} | 
 | 49 | vts_config { name: "with_manifest", test_config: "manifest.xml" } | 
 | 50 | `) | 
 | 51 |  | 
 | 52 | 	variants := ctx.ModuleVariantsForTests("plain") | 
 | 53 | 	if len(variants) > 1 { | 
 | 54 | 		t.Errorf("expected 1, got %d", len(variants)) | 
 | 55 | 	} | 
 | 56 | 	expectedOutputFilename := ctx.ModuleForTests( | 
 | 57 | 		"plain", variants[0]).Module().(*VtsConfig).OutputFilePath.Base() | 
 | 58 | 	if expectedOutputFilename != "plain" { | 
 | 59 | 		t.Errorf("expected plain, got %q", expectedOutputFilename) | 
 | 60 | 	} | 
 | 61 | } |