[gidl] Add GIDL conformance tests for union sandwiches

These are test cases that caught bugs with offsets in the go union as
xunion implementation

Change-Id: I7ded080338f97e69219fbb8bbcc2e58e74e1b69f
diff --git a/tools/fidl/gidl-conformance-suite/union.gidl b/tools/fidl/gidl-conformance-suite/union.gidl
index 753faa6..72cc415 100644
--- a/tools/fidl/gidl-conformance-suite/union.gidl
+++ b/tools/fidl/gidl-conformance-suite/union.gidl
@@ -50,3 +50,137 @@
     // TODO(mkember, bprosnitz): Add languages here as they gain support.
     bindings_allowlist = [go],
 }
+
+success("UnionSize8Alignment4") {
+	value = SandwichUnionSize8Alignment4 {
+                before: 10,
+                union: UnionSize8Alignment4 {
+                        variant: 4,
+                },
+                after: 20,
+	},
+	bytes = {
+                old = [
+                        before 4:num(10), tag 4:num(2),
+                        variant 4:num(4), after 4:num(20)
+                ],
+                v1 = [
+                        before 4:num(10), 4:padding,
+
+                        ordinal 8:num(3),
+                        num_bytes 4:num(8), num_handles 4:num(0),
+                        present 8:raw(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
+
+                        after 4:num(20), 4:padding,
+
+                        value 4:num(4), 4:padding,
+
+                ],
+        },
+        // TODO(mkember, bprosnitz): Add languages here as they gain support.
+        bindings_allowlist = [go],
+}
+
+success("UnionSize12Alignment4") {
+	value = SandwichUnionSize12Alignment4 {
+                before: 10,
+                union: UnionSize12Alignment4 {
+                        variant: [1, 2, 3, 4, 5, 6],
+                },
+                after: 20,
+	},
+	bytes = {
+                old = [
+                        before 4:num(10), tag 4:num(3),
+                        variant 6:raw(0x01, 0x02, 0x03, 0x04, 0x05, 0x06), 2:padding,
+                        after 4:num(20), 4:padding,
+                ],
+                v1 = [
+                        before 4:num(10), 4:padding,
+
+                        ordinal 8:num(4),
+                        num_bytes 4:num(8), num_handles 4:num(0),
+                        present 8:raw(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
+
+                        after 4:num(20), 4:padding,
+
+                        value 6:raw(0x01, 0x02, 0x03, 0x04, 0x05, 0x06), 2:padding,
+                ],
+        },
+        // TODO(mkember, bprosnitz): Add languages here as they gain support.
+        bindings_allowlist = [go],
+}
+
+success("UnionSize24Alignment8") {
+	value = SandwichUnionSize24Alignment8 {
+                before: 10,
+                union: UnionSize24Alignment8 {
+                        variant: StructSize16Alignment8 {
+                                f1: 1,
+                                f2: 2,
+                        },
+                },
+                after: 20,
+	},
+	bytes = {
+                old = [
+                        before 4:num(10), 4:padding,
+                        tag 4:num(3), 4:padding,
+                        f1 8:num(1), f2 8:num(2),
+                        after 4:num(20), 4:padding,
+                ],
+                v1 = [
+                        before 4:num(10), 4:padding,
+
+                        ordinal 8:num(4),
+                        num_bytes 4:num(16), num_handles 4:num(0),
+                        present 8:raw(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
+
+                        after 4:num(20), 4:padding,
+
+                        f1 8:num(1), f2 8:num(2),
+                ],
+        },
+        // TODO(mkember, bprosnitz): Add languages here as they gain support.
+        bindings_allowlist = [go],
+}
+
+success("UnionSize36Alignment4") {
+	value = SandwichUnionSize36Alignment4 {
+                before: 10,
+                union: UnionSize36Alignment4 {
+                        variant: [ 1,  2,  3,  4,  5,  6,  7,  8,
+                                   9, 10, 11, 12, 13, 14, 15, 16,
+                                  17, 18, 19, 20, 21, 22, 23, 24,
+                                  25, 26, 27, 28, 29, 30, 31, 32],
+                },
+                after: 20,
+	},
+	bytes = {
+                old = [
+                        before 4:num(10), tag 4:num(3),
+                        32:raw(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+                               0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+                               0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+                               0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20),
+                        after 4:num(20), 4:padding,
+                ],
+                v1 = [
+                        before 4:num(10), 4:padding,
+
+                        ordinal 8:num(4),
+                        num_bytes 4:num(32), num_handles 4:num(0),
+                        present 8:raw(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
+
+                        after 4:num(20), 4:padding,
+
+                        32:raw(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+                               0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+                               0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+                               0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20)
+                ],
+        },
+        // TODO(mkember, bprosnitz): Add languages here as they gain support.
+        bindings_allowlist = [go],
+}
+
diff --git a/tools/fidl/gidl-conformance-suite/union.test.fidl b/tools/fidl/gidl-conformance-suite/union.test.fidl
index 2e55963..ea456bc 100644
--- a/tools/fidl/gidl-conformance-suite/union.test.fidl
+++ b/tools/fidl/gidl-conformance-suite/union.test.fidl
@@ -19,3 +19,59 @@
 struct SingleVariantUnionStruct {
     SingleVariantUnion u;
 };
+
+union UnionSize8Alignment4 {
+    1: uint8 unused1;
+    2: uint8 unused2;
+    3: uint32 variant;
+};
+
+struct SandwichUnionSize8Alignment4 {
+    uint32 before;
+    UnionSize8Alignment4 union;
+    uint32 after;
+};
+
+union UnionSize12Alignment4 {
+    1: uint8 unused1;
+    2: uint8 unused2;
+    3: uint8 unused3;
+    4: array<uint8>:6 variant;
+};
+
+struct SandwichUnionSize12Alignment4 {
+    uint32 before;
+    UnionSize12Alignment4 union;
+    uint32 after;
+};
+
+struct StructSize16Alignment8 {
+    uint64 f1;
+    uint64 f2;
+};
+
+union UnionSize24Alignment8 {
+    1: uint8 unused1;
+    2: uint8 unused2;
+    3: uint8 unused3;
+    4: StructSize16Alignment8 variant;
+};
+
+struct SandwichUnionSize24Alignment8 {
+    uint32 before;
+    UnionSize24Alignment8 union;
+    uint32 after;
+};
+
+union UnionSize36Alignment4 {
+    1: uint8 unused1;
+    2: uint8 unused2;
+    3: uint8 unused3;
+    4: array<uint8>:32 variant;
+};
+
+struct SandwichUnionSize36Alignment4 {
+    uint32 before;
+    UnionSize36Alignment4 union;
+    uint32 after;
+};