1 /*
2  * Copyright (C) 2020 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 "aidl_test_client.h"
18 #include "gmock/gmock.h"
19 
20 #include <android/aidl/tests/INewName.h>
21 #include <android/aidl/tests/IOldName.h>
22 
23 using android::IInterface;
24 using android::String16;
25 using android::aidl::tests::INewName;
26 using android::aidl::tests::IOldName;
27 using testing::Eq;
28 
29 class RenamedInterfaceTest : public AidlTest {
30  public:
SetUp()31   void SetUp() override {
32     AidlTest::SetUp();
33 
34     ASSERT_TRUE(service->GetOldNameInterface(&oldName).isOk());
35     ASSERT_TRUE(service->GetNewNameInterface(&newName).isOk());
36   }
37 
38   sp<IOldName> oldName;
39   sp<INewName> newName;
40 };
41 
TEST_F(RenamedInterfaceTest,oldAsOld)42 TEST_F(RenamedInterfaceTest, oldAsOld) {
43   ASSERT_THAT(String16("android.aidl.tests.IOldName"), oldName->getInterfaceDescriptor());
44   String16 realName;
45   ASSERT_TRUE(oldName->RealName(&realName).isOk());
46   ASSERT_THAT(String16("OldName"), realName);
47 }
48 
TEST_F(RenamedInterfaceTest,newAsNew)49 TEST_F(RenamedInterfaceTest, newAsNew) {
50   ASSERT_THAT(String16("android.aidl.tests.IOldName"), newName->getInterfaceDescriptor());
51   String16 realName;
52   ASSERT_TRUE(newName->RealName(&realName).isOk());
53   ASSERT_THAT(String16("NewName"), realName);
54 }
55 
TEST_F(RenamedInterfaceTest,oldAsNew)56 TEST_F(RenamedInterfaceTest, oldAsNew) {
57   sp<INewName> oldAsNew = INewName::asInterface(IInterface::asBinder(oldName));
58   ASSERT_THAT(String16("android.aidl.tests.IOldName"), oldAsNew->getInterfaceDescriptor());
59   String16 realName;
60   ASSERT_TRUE(oldAsNew->RealName(&realName).isOk());
61   ASSERT_THAT(String16("OldName"), realName);
62 }
63 
TEST_F(RenamedInterfaceTest,newAsOld)64 TEST_F(RenamedInterfaceTest, newAsOld) {
65   sp<IOldName> newAsOld = IOldName::asInterface(IInterface::asBinder(newName));
66   ASSERT_THAT(String16("android.aidl.tests.IOldName"), newAsOld->getInterfaceDescriptor());
67   String16 realName;
68   ASSERT_TRUE(newAsOld->RealName(&realName).isOk());
69   ASSERT_THAT(String16("NewName"), realName);
70 }
71