-
Notifications
You must be signed in to change notification settings - Fork 0
/
aidl_unittest.cpp
5712 lines (5146 loc) · 234 KB
/
aidl_unittest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2015, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "aidl.h"
#include <android-base/format.h>
#include <android-base/stringprintf.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <variant>
#include <vector>
#include "aidl_checkapi.h"
#include "aidl_dumpapi.h"
#include "aidl_language.h"
#include "aidl_to_cpp.h"
#include "aidl_to_cpp_common.h"
#include "aidl_to_java.h"
#include "aidl_to_ndk.h"
#include "aidl_to_rust.h"
#include "comments.h"
#include "logging.h"
#include "options.h"
#include "parser.h"
#include "preprocess.h"
#include "tests/fake_io_delegate.h"
using android::aidl::test::FakeIoDelegate;
using android::base::StringPrintf;
using std::map;
using std::set;
using std::string;
using std::unique_ptr;
using std::variant;
using std::vector;
using testing::HasSubstr;
using testing::TestParamInfo;
using testing::internal::CaptureStderr;
using testing::internal::GetCapturedStderr;
namespace android {
namespace aidl {
namespace {
const char kExpectedDepFileContents[] =
R"(place/for/output/p/IFoo.java : \
p/IFoo.aidl
p/IFoo.aidl :
)";
const char kExpectedNinjaDepFileContents[] =
R"(place/for/output/p/IFoo.java : \
p/IFoo.aidl
)";
const char kExpectedParcelableDeclarationDepFileContents[] =
R"( : \
p/Foo.aidl
p/Foo.aidl :
)";
const char kExpectedStructuredParcelableDepFileContents[] =
R"(place/for/output/p/Foo.java : \
p/Foo.aidl
p/Foo.aidl :
)";
} // namespace
const string INVALID_INT8_VALUE = "Invalid type specifier for an int8 literal";
const string INVALID_FLOAT_VALUE = "Invalid type specifier for a literal float";
const string INVALID_OPERATION = "Cannot perform operation";
class AidlTest : public ::testing::TestWithParam<Options::Language> {
protected:
AidlDefinedType* Parse(const string& path, const string& contents, AidlTypenames& typenames_,
Options::Language lang, AidlError* error = nullptr,
const vector<string> additional_arguments = {}) {
io_delegate_.SetFileContents(path, contents);
vector<string> args;
args.emplace_back("aidl");
args.emplace_back("--min_sdk_version=current");
args.emplace_back("--lang=" + to_string(lang));
for (const string& s : additional_arguments) {
args.emplace_back(s);
}
for (const string& f : preprocessed_files_) {
args.emplace_back("--preprocessed=" + f);
}
args.emplace_back("--include=.");
for (const string& i : import_paths_) {
args.emplace_back("--include=" + i);
}
args.emplace_back(path);
Options options = Options::From(args);
vector<string> imported_files;
ImportResolver import_resolver{io_delegate_, path, import_paths_};
AidlError actual_error = ::android::aidl::internals::load_and_validate_aidl(
path, options, io_delegate_, &typenames_, &imported_files);
if (error != nullptr) {
*error = actual_error;
}
if (actual_error != AidlError::OK) {
return nullptr;
}
const auto& defined_types = typenames_.MainDocument().DefinedTypes();
EXPECT_EQ(1ul, defined_types.size());
return defined_types.front().get();
}
void EvaluateInvalidAssignment(string content, string expected_stderr, AidlTypenames& typenames_,
Options::Language lang) {
AidlError error;
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", content, typenames_, lang, &error));
EXPECT_THAT(GetCapturedStderr(), HasSubstr(expected_stderr));
};
void EvaluateValidAssignment(string content, string expected_stderr, AidlTypenames& typenames_,
Options::Language lang) {
AidlError error;
CaptureStderr();
EXPECT_NE(nullptr, Parse("a/IFoo.aidl", content, typenames_, lang, &error));
EXPECT_THAT(GetCapturedStderr(), HasSubstr(expected_stderr));
};
Options::Language GetLanguage() { return GetParam(); }
FakeIoDelegate io_delegate_;
vector<string> preprocessed_files_;
set<string> import_paths_;
AidlTypenames typenames_;
};
// Instantiate the AidlTest parameterized suite, calling all of the TEST_P
// tests with each of the supported languages as a parameter.
INSTANTIATE_TEST_SUITE_P(AidlTestSuite, AidlTest,
testing::Values(Options::Language::CPP, Options::Language::JAVA,
Options::Language::NDK, Options::Language::RUST),
[](const testing::TestParamInfo<Options::Language>& info) {
return to_string(info.param);
});
TEST_P(AidlTest, AcceptMissingPackage) {
EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { }", typenames_, GetLanguage()));
}
TEST_P(AidlTest, EndsInSingleLineComment) {
EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { } // foo", typenames_, GetLanguage()));
}
TEST_P(AidlTest, InterfaceRequiresCorrectPath) {
const string expected_stderr =
"ERROR: a/Foo.aidl:1.11-21: IBar should be declared in a file called a/IBar.aidl\n";
const std::string file_contents = "package a; interface IBar {}";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents;
}
TEST_P(AidlTest, ParcelableRequiresCorrectPath) {
const string expected_stderr =
"ERROR: a/Foo.aidl:1.11-21: Bar should be declared in a file called a/Bar.aidl\n";
const std::string file_contents = "package a; interface Bar {}";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents;
}
TEST_P(AidlTest, UnstructuredParcelableRequiresCorrectPath) {
const string expected_stderr =
"ERROR: a/Foo.aidl:1.22-26: Bar should be declared in a file called a/Bar.aidl\n";
const std::string file_contents = "package a; parcelable Bar cpp_header \"anything.h\";";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents;
}
TEST_P(AidlTest, EnumRequiresCorrectPath) {
const string expected_stderr =
"ERROR: a/Foo.aidl:1.16-20: Bar should be declared in a file called a/Bar.aidl\n";
const std::string file_contents = "package a; enum Bar { A, }";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", file_contents, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr()) << file_contents;
}
TEST_P(AidlTest, SupportOnlyOutParameters) {
const string interface_list = "package a; interface IBar { void f(out List<String> bar); }";
EXPECT_NE(nullptr, Parse("a/IBar.aidl", interface_list, typenames_, GetLanguage()));
}
TEST_P(AidlTest, RejectOutParametersForIBinder) {
const string interface_ibinder = "package a; interface IBaz { void f(out IBinder bar); }";
const string expected_ibinder_stderr =
"ERROR: a/IBaz.aidl:1.47-51: 'bar' can't be an out parameter because IBinder can only be an "
"in parameter.\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IBaz.aidl", interface_ibinder, typenames_, GetLanguage()));
EXPECT_EQ(expected_ibinder_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectsOutParametersInOnewayInterface) {
const string oneway_interface = "package a; oneway interface IBar { void f(out int[] bar); }";
const string expected_stderr =
"ERROR: a/IBar.aidl:1.40-42: oneway method 'f' cannot have out parameters\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_interface, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectsOutParametersInOnewayMethod) {
const string oneway_method = "package a; interface IBar { oneway void f(out int[] bar); }";
const string expected_stderr =
"ERROR: a/IBar.aidl:1.40-42: oneway method 'f' cannot have out parameters\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IBar.aidl", oneway_method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectsOnewayNonVoidReturn) {
const string oneway_method = "package a; interface IFoo { oneway int f(); }";
const string expected_stderr =
"ERROR: a/IFoo.aidl:1.39-41: oneway method 'f' cannot return a value\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectsNullablePrimitive) {
const string oneway_method = "package a; interface IFoo { @nullable int f(); }";
const string expected_stderr =
"ERROR: a/IFoo.aidl:1.38-42: Primitive type cannot get nullable annotation\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, AcceptNullableList) {
const string oneway_method = "package a; interface IFoo { @nullable List<String> f(); }";
const string expected_stderr = "";
CaptureStderr();
EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectRecursiveParcelable) {
CaptureStderr();
EXPECT_EQ(nullptr, Parse("Foo.aidl", "parcelable Foo { Foo foo; }", typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Foo is a recursive parcelable"));
}
TEST_P(AidlTest, RejectIndirectRecursiveParcelable) {
io_delegate_.SetFileContents("Bar.aidl", "parcelable Bar { Foo foo; }");
import_paths_.emplace("");
CaptureStderr();
EXPECT_EQ(nullptr, Parse("Foo.aidl", "parcelable Foo { Bar bar; }", typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Foo is a recursive parcelable"));
}
TEST_P(AidlTest, RejectRecursiveTypeEvenIfNullable) {
// Note: in native backends @nullable is mapped to non-heap wrapper like std::optional/Option<T>
io_delegate_.SetFileContents("Bar.aidl", "parcelable Bar { @nullable Foo foo; }");
import_paths_.emplace("");
CaptureStderr();
EXPECT_EQ(nullptr, Parse("Foo.aidl", "parcelable Foo { Bar bar; }", typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Foo is a recursive parcelable"));
}
TEST_P(AidlTest, OkayIfRecursionInvolvesHeapType) {
CaptureStderr();
std::string java_only_map_field;
if (GetLanguage() == Options::Language::JAVA) {
java_only_map_field = " Map<String, Foo> map;\n";
}
EXPECT_NE(nullptr, Parse("Foo.aidl",
"parcelable Foo {\n"
" List<Foo> list;\n" +
java_only_map_field +
" Foo[] arr;\n"
" @nullable(heap=true) Foo heap_nullable;\n"
"}\n",
typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), "");
}
TEST_P(AidlTest, InterfaceCanReferenceItself) {
CaptureStderr();
EXPECT_NE(nullptr, Parse("IFoo.aidl", "interface IFoo { void foo(in IFoo self); }", typenames_,
GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), "");
}
TEST_P(AidlTest, HeapNullableCantApplyToOtherThanParcelables) {
CaptureStderr();
EXPECT_EQ(nullptr, Parse("Foo.aidl",
"parcelable Foo {\n"
" @nullable(heap=true) String s;\n"
"}",
typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("@nullable(heap=true) is available to parcelables"));
}
TEST_P(AidlTest, RejectsDuplicatedArgumentNames) {
const string method = "package a; interface IFoo { void f(int a, int a); }";
const string expected_stderr =
"ERROR: a/IFoo.aidl:1.33-35: method 'f' has duplicate argument name 'a'\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectsDuplicatedFieldNames) {
const string method = "package a; parcelable Foo { int a; String a; }";
const string expected_stderr = "ERROR: a/Foo.aidl:1.42-44: 'Foo' has duplicate field name 'a'\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, AcceptsEmptyParcelable) {
CaptureStderr();
EXPECT_NE(nullptr, Parse("Foo.aidl", "parcelable Foo {}", typenames_, GetLanguage()));
EXPECT_EQ("", GetCapturedStderr());
}
TEST_P(AidlTest, RejectsDuplicatedAnnotationParams) {
const string method = "package a; interface IFoo { @UnsupportedAppUsage(foo=1, foo=2)void f(); }";
const string expected_stderr = "ERROR: a/IFoo.aidl:1.56-62: Trying to redefine parameter foo.\n";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage()));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
}
TEST_P(AidlTest, RejectUnsupportedInterfaceAnnotations) {
AidlError error;
const string method = "package a; @nullable interface IFoo { int f(); }";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage(), &error));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("@nullable is not available."));
EXPECT_EQ(AidlError::BAD_TYPE, error);
}
TEST_P(AidlTest, RejectUnsupportedTypeAnnotations) {
AidlError error;
const string method = "package a; interface IFoo { @JavaOnlyStableParcelable int f(); }";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", method, typenames_, GetLanguage(), &error));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("@JavaOnlyStableParcelable is not available."));
EXPECT_EQ(AidlError::BAD_TYPE, error);
}
TEST_P(AidlTest, RejectUnsupportedParcelableDefineAnnotations) {
AidlError error;
const string method = "package a; @nullable parcelable Foo { String a; String b; }";
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/Foo.aidl", method, typenames_, GetLanguage(), &error));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("@nullable is not available."));
EXPECT_EQ(AidlError::BAD_TYPE, error);
}
TEST_P(AidlTest, ParsesNonNullableAnnotation) {
auto parse_result =
Parse("a/IFoo.aidl", "package a; interface IFoo { String f(); }", typenames_, GetLanguage());
ASSERT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
ASSERT_NE(nullptr, interface);
ASSERT_FALSE(interface->GetMethods().empty());
EXPECT_FALSE(interface->GetMethods()[0]->GetType().IsNullable());
}
TEST_P(AidlTest, ParsesNullableAnnotation) {
auto parse_result = Parse("a/IFoo.aidl", "package a; interface IFoo { @nullable String f(); }",
typenames_, GetLanguage());
ASSERT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
ASSERT_NE(nullptr, interface);
ASSERT_FALSE(interface->GetMethods().empty());
EXPECT_TRUE(interface->GetMethods()[0]->GetType().IsNullable());
}
TEST_P(AidlTest, ParsesNonUtf8Annotations) {
auto parse_result =
Parse("a/IFoo.aidl", "package a; interface IFoo { String f(); }", typenames_, GetLanguage());
ASSERT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
ASSERT_NE(nullptr, interface);
ASSERT_FALSE(interface->GetMethods().empty());
EXPECT_FALSE(interface->GetMethods()[0]->GetType().IsUtf8InCpp());
}
TEST_P(AidlTest, ParsesUtf8Annotations) {
auto parse_result = Parse("a/IFoo.aidl", "package a; interface IFoo { @utf8InCpp String f(); }",
typenames_, GetLanguage());
ASSERT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
ASSERT_NE(nullptr, interface);
ASSERT_FALSE(interface->GetMethods().empty());
EXPECT_TRUE(interface->GetMethods()[0]->GetType().IsUtf8InCpp());
}
TEST_P(AidlTest, VintfRequiresStructuredAndStability) {
AidlError error;
const string expected_stderr =
"ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface 'stability: "
"\"vintf\"'\n"
"ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface "
"--structured\n";
CaptureStderr();
ASSERT_EQ(nullptr, Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_,
GetLanguage(), &error));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
ASSERT_EQ(AidlError::NOT_STRUCTURED, error);
}
TEST_P(AidlTest, VintfRequiresStructured) {
AidlError error;
const string expected_stderr =
"ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface "
"--structured\n";
CaptureStderr();
ASSERT_EQ(nullptr, Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_,
GetLanguage(), &error, {"--stability", "vintf"}));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
ASSERT_EQ(AidlError::NOT_STRUCTURED, error);
}
TEST_P(AidlTest, VintfRequiresSpecifiedStability) {
AidlError error;
const string expected_stderr =
"ERROR: IFoo.aidl:1.16-26: Must compile @VintfStability type w/ aidl_interface 'stability: "
"\"vintf\"'\n";
CaptureStderr();
ASSERT_EQ(nullptr, Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_,
GetLanguage(), &error, {"--structured"}));
EXPECT_EQ(expected_stderr, GetCapturedStderr());
ASSERT_EQ(AidlError::NOT_STRUCTURED, error);
}
TEST_P(AidlTest, ParsesStabilityAnnotations) {
AidlError error;
auto parse_result = Parse("IFoo.aidl", "@VintfStability interface IFoo {}", typenames_,
GetLanguage(), &error, {"--structured", "--stability", "vintf"});
ASSERT_EQ(AidlError::OK, error);
ASSERT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
ASSERT_NE(nullptr, interface);
ASSERT_TRUE(interface->IsVintfStability());
}
TEST_P(AidlTest, TypesShouldHaveVintfStabilityWhenCompilingWithTheVintfFlag) {
CaptureStderr();
string code =
"@VintfStability\n"
"parcelable Foo {\n"
" interface INested { interface INastyNester {} }"
"}";
EXPECT_NE(nullptr, Parse("Foo.aidl", code, typenames_, GetLanguage(), nullptr,
{"--structured", "--stability", "vintf"}));
EXPECT_EQ(GetCapturedStderr(), "");
auto nested = typenames_.TryGetDefinedType("Foo.INested");
ASSERT_NE(nullptr, nested);
ASSERT_TRUE(nested->IsVintfStability());
auto nastyNester = typenames_.TryGetDefinedType("Foo.INested.INastyNester");
ASSERT_NE(nullptr, nastyNester);
ASSERT_TRUE(nastyNester->IsVintfStability());
}
TEST_P(AidlTest, VintfStabilityAppliesToNestedTypesAsWell) {
CaptureStderr();
EXPECT_EQ(nullptr, Parse("Foo.aidl", "parcelable Foo {}", typenames_, GetLanguage(), nullptr,
{"--structured", "--stability", "vintf"}));
EXPECT_THAT(GetCapturedStderr(),
HasSubstr("Foo does not have VINTF level stability (marked @VintfStability)"));
}
TEST_F(AidlTest, ParsesJavaOnlyStableParcelable) {
Options java_options = Options::From("aidl -I . -o out --structured a/Foo.aidl");
Options cpp_options = Options::From("aidl -I . --lang=cpp -o out -h out/include a/Foo.aidl");
Options cpp_structured_options =
Options::From("aidl --lang=cpp -I . --structured -o out -h out/include a/Foo.aidl");
Options rust_options = Options::From("aidl -I . --lang=rust -o out --structured a/Foo.aidl");
io_delegate_.SetFileContents(
"a/Foo.aidl",
StringPrintf("package a; @JavaOnlyStableParcelable parcelable Foo cpp_header \"Foo.h\" ;"));
EXPECT_TRUE(compile_aidl(java_options, io_delegate_));
EXPECT_TRUE(compile_aidl(cpp_options, io_delegate_));
CaptureStderr();
EXPECT_FALSE(compile_aidl(cpp_structured_options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Cannot declare unstructured"));
CaptureStderr();
EXPECT_FALSE(compile_aidl(rust_options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Cannot declare unstructured"));
}
TEST_F(AidlTest, ParsesNdkOnlyStableParcelable) {
Options java_options = Options::From("aidl -I . -o out --structured a/Foo.aidl");
Options ndk_structured_options =
Options::From("aidl --lang=ndk --structured -I . -o out -h out/include a/Foo.aidl");
Options rust_options = Options::From("aidl --lang=rust -I . -o out --structured a/Foo.aidl");
Options cpp_options = Options::From("aidl --lang=cpp -I . -o out -h out/include a/Foo.aidl");
io_delegate_.SetFileContents(
"a/Foo.aidl",
StringPrintf("package a; @NdkOnlyStableParcelable parcelable Foo cpp_header \"Foo.h\" ;"));
EXPECT_TRUE(compile_aidl(cpp_options, io_delegate_));
// not considered unstructured, but it still can't be compiled directly with
// --structured AIDL - it can only be used as an import
CaptureStderr();
EXPECT_FALSE(compile_aidl(ndk_structured_options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(),
HasSubstr("Refusing to generate code with unstructured parcelables"));
CaptureStderr();
EXPECT_FALSE(compile_aidl(java_options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Cannot declare unstructured"));
CaptureStderr();
EXPECT_FALSE(compile_aidl(rust_options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("Cannot declare unstructured"));
}
TEST_P(AidlTest, NdkAndJavaStabilityIsVintfStable) {
CaptureStderr();
io_delegate_.SetFileContents("NonPortableThing.aidl",
"@NdkOnlyStableParcelable @JavaOnlyStableParcelable parcelable "
"NonPortableThing ndk_header \"lol.h\" cpp_header \"lolol.h\";");
import_paths_.emplace("");
auto result =
Parse("IFoo.aidl",
"import NonPortableThing; @VintfStability interface IFoo { NonPortableThing get(); }",
typenames_, GetLanguage(), nullptr, {"--structured", "--stability", "vintf"});
if (GetLanguage() == Options::Language::NDK || GetLanguage() == Options::Language::JAVA) {
EXPECT_NE(result, nullptr);
EXPECT_EQ(GetCapturedStderr(), "");
} else {
EXPECT_EQ(result, nullptr);
EXPECT_THAT(
GetCapturedStderr(),
HasSubstr("NonPortableThing does not have VINTF level stability (marked @VintfStability)"));
}
}
TEST_F(AidlTest, ParcelableSupportJavaDeriveToString) {
io_delegate_.SetFileContents("a/Foo.aidl", R"(package a;
@JavaDerive(toString=true) parcelable Foo { int a; float b; })");
Options java_options = Options::From("aidl --lang=java -I . -o out a/Foo.aidl");
EXPECT_TRUE(compile_aidl(java_options, io_delegate_));
string java_out;
EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/Foo.java", &java_out));
EXPECT_THAT(java_out, testing::HasSubstr("public String toString() {"));
// Other backends shouldn't be bothered
Options cpp_options = Options::From("aidl --lang=cpp -I . -o out -h out a/Foo.aidl");
EXPECT_TRUE(compile_aidl(cpp_options, io_delegate_));
Options ndk_options = Options::From("aidl --lang=ndk -I . -o out -h out a/Foo.aidl");
EXPECT_TRUE(compile_aidl(ndk_options, io_delegate_));
}
TEST_F(AidlTest, UnionSupportJavaDeriveToString) {
io_delegate_.SetFileContents("a/Foo.aidl", R"(package a;
@JavaDerive(toString=true) union Foo { int a; int[] b; })");
CaptureStderr();
Options java_options = Options::From("aidl --lang=java -I . -o out a/Foo.aidl");
EXPECT_TRUE(compile_aidl(java_options, io_delegate_));
EXPECT_EQ("", GetCapturedStderr());
const string expected_to_string_method = R"--(
@Override
public String toString() {
switch (_tag) {
case a: return "a.Foo.a(" + (getA()) + ")";
case b: return "a.Foo.b(" + (java.util.Arrays.toString(getB())) + ")";
}
throw new IllegalStateException("unknown field: " + _tag);
}
)--";
string java_out;
EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/Foo.java", &java_out));
EXPECT_THAT(java_out, testing::HasSubstr(expected_to_string_method));
}
TEST_F(AidlTest, ParcelableSupportJavaDeriveEquals) {
io_delegate_.SetFileContents("a/Foo.aidl", R"(package a;
@JavaDerive(equals=true) parcelable Foo { int a; float b; })");
CaptureStderr();
Options java_options = Options::From("aidl --lang=java -I . -o out a/Foo.aidl");
EXPECT_TRUE(compile_aidl(java_options, io_delegate_));
EXPECT_EQ("", GetCapturedStderr());
const std::string expected = R"--(
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null) return false;
if (!(other instanceof Foo)) return false;
Foo that = (Foo)other;
if (!java.util.Objects.deepEquals(a, that.a)) return false;
if (!java.util.Objects.deepEquals(b, that.b)) return false;
return true;
}
@Override
public int hashCode() {
return java.util.Arrays.deepHashCode(java.util.Arrays.asList(a, b).toArray());
}
)--";
string java_out;
EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/Foo.java", &java_out));
EXPECT_THAT(java_out, testing::HasSubstr(expected));
}
TEST_F(AidlTest, UnionSupportJavaDeriveEquals) {
io_delegate_.SetFileContents("a/Foo.aidl", R"(package a;
@JavaDerive(equals=true) union Foo { int a; int[] b; })");
CaptureStderr();
Options java_options = Options::From("aidl --lang=java -I . -o out a/Foo.aidl");
EXPECT_TRUE(compile_aidl(java_options, io_delegate_));
EXPECT_EQ("", GetCapturedStderr());
const std::string expected = R"--(
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null) return false;
if (!(other instanceof Foo)) return false;
Foo that = (Foo)other;
if (_tag != that._tag) return false;
if (!java.util.Objects.deepEquals(_value, that._value)) return false;
return true;
}
@Override
public int hashCode() {
return java.util.Arrays.deepHashCode(java.util.Arrays.asList(_tag, _value).toArray());
}
)--";
string java_out;
EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/Foo.java", &java_out));
EXPECT_THAT(java_out, testing::HasSubstr(expected));
}
TEST_F(AidlTest, RejectsJavaDeriveAnnotation) {
{
io_delegate_.SetFileContents("a/Foo.aidl",
"package a; @JavaDerive(blah=true) parcelable Foo{}");
Options java_options = Options::From("aidl --lang=java -I . -o out a/Foo.aidl");
CaptureStderr();
EXPECT_FALSE(compile_aidl(java_options, io_delegate_));
const std::string expected_stderr =
"ERROR: a/Foo.aidl:1.11-34: Parameter blah not supported for annotation JavaDerive.";
EXPECT_THAT(GetCapturedStderr(),
HasSubstr("Parameter blah not supported for annotation JavaDerive."));
}
{
io_delegate_.SetFileContents("a/IFoo.aidl", "package a; @JavaDerive interface IFoo{}");
Options java_options = Options::From("aidl --lang=java -I . -o out a/IFoo.aidl");
CaptureStderr();
EXPECT_FALSE(compile_aidl(java_options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("@JavaDerive is not available."));
}
}
TEST_P(AidlTest, ParseDescriptorAnnotation) {
AidlError error;
auto parse_result = Parse("IFoo.aidl", R"(@Descriptor(value="IBar") interface IFoo{})",
typenames_, GetLanguage(), &error, {"--structured"});
ASSERT_EQ(AidlError::OK, error);
ASSERT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
ASSERT_NE(nullptr, interface);
ASSERT_EQ("IBar", interface->GetDescriptor());
}
TEST_P(AidlTest, UnknownAnnotation) {
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", "package a; @Unknown interface IFoo { }", typenames_,
GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("not a recognized annotation"));
CaptureStderr();
EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", "package a; @Unknown(param=true) interface IFoo { }",
typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("not a recognized annotation"));
}
TEST_P(AidlTest, AcceptsOnewayMethod) {
const string oneway_method = "package a; interface IFoo { oneway void f(int a); }";
EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
}
TEST_P(AidlTest, AcceptsOnewayInterface) {
const string oneway_interface = "package a; oneway interface IBar { void f(int a); }";
EXPECT_NE(nullptr, Parse("a/IBar.aidl", oneway_interface, typenames_, GetLanguage()));
}
TEST_P(AidlTest, AcceptsAnnotatedOnewayMethod) {
const string oneway_method =
"package a; interface IFoo { @UnsupportedAppUsage oneway void f(int a); }";
EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
}
TEST_P(AidlTest, AnnotationsInMultiplePlaces) {
const string oneway_method =
"package a; interface IFoo { @UnsupportedAppUsage oneway @PropagateAllowBlocking void f(int "
"a); }";
const AidlDefinedType* defined = Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage());
ASSERT_NE(nullptr, defined);
const AidlInterface* iface = defined->AsInterface();
ASSERT_NE(nullptr, iface);
const auto& methods = iface->GetMethods();
ASSERT_EQ(1u, methods.size());
const auto& method = methods[0];
const AidlTypeSpecifier& ret_type = method->GetType();
// TODO(b/151102494): these annotations should be on the method
ASSERT_NE(nullptr, ret_type.UnsupportedAppUsage());
ASSERT_TRUE(ret_type.IsPropagateAllowBlocking());
}
TEST_P(AidlTest, AnnotationValueAttribute) {
const string content =
"package a; @Descriptor(\"descriptor_value\") interface IFoo { void f(int a); }";
const AidlDefinedType* defined = Parse("a/IFoo.aidl", content, typenames_, GetLanguage());
ASSERT_NE(nullptr, defined);
const AidlInterface* iface = defined->AsInterface();
ASSERT_NE(nullptr, iface);
ASSERT_EQ("descriptor_value", iface->GetDescriptor());
}
TEST_F(AidlTest, CheckApiForAnnotationValueAttribute) {
Options options = Options::From("aidl --checkapi=equal old new");
io_delegate_.SetFileContents("old/p/IFoo.aidl",
"package p; @Descriptor(value=\"v1\") interface IFoo{ void foo();}");
io_delegate_.SetFileContents("new/p/IFoo.aidl",
"package p; @Descriptor(\"v1\") interface IFoo{ void foo();}");
EXPECT_TRUE(::android::aidl::check_api(options, io_delegate_));
}
TEST_P(AidlTest, WritesComments) {
string foo_interface =
R"(package a;
/* foo */
interface IFoo {
/* i */
int i();
// j
@nullable String j();
// k1
/* k2 */
@UnsupportedAppUsage oneway void k(int a);
})";
CaptureStderr();
auto parse_result = Parse("a/IFoo.aidl", foo_interface, typenames_, GetLanguage());
EXPECT_NE(nullptr, parse_result);
EXPECT_EQ("", GetCapturedStderr());
EXPECT_EQ((Comments{{"/* foo */"}}), parse_result->GetComments());
const AidlInterface* interface = parse_result->AsInterface();
EXPECT_EQ((Comments{{"/* i */"}}), interface->GetMethods()[0]->GetComments());
EXPECT_EQ((Comments{{"// j\n"}}), interface->GetMethods()[1]->GetComments());
EXPECT_EQ((Comments{{"// k1\n"}, {"/* k2 */"}}), interface->GetMethods()[2]->GetComments());
}
TEST_P(AidlTest, CppHeaderCanBeIdentifierAsWell) {
io_delegate_.SetFileContents("p/cpp_header.aidl",
R"(package p;
parcelable cpp_header cpp_header "bar/header" ndk_header "ndk/bar/header";)");
import_paths_.emplace("");
const string input_path = "p/IFoo.aidl";
const string input = R"(package p;
import p.cpp_header;
interface IFoo {
// get bar
cpp_header get();
})";
auto parse_result = Parse(input_path, input, typenames_, GetLanguage());
EXPECT_NE(nullptr, parse_result);
const AidlInterface* interface = parse_result->AsInterface();
EXPECT_EQ((Comments{{"// get bar\n"}}), interface->GetMethods()[0]->GetComments());
}
TEST_F(AidlTest, RejectsIfCppHeaderIsMissing) {
io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo;");
Options options = Options::From("aidl -I . --lang cpp -h h -o o Foo.aidl");
CaptureStderr();
EXPECT_FALSE(compile_aidl(options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("must have cpp_header defined"));
}
TEST_F(AidlTest, RejectsIfTypeRefsCppHeaderIsMissing) {
io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo;");
io_delegate_.SetFileContents("IBar.aidl", "interface IBar { void bar(in Foo foo); }");
Options options = Options::From("aidl -I . --lang cpp -h h -o o IBar.aidl");
CaptureStderr();
EXPECT_FALSE(compile_aidl(options, io_delegate_));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("must have cpp_header defined"));
}
TEST_F(AidlTest, ParsesPreprocessedFile) {
string simple_content = "parcelable a.Foo;\ninterface b.IBar;";
io_delegate_.SetFileContents("path", simple_content);
EXPECT_FALSE(typenames_.ResolveTypename("a.Foo").is_resolved);
EXPECT_TRUE(Parser::Parse("path", io_delegate_, typenames_, /*is_preprocessed=*/true));
EXPECT_TRUE(typenames_.ResolveTypename("a.Foo").is_resolved);
EXPECT_TRUE(typenames_.ResolveTypename("b.IBar").is_resolved);
}
TEST_F(AidlTest, ParsesPreprocessedFileWithWhitespace) {
string simple_content = "parcelable a.Foo;\n interface b.IBar ;\t";
io_delegate_.SetFileContents("path", simple_content);
EXPECT_FALSE(typenames_.ResolveTypename("a.Foo").is_resolved);
EXPECT_TRUE(Parser::Parse("path", io_delegate_, typenames_, /*is_preprocessed=*/true));
EXPECT_TRUE(typenames_.ResolveTypename("a.Foo").is_resolved);
EXPECT_TRUE(typenames_.ResolveTypename("b.IBar").is_resolved);
}
TEST_P(AidlTest, PreferImportToPreprocessed) {
io_delegate_.SetFileContents("preprocessed", "interface another.IBar;");
io_delegate_.SetFileContents("one/IBar.aidl", "package one; "
"interface IBar {}");
preprocessed_files_.push_back("preprocessed");
import_paths_.emplace("");
auto parse_result = Parse("p/IFoo.aidl", "package p; import one.IBar; interface IFoo {}",
typenames_, GetLanguage());
EXPECT_NE(nullptr, parse_result);
// We expect to know about both kinds of IBar
EXPECT_TRUE(typenames_.ResolveTypename("one.IBar").is_resolved);
EXPECT_TRUE(typenames_.ResolveTypename("another.IBar").is_resolved);
// But if we request just "IBar" we should get our imported one.
AidlTypeSpecifier ambiguous_type(AIDL_LOCATION_HERE, "IBar", /*array=*/std::nullopt, nullptr, {});
ambiguous_type.Resolve(typenames_, parse_result);
EXPECT_EQ("one.IBar", ambiguous_type.GetName());
}
// Special case of PreferImportToPreprocessed. Imported type should be preferred
// even when the preprocessed file already has the same type.
TEST_P(AidlTest, B147918827) {
io_delegate_.SetFileContents("preprocessed", "interface another.IBar;\ninterface one.IBar;");
io_delegate_.SetFileContents("one/IBar.aidl",
"package one; "
"interface IBar {}");
preprocessed_files_.push_back("preprocessed");
import_paths_.emplace("");
auto parse_result = Parse("p/IFoo.aidl", "package p; import one.IBar; interface IFoo {}",
typenames_, GetLanguage());
EXPECT_NE(nullptr, parse_result);
// We expect to know about both kinds of IBar
EXPECT_TRUE(typenames_.ResolveTypename("one.IBar").is_resolved);
EXPECT_TRUE(typenames_.ResolveTypename("another.IBar").is_resolved);
// But if we request just "IBar" we should get our imported one.
AidlTypeSpecifier ambiguous_type(AIDL_LOCATION_HERE, "IBar", /*array=*/std::nullopt, nullptr, {});
ambiguous_type.Resolve(typenames_, parse_result);
EXPECT_EQ("one.IBar", ambiguous_type.GetName());
}
TEST_F(AidlTest, WritePreprocessedFile) {
io_delegate_.SetFileContents("p/Outer.aidl",
"package p; parcelable Outer.Inner;");
io_delegate_.SetFileContents("one/IBar.aidl", "package one; import p.Outer;"
"interface IBar {}");
vector<string> args{"aidl", "--preprocess", "preprocessed",
"-I.", "p/Outer.aidl", "one/IBar.aidl"};
Options options = Options::From(args);
EXPECT_TRUE(::android::aidl::Preprocess(options, io_delegate_));
std::map<std::string, std::string> expected = {{"preprocessed",
"parcelable p.Outer.Inner;\n"
"interface one.IBar {\n"
"}\n"}};
EXPECT_THAT(io_delegate_.OutputFiles(), testing::Eq(expected));
}
TEST_F(AidlTest, PreprocessVariousThings) {
io_delegate_.SetFileContents("foo/bar/IFoo.aidl",
"package foo.bar;\n"
"interface IFoo {\n"
" int foo();\n"
" const int FOO = foo.bar.Bar.BAR + 1; // should be 44\n"
"}\n");
io_delegate_.SetFileContents("foo/bar/Bar.aidl",
"package foo.bar;\n"
"parcelable Bar {\n"
" const int BAR = imported.Foo.FOO + 1; // should be 43\n"
" imported.Foo foo;\n"
"}\n");
io_delegate_.SetFileContents("foo/bar/Gen.aidl",
"package foo.bar;\n"
"parcelable Gen<T> {\n"
"}\n");
io_delegate_.SetFileContents("foo/bar/Enum.aidl",
"package foo.bar;\n"
"enum Enum {\n"
" FOO = 3, BAR = FOO + 3, // should be 3, 6\n"
"}\n");
io_delegate_.SetFileContents("sub/imported/Foo.aidl",
"package imported;\n"
"parcelable Foo {\n"
" const int FOO = 42;\n"
"}\n");
vector<string> args = {
"aidl",
"--preprocess",
"preprocessed",
"-Isub",
"-I.",
"foo/bar/IFoo.aidl",
"foo/bar/Bar.aidl",
"foo/bar/Gen.aidl",
"foo/bar/Enum.aidl",
};
ASSERT_TRUE(Preprocess(Options::From(args), io_delegate_));
std::string preprocessed =
"interface foo.bar.IFoo {\n"
" const int FOO = 44;\n"
"}\n"
"parcelable foo.bar.Bar {\n"
" const int BAR = 43;\n"
"}\n"
"parcelable foo.bar.Gen<T> {\n"
"}\n"
"enum foo.bar.Enum {\n"
" FOO = 3,\n"
" BAR = 6,\n"
"}\n";
std::map<std::string, std::string> expected = {{"preprocessed", preprocessed}};
EXPECT_THAT(io_delegate_.OutputFiles(), testing::Eq(expected));
// use preprocessed
io_delegate_.SetFileContents("a/Foo.aidl",
"package a; parcelable Foo { const int y = foo.bar.Bar.BAR; }");
io_delegate_.SetFileContents("preprocessed", preprocessed);
CaptureStderr();
auto options = Options::From("aidl --lang java -I . -o out a/Foo.aidl -ppreprocessed");
EXPECT_TRUE(compile_aidl(options, io_delegate_));
EXPECT_EQ("", GetCapturedStderr());
string code;
EXPECT_TRUE(io_delegate_.GetWrittenContents("out/a/Foo.java", &code));
EXPECT_THAT(code, testing::HasSubstr("public static final int y = 43;"));
}
TEST_F(AidlTest, AllowMultipleUnstructuredNestedParcelablesInASingleDocument) {
io_delegate_.SetFileContents("p/IFoo.aidl",
"package p;\n"
"import x.Outer;\n"
"interface IFoo {\n"
" void foo(in Outer.Inner1 in1, in Outer.Inner2 in2);\n"
"}");
io_delegate_.SetFileContents("imported/x/Outer.aidl",