| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 17 | #include <memory> |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 18 | #include <set> |
| 19 | #include <string> |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 22 | #include <android-base/stringprintf.h> |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | #include "aidl.h" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 26 | #include "aidl_apicheck.h" |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 27 | #include "aidl_language.h" |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 28 | #include "aidl_to_cpp.h" |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 29 | #include "tests/fake_io_delegate.h" |
| 30 | #include "type_cpp.h" |
| 31 | #include "type_java.h" |
| 32 | #include "type_namespace.h" |
| 33 | |
| 34 | using android::aidl::test::FakeIoDelegate; |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 35 | using android::base::StringPrintf; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 36 | using std::set; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 37 | using std::string; |
| 38 | using std::unique_ptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 39 | using std::vector; |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 40 | using android::aidl::internals::parse_preprocessed_file; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 41 | |
| 42 | namespace android { |
| 43 | namespace aidl { |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 44 | namespace { |
| 45 | |
| 46 | const char kExpectedDepFileContents[] = |
| 47 | R"(place/for/output/p/IFoo.java : \ |
| 48 | p/IFoo.aidl |
| 49 | |
| 50 | p/IFoo.aidl : |
| 51 | )"; |
| 52 | |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 53 | const char kExpectedNinjaDepFileContents[] = |
| 54 | R"(place/for/output/p/IFoo.java : \ |
| 55 | p/IFoo.aidl |
| 56 | )"; |
| 57 | |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 58 | const char kExpectedParcelableDepFileContents[] = |
| 59 | R"( : \ |
| 60 | p/Foo.aidl |
| 61 | |
| 62 | p/Foo.aidl : |
| 63 | )"; |
| 64 | |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 65 | const char kExepectedJavaParcelableOutputContests[] = |
| 66 | R"(/* |
| 67 | * This file is auto-generated. DO NOT MODIFY. |
| 68 | * Original file: Rect.aidl |
| 69 | */ |
| 70 | @android.annotation.SystemApi |
| 71 | public class Rect implements android.os.Parcelable |
| 72 | { |
| 73 | // Comment |
| 74 | |
| 75 | @android.annotation.SystemApi |
| 76 | public int x = 5; |
| 77 | |
| 78 | @android.annotation.UnsupportedAppUsage |
| 79 | @android.annotation.SystemApi |
| 80 | public int y; |
| 81 | public static final android.os.Parcelable.Creator<Rect> CREATOR = new android.os.Parcelable.Creator<Rect>() { |
| 82 | @Override |
| 83 | public Rect createFromParcel(android.os.Parcel _aidl_source) { |
| 84 | Rect _aidl_out = new Rect(); |
| 85 | _aidl_out.readFromParcel(_aidl_source); |
| 86 | return _aidl_out; |
| 87 | } |
| 88 | @Override |
| 89 | public Rect[] newArray(int _aidl_size) { |
| 90 | return new Rect[_aidl_size]; |
| 91 | } |
| 92 | }; |
| 93 | @Override public final void writeToParcel(android.os.Parcel _aidl_parcel, int _aidl_flag) |
| 94 | { |
| 95 | int _aidl_start_pos = _aidl_parcel.dataPosition(); |
| 96 | _aidl_parcel.writeInt(0); |
| 97 | _aidl_parcel.writeInt(x); |
| 98 | _aidl_parcel.writeInt(y); |
| 99 | int _aidl_end_pos = _aidl_parcel.dataPosition(); |
| 100 | _aidl_parcel.setDataPosition(_aidl_start_pos); |
| 101 | _aidl_parcel.writeInt(_aidl_end_pos - _aidl_start_pos); |
| 102 | _aidl_parcel.setDataPosition(_aidl_end_pos); |
| 103 | } |
| 104 | public final void readFromParcel(android.os.Parcel _aidl_parcel) |
| 105 | { |
| 106 | int _aidl_start_pos = _aidl_parcel.dataPosition(); |
| 107 | int _aidl_parcelable_size = _aidl_parcel.readInt(); |
| 108 | if (_aidl_parcelable_size < 0) return; |
| 109 | try { |
| 110 | x = _aidl_parcel.readInt(); |
| 111 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
| 112 | y = _aidl_parcel.readInt(); |
| 113 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
| 114 | } finally { |
| 115 | _aidl_parcel.setDataPosition(_aidl_start_pos + _aidl_parcelable_size); |
| 116 | } |
| 117 | } |
| 118 | @Override public int describeContents() |
| 119 | { |
| Jeongik Cha | 372a8c8 | 2018-12-12 16:31:11 +0900 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 122 | } |
| 123 | )"; |
| 124 | |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 125 | } // namespace |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 126 | |
| 127 | class AidlTest : public ::testing::Test { |
| 128 | protected: |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 129 | void SetUp() override { |
| 130 | java_types_.Init(); |
| 131 | cpp_types_.Init(); |
| 132 | } |
| 133 | |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 134 | AidlDefinedType* Parse(const string& path, const string& contents, TypeNamespace* types, |
| 135 | AidlError* error = nullptr, |
| 136 | const vector<string> additional_arguments = {}) { |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 137 | io_delegate_.SetFileContents(path, contents); |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 138 | vector<string> args; |
| 139 | if (types == &java_types_) { |
| 140 | args.emplace_back("aidl"); |
| 141 | } else { |
| 142 | args.emplace_back("aidl-cpp"); |
| 143 | } |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 144 | for (const string& s : additional_arguments) { |
| 145 | args.emplace_back(s); |
| 146 | } |
| 147 | for (const string& f : preprocessed_files_) { |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 148 | args.emplace_back("--preprocessed=" + f); |
| 149 | } |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 150 | for (const string& i : import_paths_) { |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 151 | args.emplace_back("--include=" + i); |
| 152 | } |
| 153 | args.emplace_back(path); |
| 154 | Options options = Options::From(args); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 155 | vector<AidlDefinedType*> defined_types; |
| 156 | vector<string> imported_files; |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 157 | ImportResolver import_resolver{io_delegate_, path, import_paths_, {}}; |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 158 | AidlError actual_error = ::android::aidl::internals::load_and_validate_aidl( |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 159 | path, options, io_delegate_, types, &defined_types, &imported_files); |
| 160 | |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 161 | if (error != nullptr) { |
| 162 | *error = actual_error; |
| 163 | } |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 164 | |
| 165 | if (actual_error != AidlError::OK) { |
| 166 | return nullptr; |
| 167 | } |
| 168 | |
| 169 | EXPECT_EQ(1ul, defined_types.size()); |
| 170 | |
| 171 | return defined_types.front(); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 172 | } |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 173 | |
| 174 | FakeIoDelegate io_delegate_; |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 175 | vector<string> preprocessed_files_; |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 176 | set<string> import_paths_; |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 177 | java::JavaTypeNamespace java_types_; |
| 178 | cpp::TypeNamespace cpp_types_; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
| Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 181 | TEST_F(AidlTest, AcceptMissingPackage) { |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 182 | EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { }", &java_types_)); |
| Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 183 | EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { }", &cpp_types_)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 186 | TEST_F(AidlTest, RejectsArraysOfBinders) { |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 187 | import_paths_.emplace(""); |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 188 | io_delegate_.SetFileContents("bar/IBar.aidl", |
| 189 | "package bar; interface IBar {}"); |
| 190 | string path = "foo/IFoo.aidl"; |
| 191 | string contents = "package foo;\n" |
| 192 | "import bar.IBar;\n" |
| 193 | "interface IFoo { void f(in IBar[] input); }"; |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 194 | EXPECT_EQ(nullptr, Parse(path, contents, &java_types_)); |
| 195 | EXPECT_EQ(nullptr, Parse(path, contents, &cpp_types_)); |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 198 | TEST_F(AidlTest, RejectsOnewayOutParameters) { |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 199 | string oneway_interface = |
| 200 | "package a; oneway interface IFoo { void f(out int bar); }"; |
| 201 | string oneway_method = |
| 202 | "package a; interface IBar { oneway void f(out int bar); }"; |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 203 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_interface, &cpp_types_)); |
| 204 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_interface, &java_types_)); |
| 205 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_method, &cpp_types_)); |
| 206 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_method, &java_types_)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | TEST_F(AidlTest, RejectsOnewayNonVoidReturn) { |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 210 | string oneway_method = "package a; interface IFoo { oneway int f(); }"; |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 211 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, &cpp_types_)); |
| 212 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, &java_types_)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 215 | TEST_F(AidlTest, RejectsNullablePrimitive) { |
| 216 | string oneway_method = "package a; interface IFoo { @nullable int f(); }"; |
| 217 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, &cpp_types_)); |
| 218 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, &java_types_)); |
| 219 | } |
| 220 | |
| Steven Moreland | b3cd3c7 | 2018-10-11 12:37:45 -0700 | [diff] [blame] | 221 | TEST_F(AidlTest, RejectsDuplicatedArgumentNames) { |
| 222 | string method = "package a; interface IFoo { void f(int a, int a); }"; |
| 223 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, &cpp_types_)); |
| 224 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, &java_types_)); |
| 225 | } |
| 226 | |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 227 | TEST_F(AidlTest, ParsesNullableAnnotation) { |
| 228 | for (auto is_nullable: {true, false}) { |
| 229 | auto parse_result = Parse( |
| 230 | "a/IFoo.aidl", |
| 231 | StringPrintf( "package a; interface IFoo {%s String f(); }", |
| 232 | (is_nullable) ? "@nullable" : ""), |
| 233 | &cpp_types_); |
| 234 | ASSERT_NE(nullptr, parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 235 | const AidlInterface* interface = parse_result->AsInterface(); |
| 236 | ASSERT_NE(nullptr, interface); |
| 237 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 238 | EXPECT_EQ(interface->GetMethods()[0]->GetType().IsNullable(), is_nullable); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 239 | cpp_types_.typenames_.Reset(); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | TEST_F(AidlTest, ParsesUtf8Annotations) { |
| 244 | for (auto is_utf8: {true, false}) { |
| 245 | auto parse_result = Parse( |
| 246 | "a/IFoo.aidl", |
| 247 | StringPrintf( "package a; interface IFoo {%s String f(); }", |
| Christopher Wiley | 9f40372 | 2016-01-27 16:04:11 -0800 | [diff] [blame] | 248 | (is_utf8) ? "@utf8InCpp" : ""), |
| Christopher Wiley | b7e0117 | 2016-01-28 16:32:34 -0800 | [diff] [blame] | 249 | &cpp_types_); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 250 | ASSERT_NE(nullptr, parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 251 | const AidlInterface* interface = parse_result->AsInterface(); |
| 252 | ASSERT_NE(nullptr, interface); |
| 253 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 254 | EXPECT_EQ(interface->GetMethods()[0]->GetType().IsUtf8InCpp(), is_utf8); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 255 | cpp_types_.typenames_.Reset(); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 259 | TEST_F(AidlTest, AcceptsOneway) { |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 260 | string oneway_method = "package a; interface IFoo { oneway void f(int a); }"; |
| 261 | string oneway_interface = |
| 262 | "package a; oneway interface IBar { void f(int a); }"; |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 263 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, &cpp_types_)); |
| 264 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, &java_types_)); |
| 265 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", oneway_interface, &cpp_types_)); |
| 266 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", oneway_interface, &java_types_)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 267 | } |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 268 | |
| 269 | TEST_F(AidlTest, ParsesPreprocessedFile) { |
| 270 | string simple_content = "parcelable a.Foo;\ninterface b.IBar;"; |
| 271 | io_delegate_.SetFileContents("path", simple_content); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 272 | EXPECT_FALSE(java_types_.HasTypeByCanonicalName("a.Foo")); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 273 | EXPECT_TRUE(parse_preprocessed_file(io_delegate_, "path", &java_types_, java_types_.typenames_)); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 274 | EXPECT_TRUE(java_types_.HasTypeByCanonicalName("a.Foo")); |
| 275 | EXPECT_TRUE(java_types_.HasTypeByCanonicalName("b.IBar")); |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | TEST_F(AidlTest, ParsesPreprocessedFileWithWhitespace) { |
| 279 | string simple_content = "parcelable a.Foo;\n interface b.IBar ;\t"; |
| 280 | io_delegate_.SetFileContents("path", simple_content); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 281 | EXPECT_FALSE(java_types_.HasTypeByCanonicalName("a.Foo")); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 282 | EXPECT_TRUE(parse_preprocessed_file(io_delegate_, "path", &java_types_, java_types_.typenames_)); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 283 | EXPECT_TRUE(java_types_.HasTypeByCanonicalName("a.Foo")); |
| 284 | EXPECT_TRUE(java_types_.HasTypeByCanonicalName("b.IBar")); |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 287 | TEST_F(AidlTest, PreferImportToPreprocessed) { |
| 288 | io_delegate_.SetFileContents("preprocessed", "interface another.IBar;"); |
| 289 | io_delegate_.SetFileContents("one/IBar.aidl", "package one; " |
| 290 | "interface IBar {}"); |
| 291 | preprocessed_files_.push_back("preprocessed"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 292 | import_paths_.emplace(""); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 293 | auto parse_result = Parse( |
| 294 | "p/IFoo.aidl", "package p; import one.IBar; interface IFoo {}", |
| 295 | &java_types_); |
| 296 | EXPECT_NE(nullptr, parse_result); |
| 297 | // We expect to know about both kinds of IBar |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 298 | EXPECT_TRUE(java_types_.HasTypeByCanonicalName("one.IBar")); |
| 299 | EXPECT_TRUE(java_types_.HasTypeByCanonicalName("another.IBar")); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 300 | // But if we request just "IBar" we should get our imported one. |
| Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 301 | AidlTypeSpecifier ambiguous_type(AIDL_LOCATION_HERE, "IBar", false, nullptr, ""); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 302 | const java::Type* type = java_types_.Find(ambiguous_type); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 303 | ASSERT_TRUE(type); |
| Christopher Wiley | d21bfee | 2016-01-29 15:11:38 -0800 | [diff] [blame] | 304 | EXPECT_EQ("one.IBar", type->CanonicalName()); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 307 | TEST_F(AidlTest, WritePreprocessedFile) { |
| 308 | io_delegate_.SetFileContents("p/Outer.aidl", |
| 309 | "package p; parcelable Outer.Inner;"); |
| 310 | io_delegate_.SetFileContents("one/IBar.aidl", "package one; import p.Outer;" |
| 311 | "interface IBar {}"); |
| 312 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 313 | vector<string> args { |
| 314 | "aidl", |
| 315 | "--preprocess", |
| 316 | "preprocessed", |
| 317 | "p/Outer.aidl", |
| 318 | "one/IBar.aidl"}; |
| 319 | Options options = Options::From(args); |
| Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 320 | EXPECT_TRUE(::android::aidl::preprocess_aidl(options, io_delegate_)); |
| 321 | |
| 322 | string output; |
| 323 | EXPECT_TRUE(io_delegate_.GetWrittenContents("preprocessed", &output)); |
| 324 | EXPECT_EQ("parcelable p.Outer.Inner;\ninterface one.IBar;\n", output); |
| 325 | } |
| 326 | |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 327 | TEST_F(AidlTest, JavaParcelableOutput) { |
| 328 | io_delegate_.SetFileContents("Rect.aidl", |
| 329 | "@SystemApi\n" |
| 330 | "parcelable Rect {\n" |
| 331 | " // Comment\n" |
| 332 | " @SystemApi\n" |
| 333 | " int x=5;\n" |
| 334 | " @SystemApi\n" |
| 335 | " @UnsupportedAppUsage\n" |
| 336 | " int y;\n" |
| 337 | "}"); |
| 338 | |
| 339 | vector<string> args{"aidl", "Rect.aidl"}; |
| 340 | Options options = Options::From(args); |
| 341 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 342 | |
| 343 | string output; |
| 344 | EXPECT_TRUE(io_delegate_.GetWrittenContents("Rect.java", &output)); |
| 345 | EXPECT_EQ(kExepectedJavaParcelableOutputContests, output); |
| 346 | } |
| 347 | |
| Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 348 | TEST_F(AidlTest, RequireOuterClass) { |
| 349 | io_delegate_.SetFileContents("p/Outer.aidl", |
| 350 | "package p; parcelable Outer.Inner;"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 351 | import_paths_.emplace(""); |
| Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 352 | auto parse_result = Parse( |
| 353 | "p/IFoo.aidl", |
| 354 | "package p; import p.Outer; interface IFoo { void f(in Inner c); }", |
| 355 | &java_types_); |
| 356 | EXPECT_EQ(nullptr, parse_result); |
| 357 | } |
| 358 | |
| 359 | TEST_F(AidlTest, ParseCompoundParcelableFromPreprocess) { |
| 360 | io_delegate_.SetFileContents("preprocessed", |
| 361 | "parcelable p.Outer.Inner;"); |
| 362 | preprocessed_files_.push_back("preprocessed"); |
| 363 | auto parse_result = Parse( |
| 364 | "p/IFoo.aidl", |
| 365 | "package p; interface IFoo { void f(in Inner c); }", |
| 366 | &java_types_); |
| 367 | // TODO(wiley): This should actually return nullptr because we require |
| 368 | // the outer class name. However, for legacy reasons, |
| 369 | // this behavior must be maintained. b/17415692 |
| 370 | EXPECT_NE(nullptr, parse_result); |
| 371 | } |
| 372 | |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 373 | TEST_F(AidlTest, FailOnParcelable) { |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 374 | io_delegate_.SetFileContents("p/IFoo.aidl", "package p; parcelable IFoo;"); |
| 375 | |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 376 | // By default, we shouldn't fail on parcelable. |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 377 | Options options1 = Options::From("aidl p/IFoo.aidl"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 378 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options1, io_delegate_)); |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 379 | |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 380 | // -b considers this an error |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 381 | Options options2 = Options::From("aidl -b p/IFoo.aidl"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 382 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 383 | |
| 384 | io_delegate_.SetFileContents("p/IBar.aidl", "package p; parcelable Foo; interface IBar{}"); |
| 385 | |
| 386 | // Regardless of '-b', a parcelable and an interface should fail. |
| 387 | Options options3 = Options::From("aidl p/IBar.aidl"); |
| 388 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options3, io_delegate_)); |
| 389 | Options options4 = Options::From("aidl -b p/IBar.aidl"); |
| 390 | EXPECT_NE(0, ::android::aidl::compile_aidl(options4, io_delegate_)); |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 393 | TEST_F(AidlTest, StructuredFailOnUnstructuredParcelable) { |
| 394 | io_delegate_.SetFileContents("o/WhoKnowsWhat.aidl", "package o; parcelable WhoKnowsWhat;"); |
| 395 | import_paths_.emplace(""); |
| 396 | AidlError reported_error; |
| 397 | auto parse_result = |
| 398 | Parse("p/IFoo.aidl", |
| 399 | "package p; import o.WhoKnowsWhat; interface IFoo { void f(in WhoKnowsWhat thisIs); }", |
| 400 | &java_types_, &reported_error, {"--structured"}); |
| 401 | EXPECT_EQ(nullptr, parse_result); |
| 402 | EXPECT_EQ(AidlError::NOT_STRUCTURED, reported_error); |
| 403 | } |
| 404 | |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 405 | TEST_F(AidlTest, FailOnDuplicateConstantNames) { |
| 406 | AidlError reported_error; |
| 407 | EXPECT_EQ(nullptr, |
| 408 | Parse("p/IFoo.aidl", |
| 409 | R"(package p; |
| 410 | interface IFoo { |
| 411 | const String DUPLICATED = "d"; |
| 412 | const int DUPLICATED = 1; |
| 413 | } |
| 414 | )", |
| 415 | &cpp_types_, |
| 416 | &reported_error)); |
| Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 417 | EXPECT_EQ(AidlError::BAD_TYPE, reported_error); |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 420 | TEST_F(AidlTest, FailOnManyDefinedTypes) { |
| 421 | AidlError reported_error; |
| 422 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 423 | R"(package p; |
| 424 | interface IFoo {} |
| 425 | parcelable Bar; |
| 426 | parcelable IBar {} |
| 427 | parcelable StructuredParcelable {} |
| 428 | interface IBaz {} |
| 429 | )", |
| 430 | &cpp_types_, &reported_error)); |
| 431 | // Parse success is important for clear error handling even if the cases aren't |
| 432 | // actually supported in code generation. |
| 433 | EXPECT_EQ(AidlError::BAD_TYPE, reported_error); |
| 434 | } |
| 435 | |
| 436 | TEST_F(AidlTest, FailOnNoDefinedTypes) { |
| 437 | AidlError reported_error; |
| 438 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", R"(package p;)", &cpp_types_, &reported_error)); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 439 | EXPECT_EQ(AidlError::PARSE_ERROR, reported_error); |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 442 | TEST_F(AidlTest, FailOnMalformedConstHexValue) { |
| 443 | AidlError reported_error; |
| 444 | EXPECT_EQ(nullptr, |
| 445 | Parse("p/IFoo.aidl", |
| 446 | R"(package p; |
| 447 | interface IFoo { |
| 448 | const int BAD_HEX_VALUE = 0xffffffffffffffffff; |
| 449 | } |
| 450 | )", |
| 451 | &cpp_types_, |
| 452 | &reported_error)); |
| Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 453 | EXPECT_EQ(AidlError::BAD_TYPE, reported_error); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | TEST_F(AidlTest, ParsePositiveConstHexValue) { |
| 457 | AidlError reported_error; |
| 458 | auto cpp_parse_result = |
| 459 | Parse("p/IFoo.aidl", |
| 460 | R"(package p; |
| 461 | interface IFoo { |
| 462 | const int POSITIVE_HEX_VALUE = 0xf5; |
| 463 | } |
| 464 | )", |
| 465 | &cpp_types_, |
| 466 | &reported_error); |
| 467 | EXPECT_NE(nullptr, cpp_parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 468 | const AidlInterface* interface = cpp_parse_result->AsInterface(); |
| 469 | ASSERT_NE(nullptr, interface); |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 470 | const auto& cpp_constants = interface->GetConstantDeclarations(); |
| 471 | EXPECT_EQ((size_t)1, cpp_constants.size()); |
| 472 | EXPECT_EQ("POSITIVE_HEX_VALUE", cpp_constants[0]->GetName()); |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 473 | EXPECT_EQ("245", cpp_constants[0]->ValueString(cpp::ConstantValueDecorator)); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | TEST_F(AidlTest, ParseNegativeConstHexValue) { |
| 477 | AidlError reported_error; |
| 478 | auto cpp_parse_result = |
| 479 | Parse("p/IFoo.aidl", |
| 480 | R"(package p; |
| 481 | interface IFoo { |
| 482 | const int NEGATIVE_HEX_VALUE = 0xffffffff; |
| 483 | } |
| 484 | )", |
| 485 | &cpp_types_, |
| 486 | &reported_error); |
| 487 | EXPECT_NE(nullptr, cpp_parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 488 | const AidlInterface* interface = cpp_parse_result->AsInterface(); |
| 489 | ASSERT_NE(nullptr, interface); |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 490 | const auto& cpp_constants = interface->GetConstantDeclarations(); |
| 491 | EXPECT_EQ((size_t)1, cpp_constants.size()); |
| 492 | EXPECT_EQ("NEGATIVE_HEX_VALUE", cpp_constants[0]->GetName()); |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 493 | EXPECT_EQ("-1", cpp_constants[0]->ValueString(cpp::ConstantValueDecorator)); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 496 | TEST_F(AidlTest, UnderstandsNestedParcelables) { |
| 497 | io_delegate_.SetFileContents( |
| 498 | "p/Outer.aidl", |
| 499 | "package p; parcelable Outer.Inner cpp_header \"baz/header\";"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 500 | import_paths_.emplace(""); |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 501 | const string input_path = "p/IFoo.aidl"; |
| 502 | const string input = "package p; import p.Outer; interface IFoo" |
| 503 | " { Outer.Inner get(); }"; |
| 504 | |
| 505 | auto cpp_parse_result = Parse(input_path, input, &cpp_types_); |
| 506 | EXPECT_NE(nullptr, cpp_parse_result); |
| 507 | auto cpp_type = cpp_types_.FindTypeByCanonicalName("p.Outer.Inner"); |
| 508 | ASSERT_NE(nullptr, cpp_type); |
| 509 | // C++ uses "::" instead of "." to refer to a inner class. |
| 510 | EXPECT_EQ("::p::Outer::Inner", cpp_type->CppType()); |
| 511 | } |
| 512 | |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 513 | TEST_F(AidlTest, UnderstandsNativeParcelables) { |
| 514 | io_delegate_.SetFileContents( |
| 515 | "p/Bar.aidl", |
| Casey Dahlin | cd63921 | 2015-12-15 12:51:04 -0800 | [diff] [blame] | 516 | "package p; parcelable Bar cpp_header \"baz/header\";"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 517 | import_paths_.emplace(""); |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 518 | const string input_path = "p/IFoo.aidl"; |
| 519 | const string input = "package p; import p.Bar; interface IFoo { }"; |
| 520 | |
| 521 | // C++ understands C++ specific stuff |
| 522 | auto cpp_parse_result = Parse(input_path, input, &cpp_types_); |
| 523 | EXPECT_NE(nullptr, cpp_parse_result); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 524 | auto cpp_type = cpp_types_.FindTypeByCanonicalName("p.Bar"); |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 525 | ASSERT_NE(nullptr, cpp_type); |
| Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 526 | EXPECT_EQ("::p::Bar", cpp_type->CppType()); |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 527 | set<string> headers; |
| Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 528 | cpp_type->GetHeaders(&headers); |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 529 | EXPECT_EQ(1u, headers.size()); |
| 530 | EXPECT_EQ(1u, headers.count("baz/header")); |
| 531 | |
| 532 | // Java ignores C++ specific stuff |
| 533 | auto java_parse_result = Parse(input_path, input, &java_types_); |
| 534 | EXPECT_NE(nullptr, java_parse_result); |
| Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 535 | auto java_type = java_types_.FindTypeByCanonicalName("p.Bar"); |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 536 | ASSERT_NE(nullptr, java_type); |
| 537 | EXPECT_EQ("p.Bar", java_type->InstantiableName()); |
| 538 | } |
| 539 | |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 540 | TEST_F(AidlTest, WritesCorrectDependencyFile) { |
| 541 | // While the in tree build system always gives us an output file name, |
| 542 | // other android tools take advantage of our ability to infer the intended |
| 543 | // file name. This test makes sure we handle this correctly. |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 544 | vector<string> args = { |
| 545 | "aidl", |
| 546 | "-d dep/file/path", |
| 547 | "-o place/for/output", |
| 548 | "p/IFoo.aidl"}; |
| 549 | Options options = Options::From(args); |
| 550 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 551 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 552 | string actual_dep_file_contents; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 553 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 554 | EXPECT_EQ(actual_dep_file_contents, kExpectedDepFileContents); |
| 555 | } |
| 556 | |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 557 | TEST_F(AidlTest, WritesCorrectDependencyFileNinja) { |
| 558 | // While the in tree build system always gives us an output file name, |
| 559 | // other android tools take advantage of our ability to infer the intended |
| 560 | // file name. This test makes sure we handle this correctly. |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 561 | vector<string> args = { |
| 562 | "aidl", |
| 563 | "-d dep/file/path", |
| 564 | "--ninja", |
| 565 | "-o place/for/output", |
| 566 | "p/IFoo.aidl"}; |
| 567 | Options options = Options::From(args); |
| 568 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 569 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 570 | string actual_dep_file_contents; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 571 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 572 | EXPECT_EQ(actual_dep_file_contents, kExpectedNinjaDepFileContents); |
| 573 | } |
| 574 | |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 575 | TEST_F(AidlTest, WritesTrivialDependencyFileForParcelable) { |
| 576 | // The SDK uses aidl to decide whether a .aidl file is a parcelable. It does |
| 577 | // this by calling aidl with every .aidl file it finds, then parsing the |
| 578 | // generated dependency files. Those that reference .java output files are |
| 579 | // for interfaces and those that do not are parcelables. However, for both |
| 580 | // parcelables and interfaces, we *must* generate a non-empty dependency file. |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 581 | vector<string> args = { |
| 582 | "aidl", |
| 583 | "-o place/for/output", |
| 584 | "-d dep/file/path", |
| 585 | "p/Foo.aidl"}; |
| 586 | Options options = Options::From(args); |
| 587 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo;"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 588 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 589 | string actual_dep_file_contents; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 590 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 591 | EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDepFileContents); |
| 592 | } |
| 593 | |
| Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 594 | /* not working until type_namespace.h is fixed |
| 595 | TEST_F(AidlTest, AcceptsNestedContainerType) { |
| 596 | string nested_in_iface = "package a; interface IFoo {\n" |
| 597 | " List<int, List<String, bool>> foo(); }"; |
| 598 | string nested_in_parcelable = "package a; parcelable IData {\n" |
| 599 | " List<int, List<String, bool>> foo;}"; |
| 600 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_iface, &java_types_)); |
| 601 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_iface, &cpp_types_)); |
| 602 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_parcelable, &java_types_)); |
| 603 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_parcelable, &cpp_types_)); |
| 604 | } |
| 605 | */ |
| 606 | |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 607 | TEST_F(AidlTest, ApiDump) { |
| 608 | io_delegate_.SetFileContents( |
| 609 | "foo/bar/IFoo.aidl", |
| 610 | "package foo.bar;\n" |
| 611 | "import foo.bar.Data;\n" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 612 | "// comment\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 613 | "interface IFoo {\n" |
| 614 | " int foo(out int[] a, String b, boolean c, inout List<String> d);\n" |
| 615 | " int foo2(@utf8InCpp String x, inout List<String> y);\n" |
| 616 | " IFoo foo3(IFoo foo);\n" |
| 617 | " Data getData();\n" |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 618 | " const int A = 1;\n" |
| 619 | " const String STR = \"Hello\";\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 620 | "}\n"); |
| 621 | io_delegate_.SetFileContents("foo/bar/Data.aidl", |
| 622 | "package foo.bar;\n" |
| 623 | "import foo.bar.IFoo;\n" |
| 624 | "parcelable Data {\n" |
| Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 625 | " int x = 10;\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 626 | " int y;\n" |
| 627 | " IFoo foo;\n" |
| 628 | " List<IFoo> a;\n" |
| 629 | " List<foo.bar.IFoo> b;\n" |
| Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 630 | " @nullable String[] c;\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 631 | "}\n"); |
| 632 | io_delegate_.SetFileContents("api.aidl", ""); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 633 | vector<string> args = {"aidl", "--dumpapi", "--out=dump", "foo/bar/IFoo.aidl", |
| 634 | "foo/bar/Data.aidl"}; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 635 | Options options = Options::From(args); |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 636 | bool result = dump_api(options, io_delegate_); |
| 637 | ASSERT_TRUE(result); |
| 638 | string actual; |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 639 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual)); |
| 640 | EXPECT_EQ(actual, R"(package foo.bar; |
| 641 | interface IFoo { |
| 642 | int foo(out int[] a, String b, boolean c, inout List<String> d); |
| 643 | int foo2(@utf8InCpp String x, inout List<String> y); |
| 644 | foo.bar.IFoo foo3(foo.bar.IFoo foo); |
| 645 | foo.bar.Data getData(); |
| 646 | const int A = 1; |
| 647 | const String STR = "Hello"; |
| 648 | } |
| 649 | )"); |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 650 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 651 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/Data.aidl", &actual)); |
| 652 | EXPECT_EQ(actual, R"(package foo.bar; |
| 653 | parcelable Data { |
| 654 | int x = 10; |
| 655 | int y; |
| 656 | foo.bar.IFoo foo; |
| 657 | List<foo.bar.IFoo> a; |
| 658 | List<foo.bar.IFoo> b; |
| Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 659 | @nullable String[] c; |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 660 | } |
| 661 | )"); |
| 662 | } |
| 663 | |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 664 | TEST_F(AidlTest, ApiDumpWithManualIds) { |
| 665 | io_delegate_.SetFileContents( |
| 666 | "foo/bar/IFoo.aidl", |
| 667 | "package foo.bar;\n" |
| 668 | "interface IFoo {\n" |
| 669 | " int foo() = 1;\n" |
| 670 | " int bar() = 2;\n" |
| 671 | " int baz() = 10;\n" |
| 672 | "}\n"); |
| 673 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 674 | vector<string> args = {"aidl", "--dumpapi", "-o dump", "foo/bar/IFoo.aidl"}; |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 675 | Options options = Options::From(args); |
| 676 | bool result = dump_api(options, io_delegate_); |
| 677 | ASSERT_TRUE(result); |
| 678 | string actual; |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 679 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual)); |
| 680 | EXPECT_EQ(actual, R"(package foo.bar; |
| 681 | interface IFoo { |
| 682 | int foo() = 1; |
| 683 | int bar() = 2; |
| 684 | int baz() = 10; |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 685 | } |
| 686 | )"); |
| 687 | } |
| 688 | |
| 689 | TEST_F(AidlTest, ApiDumpWithManualIdsOnlyOnSomeMethods) { |
| 690 | io_delegate_.SetFileContents( |
| 691 | "foo/bar/IFoo.aidl", |
| 692 | "package foo.bar;\n" |
| 693 | "interface IFoo {\n" |
| 694 | " int foo() = 1;\n" |
| 695 | " int bar();\n" |
| 696 | " int baz() = 10;\n" |
| 697 | "}\n"); |
| 698 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 699 | vector<string> args = {"aidl", "--dumpapi", "-o dump", "foo/bar/IFoo.aidl"}; |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 700 | Options options = Options::From(args); |
| 701 | EXPECT_FALSE(dump_api(options, io_delegate_)); |
| 702 | } |
| 703 | |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 704 | TEST_F(AidlTest, CheckNumGenericTypeSecifier) { |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 705 | Options options = Options::From("aidl p/IFoo.aidl IFoo.java"); |
| 706 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 707 | "package p; interface IFoo {" |
| 708 | "void foo(List<String, String> a);}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 709 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 710 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 711 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 712 | "package p; interface IFoo {" |
| 713 | "void foo(Map<String> a);}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 714 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 715 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 716 | Options options2 = Options::From("aidl p/Data.aidl Data.java"); |
| 717 | io_delegate_.SetFileContents(options2.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 718 | "package p; parcelable Data {" |
| 719 | "List<String, String> foo;}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 720 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 721 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 722 | io_delegate_.SetFileContents(options2.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 723 | "package p; parcelable Data {" |
| 724 | "Map<String> foo;}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 725 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
| 726 | } |
| 727 | |
| 728 | TEST_F(AidlTest, MultipleTypesInSingleFile) { |
| 729 | Options options = Options::From("aidl --lang=java -o out foo/bar/Foo.aidl"); |
| 730 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 731 | "package foo.bar;\n" |
| 732 | "interface IFoo1 { int foo(); }\n" |
| 733 | "interface IFoo2 { int foo(); }\n" |
| 734 | "parcelable Data { int a; int b;}\n"); |
| 735 | |
| 736 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 737 | |
| 738 | string content; |
| 739 | for (const auto file : |
| 740 | {"out/foo/bar/IFoo1.java", "out/foo/bar/IFoo2.java", "out/foo/bar/Data.java"}) { |
| 741 | content.clear(); |
| 742 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 743 | EXPECT_FALSE(content.empty()); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | TEST_F(AidlTest, MultipleTypesInSingleFileCpp) { |
| 748 | Options options = Options::From("aidl --lang=cpp -o out -h out/include foo/bar/Foo.aidl"); |
| 749 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 750 | "package foo.bar;\n" |
| 751 | "interface IFoo1 { int foo(); }\n" |
| 752 | "interface IFoo2 { int foo(); }\n" |
| 753 | "parcelable Data { int a; int b;}\n"); |
| 754 | |
| 755 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 756 | |
| 757 | string content; |
| 758 | for (const auto file : { |
| Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 759 | "out/foo/bar/IFoo1.cpp", "out/foo/bar/IFoo2.cpp", "out/foo/bar/Data.cpp", |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 760 | "out/include/foo/bar/IFoo1.h", "out/include/foo/bar/IFoo2.h", "out/include/foo/bar/Data.h", |
| 761 | "out/include/foo/bar/BpFoo1.h", "out/include/foo/bar/BpFoo2.h", "out/include/foo/bar/BpData.h", |
| 762 | "out/include/foo/bar/BnFoo1.h", "out/include/foo/bar/BnFoo2.h", "out/include/foo/bar/BnData.h"}) { |
| 763 | content.clear(); |
| 764 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 765 | EXPECT_FALSE(content.empty()); |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | TEST_F(AidlTest, MultipleInputFiles) { |
| 770 | Options options = Options::From( |
| 771 | "aidl --lang=java -o out foo/bar/IFoo.aidl foo/bar/Data.aidl"); |
| 772 | |
| 773 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 774 | "package foo.bar;\n" |
| 775 | "import foo.bar.Data;\n" |
| 776 | "interface IFoo { Data getData(); }\n"); |
| 777 | |
| 778 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 779 | "package foo.bar;\n" |
| 780 | "import foo.bar.IFoo;\n" |
| 781 | "parcelable Data { IFoo foo; }\n"); |
| 782 | |
| 783 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 784 | |
| 785 | string content; |
| 786 | for (const auto file : { |
| 787 | "out/foo/bar/IFoo.java", "out/foo/bar/Data.java"}) { |
| 788 | content.clear(); |
| 789 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 790 | EXPECT_FALSE(content.empty()); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | TEST_F(AidlTest, MultipleInputFilesCpp) { |
| 795 | Options options = Options::From("aidl --lang=cpp -o out -h out/include " |
| 796 | "foo/bar/IFoo.aidl foo/bar/Data.aidl"); |
| 797 | |
| 798 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 799 | "package foo.bar;\n" |
| 800 | "import foo.bar.Data;\n" |
| 801 | "interface IFoo { Data getData(); }\n"); |
| 802 | |
| 803 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 804 | "package foo.bar;\n" |
| 805 | "import foo.bar.IFoo;\n" |
| 806 | "parcelable Data { IFoo foo; }\n"); |
| 807 | |
| 808 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 809 | |
| 810 | string content; |
| 811 | for (const auto file : { |
| Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 812 | "out/foo/bar/IFoo.cpp", "out/foo/bar/Data.cpp", |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 813 | "out/include/foo/bar/IFoo.h", "out/include/foo/bar/Data.h", |
| 814 | "out/include/foo/bar/BpFoo.h", "out/include/foo/bar/BpData.h", |
| 815 | "out/include/foo/bar/BnFoo.h", "out/include/foo/bar/BnData.h"}) { |
| 816 | content.clear(); |
| 817 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 818 | EXPECT_FALSE(content.empty()); |
| 819 | } |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 820 | } |
| 821 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 822 | TEST_F(AidlTest, ConflictWithMetaTransactions) { |
| 823 | Options options = Options::From("aidl --lang=java -o place/for/output p/IFoo.aidl"); |
| 824 | // int getInterfaceVersion() is one of the meta transactions |
| 825 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 826 | "package p; interface IFoo {" |
| 827 | "int getInterfaceVersion(); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 828 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 829 | |
| 830 | // boolean getInterfaceVersion() is not, but should be prevented |
| 831 | // because return type is not part of a method signature |
| 832 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 833 | "package p; interface IFoo {" |
| 834 | "boolean getInterfaceVersion(); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 835 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 836 | |
| 837 | // this is another reserved name |
| 838 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 839 | "package p; interface IFoo {" |
| 840 | "String getTransactionName(int code); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 841 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 842 | |
| 843 | // this is not a meta interface method as it differs type arguments |
| 844 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 845 | "package p; interface IFoo {" |
| 846 | "String getTransactionName(); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 847 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 848 | } |
| 849 | |
| Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 850 | TEST_F(AidlTest, DiffrentOrderAnnotationsInCheckAPI) { |
| 851 | Options options = Options::From("aidl --checkapi old new"); |
| 852 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 853 | "package p; interface IFoo{ @utf8InCpp @nullable String foo();}"); |
| 854 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 855 | "package p; interface IFoo{ @nullable @utf8InCpp String foo();}"); |
| 856 | |
| 857 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 858 | } |
| 859 | |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 860 | TEST_F(AidlTest, SuccessOnIdenticalApiDumps) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 861 | Options options = Options::From("aidl --checkapi old new"); |
| 862 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo();}"); |
| 863 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{ void foo();}"); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 864 | |
| 865 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 866 | } |
| 867 | |
| 868 | TEST_F(AidlTest, SuccessOnCompatibleChanges) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 869 | Options options = Options::From("aidl --checkapi old new"); |
| 870 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 871 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 872 | "interface IFoo {" |
| 873 | " void foo(int a);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 874 | "}"); |
| 875 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 876 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 877 | "parcelable Data {" |
| 878 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 879 | "}"); |
| 880 | |
| 881 | // new type |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 882 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 883 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 884 | "interface IFoo {" |
| 885 | " void foo(int a);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 886 | "}"); |
| 887 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 888 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 889 | "parcelable Data {" |
| 890 | " int foo;" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 891 | "}"); |
| 892 | io_delegate_.SetFileContents("new/p/IBar.aidl", |
| 893 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 894 | "interface IBar {" |
| 895 | " void bar();" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 896 | "}"); |
| 897 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 898 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 899 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| 900 | io_delegate_.SetFileContents("new/p/IBar.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 901 | |
| 902 | // new method |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 903 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 904 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 905 | "interface IFoo {" |
| 906 | " void foo(int a);" |
| 907 | " void bar();" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 908 | "}"); |
| 909 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 910 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 911 | "parcelable Data {" |
| 912 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 913 | "}"); |
| 914 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 915 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 916 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 917 | |
| 918 | // new field |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 919 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 920 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 921 | "interface IFoo {" |
| 922 | " void foo(int a);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 923 | "}"); |
| 924 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 925 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 926 | "parcelable Data {" |
| 927 | " int foo;" |
| 928 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 929 | "}"); |
| 930 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 931 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 932 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 933 | |
| 934 | // new package |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 935 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 936 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 937 | "interface IFoo {" |
| 938 | " void foo(int a);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 939 | "}"); |
| 940 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 941 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 942 | "parcelable Data {" |
| 943 | " int foo;" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 944 | "}"); |
| 945 | io_delegate_.SetFileContents("new/q/IFoo.aidl", |
| 946 | "package q;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 947 | "interface IFoo {" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 948 | " void foo(int a);" |
| 949 | "}"); |
| 950 | io_delegate_.SetFileContents("new/q/Data.aidl", |
| 951 | "package q;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 952 | "parcelable Data {" |
| 953 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 954 | "}"); |
| 955 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 956 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 957 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| 958 | io_delegate_.SetFileContents("new/q/IFoo.aidl", ""); |
| 959 | io_delegate_.SetFileContents("new/q/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 960 | |
| 961 | // arg name change |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 962 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 963 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 964 | "interface IFoo {" |
| 965 | " void foo(int b);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 966 | "}"); |
| 967 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 968 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 969 | "parcelable Data {" |
| 970 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 971 | "}"); |
| 972 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 973 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 974 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| 975 | |
| 976 | io_delegate_.SetFileContents("old/p/IFoo.aidl", ""); |
| 977 | io_delegate_.SetFileContents("old/p/Data.aidl", ""); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 978 | |
| 979 | // added const value |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 980 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 981 | "package p; interface I {" |
| 982 | "const int A = 1; }"); |
| 983 | io_delegate_.SetFileContents("new/p/I.aidl", |
| 984 | "package p ; interface I {" |
| 985 | "const int A = 1; const int B = 2;}"); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 986 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 987 | io_delegate_.SetFileContents("old/p/I.aidl", ""); |
| 988 | io_delegate_.SetFileContents("new/p/I.aidl", ""); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 989 | |
| 990 | // changed const value order |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 991 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 992 | "package p; interface I {" |
| 993 | "const int A = 1; const int B = 2;}"); |
| 994 | io_delegate_.SetFileContents("new/p/I.aidl", |
| 995 | "package p ; interface I {" |
| 996 | "const int B = 2; const int A = 1;}"); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 997 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | TEST_F(AidlTest, FailOnIncompatibleChanges) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1001 | Options options = Options::From("aidl --checkapi old new"); |
| 1002 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1003 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1004 | "interface IFoo {" |
| 1005 | " void foo(in String[] str);" |
| 1006 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1007 | "}"); |
| 1008 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1009 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1010 | "parcelable Data {" |
| 1011 | " int foo;" |
| 1012 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1013 | "}"); |
| 1014 | |
| 1015 | // removed type |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1016 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1017 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1018 | "interface IFoo {" |
| 1019 | " void foo(in String[] str);" |
| 1020 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1021 | "}"); |
| 1022 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1023 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1024 | |
| 1025 | // removed method |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1026 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1027 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1028 | "interface IFoo {" |
| 1029 | " void foo(in String[] str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1030 | "}"); |
| 1031 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1032 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1033 | "parcelable Data {" |
| 1034 | " int foo;" |
| 1035 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1036 | "}"); |
| 1037 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1038 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1039 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1040 | |
| 1041 | // removed field |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1042 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1043 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1044 | "interface IFoo {" |
| 1045 | " void foo(in String[] str);" |
| 1046 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1047 | "}"); |
| 1048 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1049 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1050 | "parcelable Data {" |
| 1051 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1052 | "}"); |
| 1053 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1054 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1055 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1056 | |
| 1057 | // renamed method |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1058 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1059 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1060 | "interface IFoo {" |
| 1061 | " void foo(in String[] str);" |
| 1062 | " void bar2(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1063 | "}"); |
| 1064 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1065 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1066 | "parcelable Data {" |
| 1067 | " int foo;" |
| 1068 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1069 | "}"); |
| 1070 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1071 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1072 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1073 | |
| 1074 | // renamed field |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1075 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1076 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1077 | "interface IFoo {" |
| 1078 | " void foo(in String[] str);" |
| 1079 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1080 | "}"); |
| 1081 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1082 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1083 | "parcelable Data {" |
| 1084 | " int foo;" |
| 1085 | " int bar2;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1086 | "}"); |
| 1087 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1088 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1089 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1090 | |
| 1091 | // renamed type |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1092 | io_delegate_.SetFileContents("new/p/IFoo2.aidl", |
| 1093 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1094 | "interface IFoo2 {" |
| 1095 | " void foo(in String[] str);" |
| 1096 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1097 | "}"); |
| 1098 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1099 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1100 | "parcelable Data {" |
| 1101 | " int foo;" |
| 1102 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1103 | "}"); |
| 1104 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1105 | io_delegate_.SetFileContents("new/p/IFoo2.aidl", ""); |
| 1106 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1107 | |
| 1108 | // reorderd method |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1109 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1110 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1111 | "interface IFoo {" |
| 1112 | " void bar(@utf8InCpp String str);" |
| 1113 | " void foo(in String[] str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1114 | "}"); |
| 1115 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1116 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1117 | "parcelable Data {" |
| 1118 | " int foo;" |
| 1119 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1120 | "}"); |
| 1121 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1122 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1123 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1124 | |
| 1125 | // reorderd field |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1126 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1127 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1128 | "interface IFoo {" |
| 1129 | " void foo(in String[] str);" |
| 1130 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1131 | "}"); |
| 1132 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1133 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1134 | "parcelable Data {" |
| 1135 | " int bar;" |
| 1136 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1137 | "}"); |
| 1138 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1139 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1140 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1141 | |
| 1142 | // changed direction specifier |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1143 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1144 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1145 | "interface IFoo {" |
| 1146 | " void foo(out String[] str);" |
| 1147 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1148 | "}"); |
| 1149 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1150 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1151 | "parcelable Data {" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1152 | " int foo;" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1153 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1154 | "}"); |
| 1155 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1156 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1157 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1158 | |
| 1159 | // added annotation |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1160 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1161 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1162 | "interface IFoo {" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1163 | " void foo(in @utf8InCpp String[] str);" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1164 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1165 | "}"); |
| 1166 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1167 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1168 | "parcelable Data {" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1169 | " int foo;" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1170 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1171 | "}"); |
| 1172 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1173 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1174 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1175 | |
| 1176 | // removed annotation |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1177 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1178 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1179 | "interface IFoo {" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1180 | " void foo(in String[] str);" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1181 | " void bar(String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1182 | "}"); |
| 1183 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1184 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1185 | "parcelable Data {" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1186 | " int foo;" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1187 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1188 | "}"); |
| 1189 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1190 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1191 | io_delegate_.SetFileContents("new/p/Data.aidl", ""); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1192 | |
| 1193 | // removed package |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1194 | io_delegate_.SetFileContents("old/p/Data.aidl", ""); |
| 1195 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{}"); |
| 1196 | io_delegate_.SetFileContents("old/q/IFoo.aidl", "package q; interface IFoo{}"); |
| 1197 | |
| 1198 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{}"); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1199 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1200 | io_delegate_.SetFileContents("old/p/IFoo.aidl", ""); |
| 1201 | io_delegate_.SetFileContents("old/q/IFoo.aidl", ""); |
| 1202 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 1203 | |
| 1204 | // changed default value |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1205 | io_delegate_.SetFileContents("old/p/D.aidl", "package p; parcelable D { int a = 1; }"); |
| 1206 | io_delegate_.SetFileContents("new/p/D.aidl", "package p; parcelable D { int a = 2; }"); |
| Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 1207 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1208 | io_delegate_.SetFileContents("old/p/D.aidl", ""); |
| 1209 | io_delegate_.SetFileContents("new/p/D.aidl", ""); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1210 | |
| 1211 | // removed const value |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1212 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 1213 | "package p; interface I {" |
| 1214 | "const int A = 1; const int B = 2;}"); |
| 1215 | io_delegate_.SetFileContents("new/p/I.aidl", "package p; interface I { const int A = 1; }"); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1216 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1217 | io_delegate_.SetFileContents("old/p/I.aidl", ""); |
| 1218 | io_delegate_.SetFileContents("new/p/I.aidl", ""); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1219 | |
| 1220 | // changed const value |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1221 | io_delegate_.SetFileContents("old/p/I.aidl", "package p; interface I { const int A = 1; }"); |
| 1222 | io_delegate_.SetFileContents("new/p/I.aidl", "package p; interface I { const int A = 2; }"); |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1223 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1224 | io_delegate_.SetFileContents("old/p/I.aidl", ""); |
| 1225 | io_delegate_.SetFileContents("new/p/I.aidl", ""); |
| Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 1226 | } |
| 1227 | |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 1228 | TEST_F(AidlTest, RejectAmbiguousImports) { |
| 1229 | Options options = Options::From("aidl --lang=java -o out -I dir1 -I dir2 p/IFoo.aidl"); |
| 1230 | io_delegate_.SetFileContents("p/IFoo.aidl", "package p; import q.IBar; interface IFoo{}"); |
| 1231 | io_delegate_.SetFileContents("dir1/q/IBar.aidl", "package q; interface IBar{}"); |
| 1232 | io_delegate_.SetFileContents("dir2/q/IBar.aidl", "package q; interface IBar{}"); |
| 1233 | |
| 1234 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1235 | } |
| 1236 | |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1237 | TEST_F(AidlTest, HandleManualIdAssignments) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1238 | Options options = Options::From("aidl --checkapi old new"); |
| 1239 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo() = 10;}"); |
| 1240 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{ void foo() = 10;}"); |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1241 | |
| 1242 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 1243 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1244 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{ void foo() = 11;}"); |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1245 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| 1246 | } |
| 1247 | |
| Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 1248 | TEST_F(AidlTest, ParcelFileDescriptorIsBuiltinType) { |
| 1249 | Options javaOptions = Options::From("aidl --lang=java -o out p/IFoo.aidl"); |
| 1250 | Options cppOptions = Options::From("aidl --lang=cpp -h out -o out p/IFoo.aidl"); |
| 1251 | |
| 1252 | // use without import |
| 1253 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1254 | "package p; interface IFoo{ void foo(in ParcelFileDescriptor fd);}"); |
| 1255 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 1256 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
| 1257 | |
| 1258 | // use without impot but with full name |
| 1259 | io_delegate_.SetFileContents( |
| 1260 | "p/IFoo.aidl", |
| 1261 | "package p; interface IFoo{ void foo(in android.os.ParcelFileDescriptor fd);}"); |
| 1262 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 1263 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
| 1264 | |
| 1265 | // use with import (as before) |
| 1266 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1267 | "package p;" |
| 1268 | "import android.os.ParcelFileDescriptor;" |
| 1269 | "interface IFoo{" |
| 1270 | " void foo(in ParcelFileDescriptor fd);" |
| 1271 | "}"); |
| 1272 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 1273 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
| 1274 | } |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1275 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 1276 | } // namespace aidl |
| 1277 | } // namespace android |