blob: 10c320f91eb9aca9ed543ea95880271c96eca7e1 [file] [log] [blame]
Casey Dahlina834dd42015-09-23 11:52:15 -07001/*
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
17#include <string>
18
19#include <gtest/gtest.h>
20
Casey Dahlin2cc93162015-10-02 16:14:17 -070021#include "aidl.h"
Casey Dahlina834dd42015-09-23 11:52:15 -070022#include "aidl_language.h"
23#include "ast_cpp.h"
24#include "code_writer.h"
Christopher Wileyad339272015-10-05 19:11:58 -070025#include "generate_cpp.h"
Christopher Wiley4a2884b2015-10-07 11:27:45 -070026#include "tests/fake_io_delegate.h"
Christopher Wileye3550c62015-09-29 13:26:10 -070027#include "type_cpp.h"
Casey Dahlina834dd42015-09-23 11:52:15 -070028
Christopher Wiley4a2884b2015-10-07 11:27:45 -070029using android::aidl::test::FakeIoDelegate;
Casey Dahlina834dd42015-09-23 11:52:15 -070030using std::string;
31using std::unique_ptr;
32
33namespace android {
34namespace aidl {
Christopher Wileyf944e792015-09-29 10:00:46 -070035namespace cpp {
Casey Dahlina834dd42015-09-23 11:52:15 -070036namespace {
37
Casey Dahlinb0966612015-10-19 16:35:26 -070038const string kPrimitiveInterfaceAIDL =
Christopher Wiley054afbd2015-10-16 17:08:43 -070039R"(
40package android.os;
41
42interface IPingResponder {
Casey Dahlince776cf2015-10-15 18:45:54 -070043 int Ping(String token);
Casey Dahlina834dd42015-09-23 11:52:15 -070044})";
45
Casey Dahlinb0966612015-10-19 16:35:26 -070046const char kExpectedPrimitiveClientSourceOutput[] =
Christopher Wiley054afbd2015-10-16 17:08:43 -070047R"(#include <android/os/BpPingResponder.h>
Christopher Wiley36570f42015-10-08 17:20:11 -070048#include <binder/Parcel.h>
49
50namespace android {
51
Christopher Wileyb656a3b2015-10-16 11:11:09 -070052namespace os {
Christopher Wiley36570f42015-10-08 17:20:11 -070053
54BpPingResponder::BpPingResponder(const android::sp<android::IBinder>& impl)
55 : BpInterface<IPingResponder>(impl){
56}
57
Casey Dahlince776cf2015-10-15 18:45:54 -070058android::status_t BpPingResponder::Ping(android::String16 token, int32_t* _aidl_return) {
Christopher Wiley36570f42015-10-08 17:20:11 -070059android::Parcel data;
60android::Parcel reply;
61android::status_t status;
Casey Dahlince776cf2015-10-15 18:45:54 -070062status = data.writeString16(token);
Christopher Wiley36570f42015-10-08 17:20:11 -070063if (status != android::OK) { return status; }
64status = remote()->transact(IPingResponder::PING, data, &reply);
65if (status != android::OK) { return status; }
66status = reply.readInt32(_aidl_return);
67if (status != android::OK) { return status; }
68return status;
69}
70
Christopher Wileyb656a3b2015-10-16 11:11:09 -070071} // namespace os
Christopher Wiley36570f42015-10-08 17:20:11 -070072
73} // namespace android
74)";
75
Casey Dahlinb0966612015-10-19 16:35:26 -070076const char kExpectedPrimitiveServerHeaderOutput[] =
Christopher Wiley054afbd2015-10-16 17:08:43 -070077R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_
78#define AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_
Christopher Wileyfd51d602015-10-14 13:04:48 -070079
80#include <binder/IInterface.h>
Christopher Wiley054afbd2015-10-16 17:08:43 -070081#include <android/os/IPingResponder.h>
Christopher Wileyfd51d602015-10-14 13:04:48 -070082
83namespace android {
84
Christopher Wileyb656a3b2015-10-16 11:11:09 -070085namespace os {
Christopher Wileyfd51d602015-10-14 13:04:48 -070086
87class BnPingResponder : public android::BnInterface<IPingResponder> {
88public:
89android::status_t onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags = 0) override;
90}; // class BnPingResponder
91
Christopher Wileyb656a3b2015-10-16 11:11:09 -070092} // namespace os
Christopher Wileyfd51d602015-10-14 13:04:48 -070093
94} // namespace android
95
Christopher Wiley054afbd2015-10-16 17:08:43 -070096#endif // AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_)";
Christopher Wileyfd51d602015-10-14 13:04:48 -070097
Casey Dahlinb0966612015-10-19 16:35:26 -070098const char kExpectedPrimitiveServerSourceOutput[] =
Christopher Wiley054afbd2015-10-16 17:08:43 -070099R"(#include <android/os/BnPingResponder.h>
Christopher Wileyad339272015-10-05 19:11:58 -0700100#include <binder/Parcel.h>
101
102namespace android {
103
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700104namespace os {
Christopher Wileyad339272015-10-05 19:11:58 -0700105
106android::status_t BnPingResponder::onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags) {
Christopher Wiley05f4f892015-10-14 13:30:43 -0700107android::status_t status;
Christopher Wileyad339272015-10-05 19:11:58 -0700108switch (code) {
109case Call::PING:
110{
Casey Dahlince776cf2015-10-15 18:45:54 -0700111android::String16 in_token;
Christopher Wileyad339272015-10-05 19:11:58 -0700112int32_t _aidl_return;
Casey Dahlince776cf2015-10-15 18:45:54 -0700113status = data.readString16(&in_token);
Christopher Wileyad339272015-10-05 19:11:58 -0700114if (status != android::OK) { break; }
115status = Ping(in_token, &_aidl_return);
116if (status != android::OK) { break; }
Christopher Wiley36570f42015-10-08 17:20:11 -0700117status = reply->writeInt32(_aidl_return);
118if (status != android::OK) { break; }
Christopher Wileyad339272015-10-05 19:11:58 -0700119}
120break;
121default:
122{
123status = android::BBinder::onTransact(code, data, reply, flags);
124}
125break;
126}
127return status;
128}
129
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700130} // namespace os
Christopher Wileyad339272015-10-05 19:11:58 -0700131
132} // namespace android
133)";
134
Casey Dahlinb0966612015-10-19 16:35:26 -0700135const char kExpectedPrimitiveClientHeaderOutput[] =
Christopher Wiley054afbd2015-10-16 17:08:43 -0700136R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_
137#define AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_
Casey Dahlina834dd42015-09-23 11:52:15 -0700138
139#include <binder/IBinder.h>
140#include <binder/IInterface.h>
141#include <utils/Errors.h>
Christopher Wiley054afbd2015-10-16 17:08:43 -0700142#include <android/os/IPingResponder.h>
Casey Dahlina834dd42015-09-23 11:52:15 -0700143
144namespace android {
145
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700146namespace os {
Christopher Wiley0c732db2015-09-29 14:36:44 -0700147
Christopher Wiley3bb6bc12015-10-14 10:58:27 -0700148class BpPingResponder : public android::BpInterface<IPingResponder> {
Casey Dahlina834dd42015-09-23 11:52:15 -0700149public:
Christopher Wileyb23149d2015-10-14 13:52:21 -0700150explicit BpPingResponder(const android::sp<android::IBinder>& impl);
Christopher Wileyf094d582015-10-08 15:50:15 -0700151virtual ~BpPingResponder() = default;
Casey Dahlince776cf2015-10-15 18:45:54 -0700152android::status_t Ping(android::String16 token, int32_t* _aidl_return) override;
Casey Dahlina834dd42015-09-23 11:52:15 -0700153}; // class BpPingResponder
154
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700155} // namespace os
Christopher Wiley0c732db2015-09-29 14:36:44 -0700156
Casey Dahlina834dd42015-09-23 11:52:15 -0700157} // namespace android
158
Christopher Wiley054afbd2015-10-16 17:08:43 -0700159#endif // AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_)";
Casey Dahlina834dd42015-09-23 11:52:15 -0700160
Casey Dahlinb0966612015-10-19 16:35:26 -0700161const char kExpectedPrimitiveInterfaceHeaderOutput[] =
Christopher Wiley054afbd2015-10-16 17:08:43 -0700162R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_
163#define AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_
Christopher Wiley3bb6bc12015-10-14 10:58:27 -0700164
165#include <binder/IBinder.h>
Christopher Wiley0c732db2015-09-29 14:36:44 -0700166#include <binder/IInterface.h>
Casey Dahlince776cf2015-10-15 18:45:54 -0700167#include <cstdint>
168#include <utils/String16.h>
Christopher Wiley0c732db2015-09-29 14:36:44 -0700169
170namespace android {
171
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700172namespace os {
Christopher Wiley0c732db2015-09-29 14:36:44 -0700173
Christopher Wiley3bb6bc12015-10-14 10:58:27 -0700174class IPingResponder : public android::IInterface {
Christopher Wiley0c732db2015-09-29 14:36:44 -0700175public:
176DECLARE_META_INTERFACE(PingResponder);
Casey Dahlince776cf2015-10-15 18:45:54 -0700177virtual android::status_t Ping(android::String16 token, int32_t* _aidl_return) = 0;
Christopher Wiley0c732db2015-09-29 14:36:44 -0700178enum Call {
179 PING = android::IBinder::FIRST_CALL_TRANSACTION + 0,
Christopher Wiley3bb6bc12015-10-14 10:58:27 -0700180};
Christopher Wiley0c732db2015-09-29 14:36:44 -0700181}; // class IPingResponder
182
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700183} // namespace os
Christopher Wiley0c732db2015-09-29 14:36:44 -0700184
185} // namespace android
Christopher Wiley3bb6bc12015-10-14 10:58:27 -0700186
Christopher Wiley054afbd2015-10-16 17:08:43 -0700187#endif // AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_)";
Christopher Wiley0c732db2015-09-29 14:36:44 -0700188
Casey Dahlinb0966612015-10-19 16:35:26 -0700189const char kExpectedPrimitiveInterfaceSourceOutput[] =
Christopher Wiley054afbd2015-10-16 17:08:43 -0700190R"(#include <android/os/IPingResponder.h>
191#include <android/os/BpPingResponder.h>
Christopher Wiley1dd458d2015-09-30 11:05:52 -0700192
193namespace android {
194
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700195namespace os {
Christopher Wiley1dd458d2015-09-30 11:05:52 -0700196
Christopher Wiley054afbd2015-10-16 17:08:43 -0700197IMPLEMENT_META_INTERFACE(PingResponder, "android.os.IPingResponder");
Christopher Wiley1dd458d2015-09-30 11:05:52 -0700198
Christopher Wileyb656a3b2015-10-16 11:11:09 -0700199} // namespace os
Christopher Wiley1dd458d2015-09-30 11:05:52 -0700200
201} // namespace android
202)";
203
Casey Dahlinb0966612015-10-19 16:35:26 -0700204const string kComplexTypeInterfaceAIDL =
205R"(package android.os;
206interface IComplexTypeInterface {
207 int Send(in int[] token, out boolean[] item);
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700208 oneway void Piff(int times);
Casey Dahlinb0966612015-10-19 16:35:26 -0700209})";
210
211const char kExpectedComplexTypeClientHeaderOutput[] =
212R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
213#define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
214
215#include <binder/IBinder.h>
216#include <binder/IInterface.h>
217#include <utils/Errors.h>
218#include <android/os/IComplexTypeInterface.h>
219
220namespace android {
221
222namespace os {
223
224class BpComplexTypeInterface : public android::BpInterface<IComplexTypeInterface> {
225public:
226explicit BpComplexTypeInterface(const android::sp<android::IBinder>& impl);
227virtual ~BpComplexTypeInterface() = default;
228android::status_t Send(const std::vector<int32_t>& token, std::vector<bool>* item, int32_t* _aidl_return) override;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700229android::status_t Piff(int32_t times) override;
Casey Dahlinb0966612015-10-19 16:35:26 -0700230}; // class BpComplexTypeInterface
231
232} // namespace os
233
234} // namespace android
235
236#endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_)";
237
238const char kExpectedComplexTypeClientSourceOutput[] =
239R"(#include <android/os/BpComplexTypeInterface.h>
240#include <binder/Parcel.h>
241
242namespace android {
243
244namespace os {
245
246BpComplexTypeInterface::BpComplexTypeInterface(const android::sp<android::IBinder>& impl)
247 : BpInterface<IPingResponder>(impl){
248}
249
250android::status_t BpComplexTypeInterface::Send(const std::vector<int32_t>& token, std::vector<bool>* item, int32_t* _aidl_return) {
251android::Parcel data;
252android::Parcel reply;
253android::status_t status;
254status = data.writeInt32Vector(token);
255if (status != android::OK) { return status; }
256status = remote()->transact(IComplexTypeInterface::SEND, data, &reply);
257if (status != android::OK) { return status; }
258status = reply.readInt32(_aidl_return);
259if (status != android::OK) { return status; }
260status = reply.readBoolVector(item);
261if (status != android::OK) { return status; }
262return status;
263}
264
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700265android::status_t BpComplexTypeInterface::Piff(int32_t times) {
266android::Parcel data;
267android::status_t status;
268status = data.writeInt32(times);
269if (status != android::OK) { return status; }
270status = remote()->transact(IComplexTypeInterface::PIFF, data, &reply, android::IBinder::FLAG_ONEWAY);
271if (status != android::OK) { return status; }
272return status;
273}
274
Casey Dahlinb0966612015-10-19 16:35:26 -0700275} // namespace os
276
277} // namespace android
278)";
279
280const char kExpectedComplexTypeServerHeaderOutput[] =
281R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
282#define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
283
284#include <binder/IInterface.h>
285#include <android/os/IComplexTypeInterface.h>
286
287namespace android {
288
289namespace os {
290
291class BnComplexTypeInterface : public android::BnInterface<IComplexTypeInterface> {
292public:
293android::status_t onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags = 0) override;
294}; // class BnComplexTypeInterface
295
296} // namespace os
297
298} // namespace android
299
300#endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_)";
301
302const char kExpectedComplexTypeServerSourceOutput[] =
303R"(#include <android/os/BnComplexTypeInterface.h>
304#include <binder/Parcel.h>
305
306namespace android {
307
308namespace os {
309
310android::status_t BnComplexTypeInterface::onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags) {
311android::status_t status;
312switch (code) {
313case Call::SEND:
314{
315std::vector<int32_t> in_token;
316std::vector<bool> out_item;
317int32_t _aidl_return;
318status = data.readInt32Vector(&in_token);
319if (status != android::OK) { break; }
320status = Send(in_token, &out_item, &_aidl_return);
321if (status != android::OK) { break; }
322status = reply->writeInt32(_aidl_return);
323if (status != android::OK) { break; }
324status = reply->writeBoolVector(out_item);
325if (status != android::OK) { break; }
326}
327break;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700328case Call::PIFF:
329{
330int32_t in_times;
331status = data.readInt32(&in_times);
332if (status != android::OK) { break; }
333status = Piff(in_times);
334if (status != android::OK) { break; }
335}
336break;
Casey Dahlinb0966612015-10-19 16:35:26 -0700337default:
338{
339status = android::BBinder::onTransact(code, data, reply, flags);
340}
341break;
342}
343return status;
344}
345
346} // namespace os
347
348} // namespace android
349)";
350
351const char kExpectedComplexTypeInterfaceHeaderOutput[] =
352R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
353#define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
354
355#include <binder/IBinder.h>
356#include <binder/IInterface.h>
357#include <cstdint>
358#include <vector>
359
360namespace android {
361
362namespace os {
363
364class IComplexTypeInterface : public android::IInterface {
365public:
366DECLARE_META_INTERFACE(ComplexTypeInterface);
367virtual android::status_t Send(const std::vector<int32_t>& token, std::vector<bool>* item, int32_t* _aidl_return) = 0;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700368virtual android::status_t Piff(int32_t times) = 0;
Casey Dahlinb0966612015-10-19 16:35:26 -0700369enum Call {
370 SEND = android::IBinder::FIRST_CALL_TRANSACTION + 0,
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700371 PIFF = android::IBinder::FIRST_CALL_TRANSACTION + 1,
Casey Dahlinb0966612015-10-19 16:35:26 -0700372};
373}; // class IComplexTypeInterface
374
375} // namespace os
376
377} // namespace android
378
379#endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_)";
380
381const char kExpectedComplexTypeInterfaceSourceOutput[] =
382R"(#include <android/os/IComplexTypeInterface.h>
383#include <android/os/BpComplexTypeInterface.h>
384
385namespace android {
386
387namespace os {
388
389IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface");
390
391} // namespace os
392
393} // namespace android
394)";
395
Casey Dahlina834dd42015-09-23 11:52:15 -0700396} // namespace
397
Casey Dahlinb0966612015-10-19 16:35:26 -0700398class ASTTest : public ::testing::Test {
Christopher Wiley0c732db2015-09-29 14:36:44 -0700399 protected:
Casey Dahlinb0966612015-10-19 16:35:26 -0700400 virtual const string& FilePath() = 0;
401 virtual const string& FileContents() = 0;
402
Christopher Wiley90be4e32015-10-20 14:55:25 -0700403 unique_ptr<AidlInterface> Parse() {
404 FakeIoDelegate io_delegate;
Casey Dahlinb0966612015-10-19 16:35:26 -0700405 io_delegate.SetFileContents(FilePath(), FileContents());
Casey Dahlina834dd42015-09-23 11:52:15 -0700406
Christopher Wiley90be4e32015-10-20 14:55:25 -0700407 cpp::TypeNamespace types;
408 unique_ptr<AidlInterface> ret;
409 std::vector<std::unique_ptr<AidlImport>> imports;
410 int err = ::android::aidl::internals::load_and_validate_aidl(
411 {}, // no preprocessed files
412 {}, // no import paths
Casey Dahlinb0966612015-10-19 16:35:26 -0700413 FilePath(),
Christopher Wiley90be4e32015-10-20 14:55:25 -0700414 io_delegate,
415 &types,
416 &ret,
417 &imports);
Christopher Wiley4a2884b2015-10-07 11:27:45 -0700418
Casey Dahlin2cc93162015-10-02 16:14:17 -0700419 if (err)
420 return nullptr;
Casey Dahlina834dd42015-09-23 11:52:15 -0700421
Casey Dahlin2cc93162015-10-02 16:14:17 -0700422 return ret;
Christopher Wiley90be4e32015-10-20 14:55:25 -0700423 }
Casey Dahlina834dd42015-09-23 11:52:15 -0700424
Christopher Wiley0c732db2015-09-29 14:36:44 -0700425 void Compare(Document* doc, const char* expected) {
426 string output;
427 unique_ptr<CodeWriter> cw = GetStringWriter(&output);
428
429 doc->Write(cw.get());
430
431 EXPECT_EQ(expected, output);
432 }
433};
434
Casey Dahlinb0966612015-10-19 16:35:26 -0700435class PrimitiveInterfaceASTTest : public ASTTest {
436 protected:
437 const string fp_ = "android/os/IPingResponder.aidl";
438 const string& FilePath() override { return fp_; }
439 const string& FileContents() override { return kPrimitiveInterfaceAIDL; }
440};
441
442TEST_F(PrimitiveInterfaceASTTest, GeneratesClientHeader) {
Christopher Wiley90be4e32015-10-20 14:55:25 -0700443 unique_ptr<AidlInterface> interface = Parse();
Christopher Wiley0c732db2015-09-29 14:36:44 -0700444 ASSERT_NE(interface, nullptr);
Christopher Wileye3550c62015-09-29 13:26:10 -0700445 TypeNamespace types;
446 unique_ptr<Document> doc = internals::BuildClientHeader(types, *interface);
Casey Dahlinb0966612015-10-19 16:35:26 -0700447 Compare(doc.get(), kExpectedPrimitiveClientHeaderOutput);
Christopher Wiley0c732db2015-09-29 14:36:44 -0700448}
Casey Dahlina834dd42015-09-23 11:52:15 -0700449
Casey Dahlinb0966612015-10-19 16:35:26 -0700450TEST_F(PrimitiveInterfaceASTTest, GeneratesClientSource) {
Christopher Wiley90be4e32015-10-20 14:55:25 -0700451 unique_ptr<AidlInterface> interface = Parse();
Christopher Wiley36570f42015-10-08 17:20:11 -0700452 ASSERT_NE(interface, nullptr);
453 TypeNamespace types;
454 unique_ptr<Document> doc = internals::BuildClientSource(types, *interface);
Casey Dahlinb0966612015-10-19 16:35:26 -0700455 Compare(doc.get(), kExpectedPrimitiveClientSourceOutput);
Christopher Wiley36570f42015-10-08 17:20:11 -0700456}
457
Casey Dahlinb0966612015-10-19 16:35:26 -0700458TEST_F(PrimitiveInterfaceASTTest, GeneratesServerHeader) {
Christopher Wiley90be4e32015-10-20 14:55:25 -0700459 unique_ptr<AidlInterface> interface = Parse();
Christopher Wileyfd51d602015-10-14 13:04:48 -0700460 ASSERT_NE(interface, nullptr);
461 TypeNamespace types;
462 unique_ptr<Document> doc = internals::BuildServerHeader(types, *interface);
Casey Dahlinb0966612015-10-19 16:35:26 -0700463 Compare(doc.get(), kExpectedPrimitiveServerHeaderOutput);
Christopher Wileyfd51d602015-10-14 13:04:48 -0700464}
465
Casey Dahlinb0966612015-10-19 16:35:26 -0700466TEST_F(PrimitiveInterfaceASTTest, GeneratesServerSource) {
Christopher Wiley90be4e32015-10-20 14:55:25 -0700467 unique_ptr<AidlInterface> interface = Parse();
Christopher Wileyad339272015-10-05 19:11:58 -0700468 ASSERT_NE(interface, nullptr);
469 TypeNamespace types;
470 unique_ptr<Document> doc = internals::BuildServerSource(types, *interface);
Casey Dahlinb0966612015-10-19 16:35:26 -0700471 Compare(doc.get(), kExpectedPrimitiveServerSourceOutput);
Christopher Wileyad339272015-10-05 19:11:58 -0700472}
473
Casey Dahlinb0966612015-10-19 16:35:26 -0700474TEST_F(PrimitiveInterfaceASTTest, GeneratesInterfaceHeader) {
Christopher Wiley90be4e32015-10-20 14:55:25 -0700475 unique_ptr<AidlInterface> interface = Parse();
Christopher Wiley0c732db2015-09-29 14:36:44 -0700476 ASSERT_NE(interface, nullptr);
477 TypeNamespace types;
478 unique_ptr<Document> doc = internals::BuildInterfaceHeader(types, *interface);
Casey Dahlinb0966612015-10-19 16:35:26 -0700479 Compare(doc.get(), kExpectedPrimitiveInterfaceHeaderOutput);
Casey Dahlina834dd42015-09-23 11:52:15 -0700480}
481
Casey Dahlinb0966612015-10-19 16:35:26 -0700482TEST_F(PrimitiveInterfaceASTTest, GeneratesInterfaceSource) {
Christopher Wiley90be4e32015-10-20 14:55:25 -0700483 unique_ptr<AidlInterface> interface = Parse();
Christopher Wiley1dd458d2015-09-30 11:05:52 -0700484 ASSERT_NE(interface, nullptr);
485 TypeNamespace types;
486 unique_ptr<Document> doc = internals::BuildInterfaceSource(types, *interface);
Casey Dahlinb0966612015-10-19 16:35:26 -0700487 Compare(doc.get(), kExpectedPrimitiveInterfaceSourceOutput);
488}
489
490class ComplexTypeInterfaceASTTest : public ASTTest {
491 protected:
492 const string fp_ = "android/os/IComplexTypeInterface.aidl";
493 const string& FilePath() override { return fp_; }
494 const string& FileContents() override { return kComplexTypeInterfaceAIDL; }
495};
496
497TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
498 unique_ptr<AidlInterface> interface = Parse();
499 ASSERT_NE(interface, nullptr);
500 TypeNamespace types;
501 unique_ptr<Document> doc = internals::BuildClientHeader(types, *interface);
502 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
503}
504
505TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
506 unique_ptr<AidlInterface> interface = Parse();
507 ASSERT_NE(interface, nullptr);
508 TypeNamespace types;
509 unique_ptr<Document> doc = internals::BuildClientSource(types, *interface);
510 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
511}
512
513TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
514 unique_ptr<AidlInterface> interface = Parse();
515 ASSERT_NE(interface, nullptr);
516 TypeNamespace types;
517 unique_ptr<Document> doc = internals::BuildServerHeader(types, *interface);
518 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
519}
520
521TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
522 unique_ptr<AidlInterface> interface = Parse();
523 ASSERT_NE(interface, nullptr);
524 TypeNamespace types;
525 unique_ptr<Document> doc = internals::BuildServerSource(types, *interface);
526 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
527}
528
529TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
530 unique_ptr<AidlInterface> interface = Parse();
531 ASSERT_NE(interface, nullptr);
532 TypeNamespace types;
533 unique_ptr<Document> doc = internals::BuildInterfaceHeader(types, *interface);
534 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
535}
536
537TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
538 unique_ptr<AidlInterface> interface = Parse();
539 ASSERT_NE(interface, nullptr);
540 TypeNamespace types;
541 unique_ptr<Document> doc = internals::BuildInterfaceSource(types, *interface);
542 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
Christopher Wiley1dd458d2015-09-30 11:05:52 -0700543}
544
Christopher Wileyf944e792015-09-29 10:00:46 -0700545} // namespace cpp
Casey Dahlina834dd42015-09-23 11:52:15 -0700546} // namespace aidl
547} // namespace android