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