add bp2build unit tests for aidl_interface

Bug: 229251008
Test: go test ./bp2build -run TestAidlInterface
Change-Id: Ie7214d5578bc21e348410ca91ea42d7a3190eb3d
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index cb25627..d327157 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -18,6 +18,7 @@
         "testing.go",
     ],
     deps: [
+        "aidl-soong-rules",
         "soong-android",
         "soong-android-allowlists",
         "soong-android-soongconfig",
@@ -36,6 +37,7 @@
     ],
     testSrcs: [
         "aar_conversion_test.go",
+        "aidl_interface_conversion_test.go",
         "android_app_certificate_conversion_test.go",
         "android_app_conversion_test.go",
         "apex_conversion_test.go",
diff --git a/bp2build/aidl_interface_conversion_test.go b/bp2build/aidl_interface_conversion_test.go
new file mode 100644
index 0000000..38d902d
--- /dev/null
+++ b/bp2build/aidl_interface_conversion_test.go
@@ -0,0 +1,249 @@
+package bp2build
+
+import (
+	"android/soong/aidl"
+	"android/soong/android"
+	"testing"
+)
+
+func runAidlInterfaceTestCase(t *testing.T, tc Bp2buildTestCase) {
+	t.Helper()
+	RunBp2BuildTestCase(
+		t,
+		func(ctx android.RegistrationContext) {
+			ctx.RegisterModuleType("aidl_interface", aidl.AidlInterfaceFactory)
+			ctx.RegisterModuleType("aidl_interface_headers", aidl.AidlInterfaceHeadersFactory)
+		},
+		tc,
+	)
+}
+
+func TestAidlInterfaceHeaders(t *testing.T) {
+	runAidlInterfaceTestCase(t, Bp2buildTestCase{
+		Description: `aidl_interface_headers`,
+		Blueprint: `
+aidl_interface_headers {
+    name: "aidl-interface-headers",
+	include_dir: "src",
+	srcs: [
+		"src/A.aidl",
+	],
+}
+`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTargetNoRestrictions("aidl_library", "aidl-interface-headers", AttrNameToString{
+				"strip_import_prefix": `"src"`,
+				"hdrs":                `["src/A.aidl"]`,
+			}),
+		},
+	})
+}
+
+func TestAidlInterface(t *testing.T) {
+	runAidlInterfaceTestCase(t, Bp2buildTestCase{
+		Description: `aidl_interface with single "latest" aidl_interface import`,
+		Blueprint: `
+aidl_interface_headers {
+    name: "aidl-interface-headers",
+}
+aidl_interface {
+    name: "aidl-interface-import",
+    versions: [
+        "1",
+        "2",
+    ],
+}
+aidl_interface {
+    name: "aidl-interface1",
+    flags: ["--flag1"],
+    imports: [
+        "aidl-interface-import-V1",
+    ],
+    headers: [
+        "aidl-interface-headers",
+    ],
+    versions: [
+        "1",
+        "2",
+        "3",
+    ],
+}`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTargetNoRestrictions("aidl_library", "aidl-interface-headers", AttrNameToString{}),
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface-import", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+				"versions": `[
+        "1",
+        "2",
+    ]`,
+			}),
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface1", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+				"deps": `[
+        ":aidl-interface-import-V1",
+        ":aidl-interface-headers",
+    ]`,
+				"flags": `["--flag1"]`,
+				"versions": `[
+        "1",
+        "2",
+        "3",
+    ]`,
+			}),
+		},
+	})
+}
+
+func TestAidlInterfaceWithNoProperties(t *testing.T) {
+	runAidlInterfaceTestCase(t, Bp2buildTestCase{
+		Description: `aidl_interface no properties set`,
+		Blueprint: `
+aidl_interface {
+    name: "aidl-interface1",
+}
+`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface1", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+			}),
+		},
+	})
+}
+
+func TestAidlInterfaceWithDisabledBackends(t *testing.T) {
+	runAidlInterfaceTestCase(t, Bp2buildTestCase{
+		Description: `aidl_interface with some backends disabled`,
+		Blueprint: `
+aidl_interface {
+    name: "aidl-interface1",
+    backend: {
+        ndk: {
+            enabled: false,
+        },
+        cpp: {
+            enabled: false,
+        },
+    },
+}
+`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface1", AttrNameToString{
+				"backends": `["java"]`,
+			}),
+		},
+	})
+}
+
+func TestAidlInterfaceWithLatestImport(t *testing.T) {
+	runAidlInterfaceTestCase(t, Bp2buildTestCase{
+		Description: `aidl_interface with single "latest" aidl_interface import`,
+		Blueprint: `
+aidl_interface {
+    name: "aidl-interface-import",
+    versions: [
+        "1",
+        "2",
+    ],
+}
+aidl_interface {
+    name: "aidl-interface1",
+    imports: [
+        "aidl-interface-import",
+    ],
+    versions: [
+        "1",
+        "2",
+        "3",
+    ],
+}`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface-import", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+				"versions": `[
+        "1",
+        "2",
+    ]`,
+			}),
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface1", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+				"deps": `[":aidl-interface-import-latest"]`,
+				"versions": `[
+        "1",
+        "2",
+        "3",
+    ]`,
+			}),
+		},
+	})
+}
+
+func TestAidlInterfaceWithVersionedImport(t *testing.T) {
+	runAidlInterfaceTestCase(t, Bp2buildTestCase{
+		Description: `aidl_interface with single versioned aidl_interface import`,
+		Blueprint: `
+aidl_interface {
+    name: "aidl-interface-import",
+    versions: [
+        "1",
+        "2",
+    ],
+}
+aidl_interface {
+    name: "aidl-interface1",
+    imports: [
+        "aidl-interface-import-V2",
+    ],
+    versions: [
+        "1",
+        "2",
+        "3",
+    ],
+}`,
+		ExpectedBazelTargets: []string{
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface-import", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+				"versions": `[
+        "1",
+        "2",
+    ]`,
+			}),
+			MakeBazelTargetNoRestrictions("aidl_interface", "aidl-interface1", AttrNameToString{
+				"backends": `[
+        "cpp",
+        "java",
+        "ndk",
+    ]`,
+				"deps": `[":aidl-interface-import-V2"]`,
+				"versions": `[
+        "1",
+        "2",
+        "3",
+    ]`,
+			}),
+		},
+	})
+}
diff --git a/go.mod b/go.mod
index 8c1a9f0..2e28ab6 100644
--- a/go.mod
+++ b/go.mod
@@ -1,13 +1,17 @@
 module android/soong
 
-require google.golang.org/protobuf v0.0.0
-
-require github.com/google/blueprint v0.0.0
+require (
+	google.golang.org/protobuf v0.0.0
+	github.com/google/blueprint v0.0.0
+	android/soong/aidl v0.0.0
+)
 
 replace google.golang.org/protobuf v0.0.0 => ../../external/golang-protobuf
 
 replace github.com/google/blueprint v0.0.0 => ../blueprint
 
+replace android/soong/aidl v0.0.0 => ../../system/tools/aidl/build
+
 // Indirect deps from golang-protobuf
 exclude github.com/golang/protobuf v1.5.0
 
diff --git a/tests/lib.sh b/tests/lib.sh
index 6210e77..643b46a 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -93,6 +93,7 @@
   symlink_directory external/go-cmp
   symlink_directory external/golang-protobuf
   symlink_directory external/starlark-go
+  symlink_directory system/tools/aidl
 
   touch "$MOCK_TOP/Android.bp"
 }