nested types: GenerateHeaderIncludes()

Visitor-based function gathers all include files for a header with
nested types.

However GenerateHeader() doesn't support nested types yet. Upcoming
changes will make it to generate class decl for each nested type
recursively.

Bug: 182508839
Test: aidl_unittests
Test: tests/golden_test.sh check
Change-Id: I2bb6b160a6a99fef7576c4c22f10e6015f3dc5c0
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index b650e97..ab01940 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1665,6 +1665,23 @@
   }
 }
 
+TEST_F(AidlTest, HeaderForNestedTypeShouldPointToTopMostParent) {
+  const string input_path = "p/IFoo.aidl";
+  const string input =
+      "package p;\n"
+      "interface IFoo {\n"
+      "  parcelable Result {}\n"
+      "}";
+  CaptureStderr();
+  auto foo = Parse(input_path, input, typenames_, Options::Language::CPP);
+  ASSERT_NE(nullptr, foo);
+  EXPECT_EQ(GetCapturedStderr(), "");
+
+  auto result = typenames_.ResolveTypename("p.IFoo.Result").defined_type;
+  ASSERT_NE(nullptr, result);
+  EXPECT_EQ("p/IFoo.h", cpp::CppHeaderForType(*result));
+}
+
 TEST_F(AidlTest, CppNameOf_GenericType) {
   const string input_path = "p/Wrapper.aidl";
   const string input = "package p; parcelable Wrapper<T> {}";