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