check_api checks if annotation params are changed
Previously, it checks only if annotation types are matched. But some
annotations can have parameters and changed parameters can be
incompatible.
To compare annotations including parameters, the checker now compares
string representations of annotations. AidlAnnotation::ToString() works
fine for the case of re-order of parameters because it uses std::map
internally.
Bug: n/a
Test: aidl_unittests
Change-Id: I6fafbdac9983c45c3d74e6af0633d7dbc4d0848f
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index ef134fb..46c5bed 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1934,6 +1934,20 @@
EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_));
}
+TEST_F(AidlTestCompatibleChanges, ReorderedAnnatations) {
+ io_delegate_.SetFileContents("old/p/Foo.aidl",
+ "package p;"
+ "@JavaPassthrough(annotation=\"Alice\")"
+ "@JavaPassthrough(annotation=\"Bob\")"
+ "parcelable Foo {}");
+ io_delegate_.SetFileContents("new/p/Foo.aidl",
+ "package p;"
+ "@JavaPassthrough(annotation=\"Bob\")"
+ "@JavaPassthrough(annotation=\"Alice\")"
+ "parcelable Foo {}");
+ EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_));
+}
+
TEST_F(AidlTestCompatibleChanges, NewFieldOfNewType) {
io_delegate_.SetFileContents("old/p/Data.aidl",
"package p;"
@@ -2329,6 +2343,24 @@
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
+TEST_F(AidlTestIncompatibleChanges, ChangedAnnatationParams) {
+ const string expected_stderr =
+ "ERROR: new/p/Foo.aidl:1.55-59: Changed annotations: @JavaPassthrough(annotation=\"Alice\") "
+ "to @JavaPassthrough(annotation=\"Bob\")\n";
+ io_delegate_.SetFileContents("old/p/Foo.aidl",
+ "package p;"
+ "@JavaPassthrough(annotation=\"Alice\")"
+ "parcelable Foo {}");
+ io_delegate_.SetFileContents("new/p/Foo.aidl",
+ "package p;"
+ "@JavaPassthrough(annotation=\"Bob\")"
+ "parcelable Foo {}");
+
+ CaptureStderr();
+ EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_));
+ EXPECT_EQ(expected_stderr, GetCapturedStderr());
+}
+
TEST_F(AidlTestIncompatibleChanges, AddedParcelableAnnotation) {
const string expected_stderr =
"ERROR: new/p/Foo.aidl:1.47-51: Changed annotations: (empty) to @JavaOnlyStableParcelable\n";