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 #include <aidl/android/aidl/versioned/tests/IFooInterface.h>
18
19 #include <android/binder_auto_utils.h>
20 #include <android/binder_manager.h>
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23
24 using aidl::android::aidl::versioned::tests::BazUnion;
25 using aidl::android::aidl::versioned::tests::Foo;
26 using aidl::android::aidl::versioned::tests::IFooInterface;
27 using std::optional;
28 using std::pair;
29 using std::shared_ptr;
30 using std::string;
31 using std::vector;
32 using testing::Eq;
33
34 struct VersionedInterfaceTest : ::testing::Test {
SetUpVersionedInterfaceTest35 void SetUp() override {
36 ndk::SpAIBinder binder = ndk::SpAIBinder(AServiceManager_getService(IFooInterface::descriptor));
37 versioned = IFooInterface::fromBinder(binder);
38 ASSERT_NE(nullptr, versioned);
39 }
40 shared_ptr<IFooInterface> versioned;
41 };
42
TEST_F(VersionedInterfaceTest,getInterfaceVersion)43 TEST_F(VersionedInterfaceTest, getInterfaceVersion) {
44 int32_t version;
45 auto status = versioned->getInterfaceVersion(&version);
46 EXPECT_TRUE(status.isOk()) << status.getDescription();
47 EXPECT_EQ(1, version);
48 }
49
TEST_F(VersionedInterfaceTest,getInterfaceHash)50 TEST_F(VersionedInterfaceTest, getInterfaceHash) {
51 string hash;
52 auto status = versioned->getInterfaceHash(&hash);
53 EXPECT_TRUE(status.isOk()) << status.getDescription();
54 EXPECT_EQ("9e7be1859820c59d9d55dd133e71a3687b5d2e5b", hash);
55 }
56
TEST_F(VersionedInterfaceTest,arrayOfParcelableWithNewField)57 TEST_F(VersionedInterfaceTest, arrayOfParcelableWithNewField) {
58 vector<Foo> foos(42);
59 int32_t length;
60 auto status = versioned->returnsLengthOfFooArray(foos, &length);
61 EXPECT_TRUE(status.isOk()) << status.getDescription();
62 EXPECT_EQ(42, length);
63 }
64
TEST_F(VersionedInterfaceTest,readDataCorrectlyAfterParcelableWithNewField)65 TEST_F(VersionedInterfaceTest, readDataCorrectlyAfterParcelableWithNewField) {
66 Foo inFoo, inoutFoo, outFoo;
67 int32_t ret;
68 auto status = versioned->ignoreParcelablesAndRepeatInt(inFoo, &inoutFoo, &outFoo, 43, &ret);
69 EXPECT_TRUE(status.isOk()) << status.getDescription();
70 EXPECT_EQ(43, ret);
71 }