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