Check cpp_header for C++/NDK
Unstructured parcelables should have cpp_header for compilation.
Bug: 194846019
Test: atest aidl_unittests
Change-Id: I76c56d3976272f4b401ddc9d8d54fa0e37527400
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index e63df71..b2e6eb4 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -435,16 +435,14 @@
EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_));
EXPECT_EQ(0, ::android::aidl::compile_aidl(cpp_options, io_delegate_));
- const string expected_stderr =
- "ERROR: a/Foo.aidl:1.48-52: Cannot declared parcelable in a --structured interface. "
- "Parcelable must be defined in AIDL directly.\n";
+
CaptureStderr();
EXPECT_NE(0, ::android::aidl::compile_aidl(cpp_structured_options, io_delegate_));
- EXPECT_EQ(expected_stderr, GetCapturedStderr());
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("Cannot declare unstructured"));
CaptureStderr();
EXPECT_NE(0, ::android::aidl::compile_aidl(rust_options, io_delegate_));
- EXPECT_EQ(expected_stderr, GetCapturedStderr());
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("Cannot declare unstructured"));
}
TEST_F(AidlTest, ParcelableSupportJavaDeriveToString) {
@@ -672,6 +670,23 @@
EXPECT_EQ((Comments{{"// get bar\n"}}), interface->GetMethods()[0]->GetComments());
}
+TEST_F(AidlTest, RejectsIfCppHeaderIsMissing) {
+ io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo;");
+ Options options = Options::From("aidl --lang cpp -h h -o o Foo.aidl");
+ CaptureStderr();
+ EXPECT_EQ(1, ::android::aidl::compile_aidl(options, io_delegate_));
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("must have C++ header defined"));
+}
+
+TEST_F(AidlTest, RejectsIfTypeRefsCppHeaderIsMissing) {
+ io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo;");
+ io_delegate_.SetFileContents("IBar.aidl", "interface IBar { void bar(in Foo foo); }");
+ Options options = Options::From("aidl -I . --lang cpp -h h -o o IBar.aidl");
+ CaptureStderr();
+ EXPECT_EQ(1, ::android::aidl::compile_aidl(options, io_delegate_));
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("must have C++ header defined"));
+}
+
TEST_F(AidlTest, ParsesPreprocessedFile) {
string simple_content = "parcelable a.Foo;\ninterface b.IBar;";
io_delegate_.SetFileContents("path", simple_content);