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