• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021, 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.assertNotNull;
21 import static org.junit.Assert.assertThat;
22 import static org.junit.Assume.assumeTrue;
23 
24 import android.aidl.tests.nested.INestedService;
25 import android.aidl.tests.nested.ParcelableWithNested;
26 import android.os.IBinder;
27 import android.os.RemoteException;
28 import android.os.ServiceManager;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.JUnit4;
32 
33 @RunWith(JUnit4.class)
34 public class NestedTypesTests {
35   @Test
testUseNestedTypes()36   public void testUseNestedTypes() throws RemoteException {
37     IBinder binder = ServiceManager.waitForService(INestedService.class.getName());
38     assertNotNull(binder);
39     INestedService nestedService = INestedService.Stub.asInterface(binder);
40     assertNotNull(nestedService);
41 
42     // OK -> NOT_OK
43     ParcelableWithNested p = new ParcelableWithNested();
44     p.status = ParcelableWithNested.Status.OK;
45     INestedService.Result result = nestedService.flipStatus(p);
46     assertThat(result, is(ParcelableWithNested.Status.NOT_OK));
47 
48     // NOT_OK -> OK with nested callback interface
49     class Callback extends INestedService.ICallback.Stub {
50       byte received = ParcelableWithNested.Status.NOT_OK;
51       @Override
52       public void done(byte st) {
53         received = st;
54       }
55     }
56     Callback cb = new Callback();
57     nestedService.flipStatusWithCallback(p.status, cb);
58     assertThat(cb.received, is(ParcelableWithNested.Status.OK));
59   }
60 }
61