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() |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 34 | entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 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() |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 53 | entriesList := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 54 | if len(entriesList) != 2 { |
| 55 | t.Errorf("two entries are expected, but got %d", len(entriesList)) |
| 56 | } |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 57 | |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 58 | mainEntries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 59 | expected := []string{"foo"} |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 60 | actual := mainEntries.EntryMap["LOCAL_MODULE"] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 61 | if !reflect.DeepEqual(expected, actual) { |
| 62 | t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual) |
| 63 | } |
| 64 | |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 65 | subEntries := &entriesList[1] |
| 66 | expected = []string{"foo-hostdex"} |
| 67 | actual = subEntries.EntryMap["LOCAL_MODULE"] |
| 68 | if !reflect.DeepEqual(expected, actual) { |
| 69 | t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 70 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | func TestHostdexRequired(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 74 | ctx, config := testJava(t, ` |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 75 | java_library { |
| 76 | name: "foo", |
| 77 | srcs: ["a.java"], |
| 78 | hostdex: true, |
| 79 | required: ["libfoo"], |
| 80 | } |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 81 | `) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 82 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 83 | mod := ctx.ModuleForTests("foo", "android_common").Module() |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 84 | entriesList := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 85 | if len(entriesList) != 2 { |
| 86 | t.Errorf("two entries are expected, but got %d", len(entriesList)) |
| 87 | } |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 88 | |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 89 | mainEntries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 90 | expected := []string{"libfoo"} |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 91 | actual := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 92 | if !reflect.DeepEqual(expected, actual) { |
| 93 | t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) |
| 94 | } |
| 95 | |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 96 | subEntries := &entriesList[1] |
| 97 | expected = []string{"libfoo"} |
| 98 | actual = subEntries.EntryMap["LOCAL_REQUIRED_MODULES"] |
| 99 | if !reflect.DeepEqual(expected, actual) { |
| 100 | t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 101 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | func TestHostdexSpecificRequired(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 105 | ctx, config := testJava(t, ` |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 106 | java_library { |
| 107 | name: "foo", |
| 108 | srcs: ["a.java"], |
| 109 | hostdex: true, |
| 110 | target: { |
| 111 | hostdex: { |
| 112 | required: ["libfoo"], |
| 113 | }, |
| 114 | }, |
| 115 | } |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 116 | `) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 117 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 118 | mod := ctx.ModuleForTests("foo", "android_common").Module() |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 119 | entriesList := android.AndroidMkEntriesForTest(t, config, "", mod) |
| 120 | if len(entriesList) != 2 { |
| 121 | t.Errorf("two entries are expected, but got %d", len(entriesList)) |
| 122 | } |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 123 | |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 124 | mainEntries := &entriesList[0] |
| 125 | if r, ok := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"]; ok { |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 126 | t.Errorf("Unexpected required modules: %q", r) |
| 127 | } |
| 128 | |
Jiyong Park | 55bd98b | 2019-12-11 17:27:07 +0900 | [diff] [blame] | 129 | subEntries := &entriesList[1] |
| 130 | expected := []string{"libfoo"} |
| 131 | actual := subEntries.EntryMap["LOCAL_REQUIRED_MODULES"] |
| 132 | if !reflect.DeepEqual(expected, actual) { |
| 133 | t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual) |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 134 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 135 | } |