Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 1 | // Copyright 2019 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 java |
| 16 | |
| 17 | import ( |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame^] | 18 | "reflect" |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 19 | "testing" |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 22 | ) |
| 23 | |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 24 | func TestRequired(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 25 | ctx, config := testJava(t, ` |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 26 | java_library { |
| 27 | name: "foo", |
| 28 | srcs: ["a.java"], |
| 29 | required: ["libfoo"], |
| 30 | } |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 31 | `) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 32 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame^] | 33 | mod := ctx.ModuleForTests("foo", "android_common").Module() |
| 34 | entries := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 35 | |
| 36 | expected := []string{"libfoo"} |
| 37 | actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"] |
| 38 | if !reflect.DeepEqual(expected, actual) { |
| 39 | t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) |
| 40 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | func TestHostdex(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 44 | ctx, config := testJava(t, ` |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 45 | java_library { |
| 46 | name: "foo", |
| 47 | srcs: ["a.java"], |
| 48 | hostdex: true, |
| 49 | } |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 50 | `) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 51 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame^] | 52 | mod := ctx.ModuleForTests("foo", "android_common").Module() |
| 53 | entries := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 54 | |
| 55 | expected := []string{"foo"} |
| 56 | actual := entries.EntryMap["LOCAL_MODULE"] |
| 57 | if !reflect.DeepEqual(expected, actual) { |
| 58 | t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual) |
| 59 | } |
| 60 | |
| 61 | footerLines := entries.FooterLinesForTests() |
| 62 | if !android.InList("LOCAL_MODULE := foo-hostdex", footerLines) { |
| 63 | t.Errorf("foo-hostdex is not found in the footers: %q", footerLines) |
| 64 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | func TestHostdexRequired(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 68 | ctx, config := testJava(t, ` |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 69 | java_library { |
| 70 | name: "foo", |
| 71 | srcs: ["a.java"], |
| 72 | hostdex: true, |
| 73 | required: ["libfoo"], |
| 74 | } |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 75 | `) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 76 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame^] | 77 | mod := ctx.ModuleForTests("foo", "android_common").Module() |
| 78 | entries := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 79 | |
| 80 | expected := []string{"libfoo"} |
| 81 | actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"] |
| 82 | if !reflect.DeepEqual(expected, actual) { |
| 83 | t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) |
| 84 | } |
| 85 | |
| 86 | footerLines := entries.FooterLinesForTests() |
| 87 | if !android.InList("LOCAL_REQUIRED_MODULES := libfoo", footerLines) { |
| 88 | t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines) |
| 89 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | func TestHostdexSpecificRequired(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 93 | ctx, config := testJava(t, ` |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 94 | java_library { |
| 95 | name: "foo", |
| 96 | srcs: ["a.java"], |
| 97 | hostdex: true, |
| 98 | target: { |
| 99 | hostdex: { |
| 100 | required: ["libfoo"], |
| 101 | }, |
| 102 | }, |
| 103 | } |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 104 | `) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 105 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame^] | 106 | mod := ctx.ModuleForTests("foo", "android_common").Module() |
| 107 | entries := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 108 | |
| 109 | if r, ok := entries.EntryMap["LOCAL_REQUIRED_MODULES"]; ok { |
| 110 | t.Errorf("Unexpected required modules: %q", r) |
| 111 | } |
| 112 | |
| 113 | footerLines := entries.FooterLinesForTests() |
| 114 | if !android.InList("LOCAL_REQUIRED_MODULES += libfoo", footerLines) { |
| 115 | t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines) |
| 116 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 117 | } |