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> |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 23 | #include <gmock/gmock.h> |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | #include "aidl.h" |
Steven Moreland | 4958524 | 2019-12-18 16:06:49 -0800 | [diff] [blame] | 27 | #include "aidl_checkapi.h" |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 28 | #include "aidl_language.h" |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 29 | #include "aidl_to_cpp.h" |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 30 | #include "aidl_to_java.h" |
Jiyong Park | 2a7c92b | 2020-07-22 19:12:36 +0900 | [diff] [blame] | 31 | #include "logging.h" |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 32 | #include "options.h" |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 33 | #include "tests/fake_io_delegate.h" |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 34 | |
Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 35 | using android::aidl::internals::parse_preprocessed_file; |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 36 | using android::aidl::test::FakeIoDelegate; |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 37 | using android::base::StringPrintf; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 38 | using std::set; |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 39 | using std::string; |
| 40 | using std::unique_ptr; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 41 | using std::vector; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 42 | using testing::TestParamInfo; |
Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 43 | using testing::internal::CaptureStderr; |
| 44 | using testing::internal::GetCapturedStderr; |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 45 | |
| 46 | namespace android { |
| 47 | namespace aidl { |
Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | const char kExpectedDepFileContents[] = |
| 51 | R"(place/for/output/p/IFoo.java : \ |
| 52 | p/IFoo.aidl |
| 53 | |
| 54 | p/IFoo.aidl : |
| 55 | )"; |
| 56 | |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 57 | const char kExpectedNinjaDepFileContents[] = |
| 58 | R"(place/for/output/p/IFoo.java : \ |
| 59 | p/IFoo.aidl |
| 60 | )"; |
| 61 | |
Jiyong Park | df20212 | 2019-09-30 20:48:35 +0900 | [diff] [blame] | 62 | const char kExpectedParcelableDeclarationDepFileContents[] = |
| 63 | R"( : \ |
| 64 | p/Foo.aidl |
| 65 | |
| 66 | p/Foo.aidl : |
| 67 | )"; |
| 68 | |
| 69 | const char kExpectedStructuredParcelableDepFileContents[] = |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 70 | R"(place/for/output/p/Foo.java : \ |
Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 71 | p/Foo.aidl |
| 72 | |
| 73 | p/Foo.aidl : |
| 74 | )"; |
| 75 | |
Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 76 | const char kExpectedJavaParcelableOutputContests[] = |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 77 | R"(/* |
| 78 | * This file is auto-generated. DO NOT MODIFY. |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 79 | */ |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 80 | @android.annotation.Hide |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 81 | public class Rect implements android.os.Parcelable |
| 82 | { |
| 83 | // Comment |
| 84 | |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 85 | @android.annotation.Hide |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 86 | public int x = 5; |
| 87 | |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 88 | @android.annotation.Hide |
| 89 | @android.compat.annotation.UnsupportedAppUsage(expectedSignature = "dummy", implicitMember = "dummy", maxTargetSdk = 28, publicAlternatives = "dummy", trackingBug = 42L, overrideSourcePosition="Rect.aidl:7:1:10:14") |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 90 | public int y = 0; |
Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 91 | |
| 92 | public android.os.ParcelFileDescriptor fd; |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 93 | public static final android.os.Parcelable.Creator<Rect> CREATOR = new android.os.Parcelable.Creator<Rect>() { |
| 94 | @Override |
| 95 | public Rect createFromParcel(android.os.Parcel _aidl_source) { |
| 96 | Rect _aidl_out = new Rect(); |
| 97 | _aidl_out.readFromParcel(_aidl_source); |
| 98 | return _aidl_out; |
| 99 | } |
| 100 | @Override |
| 101 | public Rect[] newArray(int _aidl_size) { |
| 102 | return new Rect[_aidl_size]; |
| 103 | } |
| 104 | }; |
| 105 | @Override public final void writeToParcel(android.os.Parcel _aidl_parcel, int _aidl_flag) |
| 106 | { |
| 107 | int _aidl_start_pos = _aidl_parcel.dataPosition(); |
| 108 | _aidl_parcel.writeInt(0); |
| 109 | _aidl_parcel.writeInt(x); |
| 110 | _aidl_parcel.writeInt(y); |
Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 111 | if ((fd!=null)) { |
| 112 | _aidl_parcel.writeInt(1); |
| 113 | fd.writeToParcel(_aidl_parcel, 0); |
| 114 | } |
| 115 | else { |
| 116 | _aidl_parcel.writeInt(0); |
| 117 | } |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 118 | int _aidl_end_pos = _aidl_parcel.dataPosition(); |
| 119 | _aidl_parcel.setDataPosition(_aidl_start_pos); |
| 120 | _aidl_parcel.writeInt(_aidl_end_pos - _aidl_start_pos); |
| 121 | _aidl_parcel.setDataPosition(_aidl_end_pos); |
| 122 | } |
| 123 | public final void readFromParcel(android.os.Parcel _aidl_parcel) |
| 124 | { |
| 125 | int _aidl_start_pos = _aidl_parcel.dataPosition(); |
| 126 | int _aidl_parcelable_size = _aidl_parcel.readInt(); |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 127 | try { |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 128 | if (_aidl_parcelable_size < 0) return; |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 129 | x = _aidl_parcel.readInt(); |
| 130 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
| 131 | y = _aidl_parcel.readInt(); |
| 132 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 133 | if ((0!=_aidl_parcel.readInt())) { |
| 134 | fd = android.os.ParcelFileDescriptor.CREATOR.createFromParcel(_aidl_parcel); |
| 135 | } |
| 136 | else { |
| 137 | fd = null; |
| 138 | } |
| 139 | if (_aidl_parcel.dataPosition() - _aidl_start_pos >= _aidl_parcelable_size) return; |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 140 | } finally { |
Jeongik Cha | 8b32998 | 2020-09-01 20:59:36 +0900 | [diff] [blame] | 141 | if (_aidl_start_pos > (Integer.MAX_VALUE - _aidl_parcelable_size)) { |
| 142 | throw new android.os.BadParcelableException("Overflow in the size of parcelable"); |
| 143 | } |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 144 | _aidl_parcel.setDataPosition(_aidl_start_pos + _aidl_parcelable_size); |
| 145 | } |
| 146 | } |
| 147 | @Override public int describeContents() |
| 148 | { |
Jeongik Cha | 372a8c8 | 2018-12-12 16:31:11 +0900 | [diff] [blame] | 149 | return 0; |
| 150 | } |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 151 | } |
| 152 | )"; |
| 153 | |
Devin Moore | 2f2077a | 2020-08-28 11:27:53 -0700 | [diff] [blame] | 154 | // clang-format off |
| 155 | const char kExpectedCppHeaderOutput[] = |
| 156 | R"(#pragma once |
| 157 | |
| 158 | #include <binder/IBinder.h> |
| 159 | #include <binder/IInterface.h> |
| 160 | #include <binder/Status.h> |
| 161 | #include <optional> |
| 162 | #include <utils/String16.h> |
| 163 | #include <utils/StrongPointer.h> |
| 164 | #include <vector> |
| 165 | |
| 166 | class IFoo : public ::android::IInterface { |
| 167 | public: |
| 168 | DECLARE_META_INTERFACE(Foo) |
| 169 | virtual ::android::binder::Status foo(::std::optional<::std::vector<::std::optional<::android::String16>>>* _aidl_return) = 0; |
| 170 | }; // class IFoo |
| 171 | class IFooDefault : public IFoo { |
| 172 | public: |
| 173 | ::android::IBinder* onAsBinder() override { |
| 174 | return nullptr; |
| 175 | } |
| 176 | ::android::binder::Status foo(::std::optional<::std::vector<::std::optional<::android::String16>>>*) override { |
| 177 | return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); |
| 178 | } |
| 179 | }; // class IFooDefault |
| 180 | )"; |
| 181 | // clang-format on |
| 182 | |
Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 183 | } // namespace |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 184 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 185 | class AidlTest : public ::testing::TestWithParam<Options::Language> { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 186 | protected: |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 187 | AidlDefinedType* Parse(const string& path, const string& contents, AidlTypenames& typenames_, |
| 188 | Options::Language lang, AidlError* error = nullptr, |
Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 189 | const vector<string> additional_arguments = {}) { |
Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 190 | io_delegate_.SetFileContents(path, contents); |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 191 | vector<string> args; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 192 | args.emplace_back("aidl"); |
| 193 | args.emplace_back("--lang=" + Options::LanguageToString(lang)); |
Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 194 | for (const string& s : additional_arguments) { |
| 195 | args.emplace_back(s); |
| 196 | } |
| 197 | for (const string& f : preprocessed_files_) { |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 198 | args.emplace_back("--preprocessed=" + f); |
| 199 | } |
Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 200 | for (const string& i : import_paths_) { |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 201 | args.emplace_back("--include=" + i); |
| 202 | } |
| 203 | args.emplace_back(path); |
| 204 | Options options = Options::From(args); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 205 | vector<string> imported_files; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 206 | ImportResolver import_resolver{io_delegate_, path, import_paths_, {}}; |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 207 | AidlError actual_error = ::android::aidl::internals::load_and_validate_aidl( |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 208 | path, options, io_delegate_, &typenames_, &imported_files); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 209 | |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 210 | if (error != nullptr) { |
| 211 | *error = actual_error; |
| 212 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 213 | |
| 214 | if (actual_error != AidlError::OK) { |
| 215 | return nullptr; |
| 216 | } |
| 217 | |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 218 | const auto& defined_types = typenames_.MainDocument().DefinedTypes(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 219 | EXPECT_EQ(1ul, defined_types.size()); |
| 220 | |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 221 | return defined_types.front().get(); |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 222 | } |
Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 223 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 224 | Options::Language GetLanguage() { return GetParam(); } |
| 225 | |
Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 226 | FakeIoDelegate io_delegate_; |
Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 227 | vector<string> preprocessed_files_; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 228 | set<string> import_paths_; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 229 | AidlTypenames typenames_; |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 232 | // Instantiate the AidlTest parameterized suite, calling all of the TEST_P |
| 233 | // tests with each of the supported languages as a parameter. |
| 234 | INSTANTIATE_TEST_SUITE_P(AidlTestSuite, AidlTest, |
| 235 | testing::Values(Options::Language::CPP, Options::Language::JAVA, |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 236 | Options::Language::NDK, Options::Language::RUST), |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 237 | [](const testing::TestParamInfo<Options::Language>& info) { |
| 238 | return Options::LanguageToString(info.param); |
| 239 | }); |
| 240 | |
| 241 | TEST_P(AidlTest, AcceptMissingPackage) { |
| 242 | EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { }", typenames_, GetLanguage())); |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 245 | TEST_P(AidlTest, EndsInSingleLineComment) { |
| 246 | EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { } // foo", typenames_, GetLanguage())); |
Steven Moreland | 9c2988f | 2019-07-17 17:49:10 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 249 | TEST_P(AidlTest, InterfaceRequiresCorrectPath) { |
| 250 | const string expected_stderr = |
| 251 | "ERROR: a/Foo.aidl:1.11-21: IBar should be declared in a file called a/IBar.aidl\n"; |
| 252 | const std::string file_contents = "package a; interface IBar {}"; |
| 253 | CaptureStderr(); |
| 254 | EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage())); |
| 255 | EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents; |
| 256 | } |
| 257 | |
| 258 | TEST_P(AidlTest, ParcelableRequiresCorrectPath) { |
| 259 | const string expected_stderr = |
| 260 | "ERROR: a/Foo.aidl:1.11-21: Bar should be declared in a file called a/Bar.aidl\n"; |
| 261 | const std::string file_contents = "package a; interface Bar {}"; |
| 262 | CaptureStderr(); |
| 263 | EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage())); |
| 264 | EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents; |
| 265 | } |
| 266 | |
| 267 | TEST_P(AidlTest, UnstructuredParcelableRequiresCorrectPath) { |
| 268 | const string expected_stderr = |
| 269 | "ERROR: a/Foo.aidl:1.22-26: Bar should be declared in a file called a/Bar.aidl\n"; |
| 270 | const std::string file_contents = "package a; parcelable Bar cpp_header \"anything.h\";"; |
| 271 | CaptureStderr(); |
| 272 | EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage())); |
| 273 | EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents; |
| 274 | } |
| 275 | |
| 276 | TEST_P(AidlTest, EnumRequiresCorrectPath) { |
| 277 | const string expected_stderr = |
| 278 | "ERROR: a/Foo.aidl:1.16-20: Bar should be declared in a file called a/Bar.aidl\n"; |
| 279 | const std::string file_contents = "package a; enum Bar { A, }"; |
| 280 | CaptureStderr(); |
| 281 | EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage())); |
| 282 | EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents; |
| 283 | } |
| 284 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 285 | TEST_P(AidlTest, RejectsArraysOfBinders) { |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 286 | import_paths_.emplace(""); |
Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 287 | io_delegate_.SetFileContents("bar/IBar.aidl", |
| 288 | "package bar; interface IBar {}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 289 | const string path = "foo/IFoo.aidl"; |
| 290 | const string contents = |
| 291 | "package foo;\n" |
| 292 | "import bar.IBar;\n" |
| 293 | "interface IFoo { void f(in IBar[] input); }"; |
| 294 | const string expected_stderr = "ERROR: foo/IFoo.aidl:3.27-32: Binder type cannot be an array\n"; |
| 295 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 296 | EXPECT_EQ(nullptr, Parse(path, contents, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 297 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Christopher Wiley | 0522cd5 | 2015-10-28 15:39:44 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 300 | TEST_P(AidlTest, SupportOnlyOutParameters) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 301 | const string interface_list = "package a; interface IBar { void f(out List<String> bar); }"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 302 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", interface_list, typenames_, GetLanguage())); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 303 | } |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 304 | |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 305 | TEST_P(AidlTest, RejectOutParametersForIBinder) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 306 | const string interface_ibinder = "package a; interface IBaz { void f(out IBinder bar); }"; |
| 307 | const string expected_ibinder_stderr = |
| 308 | "ERROR: a/IBaz.aidl:1.47-51: 'out IBinder bar' can only be an in parameter.\n"; |
| 309 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 310 | EXPECT_EQ(nullptr, Parse("a/IBaz.aidl", interface_ibinder, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 311 | EXPECT_EQ(expected_ibinder_stderr, GetCapturedStderr()); |
Jeongik Cha | a2080bf | 2019-06-18 16:44:29 +0900 | [diff] [blame] | 312 | } |
| 313 | |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 314 | TEST_P(AidlTest, RejectsOutParametersInOnewayInterface) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 315 | const string oneway_interface = "package a; oneway interface IBar { void f(out int bar); }"; |
| 316 | const string expected_stderr = |
| 317 | "ERROR: a/IBar.aidl:1.40-42: oneway method 'f' cannot have out parameters\n"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 318 | CaptureStderr(); |
| 319 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_interface, typenames_, GetLanguage())); |
| 320 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 321 | } |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 322 | |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 323 | TEST_P(AidlTest, RejectsOutParametersInOnewayMethod) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 324 | const string oneway_method = "package a; interface IBar { oneway void f(out int bar); }"; |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 325 | const string expected_stderr = |
| 326 | "ERROR: a/IBar.aidl:1.40-42: oneway method 'f' cannot have out parameters\n"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 327 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 328 | EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_method, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 329 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 332 | TEST_P(AidlTest, RejectsOnewayNonVoidReturn) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 333 | const string oneway_method = "package a; interface IFoo { oneway int f(); }"; |
| 334 | const string expected_stderr = |
| 335 | "ERROR: a/IFoo.aidl:1.39-41: oneway method 'f' cannot return a value\n"; |
| 336 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 337 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 338 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 341 | TEST_P(AidlTest, RejectsNullablePrimitive) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 342 | const string oneway_method = "package a; interface IFoo { @nullable int f(); }"; |
| 343 | const string expected_stderr = |
| 344 | "ERROR: a/IFoo.aidl:1.38-42: Primitive type cannot get nullable annotation\n"; |
| 345 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 346 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 347 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Devin Moore | 2f2077a | 2020-08-28 11:27:53 -0700 | [diff] [blame] | 350 | TEST_P(AidlTest, AcceptNullableList) { |
| 351 | const string oneway_method = "package a; interface IFoo { @nullable List<String> f(); }"; |
| 352 | const string expected_stderr = ""; |
| 353 | CaptureStderr(); |
| 354 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage())); |
| 355 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 356 | } |
| 357 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 358 | TEST_P(AidlTest, RejectsDuplicatedArgumentNames) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 359 | const string method = "package a; interface IFoo { void f(int a, int a); }"; |
| 360 | const string expected_stderr = |
| 361 | "ERROR: a/IFoo.aidl:1.33-35: method 'f' has duplicate argument name 'a'\n"; |
| 362 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 363 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 364 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Steven Moreland | b3cd3c7 | 2018-10-11 12:37:45 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Jeongik Cha | 13066da | 2020-08-06 15:43:19 +0900 | [diff] [blame] | 367 | TEST_P(AidlTest, RejectsDuplicatedFieldNames) { |
| 368 | const string method = "package a; parcelable Foo { int a; String a; }"; |
| 369 | const string expected_stderr = |
| 370 | "ERROR: a/Foo.aidl:1.22-26: The parcelable 'Foo' has duplicate field name 'a'\n"; |
| 371 | CaptureStderr(); |
| 372 | EXPECT_EQ(nullptr, Parse("a/Foo.aidl", method, typenames_, GetLanguage())); |
| 373 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 374 | } |
| 375 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 376 | TEST_P(AidlTest, RejectsDuplicatedAnnotationParams) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 377 | const string method = "package a; interface IFoo { @UnsupportedAppUsage(foo=1, foo=2)void f(); }"; |
| 378 | const string expected_stderr = "ERROR: a/IFoo.aidl:1.56-62: Trying to redefine parameter foo.\n"; |
| 379 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 380 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 381 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 384 | TEST_P(AidlTest, RejectUnsupportedInterfaceAnnotations) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 385 | AidlError error; |
| 386 | const string method = "package a; @nullable interface IFoo { int f(); }"; |
| 387 | const string expected_stderr = |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 388 | "ERROR: a/IFoo.aidl:1.21-31: 'nullable' is not a supported annotation for this node. " |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 389 | "It must be one of: Hide, UnsupportedAppUsage, VintfStability, JavaPassthrough, Descriptor\n"; |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 390 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 391 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage(), &error)); |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 392 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 393 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 396 | TEST_P(AidlTest, RejectUnsupportedTypeAnnotations) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 397 | AidlError error; |
| 398 | const string method = "package a; interface IFoo { @JavaOnlyStableParcelable int f(); }"; |
| 399 | const string expected_stderr = |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 400 | "ERROR: a/IFoo.aidl:1.54-58: 'JavaOnlyStableParcelable' is not a supported annotation " |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 401 | "for this node. It must be one of: Hide, UnsupportedAppUsage, nullable, utf8InCpp, JavaPassthrough\n"; |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 402 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 403 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage(), &error)); |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 404 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 405 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 408 | TEST_P(AidlTest, RejectUnsupportedParcelableAnnotations) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 409 | AidlError error; |
| 410 | const string method = "package a; @nullable parcelable IFoo cpp_header \"IFoo.h\";"; |
| 411 | const string expected_stderr = |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 412 | "ERROR: a/IFoo.aidl:1.32-37: 'nullable' is not a supported annotation for this node. " |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 413 | "It must be one of: Hide, JavaOnlyStableParcelable, UnsupportedAppUsage, VintfStability, " |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 414 | "JavaPassthrough, JavaOnlyImmutable\n"; |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 415 | CaptureStderr(); |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 416 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage(), &error)); |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 417 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 418 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 421 | TEST_P(AidlTest, RejectUnsupportedParcelableDefineAnnotations) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 422 | AidlError error; |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 423 | const string method = "package a; @nullable parcelable IFoo { String a; String b; }"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 424 | const string expected_stderr = |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 425 | "ERROR: a/IFoo.aidl:1.32-37: 'nullable' is not a supported annotation for this node. " |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 426 | "It must be one of: Hide, UnsupportedAppUsage, VintfStability, JavaPassthrough, JavaDebug, " |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 427 | "JavaOnlyImmutable, FixedSize, RustDerive\n"; |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 428 | CaptureStderr(); |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 429 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage(), &error)); |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 430 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 431 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 434 | TEST_P(AidlTest, ParsesNonNullableAnnotation) { |
| 435 | auto parse_result = |
| 436 | Parse("a/IFoo.aidl", "package a; interface IFoo { String f(); }", typenames_, GetLanguage()); |
| 437 | ASSERT_NE(nullptr, parse_result); |
| 438 | const AidlInterface* interface = parse_result->AsInterface(); |
| 439 | ASSERT_NE(nullptr, interface); |
| 440 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 441 | EXPECT_FALSE(interface->GetMethods()[0]->GetType().IsNullable()); |
| 442 | } |
| 443 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 444 | TEST_P(AidlTest, ParsesNullableAnnotation) { |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 445 | auto parse_result = Parse("a/IFoo.aidl", "package a; interface IFoo { @nullable String f(); }", |
| 446 | typenames_, GetLanguage()); |
| 447 | ASSERT_NE(nullptr, parse_result); |
| 448 | const AidlInterface* interface = parse_result->AsInterface(); |
| 449 | ASSERT_NE(nullptr, interface); |
| 450 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 451 | EXPECT_TRUE(interface->GetMethods()[0]->GetType().IsNullable()); |
| 452 | } |
| 453 | |
| 454 | TEST_P(AidlTest, ParsesNonUtf8Annotations) { |
| 455 | auto parse_result = |
| 456 | Parse("a/IFoo.aidl", "package a; interface IFoo { String f(); }", typenames_, GetLanguage()); |
| 457 | ASSERT_NE(nullptr, parse_result); |
| 458 | const AidlInterface* interface = parse_result->AsInterface(); |
| 459 | ASSERT_NE(nullptr, interface); |
| 460 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 461 | EXPECT_FALSE(interface->GetMethods()[0]->GetType().IsUtf8InCpp()); |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 464 | TEST_P(AidlTest, ParsesUtf8Annotations) { |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 465 | auto parse_result = Parse("a/IFoo.aidl", "package a; interface IFoo { @utf8InCpp String f(); }", |
| 466 | typenames_, GetLanguage()); |
| 467 | ASSERT_NE(nullptr, parse_result); |
| 468 | const AidlInterface* interface = parse_result->AsInterface(); |
| 469 | ASSERT_NE(nullptr, interface); |
| 470 | ASSERT_FALSE(interface->GetMethods().empty()); |
| 471 | EXPECT_TRUE(interface->GetMethods()[0]->GetType().IsUtf8InCpp()); |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 474 | TEST_P(AidlTest, VintfRequiresStructuredAndStability) { |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 475 | AidlError error; |
Devin Moore | 0d0e3f6 | 2020-03-30 17:45:39 -0700 | [diff] [blame] | 476 | const string expected_stderr = |
| 477 | "ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface 'stability: " |
| 478 | "\"vintf\"'\n" |
| 479 | "ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface " |
| 480 | "--structured\n"; |
| 481 | CaptureStderr(); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 482 | ASSERT_EQ(nullptr, Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 483 | GetLanguage(), &error)); |
Devin Moore | 0d0e3f6 | 2020-03-30 17:45:39 -0700 | [diff] [blame] | 484 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 485 | ASSERT_EQ(AidlError::NOT_STRUCTURED, error); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 488 | TEST_P(AidlTest, VintfRequiresStructured) { |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 489 | AidlError error; |
Devin Moore | 0d0e3f6 | 2020-03-30 17:45:39 -0700 | [diff] [blame] | 490 | const string expected_stderr = |
| 491 | "ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface " |
| 492 | "--structured\n"; |
| 493 | CaptureStderr(); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 494 | ASSERT_EQ(nullptr, Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 495 | GetLanguage(), &error, {"--stability", "vintf"})); |
Devin Moore | 0d0e3f6 | 2020-03-30 17:45:39 -0700 | [diff] [blame] | 496 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 497 | ASSERT_EQ(AidlError::NOT_STRUCTURED, error); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 500 | TEST_P(AidlTest, VintfRequiresSpecifiedStability) { |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 501 | AidlError error; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 502 | const string expected_stderr = |
| 503 | "ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface 'stability: " |
| 504 | "\"vintf\"'\n"; |
| 505 | CaptureStderr(); |
| 506 | ASSERT_EQ(nullptr, Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 507 | GetLanguage(), &error, {"--structured"})); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 508 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 509 | ASSERT_EQ(AidlError::NOT_STRUCTURED, error); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 512 | TEST_P(AidlTest, ParsesStabilityAnnotations) { |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 513 | AidlError error; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 514 | auto parse_result = Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_, |
| 515 | GetLanguage(), &error, {"--structured", "--stability", "vintf"}); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 516 | ASSERT_EQ(AidlError::OK, error); |
| 517 | ASSERT_NE(nullptr, parse_result); |
| 518 | const AidlInterface* interface = parse_result->AsInterface(); |
| 519 | ASSERT_NE(nullptr, interface); |
| 520 | ASSERT_TRUE(interface->IsVintfStability()); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 523 | TEST_F(AidlTest, ParsesJavaOnlyStableParcelable) { |
| 524 | Options java_options = Options::From("aidl -o out --structured a/Foo.aidl"); |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 525 | Options cpp_options = Options::From("aidl --lang=cpp -o out -h out/include a/Foo.aidl"); |
| 526 | Options cpp_structured_options = |
Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 527 | Options::From("aidl --lang=cpp --structured -o out -h out/include a/Foo.aidl"); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 528 | Options rust_options = Options::From("aidl --lang=rust -o out --structured a/Foo.aidl"); |
Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 529 | io_delegate_.SetFileContents( |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 530 | "a/Foo.aidl", |
| 531 | StringPrintf("package a; @JavaOnlyStableParcelable parcelable Foo cpp_header \"Foo.h\" ;")); |
Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 532 | |
| 533 | EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 534 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cpp_options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 535 | const string expected_stderr = |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 536 | "ERROR: a/Foo.aidl:1.48-52: Cannot declared parcelable in a --structured interface. " |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 537 | "Parcelable must be defined in AIDL directly.\n"; |
| 538 | CaptureStderr(); |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 539 | EXPECT_NE(0, ::android::aidl::compile_aidl(cpp_structured_options, io_delegate_)); |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 540 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 541 | |
| 542 | CaptureStderr(); |
| 543 | EXPECT_NE(0, ::android::aidl::compile_aidl(rust_options, io_delegate_)); |
| 544 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jeongik Cha | 64783ed | 2019-06-07 18:30:54 +0900 | [diff] [blame] | 545 | } |
| 546 | |
Jiyong Park | 43113fb | 2020-07-20 16:26:19 +0900 | [diff] [blame] | 547 | TEST_F(AidlTest, ParsesJavaDebugAnnotation) { |
| 548 | io_delegate_.SetFileContents("a/IFoo.aidl", R"(package a; |
| 549 | @JavaDebug parcelable IFoo { int a; float b; })"); |
| 550 | Options java_options = Options::From("aidl --lang=java -o out a/IFoo.aidl"); |
| 551 | EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
| 552 | |
| 553 | string java_out; |
| 554 | EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/IFoo.java", &java_out)); |
| 555 | EXPECT_THAT(java_out, testing::HasSubstr("public String toString() {")); |
| 556 | |
| 557 | // Other backends shouldn't be bothered |
| 558 | Options cpp_options = Options::From("aidl --lang=cpp -o out -h out a/IFoo.aidl"); |
| 559 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cpp_options, io_delegate_)); |
| 560 | |
| 561 | Options ndk_options = Options::From("aidl --lang=ndk -o out -h out a/IFoo.aidl"); |
| 562 | EXPECT_EQ(0, ::android::aidl::compile_aidl(ndk_options, io_delegate_)); |
| 563 | } |
| 564 | |
| 565 | TEST_F(AidlTest, RejectsJavaDebugAnnotation) { |
| 566 | { |
| 567 | io_delegate_.SetFileContents("a/IFoo.aidl", "package a; @JavaDebug interface IFoo{}"); |
| 568 | Options java_options = Options::From("aidl --lang=java -o out a/IFoo.aidl"); |
| 569 | CaptureStderr(); |
| 570 | EXPECT_NE(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
| 571 | const std::string expected_stderr = |
| 572 | "ERROR: a/IFoo.aidl:1.22-32: 'JavaDebug' is not a supported annotation for this node. " |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 573 | "It must be one of: Hide, UnsupportedAppUsage, VintfStability, JavaPassthrough, " |
| 574 | "Descriptor\n"; |
Jiyong Park | 43113fb | 2020-07-20 16:26:19 +0900 | [diff] [blame] | 575 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 576 | } |
| 577 | |
| 578 | { |
| 579 | io_delegate_.SetFileContents("a/IFoo.aidl", "package a; @JavaDebug enum IFoo { A=1, }"); |
| 580 | Options java_options = Options::From("aidl --lang=java -o out a/IFoo.aidl"); |
| 581 | CaptureStderr(); |
| 582 | EXPECT_NE(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
| 583 | const std::string expected_stderr = |
| 584 | "ERROR: a/IFoo.aidl:1.27-32: 'JavaDebug' is not a supported annotation for this node. " |
| 585 | "It must be one of: Backing, Hide, VintfStability, JavaPassthrough\n"; |
| 586 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 587 | } |
| 588 | } |
| 589 | |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 590 | TEST_P(AidlTest, ParseDescriptorAnnotation) { |
| 591 | AidlError error; |
| 592 | auto parse_result = Parse("IFoo.aidl", R"(@Descriptor(value="IBar") interface IFoo{})", |
| 593 | typenames_, GetLanguage(), &error, {"--structured"}); |
| 594 | ASSERT_EQ(AidlError::OK, error); |
| 595 | ASSERT_NE(nullptr, parse_result); |
| 596 | const AidlInterface* interface = parse_result->AsInterface(); |
| 597 | ASSERT_NE(nullptr, interface); |
| 598 | ASSERT_EQ("IBar", interface->GetDescriptor()); |
| 599 | } |
| 600 | |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 601 | TEST_P(AidlTest, AcceptsOnewayMethod) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 602 | const string oneway_method = "package a; interface IFoo { oneway void f(int a); }"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 603 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage())); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | TEST_P(AidlTest, AcceptsOnewayInterface) { |
| 607 | const string oneway_interface = "package a; oneway interface IBar { void f(int a); }"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 608 | EXPECT_NE(nullptr, Parse("a/IBar.aidl", oneway_interface, typenames_, GetLanguage())); |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 609 | } |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 610 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 611 | TEST_P(AidlTest, AcceptsAnnotatedOnewayMethod) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 612 | const string oneway_method = |
| 613 | "package a; interface IFoo { @UnsupportedAppUsage oneway void f(int a); }"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 614 | EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage())); |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 615 | } |
| 616 | |
Steven Moreland | 65297cc | 2020-04-20 20:17:36 -0700 | [diff] [blame] | 617 | TEST_P(AidlTest, AnnotationsInMultiplePlaces) { |
| 618 | const string oneway_method = |
| 619 | "package a; interface IFoo { @UnsupportedAppUsage oneway @Hide void f(int a); }"; |
| 620 | const AidlDefinedType* defined = Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()); |
| 621 | ASSERT_NE(nullptr, defined); |
| 622 | const AidlInterface* iface = defined->AsInterface(); |
| 623 | ASSERT_NE(nullptr, iface); |
| 624 | |
| 625 | const auto& methods = iface->GetMethods(); |
| 626 | ASSERT_EQ(1u, methods.size()); |
| 627 | const auto& method = methods[0]; |
| 628 | const AidlTypeSpecifier& ret_type = method->GetType(); |
| 629 | |
| 630 | // TODO(b/151102494): these annotations should be on the method |
| 631 | ASSERT_NE(nullptr, ret_type.UnsupportedAppUsage()); |
| 632 | ASSERT_TRUE(ret_type.IsHide()); |
| 633 | } |
| 634 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 635 | TEST_P(AidlTest, WritesComments) { |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 636 | string foo_interface = |
| 637 | "package a; /* foo */ interface IFoo {" |
| 638 | " /* i */ int i();" |
| 639 | " /* j */ @nullable String j();" |
| 640 | " /* k */ @UnsupportedAppUsage oneway void k(int a); }"; |
| 641 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 642 | auto parse_result = Parse("a/IFoo.aidl", foo_interface, typenames_, GetLanguage()); |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 643 | EXPECT_NE(nullptr, parse_result); |
| 644 | EXPECT_EQ("/* foo */", parse_result->GetComments()); |
| 645 | |
| 646 | const AidlInterface* interface = parse_result->AsInterface(); |
| 647 | EXPECT_EQ("/* i */", interface->GetMethods()[0]->GetComments()); |
| 648 | EXPECT_EQ("/* j */", interface->GetMethods()[1]->GetComments()); |
| 649 | EXPECT_EQ("/* k */", interface->GetMethods()[2]->GetComments()); |
| 650 | } |
| 651 | |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 652 | TEST_F(AidlTest, ParsesPreprocessedFile) { |
| 653 | string simple_content = "parcelable a.Foo;\ninterface b.IBar;"; |
| 654 | io_delegate_.SetFileContents("path", simple_content); |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 655 | EXPECT_FALSE(typenames_.ResolveTypename("a.Foo").is_resolved); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 656 | EXPECT_TRUE(parse_preprocessed_file(io_delegate_, "path", &typenames_)); |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 657 | EXPECT_TRUE(typenames_.ResolveTypename("a.Foo").is_resolved); |
| 658 | EXPECT_TRUE(typenames_.ResolveTypename("b.IBar").is_resolved); |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | TEST_F(AidlTest, ParsesPreprocessedFileWithWhitespace) { |
| 662 | string simple_content = "parcelable a.Foo;\n interface b.IBar ;\t"; |
| 663 | io_delegate_.SetFileContents("path", simple_content); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 664 | |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 665 | EXPECT_FALSE(typenames_.ResolveTypename("a.Foo").is_resolved); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 666 | EXPECT_TRUE(parse_preprocessed_file(io_delegate_, "path", &typenames_)); |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 667 | EXPECT_TRUE(typenames_.ResolveTypename("a.Foo").is_resolved); |
| 668 | EXPECT_TRUE(typenames_.ResolveTypename("b.IBar").is_resolved); |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 671 | TEST_P(AidlTest, PreferImportToPreprocessed) { |
Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 672 | io_delegate_.SetFileContents("preprocessed", "interface another.IBar;"); |
| 673 | io_delegate_.SetFileContents("one/IBar.aidl", "package one; " |
| 674 | "interface IBar {}"); |
| 675 | preprocessed_files_.push_back("preprocessed"); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 676 | import_paths_.emplace(""); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 677 | auto parse_result = Parse("p/IFoo.aidl", "package p; import one.IBar; interface IFoo {}", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 678 | typenames_, GetLanguage()); |
Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 679 | EXPECT_NE(nullptr, parse_result); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 680 | |
Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 681 | // We expect to know about both kinds of IBar |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 682 | EXPECT_TRUE(typenames_.ResolveTypename("one.IBar").is_resolved); |
| 683 | EXPECT_TRUE(typenames_.ResolveTypename("another.IBar").is_resolved); |
Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 684 | // But if we request just "IBar" we should get our imported one. |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 685 | AidlTypeSpecifier ambiguous_type(AIDL_LOCATION_HERE, "IBar", false, nullptr, ""); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 686 | ambiguous_type.Resolve(typenames_); |
| 687 | EXPECT_EQ("one.IBar", ambiguous_type.GetName()); |
Christopher Wiley | 4154437 | 2015-11-03 14:52:29 -0800 | [diff] [blame] | 688 | } |
| 689 | |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 690 | // Special case of PreferImportToPreprocessed. Imported type should be preferred |
| 691 | // even when the preprocessed file already has the same type. |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 692 | TEST_P(AidlTest, B147918827) { |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 693 | io_delegate_.SetFileContents("preprocessed", "interface another.IBar;\ninterface one.IBar;"); |
| 694 | io_delegate_.SetFileContents("one/IBar.aidl", |
| 695 | "package one; " |
| 696 | "interface IBar {}"); |
| 697 | preprocessed_files_.push_back("preprocessed"); |
| 698 | import_paths_.emplace(""); |
| 699 | auto parse_result = Parse("p/IFoo.aidl", "package p; import one.IBar; interface IFoo {}", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 700 | typenames_, GetLanguage()); |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 701 | EXPECT_NE(nullptr, parse_result); |
| 702 | |
| 703 | // We expect to know about both kinds of IBar |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 704 | EXPECT_TRUE(typenames_.ResolveTypename("one.IBar").is_resolved); |
| 705 | EXPECT_TRUE(typenames_.ResolveTypename("another.IBar").is_resolved); |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 706 | // But if we request just "IBar" we should get our imported one. |
| 707 | AidlTypeSpecifier ambiguous_type(AIDL_LOCATION_HERE, "IBar", false, nullptr, ""); |
| 708 | ambiguous_type.Resolve(typenames_); |
| 709 | EXPECT_EQ("one.IBar", ambiguous_type.GetName()); |
| 710 | } |
| 711 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 712 | TEST_F(AidlTest, WritePreprocessedFile) { |
| 713 | io_delegate_.SetFileContents("p/Outer.aidl", |
| 714 | "package p; parcelable Outer.Inner;"); |
| 715 | io_delegate_.SetFileContents("one/IBar.aidl", "package one; import p.Outer;" |
| 716 | "interface IBar {}"); |
| 717 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 718 | vector<string> args { |
| 719 | "aidl", |
| 720 | "--preprocess", |
| 721 | "preprocessed", |
| 722 | "p/Outer.aidl", |
| 723 | "one/IBar.aidl"}; |
| 724 | Options options = Options::From(args); |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 725 | EXPECT_TRUE(::android::aidl::preprocess_aidl(options, io_delegate_)); |
| 726 | |
| 727 | string output; |
| 728 | EXPECT_TRUE(io_delegate_.GetWrittenContents("preprocessed", &output)); |
| 729 | EXPECT_EQ("parcelable p.Outer.Inner;\ninterface one.IBar;\n", output); |
| 730 | } |
| 731 | |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 732 | TEST_F(AidlTest, JavaParcelableOutput) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 733 | io_delegate_.SetFileContents( |
| 734 | "Rect.aidl", |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 735 | "@Hide\n" |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 736 | "parcelable Rect {\n" |
| 737 | " // Comment\n" |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 738 | " @Hide\n" |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 739 | " int x=5;\n" |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 740 | " @Hide\n" |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 741 | " @UnsupportedAppUsage(maxTargetSdk = 28, trackingBug = 42, implicitMember = \"dummy\", " |
Andrei Onea | 07fa3e0 | 2019-07-04 17:55:19 +0100 | [diff] [blame] | 742 | "expectedSignature = \"dummy\", publicAlternatives = \"d\" \n + \"u\" + \n \"m\" \n + \"m\" " |
| 743 | "+ \"y\")\n" |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 744 | " int y;\n" |
Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 745 | " ParcelFileDescriptor fd;\n" |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 746 | "}"); |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 747 | |
| 748 | vector<string> args{"aidl", "Rect.aidl"}; |
| 749 | Options options = Options::From(args); |
| 750 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 751 | |
| 752 | string output; |
| 753 | EXPECT_TRUE(io_delegate_.GetWrittenContents("Rect.java", &output)); |
Jiyong Park | d4e73c8 | 2019-07-24 21:39:15 +0900 | [diff] [blame] | 754 | EXPECT_EQ(kExpectedJavaParcelableOutputContests, output); |
Jeongik Cha | a755c2a | 2018-12-12 16:28:23 +0900 | [diff] [blame] | 755 | } |
| 756 | |
Devin Moore | 2f2077a | 2020-08-28 11:27:53 -0700 | [diff] [blame] | 757 | TEST_F(AidlTest, CppHeaderIncludes) { |
| 758 | io_delegate_.SetFileContents("IFoo.aidl", |
| 759 | "interface IFoo {\n" |
| 760 | " @nullable List<String> foo();\n" |
| 761 | "}"); |
| 762 | |
| 763 | vector<string> args{"aidl", "--lang=cpp", "IFoo.aidl"}; |
| 764 | Options options = Options::From(args); |
| 765 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 766 | std::vector<std::string> empty; |
| 767 | EXPECT_EQ(empty, io_delegate_.ListFiles("")); |
| 768 | EXPECT_EQ(empty, io_delegate_.ListFiles("/")); |
| 769 | EXPECT_EQ(empty, io_delegate_.ListFiles("out")); |
| 770 | |
| 771 | // Make sure the optional and String16.h includes are added |
| 772 | string output; |
| 773 | EXPECT_TRUE(io_delegate_.GetWrittenContents("IFoo.h", &output)); |
| 774 | EXPECT_EQ(kExpectedCppHeaderOutput, output); |
| 775 | } |
| 776 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 777 | TEST_P(AidlTest, RequireOuterClass) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 778 | const string expected_stderr = "ERROR: p/IFoo.aidl:1.54-60: Failed to resolve 'Inner'\n"; |
Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 779 | io_delegate_.SetFileContents("p/Outer.aidl", |
| 780 | "package p; parcelable Outer.Inner;"); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 781 | import_paths_.emplace(""); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 782 | CaptureStderr(); |
| 783 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 784 | "package p; import p.Outer; interface IFoo { void f(in Inner c); }", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 785 | typenames_, GetLanguage())); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 786 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 787 | } |
| 788 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 789 | TEST_P(AidlTest, ParseCompoundParcelableFromPreprocess) { |
Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 790 | io_delegate_.SetFileContents("preprocessed", |
| 791 | "parcelable p.Outer.Inner;"); |
| 792 | preprocessed_files_.push_back("preprocessed"); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 793 | auto parse_result = Parse("p/IFoo.aidl", "package p; interface IFoo { void f(in Inner c); }", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 794 | typenames_, GetLanguage()); |
Christopher Wiley | 63bce2a | 2015-11-03 14:55:03 -0800 | [diff] [blame] | 795 | // TODO(wiley): This should actually return nullptr because we require |
| 796 | // the outer class name. However, for legacy reasons, |
| 797 | // this behavior must be maintained. b/17415692 |
| 798 | EXPECT_NE(nullptr, parse_result); |
| 799 | } |
| 800 | |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 801 | TEST_F(AidlTest, FailOnParcelable) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 802 | const string expected_foo_stderr = |
| 803 | "ERROR: p/IFoo.aidl:1.22-27: Refusing to generate code with unstructured parcelables. " |
| 804 | "Declared parcelables should be in their own file and/or cannot be used with --structured " |
| 805 | "interfaces.\n"; |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 806 | io_delegate_.SetFileContents("p/IFoo.aidl", "package p; parcelable IFoo;"); |
| 807 | |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 808 | // By default, we shouldn't fail on parcelable. |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 809 | Options options1 = Options::From("aidl p/IFoo.aidl"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 810 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 811 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options1, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 812 | EXPECT_EQ("", GetCapturedStderr()); |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 813 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 814 | // -b considers this an error |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 815 | Options options2 = Options::From("aidl -b p/IFoo.aidl"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 816 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 817 | EXPECT_NE(0, ::android::aidl::compile_aidl(options2, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 818 | EXPECT_EQ(expected_foo_stderr, GetCapturedStderr()); |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 819 | |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 820 | const string expected_bar_stderr = |
| 821 | "ERROR: p/IBar.aidl:1.22-26: Refusing to generate code with unstructured parcelables. " |
| 822 | "Declared parcelables should be in their own file and/or cannot be used with --structured " |
| 823 | "interfaces.\n"; |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 824 | io_delegate_.SetFileContents("p/IBar.aidl", "package p; parcelable Foo; interface IBar{}"); |
| 825 | |
Jiyong Park | da8c693 | 2019-08-12 19:56:08 +0900 | [diff] [blame] | 826 | // With '-b' option, a parcelable and an interface should fail. |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 827 | Options options3 = Options::From("aidl p/IBar.aidl"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 828 | CaptureStderr(); |
Jiyong Park | da8c693 | 2019-08-12 19:56:08 +0900 | [diff] [blame] | 829 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options3, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 830 | EXPECT_EQ("", GetCapturedStderr()); |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 831 | Options options4 = Options::From("aidl -b p/IBar.aidl"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 832 | CaptureStderr(); |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 833 | EXPECT_NE(0, ::android::aidl::compile_aidl(options4, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 834 | EXPECT_EQ(expected_bar_stderr, GetCapturedStderr()); |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 835 | } |
| 836 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 837 | TEST_P(AidlTest, StructuredFailOnUnstructuredParcelable) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 838 | const string expected_stderr = |
| 839 | "ERROR: ./o/WhoKnowsWhat.aidl:1.22-35: o.WhoKnowsWhat is not structured, but this is a " |
| 840 | "structured interface.\n"; |
Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 841 | io_delegate_.SetFileContents("o/WhoKnowsWhat.aidl", "package o; parcelable WhoKnowsWhat;"); |
| 842 | import_paths_.emplace(""); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 843 | AidlError error; |
| 844 | CaptureStderr(); |
| 845 | EXPECT_EQ( |
| 846 | nullptr, |
Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 847 | Parse("p/IFoo.aidl", |
| 848 | "package p; import o.WhoKnowsWhat; interface IFoo { void f(in WhoKnowsWhat thisIs); }", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 849 | typenames_, GetLanguage(), &error, {"--structured"})); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 850 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 851 | EXPECT_EQ(AidlError::NOT_STRUCTURED, error); |
Steven Moreland | 1eac5fa | 2018-08-27 19:35:05 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 854 | TEST_P(AidlTest, FailOnDuplicateConstantNames) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 855 | AidlError error; |
| 856 | const string expected_stderr = |
| 857 | "ERROR: p/IFoo.aidl:4.34-45: Found duplicate constant name 'DUPLICATED'\n"; |
| 858 | CaptureStderr(); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 859 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 860 | R"(package p; |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 861 | interface IFoo { |
| 862 | const String DUPLICATED = "d"; |
| 863 | const int DUPLICATED = 1; |
| 864 | } |
| 865 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 866 | typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 867 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 868 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 871 | TEST_P(AidlTest, FailOnManyDefinedTypes) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 872 | AidlError error; |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 873 | const string expected_stderr = |
| 874 | "ERROR: p/IFoo.aidl:3.33-38: You must declare only one type per file.\n"; |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 875 | CaptureStderr(); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 876 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 877 | R"(package p; |
| 878 | interface IFoo {} |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 879 | parcelable IBar {} |
| 880 | parcelable StructuredParcelable {} |
| 881 | interface IBaz {} |
Jeongik Cha | 2a5b4d8 | 2019-08-06 19:37:59 +0900 | [diff] [blame] | 882 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 883 | typenames_, GetLanguage(), &error)); |
Devin Moore | c054bf8 | 2020-03-10 16:31:48 -0700 | [diff] [blame] | 884 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 885 | // Parse success is important for clear error handling even if the cases aren't |
| 886 | // actually supported in code generation. |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 887 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 890 | TEST_P(AidlTest, FailOnNoDefinedTypes) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 891 | AidlError error; |
| 892 | const string expected_stderr = "ERROR: p/IFoo.aidl:1.11-11: syntax error, unexpected $end\n"; |
| 893 | CaptureStderr(); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 894 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", R"(package p;)", typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 895 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 896 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Steven Moreland | f9e922f | 2020-07-08 21:15:27 +0000 | [diff] [blame] | 899 | TEST_P(AidlTest, FailOnEmptyListWithComma) { |
| 900 | AidlError error; |
| 901 | const string expected_stderr = |
| 902 | "ERROR: p/Foo.aidl:1.45-47: syntax error, unexpected ',', expecting '}'\n"; |
| 903 | CaptureStderr(); |
| 904 | EXPECT_EQ(nullptr, Parse("p/Foo.aidl", R"(package p; parcelable Foo { uint64_t[] a = { , }; })", |
| 905 | typenames_, GetLanguage(), &error)); |
| 906 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 907 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
| 908 | } |
| 909 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 910 | TEST_P(AidlTest, FailOnMalformedConstHexValue) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 911 | AidlError error; |
| 912 | const string expected_stderr = |
Devin Moore | 2a08890 | 2020-09-17 10:51:19 -0700 | [diff] [blame] | 913 | "ERROR: p/IFoo.aidl:3.50-71: Could not parse hexvalue: 0xffffffffffffffffff\n"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 914 | CaptureStderr(); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 915 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 916 | R"(package p; |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 917 | interface IFoo { |
| 918 | const int BAD_HEX_VALUE = 0xffffffffffffffffff; |
| 919 | } |
| 920 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 921 | typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 922 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 923 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 926 | TEST_P(AidlTest, FailOnMalformedQualifiedNameAsIdentifier) { |
| 927 | AidlError error; |
| 928 | const string expected_stderr = |
| 929 | "ERROR: p/IFoo.aidl:1.25-26: syntax error, unexpected ';', expecting identifier or " |
| 930 | "cpp_header (which can also be used as an identifier)\n"; |
| 931 | CaptureStderr(); |
| 932 | // Notice the trailing dot(.) in the name, which isn't a correct name |
| 933 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", R"(package p; parcelable A.; )", typenames_, |
| 934 | GetLanguage(), &error)); |
| 935 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 936 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
| 937 | } |
| 938 | |
| 939 | TEST_P(AidlTest, FailOnMalformedQualifiedNameAsPackage) { |
| 940 | AidlError error; |
| 941 | const string expected_stderr = |
| 942 | "ERROR: p/IFoo.aidl:1.11-12: syntax error, unexpected ';', expecting identifier or " |
| 943 | "cpp_header (which can also be used as an identifier)\n"; |
| 944 | CaptureStderr(); |
| 945 | // Notice the trailing dot(.) in the package name |
| 946 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", R"(package p.; parcelable A; )", typenames_, |
| 947 | GetLanguage(), &error)); |
| 948 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 949 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
| 950 | } |
| 951 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 952 | TEST_P(AidlTest, ParsePositiveConstHexValue) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 953 | AidlError error; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 954 | auto parse_result = Parse("p/IFoo.aidl", |
| 955 | R"(package p; |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 956 | interface IFoo { |
| 957 | const int POSITIVE_HEX_VALUE = 0xf5; |
| 958 | } |
| 959 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 960 | typenames_, GetLanguage(), &error); |
| 961 | EXPECT_NE(nullptr, parse_result); |
| 962 | const AidlInterface* interface = parse_result->AsInterface(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 963 | ASSERT_NE(nullptr, interface); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 964 | const auto& cpp_constants = interface->GetConstantDeclarations(); |
| 965 | EXPECT_EQ((size_t)1, cpp_constants.size()); |
| 966 | EXPECT_EQ("POSITIVE_HEX_VALUE", cpp_constants[0]->GetName()); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 967 | EXPECT_TRUE(cpp_constants[0]->CheckValid(typenames_)); |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 968 | EXPECT_EQ("245", cpp_constants[0]->ValueString(cpp::ConstantValueDecorator)); |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 971 | TEST_P(AidlTest, ParseNegativeConstHexValue) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 972 | AidlError error; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 973 | auto parse_result = Parse("p/IFoo.aidl", |
| 974 | R"(package p; |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 975 | interface IFoo { |
| 976 | const int NEGATIVE_HEX_VALUE = 0xffffffff; |
| 977 | } |
| 978 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 979 | typenames_, GetLanguage(), &error); |
| 980 | ASSERT_NE(nullptr, parse_result); |
| 981 | const AidlInterface* interface = parse_result->AsInterface(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 982 | ASSERT_NE(nullptr, interface); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 983 | const auto& cpp_constants = interface->GetConstantDeclarations(); |
| 984 | EXPECT_EQ((size_t)1, cpp_constants.size()); |
| 985 | EXPECT_EQ("NEGATIVE_HEX_VALUE", cpp_constants[0]->GetName()); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 986 | EXPECT_EQ(true, cpp_constants[0]->CheckValid(typenames_)); |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 987 | EXPECT_EQ("-1", cpp_constants[0]->ValueString(cpp::ConstantValueDecorator)); |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 990 | TEST_P(AidlTest, UnderstandsNestedParcelables) { |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 991 | io_delegate_.SetFileContents( |
| 992 | "p/Outer.aidl", |
| 993 | "package p; parcelable Outer.Inner cpp_header \"baz/header\";"); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 994 | import_paths_.emplace(""); |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 995 | const string input_path = "p/IFoo.aidl"; |
| 996 | const string input = "package p; import p.Outer; interface IFoo" |
| 997 | " { Outer.Inner get(); }"; |
| 998 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 999 | auto parse_result = Parse(input_path, input, typenames_, GetLanguage()); |
| 1000 | EXPECT_NE(nullptr, parse_result); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1001 | |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 1002 | EXPECT_TRUE(typenames_.ResolveTypename("p.Outer.Inner").is_resolved); |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 1003 | // C++ uses "::" instead of "." to refer to a inner class. |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1004 | AidlTypeSpecifier nested_type(AIDL_LOCATION_HERE, "p.Outer.Inner", false, nullptr, ""); |
| 1005 | EXPECT_EQ("::p::Outer::Inner", cpp::CppNameOf(nested_type, typenames_)); |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1008 | TEST_P(AidlTest, UnderstandsNativeParcelables) { |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 1009 | io_delegate_.SetFileContents( |
| 1010 | "p/Bar.aidl", |
Casey Dahlin | cd63921 | 2015-12-15 12:51:04 -0800 | [diff] [blame] | 1011 | "package p; parcelable Bar cpp_header \"baz/header\";"); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 1012 | import_paths_.emplace(""); |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 1013 | const string input_path = "p/IFoo.aidl"; |
| 1014 | const string input = "package p; import p.Bar; interface IFoo { }"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1015 | auto parse_result = Parse(input_path, input, typenames_, GetLanguage()); |
| 1016 | EXPECT_NE(nullptr, parse_result); |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 1017 | EXPECT_TRUE(typenames_.ResolveTypename("p.Bar").is_resolved); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1018 | AidlTypeSpecifier native_type(AIDL_LOCATION_HERE, "p.Bar", false, nullptr, ""); |
| 1019 | native_type.Resolve(typenames_); |
| 1020 | |
| 1021 | EXPECT_EQ("p.Bar", java::InstantiableJavaSignatureOf(native_type, typenames_)); |
| 1022 | // C++ understands C++ specific stuff |
| 1023 | EXPECT_EQ("::p::Bar", cpp::CppNameOf(native_type, typenames_)); |
| 1024 | set<string> headers; |
Devin Moore | 2f2077a | 2020-08-28 11:27:53 -0700 | [diff] [blame] | 1025 | cpp::AddHeaders(native_type, typenames_, &headers); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1026 | EXPECT_EQ(1u, headers.size()); |
| 1027 | EXPECT_EQ(1u, headers.count("baz/header")); |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 1030 | TEST_F(AidlTest, WritesCorrectDependencyFile) { |
| 1031 | // While the in tree build system always gives us an output file name, |
| 1032 | // other android tools take advantage of our ability to infer the intended |
| 1033 | // file name. This test makes sure we handle this correctly. |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1034 | vector<string> args = { |
| 1035 | "aidl", |
| 1036 | "-d dep/file/path", |
| 1037 | "-o place/for/output", |
| 1038 | "p/IFoo.aidl"}; |
| 1039 | Options options = Options::From(args); |
| 1040 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}"); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1041 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 1042 | string actual_dep_file_contents; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1043 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
Christopher Wiley | f813619 | 2016-04-12 14:19:35 -0700 | [diff] [blame] | 1044 | EXPECT_EQ(actual_dep_file_contents, kExpectedDepFileContents); |
| 1045 | } |
| 1046 | |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 1047 | TEST_F(AidlTest, WritesCorrectDependencyFileNinja) { |
| 1048 | // While the in tree build system always gives us an output file name, |
| 1049 | // other android tools take advantage of our ability to infer the intended |
| 1050 | // file name. This test makes sure we handle this correctly. |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1051 | vector<string> args = { |
| 1052 | "aidl", |
| 1053 | "-d dep/file/path", |
| 1054 | "--ninja", |
| 1055 | "-o place/for/output", |
| 1056 | "p/IFoo.aidl"}; |
| 1057 | Options options = Options::From(args); |
| 1058 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}"); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1059 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 1060 | string actual_dep_file_contents; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1061 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 1062 | EXPECT_EQ(actual_dep_file_contents, kExpectedNinjaDepFileContents); |
| 1063 | } |
| 1064 | |
Jiyong Park | df20212 | 2019-09-30 20:48:35 +0900 | [diff] [blame] | 1065 | TEST_F(AidlTest, WritesTrivialDependencyFileForParcelableDeclaration) { |
Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 1066 | // The SDK uses aidl to decide whether a .aidl file is a parcelable. It does |
| 1067 | // this by calling aidl with every .aidl file it finds, then parsing the |
| 1068 | // generated dependency files. Those that reference .java output files are |
| 1069 | // for interfaces and those that do not are parcelables. However, for both |
| 1070 | // parcelables and interfaces, we *must* generate a non-empty dependency file. |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1071 | vector<string> args = { |
| 1072 | "aidl", |
| 1073 | "-o place/for/output", |
| 1074 | "-d dep/file/path", |
| 1075 | "p/Foo.aidl"}; |
| 1076 | Options options = Options::From(args); |
| 1077 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo;"); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1078 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 1079 | string actual_dep_file_contents; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1080 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
Jiyong Park | df20212 | 2019-09-30 20:48:35 +0900 | [diff] [blame] | 1081 | EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDeclarationDepFileContents); |
| 1082 | } |
| 1083 | |
| 1084 | TEST_F(AidlTest, WritesDependencyFileForStructuredParcelable) { |
| 1085 | vector<string> args = { |
| 1086 | "aidl", |
| 1087 | "--structured", |
| 1088 | "-o place/for/output", |
| 1089 | "-d dep/file/path", |
| 1090 | "p/Foo.aidl"}; |
| 1091 | Options options = Options::From(args); |
| 1092 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo {int a;}"); |
| 1093 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1094 | string actual_dep_file_contents; |
| 1095 | EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents)); |
| 1096 | EXPECT_EQ(actual_dep_file_contents, kExpectedStructuredParcelableDepFileContents); |
Christopher Wiley | b1bbdf8 | 2016-04-21 11:43:45 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Jiyong Park | 9ca5c7e | 2019-10-17 15:01:14 +0900 | [diff] [blame] | 1099 | TEST_F(AidlTest, NoJavaOutputForParcelableDeclaration) { |
| 1100 | vector<string> args = { |
| 1101 | "aidl", |
| 1102 | "--lang=java", |
| 1103 | "-o place/for/output", |
| 1104 | "p/Foo.aidl"}; |
| 1105 | Options options = Options::From(args); |
| 1106 | io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo;"); |
| 1107 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1108 | string output_file_contents; |
| 1109 | EXPECT_FALSE(io_delegate_.GetWrittenContents(options.OutputFile(), &output_file_contents)); |
| 1110 | } |
| 1111 | |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1112 | // TODO(b/136048684) |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1113 | TEST_P(AidlTest, PrimitiveList) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1114 | const string primitive_interface = |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1115 | "package a; interface IFoo {\n" |
| 1116 | " List<int> foo(); }"; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1117 | string expected_stderr; |
| 1118 | switch (GetLanguage()) { |
| 1119 | case Options::Language::CPP: |
| 1120 | expected_stderr = |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 1121 | "ERROR: a/IFoo.aidl:2.1-7: A generic type cannot have any primitive type parameters.\n" |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1122 | "ERROR: a/IFoo.aidl:2.1-7: List<int> is not supported. List in cpp supports only " |
| 1123 | "String and IBinder.\n"; |
| 1124 | break; |
| 1125 | case Options::Language::JAVA: |
| 1126 | expected_stderr = |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 1127 | "ERROR: a/IFoo.aidl:2.1-7: A generic type cannot have any primitive type parameters.\n" |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1128 | "ERROR: a/IFoo.aidl:2.1-7: List<int> is not supported. List in Java supports only " |
| 1129 | "String, IBinder, and ParcelFileDescriptor.\n"; |
| 1130 | break; |
| 1131 | case Options::Language::NDK: |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 1132 | case Options::Language::RUST: |
| 1133 | expected_stderr = |
| 1134 | "ERROR: a/IFoo.aidl:2.1-7: A generic type cannot have any primitive type parameters.\n"; |
| 1135 | break; |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1136 | default: |
| 1137 | AIDL_FATAL(AIDL_LOCATION_HERE) |
| 1138 | << "Unexpected Options::Language enumerator: " << static_cast<size_t>(GetLanguage()); |
| 1139 | } |
| 1140 | CaptureStderr(); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 1141 | AidlTypenames tn1; |
| 1142 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", primitive_interface, tn1, GetLanguage())); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1143 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1144 | |
| 1145 | string primitive_parcelable = |
| 1146 | "package a; parcelable IFoo {\n" |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1147 | " List<int> foo;}"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1148 | CaptureStderr(); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 1149 | AidlTypenames tn2; |
| 1150 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", primitive_parcelable, tn2, GetLanguage())); |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 1151 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1152 | } |
| 1153 | |
Devin Moore | 21b2677 | 2020-08-26 16:37:56 -0700 | [diff] [blame] | 1154 | TEST_P(AidlTest, RejectsListArray) { |
Devin Moore | 6a01ca1 | 2020-08-28 10:24:19 -0700 | [diff] [blame] | 1155 | const string expected_stderr = "ERROR: a/Foo.aidl:2.1-7: List[] is not supported.\n"; |
Devin Moore | 21b2677 | 2020-08-26 16:37:56 -0700 | [diff] [blame] | 1156 | const string list_array_parcelable = |
| 1157 | "package a; parcelable Foo {\n" |
| 1158 | " List[] lists; }"; |
| 1159 | CaptureStderr(); |
| 1160 | EXPECT_EQ(nullptr, Parse("a/Foo.aidl", list_array_parcelable, typenames_, GetLanguage())); |
| 1161 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1162 | } |
| 1163 | |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1164 | TEST_P(AidlTest, RejectsPrimitiveListInStableAidl) { |
| 1165 | AidlError error; |
| 1166 | string expected_stderr = |
| 1167 | "ERROR: a/IFoo.aidl:2.7-11: " |
| 1168 | "Encountered an untyped List or Map. The use of untyped List/Map is " |
| 1169 | "prohibited because it is not guaranteed that the objects in the list are recognizable in " |
| 1170 | "the receiving side. Consider switching to an array or a generic List/Map.\n"; |
| 1171 | if (GetLanguage() != Options::Language::JAVA) { |
| 1172 | expected_stderr = |
| 1173 | "ERROR: a/IFoo.aidl:2.1-7: " |
| 1174 | "Currently, only the Java backend supports non-generic List.\n"; |
| 1175 | } |
| 1176 | |
| 1177 | const string primitive_interface = |
| 1178 | "package a; interface IFoo {\n" |
| 1179 | " List foo(); }"; |
| 1180 | CaptureStderr(); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 1181 | AidlTypenames tn1; |
| 1182 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", primitive_interface, tn1, GetLanguage(), &error, |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1183 | {"--structured"})); |
| 1184 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1185 | |
| 1186 | string primitive_parcelable = |
| 1187 | "package a; parcelable IFoo {\n" |
| 1188 | " List foo;}"; |
| 1189 | CaptureStderr(); |
Jiyong Park | 40782d0 | 2020-07-24 19:17:43 +0900 | [diff] [blame] | 1190 | AidlTypenames tn2; |
| 1191 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", primitive_parcelable, tn2, GetLanguage(), &error, |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1192 | {"--structured"})); |
| 1193 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1194 | } |
| 1195 | |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1196 | TEST_P(AidlTest, ExtensionTest) { |
| 1197 | CaptureStderr(); |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1198 | string extendable_parcelable = |
| 1199 | "package a; parcelable Data {\n" |
| 1200 | " ParcelableHolder extension;\n" |
| 1201 | " ParcelableHolder extension2;\n" |
| 1202 | "}"; |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1203 | if (GetLanguage() == Options::Language::NDK || GetLanguage() == Options::Language::RUST) { |
| 1204 | EXPECT_EQ(nullptr, Parse("a/Data.aidl", extendable_parcelable, typenames_, GetLanguage())); |
| 1205 | EXPECT_EQ( |
| 1206 | "ERROR: a/Data.aidl:2.1-19: The NDK and Rust backend does not support ParcelableHolder " |
| 1207 | "yet.\n", |
| 1208 | GetCapturedStderr()); |
| 1209 | } else { |
| 1210 | EXPECT_NE(nullptr, Parse("a/Data.aidl", extendable_parcelable, typenames_, GetLanguage())); |
| 1211 | EXPECT_EQ("", GetCapturedStderr()); |
| 1212 | } |
| 1213 | } |
| 1214 | TEST_P(AidlTest, ParcelableHolderAsReturnType) { |
| 1215 | CaptureStderr(); |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1216 | string parcelableholder_return_interface = |
| 1217 | "package a; interface IFoo {\n" |
| 1218 | " ParcelableHolder foo();\n" |
| 1219 | "}"; |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1220 | EXPECT_EQ(nullptr, |
| 1221 | Parse("a/IFoo.aidl", parcelableholder_return_interface, typenames_, GetLanguage())); |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1222 | |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1223 | if (GetLanguage() == Options::Language::NDK || GetLanguage() == Options::Language::RUST) { |
| 1224 | EXPECT_EQ( |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 1225 | "ERROR: a/IFoo.aidl:2.19-23: ParcelableHolder cannot be a return type\n" |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1226 | "ERROR: a/IFoo.aidl:2.1-19: The NDK and Rust backend does not support ParcelableHolder " |
| 1227 | "yet.\n", |
| 1228 | GetCapturedStderr()); |
| 1229 | return; |
| 1230 | } |
| 1231 | EXPECT_EQ("ERROR: a/IFoo.aidl:2.19-23: ParcelableHolder cannot be a return type\n", |
| 1232 | GetCapturedStderr()); |
| 1233 | } |
| 1234 | |
| 1235 | TEST_P(AidlTest, ParcelableHolderAsArgumentType) { |
| 1236 | CaptureStderr(); |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1237 | string extendable_parcelable_arg_interface = |
| 1238 | "package a; interface IFoo {\n" |
| 1239 | " void foo(in ParcelableHolder ph);\n" |
| 1240 | "}"; |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1241 | EXPECT_EQ(nullptr, |
| 1242 | Parse("a/IFoo.aidl", extendable_parcelable_arg_interface, typenames_, GetLanguage())); |
| 1243 | |
| 1244 | if (GetLanguage() == Options::Language::NDK || GetLanguage() == Options::Language::RUST) { |
| 1245 | EXPECT_EQ( |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 1246 | "ERROR: a/IFoo.aidl:2.31-34: ParcelableHolder cannot be an argument type\n" |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 1247 | "ERROR: a/IFoo.aidl:2.14-31: The NDK and Rust backend does not support ParcelableHolder " |
| 1248 | "yet.\n", |
| 1249 | GetCapturedStderr()); |
| 1250 | return; |
| 1251 | } |
| 1252 | EXPECT_EQ("ERROR: a/IFoo.aidl:2.31-34: ParcelableHolder cannot be an argument type\n", |
| 1253 | GetCapturedStderr()); |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1254 | } |
| 1255 | |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1256 | TEST_F(AidlTest, ApiDump) { |
| 1257 | io_delegate_.SetFileContents( |
| 1258 | "foo/bar/IFoo.aidl", |
| 1259 | "package foo.bar;\n" |
| 1260 | "import foo.bar.Data;\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1261 | "// comment @hide\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1262 | "interface IFoo {\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1263 | " /* @hide */\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1264 | " int foo(out int[] a, String b, boolean c, inout List<String> d);\n" |
| 1265 | " int foo2(@utf8InCpp String x, inout List<String> y);\n" |
| 1266 | " IFoo foo3(IFoo foo);\n" |
| 1267 | " Data getData();\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1268 | " // @hide\n" |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1269 | " const int A = 1;\n" |
| 1270 | " const String STR = \"Hello\";\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1271 | "}\n"); |
| 1272 | io_delegate_.SetFileContents("foo/bar/Data.aidl", |
| 1273 | "package foo.bar;\n" |
| 1274 | "import foo.bar.IFoo;\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1275 | "/* @hide*/\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1276 | "parcelable Data {\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1277 | " // @hide\n" |
Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 1278 | " int x = 10;\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1279 | " // @hide\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1280 | " int y;\n" |
| 1281 | " IFoo foo;\n" |
| 1282 | " List<IFoo> a;\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1283 | " /*@hide2*/\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1284 | " List<foo.bar.IFoo> b;\n" |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1285 | " // It should be @hide property\n" |
Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 1286 | " @nullable String[] c;\n" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1287 | "}\n"); |
| 1288 | io_delegate_.SetFileContents("api.aidl", ""); |
Jiyong Park | 633246c | 2019-11-25 10:50:05 +0900 | [diff] [blame] | 1289 | vector<string> args = {"aidl", "--dumpapi", "--out=dump", "--include=.", |
| 1290 | "foo/bar/IFoo.aidl", "foo/bar/Data.aidl"}; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1291 | Options options = Options::From(args); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1292 | bool result = dump_api(options, io_delegate_); |
| 1293 | ASSERT_TRUE(result); |
| 1294 | string actual; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1295 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual)); |
Paul Trautrim | b01451d | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 1296 | EXPECT_EQ(actual, string(kPreamble).append(R"(package foo.bar; |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1297 | /* @hide */ |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1298 | interface IFoo { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1299 | /* @hide */ |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1300 | int foo(out int[] a, String b, boolean c, inout List<String> d); |
| 1301 | int foo2(@utf8InCpp String x, inout List<String> y); |
| 1302 | foo.bar.IFoo foo3(foo.bar.IFoo foo); |
| 1303 | foo.bar.Data getData(); |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1304 | /* @hide */ |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1305 | const int A = 1; |
| 1306 | const String STR = "Hello"; |
| 1307 | } |
Paul Trautrim | b01451d | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 1308 | )")); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1309 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1310 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/Data.aidl", &actual)); |
Paul Trautrim | b01451d | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 1311 | EXPECT_EQ(actual, string(kPreamble).append(R"(package foo.bar; |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1312 | /* @hide */ |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1313 | parcelable Data { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1314 | /* @hide */ |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1315 | int x = 10; |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1316 | /* @hide */ |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1317 | int y; |
| 1318 | foo.bar.IFoo foo; |
| 1319 | List<foo.bar.IFoo> a; |
| 1320 | List<foo.bar.IFoo> b; |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1321 | /* @hide */ |
Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 1322 | @nullable String[] c; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1323 | } |
Paul Trautrim | b01451d | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 1324 | )")); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1325 | } |
| 1326 | |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1327 | TEST_F(AidlTest, ApiDumpWithManualIds) { |
| 1328 | io_delegate_.SetFileContents( |
| 1329 | "foo/bar/IFoo.aidl", |
| 1330 | "package foo.bar;\n" |
| 1331 | "interface IFoo {\n" |
| 1332 | " int foo() = 1;\n" |
| 1333 | " int bar() = 2;\n" |
| 1334 | " int baz() = 10;\n" |
| 1335 | "}\n"); |
| 1336 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1337 | vector<string> args = {"aidl", "--dumpapi", "-o dump", "foo/bar/IFoo.aidl"}; |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1338 | Options options = Options::From(args); |
| 1339 | bool result = dump_api(options, io_delegate_); |
| 1340 | ASSERT_TRUE(result); |
| 1341 | string actual; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1342 | EXPECT_TRUE(io_delegate_.GetWrittenContents("dump/foo/bar/IFoo.aidl", &actual)); |
Paul Trautrim | b01451d | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 1343 | EXPECT_EQ(actual, string(kPreamble).append(R"(package foo.bar; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1344 | interface IFoo { |
| 1345 | int foo() = 1; |
| 1346 | int bar() = 2; |
| 1347 | int baz() = 10; |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1348 | } |
Paul Trautrim | b01451d | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 1349 | )")); |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | TEST_F(AidlTest, ApiDumpWithManualIdsOnlyOnSomeMethods) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1353 | const string expected_stderr = |
| 1354 | "ERROR: foo/bar/IFoo.aidl:4.8-12: You must either assign id's to all methods or to none of " |
| 1355 | "them.\n"; |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1356 | io_delegate_.SetFileContents( |
| 1357 | "foo/bar/IFoo.aidl", |
| 1358 | "package foo.bar;\n" |
| 1359 | "interface IFoo {\n" |
| 1360 | " int foo() = 1;\n" |
| 1361 | " int bar();\n" |
| 1362 | " int baz() = 10;\n" |
| 1363 | "}\n"); |
| 1364 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1365 | vector<string> args = {"aidl", "--dumpapi", "-o dump", "foo/bar/IFoo.aidl"}; |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1366 | Options options = Options::From(args); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1367 | CaptureStderr(); |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1368 | EXPECT_FALSE(dump_api(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1369 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 1370 | } |
| 1371 | |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 1372 | TEST_F(AidlTest, CheckNumGenericTypeSecifier) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1373 | const string expected_list_stderr = |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 1374 | "ERROR: p/IFoo.aidl:1.37-41: List can only have one type parameter, but got: " |
| 1375 | "'List<String,String>'\n"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1376 | const string expected_map_stderr = |
| 1377 | "ERROR: p/IFoo.aidl:1.37-40: Map must have 0 or 2 type parameters, but got 'Map<String>'\n"; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1378 | Options options = Options::From("aidl p/IFoo.aidl IFoo.java"); |
| 1379 | io_delegate_.SetFileContents(options.InputFiles().front(), |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 1380 | "package p; interface IFoo {" |
| 1381 | "void foo(List<String, String> a);}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1382 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1383 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1384 | EXPECT_EQ(expected_list_stderr, GetCapturedStderr()); |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 1385 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1386 | io_delegate_.SetFileContents(options.InputFiles().front(), |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 1387 | "package p; interface IFoo {" |
| 1388 | "void foo(Map<String> a);}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1389 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1390 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1391 | EXPECT_EQ(expected_map_stderr, GetCapturedStderr()); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1392 | } |
| 1393 | |
Jeongik Cha | e48d994 | 2020-01-02 17:39:00 +0900 | [diff] [blame] | 1394 | TEST_F(AidlTest, CheckTypeParameterInMapType) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1395 | const string expected_stderr = |
| 1396 | "ERROR: p/IFoo.aidl:1.28-31: The type of key in map must be String, but it is 'p.Bar'\n"; |
Jeongik Cha | e48d994 | 2020-01-02 17:39:00 +0900 | [diff] [blame] | 1397 | Options options = Options::From("aidl -I p p/IFoo.aidl"); |
| 1398 | io_delegate_.SetFileContents("p/Bar.aidl", "package p; parcelable Bar { String s; }"); |
| 1399 | |
| 1400 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1401 | "package p; interface IFoo {" |
| 1402 | "Map<String, Bar> foo();}"); |
| 1403 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1404 | |
| 1405 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1406 | "package p; interface IFoo {" |
| 1407 | "Map<Bar, Bar> foo();}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1408 | CaptureStderr(); |
Jeongik Cha | e48d994 | 2020-01-02 17:39:00 +0900 | [diff] [blame] | 1409 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1410 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jeongik Cha | e48d994 | 2020-01-02 17:39:00 +0900 | [diff] [blame] | 1411 | |
| 1412 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1413 | "package p; interface IFoo {" |
| 1414 | "Map<String, String> foo();}"); |
| 1415 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1416 | |
| 1417 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1418 | "package p; interface IFoo {" |
| 1419 | "Map<String, ParcelFileDescriptor> foo();}"); |
| 1420 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1421 | } |
| 1422 | |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1423 | TEST_F(AidlTest, WrongGenericType) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1424 | const string expected_stderr = "ERROR: p/IFoo.aidl:1.28-34: String is not a generic type.\n"; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1425 | Options options = Options::From("aidl p/IFoo.aidl IFoo.java"); |
| 1426 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1427 | "package p; interface IFoo {" |
| 1428 | "String<String> foo(); }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1429 | CaptureStderr(); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1430 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1431 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | TEST_F(AidlTest, UserDefinedUnstructuredGenericParcelableType) { |
| 1435 | Options optionsForParcelable = Options::From("aidl -I p p/Bar.aidl"); |
| 1436 | io_delegate_.SetFileContents("p/Bar.aidl", "package p; parcelable Bar<T, T>;"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1437 | CaptureStderr(); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1438 | EXPECT_NE(0, ::android::aidl::compile_aidl(optionsForParcelable, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1439 | EXPECT_EQ("ERROR: p/Bar.aidl:1.22-26: Every type parameter should be unique.\n", |
| 1440 | GetCapturedStderr()); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1441 | |
| 1442 | Options options = Options::From("aidl -I p p/IFoo.aidl"); |
| 1443 | io_delegate_.SetFileContents("p/Bar.aidl", "package p; parcelable Bar;"); |
| 1444 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1445 | "package p; interface IFoo {" |
| 1446 | "Bar<String, String> foo();}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1447 | CaptureStderr(); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1448 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1449 | EXPECT_EQ("ERROR: p/IFoo.aidl:1.28-31: p.Bar is not a generic type.\n", GetCapturedStderr()); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1450 | io_delegate_.SetFileContents("p/Bar.aidl", "package p; parcelable Bar<T>;"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1451 | CaptureStderr(); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1452 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1453 | EXPECT_EQ("ERROR: p/IFoo.aidl:1.28-31: p.Bar must have 1 type parameters, but got 2\n", |
| 1454 | GetCapturedStderr()); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1455 | io_delegate_.SetFileContents("p/Bar.aidl", "package p; parcelable Bar<T, V>;"); |
| 1456 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1457 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1458 | "package p; interface IFoo {" |
| 1459 | "Bar<String, ParcelFileDescriptor> foo();}"); |
| 1460 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Jeongik Cha | e74c86d | 2019-12-12 16:54:03 +0900 | [diff] [blame] | 1461 | |
| 1462 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1463 | "package p; interface IFoo {" |
| 1464 | "Bar<int, long> foo();}"); |
| 1465 | |
| 1466 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 1467 | "package p; interface IFoo {" |
| 1468 | "Bar<int[], long[]> foo();}"); |
| 1469 | |
| 1470 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 1471 | } |
| 1472 | |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1473 | TEST_F(AidlTest, FailOnMultipleTypesInSingleFile) { |
| 1474 | std::vector<std::string> rawOptions{"aidl --lang=java -o out foo/bar/Foo.aidl", |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 1475 | "aidl --lang=cpp -o out -h out/include foo/bar/Foo.aidl", |
| 1476 | "aidl --lang=rust -o out foo/bar/Foo.aidl"}; |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 1477 | for (const auto& rawOption : rawOptions) { |
| 1478 | string expected_stderr = |
| 1479 | "ERROR: foo/bar/Foo.aidl:3.1-10: You must declare only one type per file.\n"; |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1480 | Options options = Options::From(rawOption); |
| 1481 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1482 | "package foo.bar;\n" |
| 1483 | "interface IFoo1 { int foo(); }\n" |
| 1484 | "interface IFoo2 { int foo(); }\n" |
| 1485 | "parcelable Data1 { int a; int b;}\n" |
| 1486 | "parcelable Data2 { int a; int b;}\n"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1487 | CaptureStderr(); |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1488 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1489 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1490 | |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1491 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1492 | "package foo.bar;\n" |
| 1493 | "interface IFoo1 { int foo(); }\n" |
| 1494 | "interface IFoo2 { int foo(); }\n"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1495 | CaptureStderr(); |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1496 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1497 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1498 | |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 1499 | expected_stderr = "ERROR: foo/bar/Foo.aidl:3.11-17: You must declare only one type per file.\n"; |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1500 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1501 | "package foo.bar;\n" |
| 1502 | "parcelable Data1 { int a; int b;}\n" |
| 1503 | "parcelable Data2 { int a; int b;}\n"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1504 | CaptureStderr(); |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 1505 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1506 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
Devin Moore | bdba2a8 | 2020-03-31 15:19:02 -0700 | [diff] [blame] | 1510 | TEST_P(AidlTest, FailParseOnEmptyFile) { |
| 1511 | const string contents = ""; |
| 1512 | const string expected_stderr = "ERROR: a/IFoo.aidl:1.1-1: syntax error, unexpected $end\n"; |
| 1513 | CaptureStderr(); |
| 1514 | EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", contents, typenames_, GetLanguage())); |
| 1515 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1516 | } |
| 1517 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1518 | TEST_F(AidlTest, MultipleInputFiles) { |
| 1519 | Options options = Options::From( |
Jiyong Park | 633246c | 2019-11-25 10:50:05 +0900 | [diff] [blame] | 1520 | "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] | 1521 | |
| 1522 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 1523 | "package foo.bar;\n" |
| 1524 | "import foo.bar.Data;\n" |
| 1525 | "interface IFoo { Data getData(); }\n"); |
| 1526 | |
| 1527 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 1528 | "package foo.bar;\n" |
| 1529 | "import foo.bar.IFoo;\n" |
| 1530 | "parcelable Data { IFoo foo; }\n"); |
| 1531 | |
| 1532 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1533 | |
| 1534 | string content; |
| 1535 | for (const auto file : { |
| 1536 | "out/foo/bar/IFoo.java", "out/foo/bar/Data.java"}) { |
| 1537 | content.clear(); |
| 1538 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 1539 | EXPECT_FALSE(content.empty()); |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | TEST_F(AidlTest, MultipleInputFilesCpp) { |
| 1544 | Options options = Options::From("aidl --lang=cpp -o out -h out/include " |
Jiyong Park | 633246c | 2019-11-25 10:50:05 +0900 | [diff] [blame] | 1545 | "-I . foo/bar/IFoo.aidl foo/bar/Data.aidl"); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1546 | |
| 1547 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 1548 | "package foo.bar;\n" |
| 1549 | "import foo.bar.Data;\n" |
| 1550 | "interface IFoo { Data getData(); }\n"); |
| 1551 | |
| 1552 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 1553 | "package foo.bar;\n" |
| 1554 | "import foo.bar.IFoo;\n" |
| 1555 | "parcelable Data { IFoo foo; }\n"); |
| 1556 | |
| 1557 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1558 | |
| 1559 | string content; |
| 1560 | for (const auto file : { |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 1561 | "out/foo/bar/IFoo.cpp", "out/foo/bar/Data.cpp", |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1562 | "out/include/foo/bar/IFoo.h", "out/include/foo/bar/Data.h", |
| 1563 | "out/include/foo/bar/BpFoo.h", "out/include/foo/bar/BpData.h", |
| 1564 | "out/include/foo/bar/BnFoo.h", "out/include/foo/bar/BnData.h"}) { |
| 1565 | content.clear(); |
| 1566 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 1567 | EXPECT_FALSE(content.empty()); |
| 1568 | } |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 1569 | } |
| 1570 | |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 1571 | TEST_F(AidlTest, MultipleInputFilesRust) { |
| 1572 | Options options = |
| 1573 | Options::From("aidl --lang=rust -o out -I . foo/bar/IFoo.aidl foo/bar/Data.aidl"); |
| 1574 | |
| 1575 | io_delegate_.SetFileContents(options.InputFiles().at(0), |
| 1576 | "package foo.bar;\n" |
| 1577 | "import foo.bar.Data;\n" |
| 1578 | "interface IFoo { Data getData(); }\n"); |
| 1579 | |
| 1580 | io_delegate_.SetFileContents(options.InputFiles().at(1), |
| 1581 | "package foo.bar;\n" |
| 1582 | "import foo.bar.IFoo;\n" |
| 1583 | "parcelable Data { IFoo foo; }\n"); |
| 1584 | |
| 1585 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 1586 | |
| 1587 | string content; |
| 1588 | for (const auto file : {"out/foo/bar/IFoo.rs", "out/foo/bar/Data.rs"}) { |
| 1589 | content.clear(); |
| 1590 | EXPECT_TRUE(io_delegate_.GetWrittenContents(file, &content)); |
| 1591 | EXPECT_FALSE(content.empty()); |
| 1592 | } |
| 1593 | } |
| 1594 | |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1595 | TEST_F(AidlTest, ConflictWithMetaTransactionGetVersion) { |
| 1596 | const string expected_stderr = |
| 1597 | "ERROR: p/IFoo.aidl:1.31-51: method getInterfaceVersion() is reserved for internal use.\n"; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1598 | Options options = Options::From("aidl --lang=java -o place/for/output p/IFoo.aidl"); |
| 1599 | // int getInterfaceVersion() is one of the meta transactions |
| 1600 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1601 | "package p; interface IFoo {" |
| 1602 | "int getInterfaceVersion(); }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1603 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1604 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1605 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1606 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1607 | |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1608 | TEST_F(AidlTest, ConflictWithSimilarMetaTransaction) { |
| 1609 | // boolean getInterfaceVersion() is not a meta transaction, but should be |
| 1610 | // prevented because return type is not part of a method signature |
| 1611 | const string expected_stderr = |
| 1612 | "ERROR: p/IFoo.aidl:1.35-55: method getInterfaceVersion() is reserved for internal use.\n"; |
| 1613 | Options options = Options::From("aidl --lang=java -o place/for/output p/IFoo.aidl"); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1614 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1615 | "package p; interface IFoo {" |
| 1616 | "boolean getInterfaceVersion(); }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1617 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1618 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1619 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1620 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1621 | |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1622 | TEST_F(AidlTest, ConflictWithMetaTransactionGetName) { |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1623 | // this is another reserved name |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1624 | const string expected_stderr = |
| 1625 | "ERROR: p/IFoo.aidl:1.34-53: method getTransactionName(int) is reserved for internal use.\n"; |
| 1626 | Options options = Options::From("aidl --lang=java -o place/for/output p/IFoo.aidl"); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1627 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1628 | "package p; interface IFoo {" |
| 1629 | "String getTransactionName(int code); }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1630 | CaptureStderr(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1631 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1632 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1633 | |
| 1634 | // this is not a meta interface method as it differs type arguments |
| 1635 | io_delegate_.SetFileContents(options.InputFiles().front(), |
| 1636 | "package p; interface IFoo {" |
| 1637 | "String getTransactionName(); }"); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 1638 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1639 | } |
| 1640 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1641 | TEST_F(AidlTest, DifferentOrderAnnotationsInCheckAPI) { |
Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 1642 | Options options = Options::From("aidl --checkapi old new"); |
| 1643 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1644 | "package p; interface IFoo{ @utf8InCpp @nullable String foo();}"); |
| 1645 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1646 | "package p; interface IFoo{ @nullable @utf8InCpp String foo();}"); |
| 1647 | |
| 1648 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 1649 | } |
| 1650 | |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1651 | TEST_F(AidlTest, SuccessOnIdenticalApiDumps) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1652 | Options options = Options::From("aidl --checkapi old new"); |
| 1653 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo();}"); |
| 1654 | 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] | 1655 | |
| 1656 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 1657 | } |
| 1658 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1659 | class AidlTestCompatibleChanges : public AidlTest { |
| 1660 | protected: |
| 1661 | Options options_ = Options::From("aidl --checkapi old new"); |
| 1662 | }; |
| 1663 | |
| 1664 | TEST_F(AidlTestCompatibleChanges, NewType) { |
| 1665 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1666 | "package p;" |
| 1667 | "interface IFoo {" |
| 1668 | " void foo(int a);" |
| 1669 | "}"); |
| 1670 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1671 | "package p;" |
| 1672 | "interface IFoo {" |
| 1673 | " void foo(int a);" |
| 1674 | "}"); |
| 1675 | io_delegate_.SetFileContents("new/p/IBar.aidl", |
| 1676 | "package p;" |
| 1677 | "interface IBar {" |
| 1678 | " void bar();" |
| 1679 | "}"); |
| 1680 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1681 | } |
| 1682 | |
| 1683 | TEST_F(AidlTestCompatibleChanges, NewMethod) { |
| 1684 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1685 | "package p;" |
| 1686 | "interface IFoo {" |
| 1687 | " void foo(int a);" |
| 1688 | "}"); |
| 1689 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1690 | "package p;" |
| 1691 | "interface IFoo {" |
| 1692 | " void foo(int a);" |
| 1693 | " void bar();" |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1694 | " void baz(in List<IFoo> arg);" |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1695 | "}"); |
| 1696 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1697 | } |
| 1698 | |
| 1699 | TEST_F(AidlTestCompatibleChanges, NewField) { |
| 1700 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1701 | "package p;" |
| 1702 | "parcelable Data {" |
| 1703 | " int foo;" |
| 1704 | "}"); |
| 1705 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1706 | "package p;" |
| 1707 | "parcelable Data {" |
| 1708 | " int foo;" |
Steven Moreland | 370ed34 | 2020-04-28 18:14:39 -0700 | [diff] [blame] | 1709 | " int bar = 0;" |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1710 | " @nullable List<Data> list;" |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1711 | "}"); |
| 1712 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1713 | } |
| 1714 | |
| 1715 | TEST_F(AidlTestCompatibleChanges, NewEnumerator) { |
| 1716 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1717 | "package p;" |
| 1718 | "enum Enum {" |
| 1719 | " FOO = 1," |
| 1720 | "}"); |
| 1721 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1722 | "package p;" |
| 1723 | "enum Enum {" |
| 1724 | " FOO = 1," |
| 1725 | " BAR = 2," |
| 1726 | "}"); |
| 1727 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1728 | } |
| 1729 | |
| 1730 | TEST_F(AidlTestCompatibleChanges, ReorderedEnumerator) { |
| 1731 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1732 | "package p;" |
| 1733 | "enum Enum {" |
| 1734 | " FOO = 1," |
| 1735 | " BAR = 2," |
| 1736 | "}"); |
| 1737 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1738 | "package p;" |
| 1739 | "enum Enum {" |
| 1740 | " BAR = 2," |
| 1741 | " FOO = 1," |
| 1742 | "}"); |
| 1743 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1744 | } |
| 1745 | |
| 1746 | TEST_F(AidlTestCompatibleChanges, NewPackage) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1747 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1748 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1749 | "interface IFoo {" |
| 1750 | " void foo(int a);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1751 | "}"); |
| 1752 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1753 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1754 | "parcelable Data {" |
| 1755 | " int foo;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1756 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1757 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1758 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1759 | "interface IFoo {" |
| 1760 | " void foo(int a);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1761 | "}"); |
| 1762 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1763 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1764 | "parcelable Data {" |
| 1765 | " int foo;" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1766 | "}"); |
| 1767 | io_delegate_.SetFileContents("new/q/IFoo.aidl", |
| 1768 | "package q;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1769 | "interface IFoo {" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1770 | " void foo(int a);" |
| 1771 | "}"); |
| 1772 | io_delegate_.SetFileContents("new/q/Data.aidl", |
| 1773 | "package q;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1774 | "parcelable Data {" |
| 1775 | " int foo;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1776 | "}"); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1777 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1778 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1779 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1780 | TEST_F(AidlTestCompatibleChanges, ArgNameChange) { |
| 1781 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1782 | "package p;" |
| 1783 | "interface IFoo {" |
| 1784 | " void foo(int a);" |
| 1785 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1786 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1787 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1788 | "interface IFoo {" |
| 1789 | " void foo(int b);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1790 | "}"); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1791 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1792 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1793 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1794 | TEST_F(AidlTestCompatibleChanges, AddedConstValue) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1795 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 1796 | "package p; interface I {" |
| 1797 | "const int A = 1; }"); |
| 1798 | io_delegate_.SetFileContents("new/p/I.aidl", |
| 1799 | "package p ; interface I {" |
| 1800 | "const int A = 1; const int B = 2;}"); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1801 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
| 1802 | } |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1803 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1804 | TEST_F(AidlTestCompatibleChanges, ChangedConstValueOrder) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1805 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 1806 | "package p; interface I {" |
| 1807 | "const int A = 1; const int B = 2;}"); |
| 1808 | io_delegate_.SetFileContents("new/p/I.aidl", |
| 1809 | "package p ; interface I {" |
| 1810 | "const int B = 2; const int A = 1;}"); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1811 | EXPECT_TRUE(::android::aidl::check_api(options_, io_delegate_)); |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1812 | } |
| 1813 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1814 | class AidlTestIncompatibleChanges : public AidlTest { |
| 1815 | protected: |
| 1816 | Options options_ = Options::From("aidl --checkapi old new"); |
| 1817 | }; |
| 1818 | |
| 1819 | TEST_F(AidlTestIncompatibleChanges, RemovedType) { |
Jiyong Park | 0cf03b1 | 2020-07-22 19:36:34 +0900 | [diff] [blame] | 1820 | const string expected_stderr = "ERROR: old/p/IFoo.aidl:1.11-20: Removed type: p.IFoo\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1821 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1822 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1823 | "interface IFoo {" |
| 1824 | " void foo(in String[] str);" |
| 1825 | " void bar(@utf8InCpp String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1826 | "}"); |
Devin Moore | d131d5e | 2020-03-31 10:39:10 -0700 | [diff] [blame] | 1827 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1828 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | d131d5e | 2020-03-31 10:39:10 -0700 | [diff] [blame] | 1829 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | TEST_F(AidlTestIncompatibleChanges, RemovedMethod) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1833 | const string expected_stderr = |
| 1834 | "ERROR: old/p/IFoo.aidl:1.61-65: Removed or changed method: p.IFoo.bar(String)\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1835 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1836 | "package p;" |
| 1837 | "interface IFoo {" |
| 1838 | " void foo(in String[] str);" |
| 1839 | " void bar(@utf8InCpp String str);" |
| 1840 | "}"); |
| 1841 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1842 | "package p;" |
| 1843 | "interface IFoo {" |
| 1844 | " void foo(in String[] str);" |
| 1845 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1846 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1847 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1848 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Jiyong Park | f8d5361 | 2020-05-04 14:06:13 +0900 | [diff] [blame] | 1851 | TEST_F(AidlTestIncompatibleChanges, UntypedListInInterface) { |
| 1852 | const string expected_stderr = |
| 1853 | "ERROR: new/p/IFoo.aidl:1.61-65: " |
| 1854 | "Encountered an untyped List or Map. The use of untyped List/Map is " |
| 1855 | "prohibited because it is not guaranteed that the objects in the list are recognizable in " |
| 1856 | "the receiving side. Consider switching to an array or a generic List/Map.\n" |
| 1857 | "ERROR: new/p/IFoo.aidl: Failed to read.\n"; |
| 1858 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1859 | "package p;" |
| 1860 | "interface IFoo {" |
| 1861 | " void foo(in String[] str);" |
| 1862 | "}"); |
| 1863 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1864 | "package p;" |
| 1865 | "interface IFoo {" |
| 1866 | " void foo(in String[] str);" |
| 1867 | " void bar(in List arg);" |
| 1868 | "}"); |
| 1869 | CaptureStderr(); |
| 1870 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1871 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1872 | } |
| 1873 | |
| 1874 | TEST_F(AidlTestCompatibleChanges, UntypedListInParcelable) { |
| 1875 | const string expected_stderr = |
| 1876 | "ERROR: new/p/Data.aidl:1.54-59: " |
| 1877 | "Encountered an untyped List or Map. The use of untyped List/Map is " |
| 1878 | "prohibited because it is not guaranteed that the objects in the list are recognizable in " |
| 1879 | "the receiving side. Consider switching to an array or a generic List/Map.\n" |
| 1880 | "ERROR: new/p/Data.aidl: Failed to read.\n"; |
| 1881 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1882 | "package p;" |
| 1883 | "parcelable Data {" |
| 1884 | " int foo;" |
| 1885 | "}"); |
| 1886 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1887 | "package p;" |
| 1888 | "parcelable Data {" |
| 1889 | " int foo;" |
| 1890 | " @nullable List list;" |
| 1891 | "}"); |
| 1892 | CaptureStderr(); |
| 1893 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 1894 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 1895 | } |
| 1896 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1897 | TEST_F(AidlTestIncompatibleChanges, RemovedField) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1898 | const string expected_stderr = |
| 1899 | "ERROR: new/p/Data.aidl:1.21-26: Number of fields in p.Data is reduced from 2 to 1.\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1900 | io_delegate_.SetFileContents("old/p/Data.aidl", |
| 1901 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1902 | "parcelable Data {" |
| 1903 | " int foo;" |
| 1904 | " int bar;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1905 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1906 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 1907 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1908 | "parcelable Data {" |
| 1909 | " int foo;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1910 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1911 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1912 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1913 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1914 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1915 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1916 | TEST_F(AidlTestIncompatibleChanges, RemovedEnumerator) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1917 | const string expected_stderr = |
| 1918 | "ERROR: new/p/Enum.aidl:1.15-20: Removed enumerator from p.Enum: FOO\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1919 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1920 | "package p;" |
| 1921 | "enum Enum {" |
| 1922 | " FOO = 1," |
| 1923 | " BAR = 2," |
| 1924 | "}"); |
| 1925 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1926 | "package p;" |
| 1927 | "enum Enum {" |
| 1928 | " BAR = 2," |
| 1929 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1930 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1931 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1932 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | TEST_F(AidlTestIncompatibleChanges, RenamedMethod) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1936 | const string expected_stderr = |
| 1937 | "ERROR: old/p/IFoo.aidl:1.61-65: Removed or changed method: p.IFoo.bar(String)\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1938 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1939 | "package p;" |
| 1940 | "interface IFoo {" |
| 1941 | " void foo(in String[] str);" |
| 1942 | " void bar(@utf8InCpp String str);" |
| 1943 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1944 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 1945 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1946 | "interface IFoo {" |
| 1947 | " void foo(in String[] str);" |
| 1948 | " void bar2(@utf8InCpp String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1949 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1950 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1951 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1952 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1955 | TEST_F(AidlTestIncompatibleChanges, RenamedType) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1956 | const string expected_stderr = "ERROR: old/p/IFoo.aidl:1.11-20: Removed type: p.IFoo\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1957 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 1958 | "package p;" |
| 1959 | "interface IFoo {" |
| 1960 | " void foo(in String[] str);" |
| 1961 | " void bar(@utf8InCpp String str);" |
| 1962 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1963 | io_delegate_.SetFileContents("new/p/IFoo2.aidl", |
| 1964 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1965 | "interface IFoo2 {" |
| 1966 | " void foo(in String[] str);" |
| 1967 | " void bar(@utf8InCpp String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 1968 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1969 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1970 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1971 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1972 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 1973 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1974 | TEST_F(AidlTestIncompatibleChanges, ChangedEnumerator) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1975 | const string expected_stderr = |
| 1976 | "ERROR: new/p/Enum.aidl:1.15-20: Changed enumerator value: p.Enum::FOO from 1 to 3.\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1977 | io_delegate_.SetFileContents("old/p/Enum.aidl", |
| 1978 | "package p;" |
| 1979 | "enum Enum {" |
| 1980 | " FOO = 1," |
| 1981 | " BAR = 2," |
| 1982 | "}"); |
| 1983 | io_delegate_.SetFileContents("new/p/Enum.aidl", |
| 1984 | "package p;" |
| 1985 | "enum Enum {" |
| 1986 | " FOO = 3," |
| 1987 | " BAR = 2," |
| 1988 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1989 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1990 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1991 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | TEST_F(AidlTestIncompatibleChanges, ReorderedMethod) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1995 | const string expected_stderr = |
| 1996 | "ERROR: new/p/IFoo.aidl:1.67-71: Transaction ID changed: p.IFoo.foo(String[]) is changed " |
| 1997 | "from 0 to 1.\n" |
| 1998 | "ERROR: new/p/IFoo.aidl:1.33-37: Transaction ID changed: p.IFoo.bar(String) is changed from " |
| 1999 | "1 to 0.\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2000 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 2001 | "package p;" |
| 2002 | "interface IFoo {" |
| 2003 | " void foo(in String[] str);" |
| 2004 | " void bar(@utf8InCpp String str);" |
| 2005 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2006 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 2007 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2008 | "interface IFoo {" |
| 2009 | " void bar(@utf8InCpp String str);" |
| 2010 | " void foo(in String[] str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2011 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2012 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2013 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2014 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | TEST_F(AidlTestIncompatibleChanges, ReorderedField) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2018 | const string expected_stderr = |
Jiyong Park | b07d993 | 2020-05-15 12:56:54 +0900 | [diff] [blame] | 2019 | "ERROR: new/p/Data.aidl:1.33-37: Reordered bar from 1 to 0.\n" |
| 2020 | "ERROR: new/p/Data.aidl:1.43-47: Reordered foo from 0 to 1.\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2021 | io_delegate_.SetFileContents("old/p/Data.aidl", |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2022 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2023 | "parcelable Data {" |
| 2024 | " int foo;" |
| 2025 | " int bar;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2026 | "}"); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2027 | io_delegate_.SetFileContents("new/p/Data.aidl", |
| 2028 | "package p;" |
| 2029 | "parcelable Data {" |
| 2030 | " int bar;" |
| 2031 | " int foo;" |
| 2032 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2033 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2034 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2035 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2036 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2037 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2038 | TEST_F(AidlTestIncompatibleChanges, ChangedDirectionSpecifier) { |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 2039 | const string expected_stderr = "ERROR: new/p/IFoo.aidl:1.33-37: Direction changed: in to out.\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2040 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2041 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2042 | "interface IFoo {" |
| 2043 | " void foo(in String[] str);" |
| 2044 | " void bar(@utf8InCpp String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2045 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2046 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 2047 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2048 | "interface IFoo {" |
| 2049 | " void foo(out String[] str);" |
| 2050 | " void bar(@utf8InCpp String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2051 | "}"); |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 2052 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2053 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 2054 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2055 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2056 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2057 | TEST_F(AidlTestIncompatibleChanges, AddedAnnotation) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2058 | const string expected_stderr = |
| 2059 | "ERROR: new/p/IFoo.aidl:1.51-58: Changed annotations: (empty) to @utf8InCpp\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2060 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 2061 | "package p;" |
| 2062 | "interface IFoo {" |
| 2063 | " void foo(in String[] str);" |
| 2064 | " void bar(@utf8InCpp String str);" |
| 2065 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2066 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 2067 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2068 | "interface IFoo {" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2069 | " void foo(in @utf8InCpp String[] str);" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2070 | " void bar(@utf8InCpp String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2071 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2072 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2073 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2074 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2075 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2076 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2077 | TEST_F(AidlTestIncompatibleChanges, RemovedAnnotation) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2078 | const string expected_stderr = |
| 2079 | "ERROR: new/p/IFoo.aidl:1.66-72: Changed annotations: @utf8InCpp to (empty)\n"; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2080 | io_delegate_.SetFileContents("old/p/IFoo.aidl", |
| 2081 | "package p;" |
| 2082 | "interface IFoo {" |
| 2083 | " void foo(in String[] str);" |
| 2084 | " void bar(@utf8InCpp String str);" |
| 2085 | "}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2086 | io_delegate_.SetFileContents("new/p/IFoo.aidl", |
| 2087 | "package p;" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2088 | "interface IFoo {" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2089 | " void foo(in String[] str);" |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2090 | " void bar(String str);" |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2091 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2092 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2093 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2094 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2095 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 2096 | |
Devin Moore | db7ac51 | 2020-08-07 11:17:36 -0700 | [diff] [blame] | 2097 | TEST_F(AidlTestIncompatibleChanges, AddedParcelableAnnotation) { |
| 2098 | const string expected_stderr = |
| 2099 | "ERROR: new/p/Foo.aidl:1.47-51: Changed annotations: (empty) to @JavaOnlyStableParcelable\n"; |
| 2100 | io_delegate_.SetFileContents("old/p/Foo.aidl", |
| 2101 | "package p;" |
| 2102 | "parcelable Foo {" |
| 2103 | " int A;" |
| 2104 | "}"); |
| 2105 | io_delegate_.SetFileContents("new/p/Foo.aidl", |
| 2106 | "package p;" |
| 2107 | "@JavaOnlyStableParcelable parcelable Foo {" |
| 2108 | " int A;" |
| 2109 | "}"); |
| 2110 | CaptureStderr(); |
| 2111 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 2112 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2113 | } |
| 2114 | |
| 2115 | TEST_F(AidlTestIncompatibleChanges, RemovedParcelableAnnotation) { |
| 2116 | const string expected_stderr = |
| 2117 | "ERROR: new/p/Foo.aidl:1.21-25: Changed annotations: @JavaOnlyStableParcelable to (empty)\n"; |
| 2118 | io_delegate_.SetFileContents("old/p/Foo.aidl", |
| 2119 | "package p;" |
| 2120 | "@JavaOnlyStableParcelable parcelable Foo {" |
| 2121 | " int A;" |
| 2122 | "}"); |
| 2123 | io_delegate_.SetFileContents("new/p/Foo.aidl", |
| 2124 | "package p;" |
| 2125 | "parcelable Foo {" |
| 2126 | " int A;" |
| 2127 | "}"); |
| 2128 | CaptureStderr(); |
| 2129 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 2130 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2131 | } |
| 2132 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2133 | TEST_F(AidlTestIncompatibleChanges, RemovedPackage) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2134 | const string expected_stderr = "ERROR: old/q/IFoo.aidl:1.11-21: Removed type: q.IFoo\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2135 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{}"); |
| 2136 | io_delegate_.SetFileContents("old/q/IFoo.aidl", "package q; interface IFoo{}"); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2137 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2138 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2139 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2140 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2141 | } |
Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 2142 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2143 | TEST_F(AidlTestIncompatibleChanges, ChangedDefaultValue) { |
Steven Moreland | 370ed34 | 2020-04-28 18:14:39 -0700 | [diff] [blame] | 2144 | const string expected_stderr = "ERROR: new/p/D.aidl:1.30-32: Changed default value: 1 to 2.\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2145 | io_delegate_.SetFileContents("old/p/D.aidl", "package p; parcelable D { int a = 1; }"); |
| 2146 | io_delegate_.SetFileContents("new/p/D.aidl", "package p; parcelable D { int a = 2; }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2147 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2148 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2149 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2150 | } |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 2151 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2152 | TEST_F(AidlTestIncompatibleChanges, RemovedConstValue) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2153 | const string expected_stderr = |
| 2154 | "ERROR: old/p/I.aidl:1.51-53: Removed constant declaration: p.I.B\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2155 | io_delegate_.SetFileContents("old/p/I.aidl", |
| 2156 | "package p; interface I {" |
| 2157 | "const int A = 1; const int B = 2;}"); |
| 2158 | io_delegate_.SetFileContents("new/p/I.aidl", "package p; interface I { const int A = 1; }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2159 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2160 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2161 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2162 | } |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 2163 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2164 | TEST_F(AidlTestIncompatibleChanges, ChangedConstValue) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2165 | const string expected_stderr = |
| 2166 | "ERROR: new/p/I.aidl:1.11-21: Changed constant value: p.I.A from 1 to 2.\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2167 | io_delegate_.SetFileContents("old/p/I.aidl", "package p; interface I { const int A = 1; }"); |
| 2168 | io_delegate_.SetFileContents("new/p/I.aidl", "package p; interface I { const int A = 2; }"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2169 | CaptureStderr(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 2170 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2171 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 2172 | } |
| 2173 | |
Devin Moore | c7e47a3 | 2020-08-07 10:55:25 -0700 | [diff] [blame] | 2174 | TEST_F(AidlTestIncompatibleChanges, FixedSizeAddedField) { |
| 2175 | const string expected_stderr = |
| 2176 | "ERROR: new/p/Foo.aidl:1.33-37: Number of fields in p.Foo is changed from 1 to 2. " |
| 2177 | "This is an incompatible change for FixedSize types.\n"; |
| 2178 | io_delegate_.SetFileContents("old/p/Foo.aidl", |
| 2179 | "package p; @FixedSize parcelable Foo { int A = 1; }"); |
| 2180 | io_delegate_.SetFileContents("new/p/Foo.aidl", |
| 2181 | "package p; @FixedSize parcelable Foo { int A = 1; int B = 2; }"); |
| 2182 | CaptureStderr(); |
| 2183 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 2184 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2185 | } |
| 2186 | |
| 2187 | TEST_F(AidlTestIncompatibleChanges, FixedSizeRemovedField) { |
| 2188 | const string expected_stderr = |
| 2189 | "ERROR: new/p/Foo.aidl:1.33-37: Number of fields in p.Foo is reduced from 2 to 1.\n"; |
| 2190 | io_delegate_.SetFileContents("old/p/Foo.aidl", |
| 2191 | "package p; @FixedSize parcelable Foo { int A = 1; int B = 1; }"); |
| 2192 | io_delegate_.SetFileContents("new/p/Foo.aidl", |
| 2193 | "package p; @FixedSize parcelable Foo { int A = 1; }"); |
| 2194 | CaptureStderr(); |
| 2195 | EXPECT_FALSE(::android::aidl::check_api(options_, io_delegate_)); |
| 2196 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2197 | } |
| 2198 | |
| 2199 | TEST_P(AidlTest, RejectNonFixedSizeFromFixedSize) { |
| 2200 | const string expected_stderr = |
| 2201 | "ERROR: Foo.aidl:1.36-38: The @FixedSize parcelable 'Foo' has a non-fixed size field named " |
| 2202 | "a.\n" |
| 2203 | "ERROR: Foo.aidl:1.44-46: The @FixedSize parcelable 'Foo' has a non-fixed size field named " |
| 2204 | "b.\n" |
| 2205 | "ERROR: Foo.aidl:1.55-57: The @FixedSize parcelable 'Foo' has a non-fixed size field named " |
| 2206 | "c.\n" |
| 2207 | "ERROR: Foo.aidl:1.80-82: The @FixedSize parcelable 'Foo' has a non-fixed size field named " |
| 2208 | "d.\n" |
| 2209 | "ERROR: Foo.aidl:1.92-94: The @FixedSize parcelable 'Foo' has a non-fixed size field named " |
| 2210 | "e.\n" |
| 2211 | "ERROR: Foo.aidl:1.109-111: The @FixedSize parcelable 'Foo' has a non-fixed size field named " |
| 2212 | "f.\n"; |
| 2213 | |
| 2214 | io_delegate_.SetFileContents("Foo.aidl", |
| 2215 | "@FixedSize parcelable Foo { " |
| 2216 | " int[] a;" |
| 2217 | " Bar b;" |
| 2218 | " String c;" |
| 2219 | " ParcelFileDescriptor d;" |
| 2220 | " IBinder e;" |
| 2221 | " List<String> f;" |
Steven Moreland | 265f3d4 | 2020-09-24 19:06:54 +0000 | [diff] [blame] | 2222 | " int isFixedSize;" |
Devin Moore | c7e47a3 | 2020-08-07 10:55:25 -0700 | [diff] [blame] | 2223 | "}"); |
| 2224 | io_delegate_.SetFileContents("Bar.aidl", "parcelable Bar { int a; }"); |
| 2225 | Options options = |
| 2226 | Options::From("aidl Foo.aidl -I . --lang=" + Options::LanguageToString(GetLanguage())); |
| 2227 | |
| 2228 | CaptureStderr(); |
| 2229 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2230 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2231 | } |
| 2232 | |
| 2233 | TEST_P(AidlTest, AcceptFixedSizeFromFixedSize) { |
| 2234 | const string expected_stderr = ""; |
| 2235 | |
| 2236 | io_delegate_.SetFileContents("Foo.aidl", "@FixedSize parcelable Foo { int a; Bar b; }"); |
| 2237 | io_delegate_.SetFileContents("Bar.aidl", "@FixedSize parcelable Bar { Val c; }"); |
| 2238 | io_delegate_.SetFileContents("Val.aidl", "enum Val { A, B, }"); |
| 2239 | Options options = |
| 2240 | Options::From("aidl Foo.aidl -I . --lang=" + Options::LanguageToString(GetLanguage())); |
| 2241 | |
| 2242 | CaptureStderr(); |
| 2243 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2244 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2245 | } |
| 2246 | |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 2247 | TEST_F(AidlTest, RejectAmbiguousImports) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2248 | const string expected_stderr = |
| 2249 | "ERROR: p/IFoo.aidl: Duplicate files found for q.IBar from:\n" |
| 2250 | "dir1/q/IBar.aidl\n" |
| 2251 | "dir2/q/IBar.aidl\n" |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 2252 | "ERROR: p/IFoo.aidl: Couldn't find import for class q.IBar\n"; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 2253 | Options options = Options::From("aidl --lang=java -o out -I dir1 -I dir2 p/IFoo.aidl"); |
| 2254 | io_delegate_.SetFileContents("p/IFoo.aidl", "package p; import q.IBar; interface IFoo{}"); |
| 2255 | io_delegate_.SetFileContents("dir1/q/IBar.aidl", "package q; interface IBar{}"); |
| 2256 | io_delegate_.SetFileContents("dir2/q/IBar.aidl", "package q; interface IBar{}"); |
| 2257 | |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2258 | CaptureStderr(); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 2259 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2260 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 2261 | } |
| 2262 | |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 2263 | TEST_F(AidlTest, HandleManualIdAssignments) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2264 | const string expected_stderr = |
| 2265 | "ERROR: new/p/IFoo.aidl:1.32-36: Transaction ID changed: p.IFoo.foo() is changed from 10 to " |
| 2266 | "11.\n"; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2267 | Options options = Options::From("aidl --checkapi old new"); |
| 2268 | io_delegate_.SetFileContents("old/p/IFoo.aidl", "package p; interface IFoo{ void foo() = 10;}"); |
| 2269 | 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] | 2270 | |
| 2271 | EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_)); |
| 2272 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 2273 | io_delegate_.SetFileContents("new/p/IFoo.aidl", "package p; interface IFoo{ void foo() = 11;}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2274 | CaptureStderr(); |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 2275 | EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2276 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 2277 | } |
| 2278 | |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 2279 | TEST_F(AidlTest, ParcelFileDescriptorIsBuiltinType) { |
| 2280 | Options javaOptions = Options::From("aidl --lang=java -o out p/IFoo.aidl"); |
| 2281 | Options cppOptions = Options::From("aidl --lang=cpp -h out -o out p/IFoo.aidl"); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 2282 | Options rustOptions = Options::From("aidl --lang=rust -o out p/IFoo.aidl"); |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 2283 | |
| 2284 | // use without import |
| 2285 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 2286 | "package p; interface IFoo{ void foo(in ParcelFileDescriptor fd);}"); |
| 2287 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 2288 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 2289 | EXPECT_EQ(0, ::android::aidl::compile_aidl(rustOptions, io_delegate_)); |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 2290 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2291 | // use without import but with full name |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 2292 | io_delegate_.SetFileContents( |
| 2293 | "p/IFoo.aidl", |
| 2294 | "package p; interface IFoo{ void foo(in android.os.ParcelFileDescriptor fd);}"); |
| 2295 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 2296 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 2297 | EXPECT_EQ(0, ::android::aidl::compile_aidl(rustOptions, io_delegate_)); |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 2298 | |
| 2299 | // use with import (as before) |
| 2300 | io_delegate_.SetFileContents("p/IFoo.aidl", |
| 2301 | "package p;" |
| 2302 | "import android.os.ParcelFileDescriptor;" |
| 2303 | "interface IFoo{" |
| 2304 | " void foo(in ParcelFileDescriptor fd);" |
| 2305 | "}"); |
| 2306 | EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_)); |
| 2307 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_)); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 2308 | EXPECT_EQ(0, ::android::aidl::compile_aidl(rustOptions, io_delegate_)); |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 2309 | } |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 2310 | |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2311 | TEST_F(AidlTest, ManualIds) { |
| 2312 | Options options = Options::From("aidl --lang=java -o out IFoo.aidl"); |
| 2313 | io_delegate_.SetFileContents("IFoo.aidl", |
| 2314 | "interface IFoo {\n" |
| 2315 | " void foo() = 0;\n" |
| 2316 | " void bar() = 1;\n" |
| 2317 | "}"); |
| 2318 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2319 | } |
| 2320 | |
| 2321 | TEST_F(AidlTest, ManualIdsWithMetaTransactions) { |
| 2322 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 2323 | io_delegate_.SetFileContents("IFoo.aidl", |
| 2324 | "interface IFoo {\n" |
| 2325 | " void foo() = 0;\n" |
| 2326 | " void bar() = 1;\n" |
| 2327 | "}"); |
| 2328 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2329 | } |
| 2330 | |
| 2331 | TEST_F(AidlTest, FailOnDuplicatedIds) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2332 | const string expected_stderr = |
| 2333 | "ERROR: IFoo.aidl:3.7-11: Found duplicate method id (3) for method bar\n"; |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2334 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 2335 | io_delegate_.SetFileContents("IFoo.aidl", |
| 2336 | "interface IFoo {\n" |
| 2337 | " void foo() = 3;\n" |
| 2338 | " void bar() = 3;\n" |
| 2339 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2340 | CaptureStderr(); |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2341 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2342 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | TEST_F(AidlTest, FailOnOutOfRangeIds) { |
| 2346 | // 16777115 is kLastMetaMethodId + 1 |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2347 | const string expected_stderr = |
| 2348 | "ERROR: IFoo.aidl:3.7-11: Found out of bounds id (16777115) for method bar. " |
| 2349 | "Value for id must be between 0 and 16777114 inclusive.\n"; |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2350 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 2351 | io_delegate_.SetFileContents("IFoo.aidl", |
| 2352 | "interface IFoo {\n" |
| 2353 | " void foo() = 3;\n" |
| 2354 | " void bar() = 16777115;\n" |
| 2355 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2356 | CaptureStderr(); |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2357 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2358 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | TEST_F(AidlTest, FailOnPartiallyAssignedIds) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2362 | const string expected_stderr = |
| 2363 | "ERROR: IFoo.aidl:3.7-11: You must either assign id's to all methods or to none of them.\n"; |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2364 | Options options = Options::From("aidl --lang=java --version 10 -o out IFoo.aidl"); |
| 2365 | io_delegate_.SetFileContents("IFoo.aidl", |
| 2366 | "interface IFoo {\n" |
| 2367 | " void foo() = 3;\n" |
| 2368 | " void bar();\n" |
| 2369 | "}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2370 | CaptureStderr(); |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2371 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2372 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 2373 | } |
| 2374 | |
Jiyong Park | c681625 | 2019-07-08 08:12:28 +0900 | [diff] [blame] | 2375 | TEST_F(AidlTest, AllowDuplicatedImportPaths) { |
| 2376 | Options options = Options::From("aidl --lang=java -I dir -I dir IFoo.aidl"); |
| 2377 | io_delegate_.SetFileContents("dir/IBar.aidl", "interface IBar{}"); |
| 2378 | io_delegate_.SetFileContents("IFoo.aidl", "import IBar; interface IFoo{}"); |
| 2379 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2380 | } |
| 2381 | |
| 2382 | TEST_F(AidlTest, FailOnAmbiguousImports) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2383 | const string expected_stderr = |
| 2384 | "ERROR: IFoo.aidl: Duplicate files found for IBar from:\n" |
| 2385 | "dir/IBar.aidl\n" |
| 2386 | "dir2/IBar.aidl\n" |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 2387 | "ERROR: IFoo.aidl: Couldn't find import for class IBar\n"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2388 | |
Jiyong Park | c681625 | 2019-07-08 08:12:28 +0900 | [diff] [blame] | 2389 | Options options = Options::From("aidl --lang=java -I dir -I dir2 IFoo.aidl"); |
| 2390 | io_delegate_.SetFileContents("dir/IBar.aidl", "interface IBar{}"); |
| 2391 | io_delegate_.SetFileContents("dir2/IBar.aidl", "interface IBar{}"); |
| 2392 | io_delegate_.SetFileContents("IFoo.aidl", "import IBar; interface IFoo{}"); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2393 | CaptureStderr(); |
Jiyong Park | c681625 | 2019-07-08 08:12:28 +0900 | [diff] [blame] | 2394 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2395 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Jiyong Park | c681625 | 2019-07-08 08:12:28 +0900 | [diff] [blame] | 2396 | } |
| 2397 | |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 2398 | TEST_F(AidlTest, UnusedImportDoesNotContributeInclude) { |
| 2399 | io_delegate_.SetFileContents("a/b/IFoo.aidl", |
| 2400 | "package a.b;\n" |
| 2401 | "import a.b.IBar;\n" |
| 2402 | "import a.b.IQux;\n" |
| 2403 | "interface IFoo { IQux foo(); }\n"); |
| 2404 | io_delegate_.SetFileContents("a/b/IBar.aidl", "package a.b; interface IBar { void foo(); }"); |
| 2405 | io_delegate_.SetFileContents("a/b/IQux.aidl", "package a.b; interface IQux { void foo(); }"); |
| 2406 | |
| 2407 | Options options = Options::From("aidl --lang=ndk a/b/IFoo.aidl -I . -o out -h out/include"); |
| 2408 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2409 | |
| 2410 | string output; |
| 2411 | EXPECT_TRUE(io_delegate_.GetWrittenContents("out/include/aidl/a/b/IFoo.h", &output)); |
| 2412 | // IBar was imported but wasn't used. include is not expected. |
| 2413 | EXPECT_THAT(output, Not(testing::HasSubstr("#include <aidl/a/b/IBar.h>"))); |
| 2414 | // IBar was imported and used. include is expected. |
| 2415 | EXPECT_THAT(output, (testing::HasSubstr("#include <aidl/a/b/IQux.h>"))); |
| 2416 | } |
| 2417 | |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 2418 | TEST_F(AidlTest, ParseJavaPassthroughAnnotation) { |
Jooyung Han | e6bc5e1 | 2020-10-13 10:57:10 +0900 | [diff] [blame^] | 2419 | io_delegate_.SetFileContents("a/IFoo.aidl", R"--(package a; |
| 2420 | @JavaPassthrough(annotation="@com.android.Alice(arg=com.android.Alice.Value.A)") |
| 2421 | @JavaPassthrough(annotation="@com.android.AliceTwo") |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 2422 | interface IFoo { |
| 2423 | @JavaPassthrough(annotation="@com.android.Bob") |
| 2424 | void foo(@JavaPassthrough(annotation="@com.android.Cat") int x); |
Jiyong Park | 7c3b0e4 | 2020-08-04 16:08:32 +0900 | [diff] [blame] | 2425 | const @JavaPassthrough(annotation="@com.android.David") int A = 3; |
Jooyung Han | e6bc5e1 | 2020-10-13 10:57:10 +0900 | [diff] [blame^] | 2426 | })--"); |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 2427 | |
| 2428 | Options java_options = Options::From("aidl --lang=java -o out a/IFoo.aidl"); |
| 2429 | EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
| 2430 | |
| 2431 | string java_out; |
| 2432 | EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/IFoo.java", &java_out)); |
Jooyung Han | e6bc5e1 | 2020-10-13 10:57:10 +0900 | [diff] [blame^] | 2433 | // type-decl-level annotations with newline at the end |
| 2434 | EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Alice(arg=com.android.Alice.Value.A)\n")); |
| 2435 | EXPECT_THAT(java_out, testing::HasSubstr("@com.android.AliceTwo\n")); |
| 2436 | // member-decl-level annotations with newline at the end |
| 2437 | EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Bob\n")); |
| 2438 | EXPECT_THAT(java_out, testing::HasSubstr("@com.android.David\n")); |
| 2439 | // inline annotations with space at the end |
| 2440 | EXPECT_THAT(java_out, testing::HasSubstr("@com.android.Cat ")); |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 2441 | |
| 2442 | // Other backends shouldn't be bothered |
| 2443 | Options cpp_options = Options::From("aidl --lang=cpp -o out -h out a/IFoo.aidl"); |
| 2444 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cpp_options, io_delegate_)); |
| 2445 | |
| 2446 | Options ndk_options = Options::From("aidl --lang=ndk -o out -h out a/IFoo.aidl"); |
| 2447 | EXPECT_EQ(0, ::android::aidl::compile_aidl(ndk_options, io_delegate_)); |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 2448 | |
| 2449 | Options rust_options = Options::From("aidl --lang=rust -o out a/IFoo.aidl"); |
| 2450 | EXPECT_EQ(0, ::android::aidl::compile_aidl(rust_options, io_delegate_)); |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 2451 | } |
| 2452 | |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 2453 | TEST_F(AidlTest, ParseRustDerive) { |
| 2454 | io_delegate_.SetFileContents("a/Foo.aidl", R"(package a; |
| 2455 | @RustDerive(Clone=true, Copy=false) |
| 2456 | parcelable Foo { |
| 2457 | int a; |
| 2458 | })"); |
| 2459 | |
| 2460 | Options rust_options = Options::From("aidl --lang=rust -o out a/Foo.aidl"); |
| 2461 | EXPECT_EQ(0, ::android::aidl::compile_aidl(rust_options, io_delegate_)); |
| 2462 | |
| 2463 | string rust_out; |
| 2464 | EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/Foo.rs", &rust_out)); |
| 2465 | EXPECT_THAT(rust_out, testing::HasSubstr("#[derive(Debug, Clone)]")); |
| 2466 | |
| 2467 | // Other backends shouldn't be bothered |
| 2468 | Options cpp_options = Options::From("aidl --lang=cpp -o out -h out a/Foo.aidl"); |
| 2469 | EXPECT_EQ(0, ::android::aidl::compile_aidl(cpp_options, io_delegate_)); |
| 2470 | |
| 2471 | Options ndk_options = Options::From("aidl --lang=ndk -o out -h out a/Foo.aidl"); |
| 2472 | EXPECT_EQ(0, ::android::aidl::compile_aidl(ndk_options, io_delegate_)); |
| 2473 | |
| 2474 | Options java_options = Options::From("aidl --lang=java -o out a/Foo.aidl"); |
| 2475 | EXPECT_EQ(0, ::android::aidl::compile_aidl(java_options, io_delegate_)); |
| 2476 | } |
| 2477 | |
Jiyong Park | 56f73d7 | 2019-06-11 12:20:28 +0900 | [diff] [blame] | 2478 | class AidlOutputPathTest : public AidlTest { |
| 2479 | protected: |
| 2480 | void SetUp() override { |
| 2481 | AidlTest::SetUp(); |
| 2482 | io_delegate_.SetFileContents("sub/dir/foo/bar/IFoo.aidl", "package foo.bar; interface IFoo {}"); |
| 2483 | } |
| 2484 | |
| 2485 | void Test(const Options& options, const std::string expected_output_path) { |
| 2486 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2487 | // check the existence |
| 2488 | EXPECT_TRUE(io_delegate_.GetWrittenContents(expected_output_path, nullptr)); |
| 2489 | } |
| 2490 | }; |
| 2491 | |
| 2492 | TEST_F(AidlOutputPathTest, OutDirWithNoOutputFile) { |
| 2493 | // <out_dir> / <package_name> / <type_name>.java |
| 2494 | Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl"), "out/foo/bar/IFoo.java"); |
| 2495 | } |
| 2496 | |
| 2497 | TEST_F(AidlOutputPathTest, OutDirWithOutputFile) { |
| 2498 | // when output file is explicitly set, it is always respected. -o option is |
| 2499 | // ignored. |
| 2500 | Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl output/IFoo.java"), "output/IFoo.java"); |
| 2501 | } |
| 2502 | |
| 2503 | TEST_F(AidlOutputPathTest, NoOutDirWithOutputFile) { |
| 2504 | Test(Options::From("aidl -o out sub/dir/foo/bar/IFoo.aidl output/IFoo.java"), "output/IFoo.java"); |
| 2505 | } |
| 2506 | |
| 2507 | TEST_F(AidlOutputPathTest, NoOutDirWithNoOutputFile) { |
| 2508 | // output is the same as the input file except for the suffix |
| 2509 | Test(Options::From("aidl sub/dir/foo/bar/IFoo.aidl"), "sub/dir/foo/bar/IFoo.java"); |
| 2510 | } |
| 2511 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2512 | TEST_P(AidlTest, FailOnOutOfBoundsInt32MaxConstInt) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2513 | AidlError error; |
| 2514 | const string expected_stderr = |
| 2515 | "ERROR: p/IFoo.aidl:3.58-69: Invalid type specifier for an int64 literal: int\n"; |
| 2516 | CaptureStderr(); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2517 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 2518 | R"(package p; |
| 2519 | interface IFoo { |
| 2520 | const int int32_max_oob = 2147483650; |
| 2521 | } |
| 2522 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2523 | typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2524 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2525 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2528 | TEST_P(AidlTest, FailOnOutOfBoundsInt32MinConstInt) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2529 | AidlError error; |
| 2530 | const string expected_stderr = |
| 2531 | "ERROR: p/IFoo.aidl:3.58-60: Invalid type specifier for an int64 literal: int\n"; |
| 2532 | CaptureStderr(); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2533 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 2534 | R"(package p; |
| 2535 | interface IFoo { |
| 2536 | const int int32_min_oob = -2147483650; |
| 2537 | } |
| 2538 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2539 | typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2540 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2541 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2544 | TEST_P(AidlTest, FailOnOutOfBoundsInt64MaxConstInt) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2545 | AidlError error; |
| 2546 | const string expected_stderr = |
Devin Moore | 2a08890 | 2020-09-17 10:51:19 -0700 | [diff] [blame] | 2547 | "ERROR: p/IFoo.aidl:3.59-86: Could not parse integer: 21474836509999999999999999\n"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2548 | CaptureStderr(); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2549 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 2550 | R"(package p; |
| 2551 | interface IFoo { |
| 2552 | const long int64_max_oob = 21474836509999999999999999; |
| 2553 | } |
| 2554 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2555 | typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2556 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2557 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2560 | TEST_P(AidlTest, FailOnOutOfBoundsInt64MinConstInt) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2561 | AidlError error; |
| 2562 | const string expected_stderr = |
Devin Moore | 2a08890 | 2020-09-17 10:51:19 -0700 | [diff] [blame] | 2563 | "ERROR: p/IFoo.aidl:3.61-87: Could not parse integer: 21474836509999999999999999\n"; |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2564 | CaptureStderr(); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2565 | EXPECT_EQ(nullptr, Parse("p/IFoo.aidl", |
| 2566 | R"(package p; |
| 2567 | interface IFoo { |
| 2568 | const long int64_min_oob = -21474836509999999999999999; |
| 2569 | } |
| 2570 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2571 | typenames_, GetLanguage(), &error)); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2572 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2573 | EXPECT_EQ(AidlError::PARSE_ERROR, error); |
Will McVicker | a4e5b13 | 2019-10-03 13:52:21 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2576 | TEST_P(AidlTest, FailOnOutOfBoundsAutofilledEnum) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2577 | AidlError error; |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 2578 | const string expected_stderr = |
| 2579 | "ERROR: p/TestEnum.aidl:3.35-44: Invalid type specifier for an int32 " |
| 2580 | "literal: byte\n" |
| 2581 | "ERROR: p/TestEnum.aidl:5.1-36: Enumerator type differs from enum backing type.\n"; |
| 2582 | CaptureStderr(); |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 2583 | EXPECT_EQ(nullptr, Parse("p/TestEnum.aidl", |
| 2584 | R"(package p; |
| 2585 | @Backing(type="byte") |
| 2586 | enum TestEnum { |
| 2587 | FOO = 127, |
| 2588 | BAR, |
| 2589 | } |
| 2590 | )", |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 2591 | typenames_, GetLanguage(), &error)); |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 2592 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 2593 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Devin Moore | decaf29 | 2020-04-30 09:16:40 -0700 | [diff] [blame] | 2596 | TEST_P(AidlTest, UnsupportedBackingAnnotationParam) { |
| 2597 | AidlError error; |
| 2598 | const string expected_stderr = |
| 2599 | "ERROR: p/TestEnum.aidl:2.1-51: Parameter foo not supported for annotation Backing. It must " |
| 2600 | "be one of: type\n" |
| 2601 | "ERROR: p/TestEnum.aidl:2.1-51: Parameter foo not supported for annotation Backing. It must " |
| 2602 | "be one of: type\n"; |
| 2603 | CaptureStderr(); |
| 2604 | EXPECT_EQ(nullptr, Parse("p/TestEnum.aidl", |
| 2605 | R"(package p; |
| 2606 | @Backing(foo="byte") |
| 2607 | enum TestEnum { |
| 2608 | FOO = 1, |
| 2609 | BAR, |
| 2610 | } |
| 2611 | )", |
| 2612 | typenames_, GetLanguage(), &error)); |
| 2613 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2614 | EXPECT_EQ(AidlError::BAD_TYPE, error); |
| 2615 | } |
| 2616 | |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 2617 | TEST_P(AidlTest, SupportJavaOnlyImmutableAnnotation) { |
| 2618 | io_delegate_.SetFileContents("Foo.aidl", |
| 2619 | "@JavaOnlyImmutable parcelable Foo { int a; Bar b; List<Bar> c; " |
| 2620 | "Map<String, Baz> d; Bar[] e; }"); |
| 2621 | io_delegate_.SetFileContents("Bar.aidl", "@JavaOnlyImmutable parcelable Bar { String a; }"); |
| 2622 | io_delegate_.SetFileContents("Baz.aidl", |
| 2623 | "@JavaOnlyImmutable @JavaOnlyStableParcelable parcelable Baz;"); |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 2624 | Options options = Options::From("aidl --lang=java -I . Foo.aidl"); |
| 2625 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2626 | } |
| 2627 | |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 2628 | TEST_P(AidlTest, RejectMutableParcelableFromJavaOnlyImmutableParcelable) { |
| 2629 | io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { Bar bar; }"); |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 2630 | io_delegate_.SetFileContents("Bar.aidl", "parcelable Bar { String a; }"); |
| 2631 | Options options = Options::From("aidl --lang=java Foo.aidl -I ."); |
| 2632 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2633 | } |
| 2634 | |
| 2635 | TEST_P(AidlTest, ImmtuableParcelableCannotBeInOut) { |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 2636 | io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { int a; }"); |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 2637 | io_delegate_.SetFileContents("IBar.aidl", "interface IBar { void my(inout Foo); }"); |
| 2638 | Options options = Options::From("aidl --lang=java IBar.aidl -I ."); |
| 2639 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2640 | } |
| 2641 | |
| 2642 | TEST_P(AidlTest, ImmtuableParcelableCannotBeOut) { |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 2643 | io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { int a; }"); |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 2644 | io_delegate_.SetFileContents("IBar.aidl", "interface IBar { void my(out Foo); }"); |
| 2645 | Options options = Options::From("aidl --lang=java IBar.aidl -I ."); |
| 2646 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2647 | } |
| 2648 | |
Jeongik Cha | 9118025 | 2020-07-31 15:43:11 +0900 | [diff] [blame] | 2649 | TEST_P(AidlTest, ImmtuableParcelableFieldNameRestriction) { |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 2650 | io_delegate_.SetFileContents("Foo.aidl", "@JavaOnlyImmutable parcelable Foo { int a; int A; }"); |
Jeongik Cha | 9118025 | 2020-07-31 15:43:11 +0900 | [diff] [blame] | 2651 | Options options = Options::From("aidl --lang=java Foo.aidl"); |
| 2652 | const string expected_stderr = |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 2653 | "ERROR: Foo.aidl:1.30-34: The parcelable 'Foo' has duplicate field name 'A' after " |
Jeongik Cha | 9118025 | 2020-07-31 15:43:11 +0900 | [diff] [blame] | 2654 | "capitalizing the first letter\n"; |
| 2655 | CaptureStderr(); |
| 2656 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2657 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2658 | } |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 2659 | |
| 2660 | TEST_P(AidlTest, GenericStructuredParcelable) { |
| 2661 | io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo<T, U> { int a; int A; }"); |
| 2662 | Options options = |
| 2663 | Options::From("aidl Foo.aidl --lang=" + Options::LanguageToString(GetLanguage())); |
| 2664 | const string expected_stderr = ""; |
| 2665 | CaptureStderr(); |
| 2666 | EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2667 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2668 | } |
| 2669 | |
| 2670 | TEST_P(AidlTest, RejectGenericStructuredParcelabelRepeatedParam) { |
| 2671 | io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo<T,T> { int a; int A; }"); |
| 2672 | Options options = |
| 2673 | Options::From("aidl Foo.aidl --lang=" + Options::LanguageToString(GetLanguage())); |
| 2674 | const string expected_stderr = |
| 2675 | "ERROR: Foo.aidl:1.11-15: Every type parameter should be unique.\n"; |
| 2676 | CaptureStderr(); |
| 2677 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2678 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2679 | } |
| 2680 | |
| 2681 | TEST_P(AidlTest, RejectGenericStructuredParcelableField) { |
| 2682 | io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo<T,T> { T a; int A; }"); |
| 2683 | Options options = |
| 2684 | Options::From("aidl Foo.aidl --lang=" + Options::LanguageToString(GetLanguage())); |
| 2685 | const string expected_stderr = "ERROR: Foo.aidl:1.22-24: Failed to resolve 'T'\n"; |
| 2686 | CaptureStderr(); |
| 2687 | EXPECT_NE(0, ::android::aidl::compile_aidl(options, io_delegate_)); |
| 2688 | EXPECT_EQ(expected_stderr, GetCapturedStderr()); |
| 2689 | } |
| 2690 | |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 2691 | } // namespace aidl |
| 2692 | } // namespace android |