1 /*
2  * Copyright (C) 2019, 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 package android.aidl.tests;
18 
19 import static org.hamcrest.core.Is.is;
20 import static org.junit.Assert.assertThat;
21 
22 import android.aidl.tests.IntEnum;
23 import android.aidl.tests.generic.Baz;
24 import android.aidl.tests.generic.IFaz;
25 import android.aidl.tests.generic.Pair;
26 import android.os.IBinder;
27 import android.os.RemoteException;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.JUnit4;
31 
32 @RunWith(JUnit4.class)
33 public class GenericTests {
34 
35     @Test
testGeneric()36     public void testGeneric() throws RemoteException {
37         IFaz.Stub ifaz = new IFaz.Stub() {
38             public Pair<Integer, String> getPair() {
39                 Pair<Integer, String> ret = new Pair<Integer, String>();
40                 ret.mFirst = 15;
41                 ret.mSecond = "My";
42                 return ret;
43             }
44             public Pair<Baz, Baz> getPair2() {
45                 Pair<Baz, Baz> ret = new Pair<Baz, Baz>();
46                 ret.mFirst = new Baz();
47                 ret.mFirst.a = 15;
48                 ret.mSecond = new Baz();
49                 ret.mSecond.a = 16;
50                 return ret;
51             }
52 
53             public Pair<Integer, Integer> getPair3() {
54               Pair<Integer, Integer> ret = new Pair<Integer, Integer>();
55               ret.mFirst = 15;
56               ret.mSecond = IntEnum.BAR;
57               return ret;
58             }
59         };
60 
61         IFaz service = IFaz.Stub.asInterface(ifaz);
62         assertThat(service.getPair().mFirst, is(15));
63         assertThat(service.getPair().mSecond, is("My"));
64 
65         assertThat(service.getPair2().mFirst.a, is(15));
66         assertThat(service.getPair2().mSecond.a, is(16));
67 
68         assertThat(service.getPair3().mFirst, is(15));
69         assertThat(service.getPair3().mSecond, is(IntEnum.BAR));
70     }
71 }
72