--structured: test for no unstructured parcelables
Bug: 110758329
Test: runtests.sh
Change-Id: Ie6583515e3eb2c6753f9d67da776949ac69f747a
diff --git a/aidl.cpp b/aidl.cpp
index 1f804bc..a3a5328 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -685,7 +685,7 @@
if (options.IsStructured()) {
types->typenames_.IterateTypes([&](const AidlDefinedType& type) {
if (type.AsUnstructuredParcelable() != nullptr) {
- err = AidlError::BAD_TYPE;
+ err = AidlError::NOT_STRUCTURED;
LOG(ERROR) << type.GetCanonicalName()
<< " is not structured, but this is a structured interface.";
}
diff --git a/aidl.h b/aidl.h
index c1591ac..9b94ae6 100644
--- a/aidl.h
+++ b/aidl.h
@@ -42,6 +42,7 @@
GENERATION_ERROR,
BAD_CONSTANTS,
BAD_INPUT,
+ NOT_STRUCTURED,
OK = 0,
};
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 8ef9e72..f2c4a8f 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -71,8 +71,9 @@
cpp_types_.Init();
}
- AidlDefinedType* Parse(const string& path, const string& contents,
- TypeNamespace* types, AidlError* error = nullptr) {
+ AidlDefinedType* Parse(const string& path, const string& contents, TypeNamespace* types,
+ AidlError* error = nullptr,
+ const vector<string> additional_arguments = {}) {
io_delegate_.SetFileContents(path, contents);
vector<string> args;
if (types == &java_types_) {
@@ -80,10 +81,13 @@
} else {
args.emplace_back("aidl-cpp");
}
- for (const auto& f : preprocessed_files_) {
+ for (const string& s : additional_arguments) {
+ args.emplace_back(s);
+ }
+ for (const string& f : preprocessed_files_) {
args.emplace_back("--preprocessed=" + f);
}
- for (const auto& i : import_paths_) {
+ for (const string& i : import_paths_) {
args.emplace_back("--include=" + i);
}
args.emplace_back(path);
@@ -299,6 +303,18 @@
EXPECT_NE(0, ::android::aidl::compile_aidl(options4, io_delegate_));
}
+TEST_F(AidlTest, StructuredFailOnUnstructuredParcelable) {
+ io_delegate_.SetFileContents("o/WhoKnowsWhat.aidl", "package o; parcelable WhoKnowsWhat;");
+ import_paths_.emplace("");
+ AidlError reported_error;
+ auto parse_result =
+ Parse("p/IFoo.aidl",
+ "package p; import o.WhoKnowsWhat; interface IFoo { void f(in WhoKnowsWhat thisIs); }",
+ &java_types_, &reported_error, {"--structured"});
+ EXPECT_EQ(nullptr, parse_result);
+ EXPECT_EQ(AidlError::NOT_STRUCTURED, reported_error);
+}
+
TEST_F(AidlTest, FailOnDuplicateConstantNames) {
AidlError reported_error;
EXPECT_EQ(nullptr,