| 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" |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 29 | #include "aidl_to_java.h" |
| 30 | #include "options.h" |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 31 | #include "tests/fake_io_delegate.h" |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 32 | |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 33 | using android::aidl::internals::parse_preprocessed_file; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 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; |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 40 | using testing::internal::CaptureStderr; |
| 41 | using testing::internal::GetCapturedStderr; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 42 | |
| 43 | namespace android { |
| 44 | namespace aidl { |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 45 | namespace { |
| 46 | |
| 47 | const char kExpectedDepFileContents[] = |
| 48 | R"(place/for/output/p/IFoo.java : \ |
| 49 | p/IFoo.aidl |
| 50 | |
| 51 | p/IFoo.aidl : |
| 52 | )"; |
| 53 | |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 54 | const char kExpectedNinjaDepFileContents[] = |
| 55 | R"(place/for/output/p/IFoo.java : \ |
| 56 | p/IFoo.aidl |
| 57 | )"; |
| 58 | |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 59 | const char kExpectedParcelableDepFileContents[] = |
| Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 60 | R"(place/for/output/p/Foo.java : \ |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 61 | p/Foo.aidl |
| 62 | |
| 63 | p/Foo.aidl : |
| 64 | )"; |
| 65 | |
| Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 66 | const char kExpectedJavaParcelableOutputContests[] = |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 67 | R"(/* |
| 68 | * This file is auto-generated. DO NOT MODIFY. |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 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 | |
| Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 78 | @dalvik.annotation.compat.UnsupportedAppUsage(expectedSignature = "dummy", implicitMember = "dummy", maxTargetSdk = 28, publicAlternatives = "dummy", trackingBug = 42) |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 79 | @android.annotation.SystemApi |
| 80 | public int y; |
| Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 81 | |
| 82 | public android.os.ParcelFileDescriptor fd; |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 83 | public static final android.os.Parcelable.Creator<Rect> CREATOR = new android.os.Parcelable.Creator<Rect>() { |
| 84 | @Override |
| 85 | public Rect createFromParcel(android.os.Parcel _aidl_source) { |
| 86 | Rect _aidl_out = new Rect(); |
| 87 | _aidl_out.readFromParcel(_aidl_source); |
| 88 | return _aidl_out; |
| 89 | } |
| 90 | @Override |
| 91 | public Rect[] newArray(int _aidl_size) { |
| 92 | return new Rect[_aidl_size]; |
| 93 | } |
| 94 | }; |
| 95 | @Override public final void writeToParcel(android.os.Parcel _aidl_parcel, int _aidl_flag) |
| 96 | { |
| 97 | int _aidl_start_pos = _aidl_parcel.dataPosition(); |
| 98 | _aidl_parcel.writeInt(0); |
| 99 | _aidl_parcel.writeInt(x); |
| 100 | _aidl_parcel.writeInt(y); |
| Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 101 | if ((fd!=null)) { |
| 102 | _aidl_parcel.writeInt(1); |
| 103 | fd.writeToParcel(_aidl_parcel, 0); |
| 104 | } |
| 105 | else { |
| 106 | _aidl_parcel.writeInt(0); |
| 107 | } |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 108 | int _aidl_end_pos = _aidl_parcel.dataPosition(); |
| 109 | _aidl_parcel.setDataPosition(_aidl_start_pos); |
| 110 | _aidl_parcel.writeInt(_aidl_end_pos - _aidl_start_pos); |
| 111 | _aidl_parcel.setDataPosition(_aidl_end_pos); |
| 112 | } |
| 113 | public final void readFromParcel(android.os.Parcel _aidl_parcel) |
| 114 | { |
| 115 | int _aidl_start_pos = _aidl_parcel.dataPosition(); |
| 116 | int _aidl_parcelable_size = _aidl_parcel.readInt(); |
| 117 | if (_aidl_parcelable_size < 0) return; |
| 118 | try { |
| 119 | x = _aidl_parcel.readInt(); |
| 120 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
| 121 | y = _aidl_parcel.readInt(); |
| 122 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
| Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 123 | if ((0!=_aidl_parcel.readInt())) { |
| 124 | fd = android.os.ParcelFileDescriptor.CREATOR.createFromParcel(_aidl_parcel); |
| 125 | } |
| 126 | else { |
| 127 | fd = null; |
| 128 | } |
| 129 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 130 | } finally { |
| 131 | _aidl_parcel.setDataPosition(_aidl_start_pos + _aidl_parcelable_size); |
| 132 | } |
| 133 | } |
| 134 | @Override public int describeContents() |
| 135 | { |
| Jeongik Cha | 372a8c8 | 2018-12-12 16:31:11 +0900 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 138 | } |
| 139 | )"; |
| 140 | |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 141 | } // namespace |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 142 | |
| 143 | class AidlTest : public ::testing::Test { |
| 144 | protected: |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 145 | void SetUp() override { |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 146 | CaptureStderr(); |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 149 | void TearDown() override { |
| 150 | auto actual_stderr = GetCapturedStderr(); |
| 151 | if (expected_stderr_.size() > 0) { |
| 152 | EXPECT_EQ(android::base::Join(expected_stderr_, ""), actual_stderr); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void AddExpectedStderr(string expected) { expected_stderr_.push_back(expected); } |
| 157 | |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 158 | AidlDefinedType* Parse(const string& path, const string& contents, AidlTypenames& typenames_, |
| 159 | Options::Language lang, AidlError* error = nullptr, |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 160 | const vector<string> additional_arguments = {}) { |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 161 | io_delegate_.SetFileContents(path, contents); |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 162 | vector<string> args; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 163 | if (lang == Options::Language::CPP) { |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 164 | args.emplace_back("aidl-cpp"); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 165 | } else { |
| 166 | args.emplace_back("aidl"); |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 167 | } |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 168 | for (const string& s : additional_arguments) { |
| 169 | args.emplace_back(s); |
| 170 | } |
| 171 | for (const string& f : preprocessed_files_) { |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 172 | args.emplace_back("--preprocessed=" + f); |
| 173 | } |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 174 | for (const string& i : import_paths_) { |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 175 | args.emplace_back("--include=" + i); |
| 176 | } |
| 177 | args.emplace_back(path); |
| 178 | Options options = Options::From(args); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 179 | vector<AidlDefinedType*> defined_types; |
| 180 | vector<string> imported_files; |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 181 | ImportResolver import_resolver{io_delegate_, path, import_paths_, {}}; |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 182 | AidlError actual_error = ::android::aidl::internals::load_and_validate_aidl( |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 183 | path, options, io_delegate_, &typenames_, &defined_types, &imported_files); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 184 | |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 185 | if (error != nullptr) { |
| 186 | *error = actual_error; |
| 187 | } |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 188 | |
| 189 | if (actual_error != AidlError::OK) { |
| 190 | return nullptr; |
| 191 | } |
| 192 | |
| 193 | EXPECT_EQ(1ul, defined_types.size()); |
| 194 | |
| 195 | return defined_types.front(); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 196 | } |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 197 | |
| 198 | FakeIoDelegate io_delegate_; |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 199 | vector<string> preprocessed_files_; |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 200 | set<string> import_paths_; |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 201 | vector<string> expected_stderr_; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 202 | AidlTypenames typenames_; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 205 | TEST_F(AidlTest, AcceptMissingPackage) { |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 206 | EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { }", typenames_, Options::Language::JAVA)); |
| 207 | typenames_.Reset(); |
| 208 | EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { }", typenames_, Options::Language::CPP)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| Steven Moreland | 9c2988f | 2019-07-17 17:49:10 -0700 | [diff] [blame] | 211 | TEST_F(AidlTest, EndsInSingleLineComment) { |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 212 | EXPECT_NE(nullptr, |
| 213 | Parse("IFoo.aidl", "interface IFoo { } // foo", typenames_, Options::Language::JAVA)); |
| 214 | typenames_.Reset(); |
| 215 | EXPECT_NE(nullptr, |
| 216 | Parse("IFoo.aidl", "interface IFoo { } // foo", typenames_, Options::Language::CPP)); |
| Steven Moreland | 9c2988f | 2019-07-17 17:49:10 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 219 | TEST_F(AidlTest, RejectsArraysOfBinders) { |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 220 | import_paths_.emplace(""); |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 221 | io_delegate_.SetFileContents("bar/IBar.aidl", |
| 222 | "package bar; interface IBar {}"); |
| 223 | string path = "foo/IFoo.aidl"; |
| 224 | string contents = "package foo;\n" |
| 225 | "import bar.IBar;\n" |
| 226 | "interface IFoo { void f(in IBar[] input); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 227 | EXPECT_EQ(nullptr, Parse(path, contents, typenames_, Options::Language::JAVA)); |
| 228 | typenames_.Reset(); |
| 229 | EXPECT_EQ(nullptr, Parse(path, contents, typenames_, Options::Language::CPP)); |
| Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| Jeongik Cha | a2080bf | 2019-06-18 16:44:29 +0900 | [diff] [blame] | 232 | TEST_F(AidlTest, SupportOnlyOutParameters) { |
| Jeongik Cha | a2080bf | 2019-06-18 16:44:29 +0900 | [diff] [blame] | 233 | string interface_list = "package a; interface IBar { void f(out List bar); }"; |
| 234 | string interface_ibinder = "package a; interface IBaz { void f(out IBinder bar); }"; |
| Jeongik Cha | a2080bf | 2019-06-18 16:44:29 +0900 | [diff] [blame] | 235 | // List without type isn't supported in cpp. |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 236 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", interface_list, typenames_, Options::Language::CPP)); |
| 237 | typenames_.Reset(); |
| 238 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", interface_list, typenames_, Options::Language::JAVA)); |
| 239 | typenames_.Reset(); |
| 240 | EXPECT_EQ(nullptr, Parse("a/IBaz.aidl", interface_ibinder, typenames_, Options::Language::CPP)); |
| 241 | typenames_.Reset(); |
| 242 | EXPECT_EQ(nullptr, Parse("a/IBaz.aidl", interface_ibinder, typenames_, Options::Language::JAVA)); |
| Jeongik Cha | a2080bf | 2019-06-18 16:44:29 +0900 | [diff] [blame] | 243 | } |
| 244 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 245 | TEST_F(AidlTest, RejectsOnewayOutParameters) { |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 246 | string oneway_interface = |
| 247 | "package a; oneway interface IFoo { void f(out int bar); }"; |
| 248 | string oneway_method = |
| 249 | "package a; interface IBar { oneway void f(out int bar); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 250 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_interface, typenames_, Options::Language::CPP)); |
| 251 | typenames_.Reset(); |
| 252 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_interface, typenames_, Options::Language::JAVA)); |
| 253 | typenames_.Reset(); |
| 254 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_method, typenames_, Options::Language::CPP)); |
| 255 | typenames_.Reset(); |
| 256 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_method, typenames_, Options::Language::JAVA)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | TEST_F(AidlTest, RejectsOnewayNonVoidReturn) { |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 260 | string oneway_method = "package a; interface IFoo { oneway int f(); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 261 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::CPP)); |
| 262 | typenames_.Reset(); |
| 263 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::JAVA)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 266 | TEST_F(AidlTest, RejectsNullablePrimitive) { |
| 267 | string oneway_method = "package a; interface IFoo { @nullable int f(); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 268 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::CPP)); |
| 269 | typenames_.Reset(); |
| 270 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::JAVA)); |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| Steven Moreland | b3cd3c7 | 2018-10-11 12:37:45 -0700 | [diff] [blame] | 273 | TEST_F(AidlTest, RejectsDuplicatedArgumentNames) { |
| 274 | string method = "package a; interface IFoo { void f(int a, int a); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 275 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, Options::Language::CPP)); |
| 276 | typenames_.Reset(); |
| 277 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, Options::Language::JAVA)); |
| Steven Moreland | b3cd3c7 | 2018-10-11 12:37:45 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 280 | TEST_F(AidlTest, RejectsDuplicatedAnnotationParams) { |
| 281 | string method = "package a; interface IFoo { @UnsupportedAppUsage(foo=1, foo=2)void f(); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 282 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, Options::Language::CPP)); |
| 283 | typenames_.Reset(); |
| 284 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, Options::Language::JAVA)); |
| Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 287 | TEST_F(AidlTest, ParsesNullableAnnotation) { |
| 288 | for (auto is_nullable: {true, false}) { |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 289 | auto parse_result = Parse("a/IFoo.aidl", |
| 290 | StringPrintf("package a; interface IFoo {%s String f(); }", |
| 291 | (is_nullable) ? "@nullable" : ""), |
| 292 | typenames_, Options::Language::CPP); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 293 | ASSERT_NE(nullptr, parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 294 | const AidlInterface* interface = parse_result->AsInterface(); |
| 295 | ASSERT_NE(nullptr, interface); |
| 296 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 297 | EXPECT_EQ(interface->GetMethods()[0]->GetType().IsNullable(), is_nullable); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 298 | typenames_.Reset(); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | TEST_F(AidlTest, ParsesUtf8Annotations) { |
| 303 | for (auto is_utf8: {true, false}) { |
| 304 | auto parse_result = Parse( |
| 305 | "a/IFoo.aidl", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 306 | StringPrintf("package a; interface IFoo {%s String f(); }", (is_utf8) ? "@utf8InCpp" : ""), |
| 307 | typenames_, Options::Language::CPP); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 308 | ASSERT_NE(nullptr, parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 309 | const AidlInterface* interface = parse_result->AsInterface(); |
| 310 | ASSERT_NE(nullptr, interface); |
| 311 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 312 | EXPECT_EQ(interface->GetMethods()[0]->GetType().IsUtf8InCpp(), is_utf8); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 313 | typenames_.Reset(); |
| Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 317 | TEST_F(AidlTest, VintfRequiresStructuredAndStability) { |
| 318 | AidlError error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 319 | auto parse_result = Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
| 320 | Options::Language::CPP, &error); |
| Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 321 | ASSERT_EQ(AidlError::NOT_STRUCTURED, error); |
| 322 | ASSERT_EQ(nullptr, parse_result); |
| 323 | } |
| 324 | |
| 325 | TEST_F(AidlTest, VintfRequiresStructured) { |
| 326 | AidlError error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 327 | auto parse_result = Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
| 328 | Options::Language::CPP, &error, {"--stability", "vintf"}); |
| Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 329 | ASSERT_EQ(AidlError::NOT_STRUCTURED, error); |
| 330 | ASSERT_EQ(nullptr, parse_result); |
| 331 | } |
| 332 | |
| 333 | TEST_F(AidlTest, VintfRequiresSpecifiedStability) { |
| 334 | AidlError error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 335 | auto parse_result = Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
| 336 | Options::Language::CPP, &error, {"--structured"}); |
| Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 337 | ASSERT_EQ(AidlError::NOT_STRUCTURED, error); |
| 338 | ASSERT_EQ(nullptr, parse_result); |
| 339 | } |
| 340 | |
| 341 | TEST_F(AidlTest, ParsesStabilityAnnotations) { |
| 342 | AidlError error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 343 | auto parse_result = |
| 344 | Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, Options::Language::CPP, |
| 345 | &error, {"--structured", "--stability", "vintf"}); |
| Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 346 | ASSERT_EQ(AidlError::OK, error); |
| 347 | ASSERT_NE(nullptr, parse_result); |
| 348 | const AidlInterface* interface = parse_result->AsInterface(); |
| 349 | ASSERT_NE(nullptr, interface); |
| 350 | ASSERT_TRUE(interface->IsVintfStability()); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 351 | typenames_.Reset(); |
| Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 354 | TEST_F(AidlTest, ParsesJavaOnlyStableParcelable) { |
| 355 | Options java_options = Options::From("aidl -o out --structured a/Foo.aidl"); |
| 356 | Options cpp_options = |
| 357 | Options::From("aidl --lang=cpp --structured -o out -h out/include a/Foo.aidl"); |
| 358 | io_delegate_.SetFileContents( |
| 359 | "a/Foo.aidl", StringPrintf("package a; @JavaOnlyStableParcelable parcelable Foo;")); |
| 360 | |
| 361 | EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 362 | AddExpectedStderr( |
| 363 | "ERROR: a/Foo.aidl:1.48-52: @JavaOnlyStableParcelable supports only Java target.\n"); |
| Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 364 | EXPECT_NE(0, ::android::aidl::compile_aidl(cpp_options, io_delegate_)); |
| 365 | } |
| 366 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 367 | TEST_F(AidlTest, AcceptsOneway) { |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 368 | string oneway_method = "package a; interface IFoo { oneway void f(int a); }"; |
| 369 | string oneway_interface = |
| 370 | "package a; oneway interface IBar { void f(int a); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 371 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::CPP)); |
| 372 | typenames_.Reset(); |
| 373 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::JAVA)); |
| 374 | typenames_.Reset(); |
| 375 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", oneway_interface, typenames_, Options::Language::CPP)); |
| 376 | typenames_.Reset(); |
| 377 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", oneway_interface, typenames_, Options::Language::JAVA)); |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 378 | } |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 379 | |
| Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 380 | TEST_F(AidlTest, AcceptsAnnotatedOnewayMethod) { |
| 381 | string oneway_method = "package a; interface IFoo { @UnsupportedAppUsage oneway void f(int a); }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 382 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::CPP)); |
| 383 | typenames_.Reset(); |
| 384 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, Options::Language::JAVA)); |
| Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | TEST_F(AidlTest, WritesComments) { |
| 388 | string foo_interface = |
| 389 | "package a; /* foo */ interface IFoo {" |
| 390 | " /* i */ int i();" |
| 391 | " /* j */ @nullable String j();" |
| 392 | " /* k */ @UnsupportedAppUsage oneway void k(int a); }"; |
| 393 | |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 394 | auto parse_result = Parse("a/IFoo.aidl", foo_interface, typenames_, Options::Language::JAVA); |
| Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 395 | EXPECT_NE(nullptr, parse_result); |
| 396 | EXPECT_EQ("/* foo */", parse_result->GetComments()); |
| 397 | |
| 398 | const AidlInterface* interface = parse_result->AsInterface(); |
| 399 | EXPECT_EQ("/* i */", interface->GetMethods()[0]->GetComments()); |
| 400 | EXPECT_EQ("/* j */", interface->GetMethods()[1]->GetComments()); |
| 401 | EXPECT_EQ("/* k */", interface->GetMethods()[2]->GetComments()); |
| 402 | } |
| 403 | |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 404 | TEST_F(AidlTest, ParsesPreprocessedFile) { |
| 405 | string simple_content = "parcelable a.Foo;\ninterface b.IBar;"; |
| 406 | io_delegate_.SetFileContents("path", simple_content); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 407 | EXPECT_FALSE(typenames_.ResolveTypename("a.Foo").second); |
| 408 | EXPECT_TRUE(parse_preprocessed_file(io_delegate_, "path", &typenames_)); |
| 409 | EXPECT_TRUE(typenames_.ResolveTypename("a.Foo").second); |
| 410 | EXPECT_TRUE(typenames_.ResolveTypename("b.IBar").second); |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | TEST_F(AidlTest, ParsesPreprocessedFileWithWhitespace) { |
| 414 | string simple_content = "parcelable a.Foo;\n interface b.IBar ;\t"; |
| 415 | io_delegate_.SetFileContents("path", simple_content); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 416 | |
| 417 | EXPECT_FALSE(typenames_.ResolveTypename("a.Foo").second); |
| 418 | EXPECT_TRUE(parse_preprocessed_file(io_delegate_, "path", &typenames_)); |
| 419 | EXPECT_TRUE(typenames_.ResolveTypename("a.Foo").second); |
| 420 | EXPECT_TRUE(typenames_.ResolveTypename("b.IBar").second); |
| Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 423 | TEST_F(AidlTest, PreferImportToPreprocessed) { |
| 424 | io_delegate_.SetFileContents("preprocessed", "interface another.IBar;"); |
| 425 | io_delegate_.SetFileContents("one/IBar.aidl", "package one; " |
| 426 | "interface IBar {}"); |
| 427 | preprocessed_files_.push_back("preprocessed"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 428 | import_paths_.emplace(""); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 429 | auto parse_result = Parse("p/IFoo.aidl", "package p; import one.IBar; interface IFoo {}", |
| 430 | typenames_, Options::Language::JAVA); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 431 | EXPECT_NE(nullptr, parse_result); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 432 | |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 433 | // We expect to know about both kinds of IBar |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 434 | EXPECT_TRUE(typenames_.ResolveTypename("one.IBar").second); |
| 435 | EXPECT_TRUE(typenames_.ResolveTypename("another.IBar").second); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 436 | // But if we request just "IBar" we should get our imported one. |
| Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 437 | AidlTypeSpecifier ambiguous_type(AIDL_LOCATION_HERE, "IBar", false, nullptr, ""); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 438 | ambiguous_type.Resolve(typenames_); |
| 439 | EXPECT_EQ("one.IBar", ambiguous_type.GetName()); |
| Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 442 | TEST_F(AidlTest, WritePreprocessedFile) { |
| 443 | io_delegate_.SetFileContents("p/Outer.aidl", |
| 444 | "package p; parcelable Outer.Inner;"); |
| 445 | io_delegate_.SetFileContents("one/IBar.aidl", "package one; import p.Outer;" |
| 446 | "interface IBar {}"); |
| 447 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 448 | vector<string> args { |
| 449 | "aidl", |
| 450 | "--preprocess", |
| 451 | "preprocessed", |
| 452 | "p/Outer.aidl", |
| 453 | "one/IBar.aidl"}; |
| 454 | Options options = Options::From(args); |
| Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 455 | EXPECT_TRUE(::android::aidl::preprocess_aidl(options, io_delegate_)); |
| 456 | |
| 457 | string output; |
| 458 | EXPECT_TRUE(io_delegate_.GetWrittenContents("preprocessed", &output)); |
| 459 | EXPECT_EQ("parcelable p.Outer.Inner;\ninterface one.IBar;\n", output); |
| 460 | } |
| 461 | |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 462 | TEST_F(AidlTest, JavaParcelableOutput) { |
| Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 463 | io_delegate_.SetFileContents( |
| 464 | "Rect.aidl", |
| 465 | "@SystemApi\n" |
| 466 | "parcelable Rect {\n" |
| 467 | " // Comment\n" |
| 468 | " @SystemApi\n" |
| 469 | " int x=5;\n" |
| 470 | " @SystemApi\n" |
| 471 | " @UnsupportedAppUsage(maxTargetSdk = 28, trackingBug = 42, implicitMember = \"dummy\", " |
| Andrei Onea | 07fa3e0 | 2019-07-04 17:55:19 +0100 | [diff] [blame] | 472 | "expectedSignature = \"dummy\", publicAlternatives = \"d\" \n + \"u\" + \n \"m\" \n + \"m\" " |
| 473 | "+ \"y\")\n" |
| Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 474 | " int y;\n" |
| Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 475 | " ParcelFileDescriptor fd;\n" |
| Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 476 | "}"); |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 477 | |
| 478 | vector<string> args{"aidl", "Rect.aidl"}; |
| 479 | Options options = Options::From(args); |
| 480 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 481 | |
| 482 | string output; |
| 483 | EXPECT_TRUE(io_delegate_.GetWrittenContents("Rect.java", &output)); |
| Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 484 | EXPECT_EQ(kExpectedJavaParcelableOutputContests, output); |
| Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 485 | } |
| 486 | |
| Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 487 | TEST_F(AidlTest, RequireOuterClass) { |
| 488 | io_delegate_.SetFileContents("p/Outer.aidl", |
| 489 | "package p; parcelable Outer.Inner;"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 490 | import_paths_.emplace(""); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 491 | auto parse_result = |
| 492 | Parse("p/IFoo.aidl", "package p; import p.Outer; interface IFoo { void f(in Inner c); }", |
| 493 | typenames_, Options::Language::JAVA); |
| Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 494 | EXPECT_EQ(nullptr, parse_result); |
| 495 | } |
| 496 | |
| 497 | TEST_F(AidlTest, ParseCompoundParcelableFromPreprocess) { |
| 498 | io_delegate_.SetFileContents("preprocessed", |
| 499 | "parcelable p.Outer.Inner;"); |
| 500 | preprocessed_files_.push_back("preprocessed"); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 501 | auto parse_result = Parse("p/IFoo.aidl", "package p; interface IFoo { void f(in Inner c); }", |
| 502 | typenames_, Options::Language::JAVA); |
| Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 503 | // TODO(wiley): This should actually return nullptr because we require |
| 504 | // the outer class name. However, for legacy reasons, |
| 505 | // this behavior must be maintained. b/17415692 |
| 506 | EXPECT_NE(nullptr, parse_result); |
| 507 | } |
| 508 | |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 509 | TEST_F(AidlTest, FailOnParcelable) { |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 510 | io_delegate_.SetFileContents("p/IFoo.aidl", "package p; parcelable IFoo;"); |
| 511 | |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 512 | // By default, we shouldn't fail on parcelable. |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 513 | Options options1 = Options::From("aidl p/IFoo.aidl"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 514 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options1, io_delegate_)); |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 515 | |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 516 | // -b considers this an error |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 517 | Options options2 = Options::From("aidl -b p/IFoo.aidl"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 518 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 519 | |
| 520 | io_delegate_.SetFileContents("p/IBar.aidl", "package p; parcelable Foo; interface IBar{}"); |
| 521 | |
| Jiyong Park | da8c693 | 2019-08-12 19:56:08 +0900 | [diff] [blame] | 522 | // With '-b' option, a parcelable and an interface should fail. |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 523 | Options options3 = Options::From("aidl p/IBar.aidl"); |
| Jiyong Park | da8c693 | 2019-08-12 19:56:08 +0900 | [diff] [blame] | 524 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options3, io_delegate_)); |
| Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 525 | Options options4 = Options::From("aidl -b p/IBar.aidl"); |
| 526 | EXPECT_NE(0, ::android::aidl::compile_aidl(options4, io_delegate_)); |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 527 | } |
| 528 | |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 529 | TEST_F(AidlTest, StructuredFailOnUnstructuredParcelable) { |
| 530 | io_delegate_.SetFileContents("o/WhoKnowsWhat.aidl", "package o; parcelable WhoKnowsWhat;"); |
| 531 | import_paths_.emplace(""); |
| 532 | AidlError reported_error; |
| 533 | auto parse_result = |
| 534 | Parse("p/IFoo.aidl", |
| 535 | "package p; import o.WhoKnowsWhat; interface IFoo { void f(in WhoKnowsWhat thisIs); }", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 536 | typenames_, Options::Language::JAVA, &reported_error, {"--structured"}); |
| Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 537 | EXPECT_EQ(nullptr, parse_result); |
| 538 | EXPECT_EQ(AidlError::NOT_STRUCTURED, reported_error); |
| 539 | } |
| 540 | |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 541 | TEST_F(AidlTest, FailOnDuplicateConstantNames) { |
| 542 | AidlError reported_error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 543 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 544 | R"(package p; |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 545 | interface IFoo { |
| 546 | const String DUPLICATED = "d"; |
| 547 | const int DUPLICATED = 1; |
| 548 | } |
| 549 | )", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 550 | typenames_, Options::Language::CPP, &reported_error)); |
| Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 551 | EXPECT_EQ(AidlError::BAD_TYPE, reported_error); |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 554 | TEST_F(AidlTest, FailOnManyDefinedTypes) { |
| 555 | AidlError reported_error; |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 556 | AddExpectedStderr("ERROR: p/IFoo.aidl: You must declare only one type per a file.\n"); |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 557 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 558 | R"(package p; |
| 559 | interface IFoo {} |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 560 | parcelable IBar {} |
| 561 | parcelable StructuredParcelable {} |
| 562 | interface IBaz {} |
| Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 563 | )", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 564 | typenames_, Options::Language::CPP, &reported_error)); |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 565 | // Parse success is important for clear error handling even if the cases aren't |
| 566 | // actually supported in code generation. |
| 567 | EXPECT_EQ(AidlError::BAD_TYPE, reported_error); |
| 568 | } |
| 569 | |
| 570 | TEST_F(AidlTest, FailOnNoDefinedTypes) { |
| 571 | AidlError reported_error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 572 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", R"(package p;)", typenames_, Options::Language::CPP, |
| 573 | &reported_error)); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 574 | EXPECT_EQ(AidlError::PARSE_ERROR, reported_error); |
| Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 577 | TEST_F(AidlTest, FailOnMalformedConstHexValue) { |
| 578 | AidlError reported_error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 579 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 580 | R"(package p; |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 581 | interface IFoo { |
| 582 | const int BAD_HEX_VALUE = 0xffffffffffffffffff; |
| 583 | } |
| 584 | )", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 585 | typenames_, Options::Language::CPP, &reported_error)); |
| Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 586 | EXPECT_EQ(AidlError::BAD_TYPE, reported_error); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | TEST_F(AidlTest, ParsePositiveConstHexValue) { |
| 590 | AidlError reported_error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 591 | auto cpp_parse_result = Parse("p/IFoo.aidl", |
| 592 | R"(package p; |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 593 | interface IFoo { |
| 594 | const int POSITIVE_HEX_VALUE = 0xf5; |
| 595 | } |
| 596 | )", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 597 | typenames_, Options::Language::CPP, &reported_error); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 598 | EXPECT_NE(nullptr, cpp_parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 599 | const AidlInterface* interface = cpp_parse_result->AsInterface(); |
| 600 | ASSERT_NE(nullptr, interface); |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 601 | const auto& cpp_constants = interface->GetConstantDeclarations(); |
| 602 | EXPECT_EQ((size_t)1, cpp_constants.size()); |
| 603 | EXPECT_EQ("POSITIVE_HEX_VALUE", cpp_constants[0]->GetName()); |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 604 | EXPECT_EQ("245", cpp_constants[0]->ValueString(cpp::ConstantValueDecorator)); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | TEST_F(AidlTest, ParseNegativeConstHexValue) { |
| 608 | AidlError reported_error; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 609 | auto cpp_parse_result = Parse("p/IFoo.aidl", |
| 610 | R"(package p; |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 611 | interface IFoo { |
| 612 | const int NEGATIVE_HEX_VALUE = 0xffffffff; |
| 613 | } |
| 614 | )", |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 615 | typenames_, Options::Language::CPP, &reported_error); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 616 | EXPECT_NE(nullptr, cpp_parse_result); |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 617 | const AidlInterface* interface = cpp_parse_result->AsInterface(); |
| 618 | ASSERT_NE(nullptr, interface); |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 619 | const auto& cpp_constants = interface->GetConstantDeclarations(); |
| 620 | EXPECT_EQ((size_t)1, cpp_constants.size()); |
| 621 | EXPECT_EQ("NEGATIVE_HEX_VALUE", cpp_constants[0]->GetName()); |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 622 | EXPECT_EQ("-1", cpp_constants[0]->ValueString(cpp::ConstantValueDecorator)); |
| Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 625 | TEST_F(AidlTest, UnderstandsNestedParcelables) { |
| 626 | io_delegate_.SetFileContents( |
| 627 | "p/Outer.aidl", |
| 628 | "package p; parcelable Outer.Inner cpp_header \"baz/header\";"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 629 | import_paths_.emplace(""); |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 630 | const string input_path = "p/IFoo.aidl"; |
| 631 | const string input = "package p; import p.Outer; interface IFoo" |
| 632 | " { Outer.Inner get(); }"; |
| 633 | |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 634 | auto cpp_parse_result = Parse(input_path, input, typenames_, Options::Language::CPP); |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 635 | EXPECT_NE(nullptr, cpp_parse_result); |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 636 | |
| 637 | auto pair = typenames_.ResolveTypename("p.Outer.Inner"); |
| 638 | EXPECT_TRUE(pair.second); |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 639 | // C++ uses "::" instead of "." to refer to a inner class. |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 640 | AidlTypeSpecifier nested_type(AIDL_LOCATION_HERE, "p.Outer.Inner", false, nullptr, ""); |
| 641 | EXPECT_EQ("::p::Outer::Inner", cpp::CppNameOf(nested_type, typenames_)); |
| Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 644 | TEST_F(AidlTest, UnderstandsNativeParcelables) { |
| 645 | io_delegate_.SetFileContents( |
| 646 | "p/Bar.aidl", |
| Casey Dahlin | cd63921 | 2015-12-15 12:51:04 -0800 | [diff] [blame] | 647 | "package p; parcelable Bar cpp_header \"baz/header\";"); |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 648 | import_paths_.emplace(""); |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 649 | const string input_path = "p/IFoo.aidl"; |
| 650 | const string input = "package p; import p.Bar; interface IFoo { }"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 651 | { |
| 652 | // C++ understands C++ specific stuff |
| 653 | auto cpp_parse_result = Parse(input_path, input, typenames_, Options::Language::CPP); |
| 654 | EXPECT_NE(nullptr, cpp_parse_result); |
| 655 | auto pair = typenames_.ResolveTypename("p.Bar"); |
| 656 | EXPECT_TRUE(pair.second); |
| 657 | AidlTypeSpecifier native_type(AIDL_LOCATION_HERE, "p.Bar", false, nullptr, ""); |
| 658 | native_type.Resolve(typenames_); |
| 659 | EXPECT_EQ("::p::Bar", cpp::CppNameOf(native_type, typenames_)); |
| 660 | set<string> headers; |
| 661 | cpp::AddHeaders(native_type, typenames_, headers); |
| 662 | EXPECT_EQ(1u, headers.size()); |
| 663 | EXPECT_EQ(1u, headers.count("baz/header")); |
| 664 | } |
| 665 | typenames_.Reset(); |
| 666 | { |
| 667 | // Java ignores C++ specific stuff |
| 668 | auto java_parse_result = Parse(input_path, input, typenames_, Options::Language::JAVA); |
| 669 | EXPECT_NE(nullptr, java_parse_result); |
| 670 | auto pair = typenames_.ResolveTypename("p.Bar"); |
| 671 | EXPECT_TRUE(pair.second); |
| 672 | AidlTypeSpecifier native_type(AIDL_LOCATION_HERE, "p.Bar", false, nullptr, ""); |
| 673 | native_type.Resolve(typenames_); |
| 674 | EXPECT_EQ("p.Bar", java::InstantiableJavaSignatureOf(native_type)); |
| 675 | } |
| Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 676 | } |
| 677 | |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 678 | TEST_F(AidlTest, WritesCorrectDependencyFile) { |
| 679 | // While the in tree build system always gives us an output file name, |
| 680 | // other android tools take advantage of our ability to infer the intended |
| 681 | // file name. This test makes sure we handle this correctly. |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 682 | vector<string> args = { |
| 683 | "aidl", |
| 684 | "-d dep/file/path", |
| 685 | "-o place/for/output", |
| 686 | "p/IFoo.aidl"}; |
| 687 | Options options = Options::From(args); |
| 688 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 689 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 690 | string actual_dep_file_contents; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 691 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 692 | EXPECT_EQ(actual_dep_file_contents, kExpectedDepFileContents); |
| 693 | } |
| 694 | |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 695 | TEST_F(AidlTest, WritesCorrectDependencyFileNinja) { |
| 696 | // While the in tree build system always gives us an output file name, |
| 697 | // other android tools take advantage of our ability to infer the intended |
| 698 | // file name. This test makes sure we handle this correctly. |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 699 | vector<string> args = { |
| 700 | "aidl", |
| 701 | "-d dep/file/path", |
| 702 | "--ninja", |
| 703 | "-o place/for/output", |
| 704 | "p/IFoo.aidl"}; |
| 705 | Options options = Options::From(args); |
| 706 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 707 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 708 | string actual_dep_file_contents; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 709 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 710 | EXPECT_EQ(actual_dep_file_contents, kExpectedNinjaDepFileContents); |
| 711 | } |
| 712 | |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 713 | TEST_F(AidlTest, WritesTrivialDependencyFileForParcelable) { |
| 714 | // The SDK uses aidl to decide whether a .aidl file is a parcelable. It does |
| 715 | // this by calling aidl with every .aidl file it finds, then parsing the |
| 716 | // generated dependency files. Those that reference .java output files are |
| 717 | // for interfaces and those that do not are parcelables. However, for both |
| 718 | // parcelables and interfaces, we *must* generate a non-empty dependency file. |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 719 | vector<string> args = { |
| 720 | "aidl", |
| 721 | "-o place/for/output", |
| 722 | "-d dep/file/path", |
| 723 | "p/Foo.aidl"}; |
| 724 | Options options = Options::From(args); |
| 725 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo;"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 726 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 727 | string actual_dep_file_contents; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 728 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 729 | EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDepFileContents); |
| 730 | } |
| 731 | |
| Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 732 | /* not working until type_namespace.h is fixed |
| 733 | TEST_F(AidlTest, AcceptsNestedContainerType) { |
| 734 | string nested_in_iface = "package a; interface IFoo {\n" |
| 735 | " List<int, List<String, bool>> foo(); }"; |
| 736 | string nested_in_parcelable = "package a; parcelable IData {\n" |
| 737 | " List<int, List<String, bool>> foo;}"; |
| Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 738 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_iface, typenames_, Options::Language::JAVA)); |
| 739 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_iface, typenames_, Options::Language::CPP)); |
| 740 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_parcelable, typenames_, |
| 741 | Options::Language::JAVA)); EXPECT_NE(nullptr, Parse("a/IFoo.aidl", nested_in_parcelable, typenames_, |
| 742 | Options::Language::CPP)); |
| Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 743 | } |
| 744 | */ |
| 745 | |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 746 | TEST_F(AidlTest, ApiDump) { |
| 747 | io_delegate_.SetFileContents( |
| 748 | "foo/bar/IFoo.aidl", |
| 749 | "package foo.bar;\n" |
| 750 | "import foo.bar.Data;\n" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 751 | "// comment\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 752 | "interface IFoo {\n" |
| 753 | " int foo(out int[] a, String b, boolean c, inout List<String> d);\n" |
| 754 | " int foo2(@utf8InCpp String x, inout List<String> y);\n" |
| 755 | " IFoo foo3(IFoo foo);\n" |
| 756 | " Data getData();\n" |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 757 | " const int A = 1;\n" |
| 758 | " const String STR = \"Hello\";\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 759 | "}\n"); |
| 760 | io_delegate_.SetFileContents("foo/bar/Data.aidl", |
| 761 | "package foo.bar;\n" |
| 762 | "import foo.bar.IFoo;\n" |
| 763 | "parcelable Data {\n" |
| Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 764 | " int x = 10;\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 765 | " int y;\n" |
| 766 | " IFoo foo;\n" |
| 767 | " List<IFoo> a;\n" |
| 768 | " List<foo.bar.IFoo> b;\n" |
| Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 769 | " @nullable String[] c;\n" |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 770 | "}\n"); |
| 771 | io_delegate_.SetFileContents("api.aidl", ""); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 772 | vector<string> args = {"aidl", "--dumpapi", "--out=dump", "foo/bar/IFoo.aidl", |
| 773 | "foo/bar/Data.aidl"}; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 774 | Options options = Options::From(args); |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 775 | bool result = dump_api(options, io_delegate_); |
| 776 | ASSERT_TRUE(result); |
| 777 | string actual; |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 778 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual)); |
| 779 | EXPECT_EQ(actual, R"(package foo.bar; |
| 780 | interface IFoo { |
| 781 | int foo(out int[] a, String b, boolean c, inout List<String> d); |
| 782 | int foo2(@utf8InCpp String x, inout List<String> y); |
| 783 | foo.bar.IFoo foo3(foo.bar.IFoo foo); |
| 784 | foo.bar.Data getData(); |
| 785 | const int A = 1; |
| 786 | const String STR = "Hello"; |
| 787 | } |
| 788 | )"); |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 789 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 790 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/Data.aidl", &actual)); |
| 791 | EXPECT_EQ(actual, R"(package foo.bar; |
| 792 | parcelable Data { |
| 793 | int x = 10; |
| 794 | int y; |
| 795 | foo.bar.IFoo foo; |
| 796 | List<foo.bar.IFoo> a; |
| 797 | List<foo.bar.IFoo> b; |
| Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 798 | @nullable String[] c; |
| Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 799 | } |
| 800 | )"); |
| 801 | } |
| 802 | |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 803 | TEST_F(AidlTest, ApiDumpWithManualIds) { |
| 804 | io_delegate_.SetFileContents( |
| 805 | "foo/bar/IFoo.aidl", |
| 806 | "package foo.bar;\n" |
| 807 | "interface IFoo {\n" |
| 808 | " int foo() = 1;\n" |
| 809 | " int bar() = 2;\n" |
| 810 | " int baz() = 10;\n" |
| 811 | "}\n"); |
| 812 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 813 | vector<string> args = {"aidl", "--dumpapi", "-o dump", "foo/bar/IFoo.aidl"}; |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 814 | Options options = Options::From(args); |
| 815 | bool result = dump_api(options, io_delegate_); |
| 816 | ASSERT_TRUE(result); |
| 817 | string actual; |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 818 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual)); |
| 819 | EXPECT_EQ(actual, R"(package foo.bar; |
| 820 | interface IFoo { |
| 821 | int foo() = 1; |
| 822 | int bar() = 2; |
| 823 | int baz() = 10; |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 824 | } |
| 825 | )"); |
| 826 | } |
| 827 | |
| 828 | TEST_F(AidlTest, ApiDumpWithManualIdsOnlyOnSomeMethods) { |
| 829 | io_delegate_.SetFileContents( |
| 830 | "foo/bar/IFoo.aidl", |
| 831 | "package foo.bar;\n" |
| 832 | "interface IFoo {\n" |
| 833 | " int foo() = 1;\n" |
| 834 | " int bar();\n" |
| 835 | " int baz() = 10;\n" |
| 836 | "}\n"); |
| 837 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 838 | vector<string> args = {"aidl", "--dumpapi", "-o dump", "foo/bar/IFoo.aidl"}; |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 839 | Options options = Options::From(args); |
| 840 | EXPECT_FALSE(dump_api(options, io_delegate_)); |
| 841 | } |
| 842 | |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 843 | TEST_F(AidlTest, CheckNumGenericTypeSecifier) { |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 844 | Options options = Options::From("aidl p/IFoo.aidl IFoo.java"); |
| 845 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 846 | "package p; interface IFoo {" |
| 847 | "void foo(List<String, String> a);}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 848 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 849 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 850 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 851 | "package p; interface IFoo {" |
| 852 | "void foo(Map<String> a);}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 853 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 854 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 855 | Options options2 = Options::From("aidl p/Data.aidl Data.java"); |
| 856 | io_delegate_.SetFileContents(options2.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 857 | "package p; parcelable Data {" |
| 858 | "List<String, String> foo;}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 859 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 860 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 861 | io_delegate_.SetFileContents(options2.InputFiles().front(), |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 862 | "package p; parcelable Data {" |
| 863 | "Map<String> foo;}"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 864 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
| 865 | } |
| 866 | |
| Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 867 | TEST_F(AidlTest, FailOnMultipleTypesInSingleFile) { |
| 868 | std::vector<std::string> rawOptions{"aidl --lang=java -o out foo/bar/Foo.aidl", |
| 869 | "aidl --lang=cpp -o out -h out/include foo/bar/Foo.aidl"}; |
| 870 | for (auto& rawOption : rawOptions) { |
| 871 | Options options = Options::From(rawOption); |
| 872 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 873 | "package foo.bar;\n" |
| 874 | "interface IFoo1 { int foo(); }\n" |
| 875 | "interface IFoo2 { int foo(); }\n" |
| 876 | "parcelable Data1 { int a; int b;}\n" |
| 877 | "parcelable Data2 { int a; int b;}\n"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 878 | |
| Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 879 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 880 | |
| Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 881 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 882 | "package foo.bar;\n" |
| 883 | "interface IFoo1 { int foo(); }\n" |
| 884 | "interface IFoo2 { int foo(); }\n"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 885 | |
| Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 886 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 887 | |
| Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 888 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 889 | "package foo.bar;\n" |
| 890 | "parcelable Data1 { int a; int b;}\n" |
| 891 | "parcelable Data2 { int a; int b;}\n"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 892 | |
| Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 893 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
| 897 | TEST_F(AidlTest, MultipleInputFiles) { |
| 898 | Options options = Options::From( |
| 899 | "aidl --lang=java -o out foo/bar/IFoo.aidl foo/bar/Data.aidl"); |
| 900 | |
| 901 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 902 | "package foo.bar;\n" |
| 903 | "import foo.bar.Data;\n" |
| 904 | "interface IFoo { Data getData(); }\n"); |
| 905 | |
| 906 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 907 | "package foo.bar;\n" |
| 908 | "import foo.bar.IFoo;\n" |
| 909 | "parcelable Data { IFoo foo; }\n"); |
| 910 | |
| 911 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 912 | |
| 913 | string content; |
| 914 | for (const auto file : { |
| 915 | "out/foo/bar/IFoo.java", "out/foo/bar/Data.java"}) { |
| 916 | content.clear(); |
| 917 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 918 | EXPECT_FALSE(content.empty()); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | TEST_F(AidlTest, MultipleInputFilesCpp) { |
| 923 | Options options = Options::From("aidl --lang=cpp -o out -h out/include " |
| 924 | "foo/bar/IFoo.aidl foo/bar/Data.aidl"); |
| 925 | |
| 926 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 927 | "package foo.bar;\n" |
| 928 | "import foo.bar.Data;\n" |
| 929 | "interface IFoo { Data getData(); }\n"); |
| 930 | |
| 931 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 932 | "package foo.bar;\n" |
| 933 | "import foo.bar.IFoo;\n" |
| 934 | "parcelable Data { IFoo foo; }\n"); |
| 935 | |
| 936 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 937 | |
| 938 | string content; |
| 939 | for (const auto file : { |
| Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 940 | "out/foo/bar/IFoo.cpp", "out/foo/bar/Data.cpp", |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 941 | "out/include/foo/bar/IFoo.h", "out/include/foo/bar/Data.h", |
| 942 | "out/include/foo/bar/BpFoo.h", "out/include/foo/bar/BpData.h", |
| 943 | "out/include/foo/bar/BnFoo.h", "out/include/foo/bar/BnData.h"}) { |
| 944 | content.clear(); |
| 945 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 946 | EXPECT_FALSE(content.empty()); |
| 947 | } |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 948 | } |
| 949 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 950 | TEST_F(AidlTest, ConflictWithMetaTransactions) { |
| 951 | Options options = Options::From("aidl --lang=java -o place/for/output p/IFoo.aidl"); |
| 952 | // int getInterfaceVersion() is one of the meta transactions |
| 953 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 954 | "package p; interface IFoo {" |
| 955 | "int getInterfaceVersion(); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 956 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 957 | |
| 958 | // boolean getInterfaceVersion() is not, but should be prevented |
| 959 | // because return type is not part of a method signature |
| 960 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 961 | "package p; interface IFoo {" |
| 962 | "boolean getInterfaceVersion(); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 963 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 964 | |
| 965 | // this is another reserved name |
| 966 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 967 | "package p; interface IFoo {" |
| 968 | "String getTransactionName(int code); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 969 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 970 | |
| 971 | // this is not a meta interface method as it differs type arguments |
| 972 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 973 | "package p; interface IFoo {" |
| 974 | "String getTransactionName(); }"); |
| Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 975 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 976 | } |
| 977 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 978 | TEST_F(AidlTest, DifferentOrderAnnotationsInCheckAPI) { |
| Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 979 | Options options = Options::From("aidl --checkapi old new"); |
| 980 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 981 | "package p; interface IFoo{ @utf8InCpp @nullable String foo();}"); |
| 982 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 983 | "package p; interface IFoo{ @nullable @utf8InCpp String foo();}"); |
| 984 | |
| 985 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 986 | } |
| 987 | |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 988 | TEST_F(AidlTest, SuccessOnIdenticalApiDumps) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 989 | Options options = Options::From("aidl --checkapi old new"); |
| 990 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo();}"); |
| 991 | 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] | 992 | |
| 993 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 994 | } |
| 995 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 996 | class AidlTestCompatibleChanges : public AidlTest { |
| 997 | protected: |
| 998 | Options options_ = Options::From("aidl --checkapi old new"); |
| 999 | }; |
| 1000 | |
| 1001 | TEST_F(AidlTestCompatibleChanges, NewType) { |
| 1002 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1003 | "package p;" |
| 1004 | "interface IFoo {" |
| 1005 | " void foo(int a);" |
| 1006 | "}"); |
| 1007 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1008 | "package p;" |
| 1009 | "interface IFoo {" |
| 1010 | " void foo(int a);" |
| 1011 | "}"); |
| 1012 | io_delegate_.SetFileContents("new/p/IBar.aidl", |
| 1013 | "package p;" |
| 1014 | "interface IBar {" |
| 1015 | " void bar();" |
| 1016 | "}"); |
| 1017 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1018 | } |
| 1019 | |
| 1020 | TEST_F(AidlTestCompatibleChanges, NewMethod) { |
| 1021 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1022 | "package p;" |
| 1023 | "interface IFoo {" |
| 1024 | " void foo(int a);" |
| 1025 | "}"); |
| 1026 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1027 | "package p;" |
| 1028 | "interface IFoo {" |
| 1029 | " void foo(int a);" |
| 1030 | " void bar();" |
| 1031 | "}"); |
| 1032 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1033 | } |
| 1034 | |
| 1035 | TEST_F(AidlTestCompatibleChanges, NewField) { |
| 1036 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1037 | "package p;" |
| 1038 | "parcelable Data {" |
| 1039 | " int foo;" |
| 1040 | "}"); |
| 1041 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1042 | "package p;" |
| 1043 | "parcelable Data {" |
| 1044 | " int foo;" |
| 1045 | " int bar;" |
| 1046 | "}"); |
| 1047 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1048 | } |
| 1049 | |
| 1050 | TEST_F(AidlTestCompatibleChanges, NewEnumerator) { |
| 1051 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1052 | "package p;" |
| 1053 | "enum Enum {" |
| 1054 | " FOO = 1," |
| 1055 | "}"); |
| 1056 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1057 | "package p;" |
| 1058 | "enum Enum {" |
| 1059 | " FOO = 1," |
| 1060 | " BAR = 2," |
| 1061 | "}"); |
| 1062 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1063 | } |
| 1064 | |
| 1065 | TEST_F(AidlTestCompatibleChanges, ReorderedEnumerator) { |
| 1066 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1067 | "package p;" |
| 1068 | "enum Enum {" |
| 1069 | " FOO = 1," |
| 1070 | " BAR = 2," |
| 1071 | "}"); |
| 1072 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1073 | "package p;" |
| 1074 | "enum Enum {" |
| 1075 | " BAR = 2," |
| 1076 | " FOO = 1," |
| 1077 | "}"); |
| 1078 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1079 | } |
| 1080 | |
| 1081 | TEST_F(AidlTestCompatibleChanges, NewPackage) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1082 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1083 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1084 | "interface IFoo {" |
| 1085 | " void foo(int a);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1086 | "}"); |
| 1087 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1088 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1089 | "parcelable Data {" |
| 1090 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1091 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1092 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1093 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1094 | "interface IFoo {" |
| 1095 | " void foo(int a);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1096 | "}"); |
| 1097 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1098 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1099 | "parcelable Data {" |
| 1100 | " int foo;" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1101 | "}"); |
| 1102 | io_delegate_.SetFileContents("new/q/IFoo.aidl", |
| 1103 | "package q;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1104 | "interface IFoo {" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1105 | " void foo(int a);" |
| 1106 | "}"); |
| 1107 | io_delegate_.SetFileContents("new/q/Data.aidl", |
| 1108 | "package q;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1109 | "parcelable Data {" |
| 1110 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1111 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1112 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1113 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1114 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1115 | TEST_F(AidlTestCompatibleChanges, ArgNameChange) { |
| 1116 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1117 | "package p;" |
| 1118 | "interface IFoo {" |
| 1119 | " void foo(int a);" |
| 1120 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1121 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1122 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1123 | "interface IFoo {" |
| 1124 | " void foo(int b);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1125 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1126 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1127 | } |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1128 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1129 | TEST_F(AidlTestCompatibleChanges, AddedConstValue) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1130 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 1131 | "package p; interface I {" |
| 1132 | "const int A = 1; }"); |
| 1133 | io_delegate_.SetFileContents("new/p/I.aidl", |
| 1134 | "package p ; interface I {" |
| 1135 | "const int A = 1; const int B = 2;}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1136 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1137 | } |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1138 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1139 | TEST_F(AidlTestCompatibleChanges, ChangedConstValueOrder) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1140 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 1141 | "package p; interface I {" |
| 1142 | "const int A = 1; const int B = 2;}"); |
| 1143 | io_delegate_.SetFileContents("new/p/I.aidl", |
| 1144 | "package p ; interface I {" |
| 1145 | "const int B = 2; const int A = 1;}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1146 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1147 | } |
| 1148 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1149 | class AidlTestIncompatibleChanges : public AidlTest { |
| 1150 | protected: |
| 1151 | Options options_ = Options::From("aidl --checkapi old new"); |
| 1152 | }; |
| 1153 | |
| 1154 | TEST_F(AidlTestIncompatibleChanges, RemovedType) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1155 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1156 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1157 | "interface IFoo {" |
| 1158 | " void foo(in String[] str);" |
| 1159 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1160 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1161 | io_delegate_.SetFileContents("new/p/IFoo.aidl", ""); |
| 1162 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1163 | } |
| 1164 | |
| 1165 | TEST_F(AidlTestIncompatibleChanges, RemovedMethod) { |
| 1166 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1167 | "package p;" |
| 1168 | "interface IFoo {" |
| 1169 | " void foo(in String[] str);" |
| 1170 | " void bar(@utf8InCpp String str);" |
| 1171 | "}"); |
| 1172 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1173 | "package p;" |
| 1174 | "interface IFoo {" |
| 1175 | " void foo(in String[] str);" |
| 1176 | "}"); |
| 1177 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1178 | } |
| 1179 | |
| 1180 | TEST_F(AidlTestIncompatibleChanges, RemovedField) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1181 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1182 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1183 | "parcelable Data {" |
| 1184 | " int foo;" |
| 1185 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1186 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1187 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1188 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1189 | "parcelable Data {" |
| 1190 | " int foo;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1191 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1192 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1193 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1194 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1195 | TEST_F(AidlTestIncompatibleChanges, RemovedEnumerator) { |
| 1196 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1197 | "package p;" |
| 1198 | "enum Enum {" |
| 1199 | " FOO = 1," |
| 1200 | " BAR = 2," |
| 1201 | "}"); |
| 1202 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1203 | "package p;" |
| 1204 | "enum Enum {" |
| 1205 | " BAR = 2," |
| 1206 | "}"); |
| 1207 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1208 | } |
| 1209 | |
| 1210 | TEST_F(AidlTestIncompatibleChanges, RenamedMethod) { |
| 1211 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1212 | "package p;" |
| 1213 | "interface IFoo {" |
| 1214 | " void foo(in String[] str);" |
| 1215 | " void bar(@utf8InCpp String str);" |
| 1216 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1217 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1218 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1219 | "interface IFoo {" |
| 1220 | " void foo(in String[] str);" |
| 1221 | " void bar2(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1222 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1223 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1224 | } |
| 1225 | |
| 1226 | TEST_F(AidlTestIncompatibleChanges, RenamedField) { |
| 1227 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1228 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1229 | "parcelable Data {" |
| 1230 | " int foo;" |
| 1231 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1232 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1233 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1234 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1235 | "parcelable Data {" |
| 1236 | " int foo;" |
| 1237 | " int bar2;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1238 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1239 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1240 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1241 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1242 | TEST_F(AidlTestIncompatibleChanges, RenamedType) { |
| 1243 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1244 | "package p;" |
| 1245 | "interface IFoo {" |
| 1246 | " void foo(in String[] str);" |
| 1247 | " void bar(@utf8InCpp String str);" |
| 1248 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1249 | io_delegate_.SetFileContents("new/p/IFoo2.aidl", |
| 1250 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1251 | "interface IFoo2 {" |
| 1252 | " void foo(in String[] str);" |
| 1253 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1254 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1255 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1256 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1257 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1258 | TEST_F(AidlTestIncompatibleChanges, ChangedEnumerator) { |
| 1259 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1260 | "package p;" |
| 1261 | "enum Enum {" |
| 1262 | " FOO = 1," |
| 1263 | " BAR = 2," |
| 1264 | "}"); |
| 1265 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1266 | "package p;" |
| 1267 | "enum Enum {" |
| 1268 | " FOO = 3," |
| 1269 | " BAR = 2," |
| 1270 | "}"); |
| 1271 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1272 | } |
| 1273 | |
| 1274 | TEST_F(AidlTestIncompatibleChanges, ReorderedMethod) { |
| 1275 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1276 | "package p;" |
| 1277 | "interface IFoo {" |
| 1278 | " void foo(in String[] str);" |
| 1279 | " void bar(@utf8InCpp String str);" |
| 1280 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1281 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1282 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1283 | "interface IFoo {" |
| 1284 | " void bar(@utf8InCpp String str);" |
| 1285 | " void foo(in String[] str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1286 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1287 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1288 | } |
| 1289 | |
| 1290 | TEST_F(AidlTestIncompatibleChanges, ReorderedField) { |
| 1291 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1292 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1293 | "parcelable Data {" |
| 1294 | " int foo;" |
| 1295 | " int bar;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1296 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1297 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1298 | "package p;" |
| 1299 | "parcelable Data {" |
| 1300 | " int bar;" |
| 1301 | " int foo;" |
| 1302 | "}"); |
| 1303 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1304 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1305 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1306 | TEST_F(AidlTestIncompatibleChanges, ChangedDirectionSpecifier) { |
| 1307 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1308 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1309 | "interface IFoo {" |
| 1310 | " void foo(in String[] str);" |
| 1311 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1312 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1313 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1314 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1315 | "interface IFoo {" |
| 1316 | " void foo(out String[] str);" |
| 1317 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1318 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1319 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1320 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1321 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1322 | TEST_F(AidlTestIncompatibleChanges, AddedAnnotation) { |
| 1323 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1324 | "package p;" |
| 1325 | "interface IFoo {" |
| 1326 | " void foo(in String[] str);" |
| 1327 | " void bar(@utf8InCpp String str);" |
| 1328 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1329 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1330 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1331 | "interface IFoo {" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1332 | " void foo(in @utf8InCpp String[] str);" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1333 | " void bar(@utf8InCpp String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1334 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1335 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1336 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1337 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1338 | TEST_F(AidlTestIncompatibleChanges, RemovedAnnotation) { |
| 1339 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1340 | "package p;" |
| 1341 | "interface IFoo {" |
| 1342 | " void foo(in String[] str);" |
| 1343 | " void bar(@utf8InCpp String str);" |
| 1344 | "}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1345 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1346 | "package p;" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1347 | "interface IFoo {" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1348 | " void foo(in String[] str);" |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1349 | " void bar(String str);" |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1350 | "}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1351 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1352 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1353 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1354 | TEST_F(AidlTestIncompatibleChanges, RemovedPackage) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1355 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{}"); |
| 1356 | io_delegate_.SetFileContents("old/q/IFoo.aidl", "package q; interface IFoo{}"); |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1357 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{}"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1358 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1359 | } |
| Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 1360 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1361 | TEST_F(AidlTestIncompatibleChanges, ChangedDefaultValue) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1362 | io_delegate_.SetFileContents("old/p/D.aidl", "package p; parcelable D { int a = 1; }"); |
| 1363 | io_delegate_.SetFileContents("new/p/D.aidl", "package p; parcelable D { int a = 2; }"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1364 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1365 | } |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1366 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1367 | TEST_F(AidlTestIncompatibleChanges, RemovedConstValue) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1368 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 1369 | "package p; interface I {" |
| 1370 | "const int A = 1; const int B = 2;}"); |
| 1371 | io_delegate_.SetFileContents("new/p/I.aidl", "package p; interface I { const int A = 1; }"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1372 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1373 | } |
| Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1374 | |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1375 | TEST_F(AidlTestIncompatibleChanges, ChangedConstValue) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1376 | io_delegate_.SetFileContents("old/p/I.aidl", "package p; interface I { const int A = 1; }"); |
| 1377 | io_delegate_.SetFileContents("new/p/I.aidl", "package p; interface I { const int A = 2; }"); |
| Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1378 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 1379 | } |
| 1380 | |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 1381 | TEST_F(AidlTest, RejectAmbiguousImports) { |
| 1382 | Options options = Options::From("aidl --lang=java -o out -I dir1 -I dir2 p/IFoo.aidl"); |
| 1383 | io_delegate_.SetFileContents("p/IFoo.aidl", "package p; import q.IBar; interface IFoo{}"); |
| 1384 | io_delegate_.SetFileContents("dir1/q/IBar.aidl", "package q; interface IBar{}"); |
| 1385 | io_delegate_.SetFileContents("dir2/q/IBar.aidl", "package q; interface IBar{}"); |
| 1386 | |
| 1387 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1388 | } |
| 1389 | |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1390 | TEST_F(AidlTest, HandleManualIdAssignments) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1391 | Options options = Options::From("aidl --checkapi old new"); |
| 1392 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo() = 10;}"); |
| 1393 | 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] | 1394 | |
| 1395 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 1396 | |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1397 | 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] | 1398 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
| 1399 | } |
| 1400 | |
| Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 1401 | TEST_F(AidlTest, ParcelFileDescriptorIsBuiltinType) { |
| 1402 | Options javaOptions = Options::From("aidl --lang=java -o out p/IFoo.aidl"); |
| 1403 | Options cppOptions = Options::From("aidl --lang=cpp -h out -o out p/IFoo.aidl"); |
| 1404 | |
| 1405 | // use without import |
| 1406 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1407 | "package p; interface IFoo{ void foo(in ParcelFileDescriptor fd);}"); |
| 1408 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 1409 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
| 1410 | |
| 1411 | // use without impot but with full name |
| 1412 | io_delegate_.SetFileContents( |
| 1413 | "p/IFoo.aidl", |
| 1414 | "package p; interface IFoo{ void foo(in android.os.ParcelFileDescriptor fd);}"); |
| 1415 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 1416 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
| 1417 | |
| 1418 | // use with import (as before) |
| 1419 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1420 | "package p;" |
| 1421 | "import android.os.ParcelFileDescriptor;" |
| 1422 | "interface IFoo{" |
| 1423 | " void foo(in ParcelFileDescriptor fd);" |
| 1424 | "}"); |
| 1425 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 1426 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
| 1427 | } |
| Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1428 | |
| Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 1429 | TEST_F(AidlTest, ManualIds) { |
| 1430 | Options options = Options::From("aidl --lang=java -o out IFoo.aidl"); |
| 1431 | io_delegate_.SetFileContents("IFoo.aidl", |
| 1432 | "interface IFoo {\n" |
| 1433 | " void foo() = 0;\n" |
| 1434 | " void bar() = 1;\n" |
| 1435 | "}"); |
| 1436 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1437 | } |
| 1438 | |
| 1439 | TEST_F(AidlTest, ManualIdsWithMetaTransactions) { |
| 1440 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 1441 | io_delegate_.SetFileContents("IFoo.aidl", |
| 1442 | "interface IFoo {\n" |
| 1443 | " void foo() = 0;\n" |
| 1444 | " void bar() = 1;\n" |
| 1445 | "}"); |
| 1446 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1447 | } |
| 1448 | |
| 1449 | TEST_F(AidlTest, FailOnDuplicatedIds) { |
| 1450 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 1451 | io_delegate_.SetFileContents("IFoo.aidl", |
| 1452 | "interface IFoo {\n" |
| 1453 | " void foo() = 3;\n" |
| 1454 | " void bar() = 3;\n" |
| 1455 | "}"); |
| 1456 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1457 | } |
| 1458 | |
| 1459 | TEST_F(AidlTest, FailOnOutOfRangeIds) { |
| 1460 | // 16777115 is kLastMetaMethodId + 1 |
| 1461 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 1462 | io_delegate_.SetFileContents("IFoo.aidl", |
| 1463 | "interface IFoo {\n" |
| 1464 | " void foo() = 3;\n" |
| 1465 | " void bar() = 16777115;\n" |
| 1466 | "}"); |
| 1467 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1468 | } |
| 1469 | |
| 1470 | TEST_F(AidlTest, FailOnPartiallyAssignedIds) { |
| 1471 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 1472 | io_delegate_.SetFileContents("IFoo.aidl", |
| 1473 | "interface IFoo {\n" |
| 1474 | " void foo() = 3;\n" |
| 1475 | " void bar();\n" |
| 1476 | "}"); |
| 1477 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1478 | } |
| 1479 | |
| Jiyong Park | c681625 | 2019-07-08 08:12:28 +0900 | [diff] [blame] | 1480 | TEST_F(AidlTest, AllowDuplicatedImportPaths) { |
| 1481 | Options options = Options::From("aidl --lang=java -I dir -I dir IFoo.aidl"); |
| 1482 | io_delegate_.SetFileContents("dir/IBar.aidl", "interface IBar{}"); |
| 1483 | io_delegate_.SetFileContents("IFoo.aidl", "import IBar; interface IFoo{}"); |
| 1484 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1485 | } |
| 1486 | |
| 1487 | TEST_F(AidlTest, FailOnAmbiguousImports) { |
| 1488 | Options options = Options::From("aidl --lang=java -I dir -I dir2 IFoo.aidl"); |
| 1489 | io_delegate_.SetFileContents("dir/IBar.aidl", "interface IBar{}"); |
| 1490 | io_delegate_.SetFileContents("dir2/IBar.aidl", "interface IBar{}"); |
| 1491 | io_delegate_.SetFileContents("IFoo.aidl", "import IBar; interface IFoo{}"); |
| 1492 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1493 | } |
| 1494 | |
| Jiyong Park | 56f73d7 | 2019-06-11 12:20:28 +0900 | [diff] [blame] | 1495 | class AidlOutputPathTest : public AidlTest { |
| 1496 | protected: |
| 1497 | void SetUp() override { |
| 1498 | AidlTest::SetUp(); |
| 1499 | io_delegate_.SetFileContents("sub/dir/foo/bar/IFoo.aidl", "package foo.bar; interface IFoo {}"); |
| 1500 | } |
| 1501 | |
| 1502 | void Test(const Options& options, const std::string expected_output_path) { |
| 1503 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1504 | // check the existence |
| 1505 | EXPECT_TRUE(io_delegate_.GetWrittenContents(expected_output_path, nullptr)); |
| 1506 | } |
| 1507 | }; |
| 1508 | |
| 1509 | TEST_F(AidlOutputPathTest, OutDirWithNoOutputFile) { |
| 1510 | // <out_dir> / <package_name> / <type_name>.java |
| 1511 | Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl"), "out/foo/bar/IFoo.java"); |
| 1512 | } |
| 1513 | |
| 1514 | TEST_F(AidlOutputPathTest, OutDirWithOutputFile) { |
| 1515 | // when output file is explicitly set, it is always respected. -o option is |
| 1516 | // ignored. |
| 1517 | Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl output/IFoo.java"), "output/IFoo.java"); |
| 1518 | } |
| 1519 | |
| 1520 | TEST_F(AidlOutputPathTest, NoOutDirWithOutputFile) { |
| 1521 | Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl output/IFoo.java"), "output/IFoo.java"); |
| 1522 | } |
| 1523 | |
| 1524 | TEST_F(AidlOutputPathTest, NoOutDirWithNoOutputFile) { |
| 1525 | // output is the same as the input file except for the suffix |
| 1526 | Test(Options::From("aidl sub/dir/foo/bar/IFoo.aidl"), "sub/dir/foo/bar/IFoo.java"); |
| 1527 | } |
| 1528 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 1529 | } // namespace aidl |
| 1530 | } // namespace android |