1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "ability_manager_ipc_interface_code.h"
19 #include "auto_startup_info.h"
20 #include "event_handler.h"
21 #include "ipc_types.h"
22 #include "message_parcel.h"
23 #define private public
24 #include "mock_auto_startup_callback_stub.h"
25 #undef private
26
27 using namespace testing;
28 using namespace testing::ext;
29 namespace OHOS {
30 namespace AbilityRuntime {
31
32 class AutoStartupCallBackStubTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 void WriteInterfaceToken(MessageParcel &parcel);
39 };
40
SetUpTestCase(void)41 void AutoStartupCallBackStubTest::SetUpTestCase(void) {}
42
TearDownTestCase(void)43 void AutoStartupCallBackStubTest::TearDownTestCase(void) {}
44
SetUp()45 void AutoStartupCallBackStubTest::SetUp() {}
46
TearDown()47 void AutoStartupCallBackStubTest::TearDown() {}
48
WriteInterfaceToken(MessageParcel & parcel)49 void AutoStartupCallBackStubTest::WriteInterfaceToken(MessageParcel &parcel)
50 {
51 parcel.WriteInterfaceToken(AutoStartupCallBackStub::GetDescriptor());
52 }
53
54 /*
55 * Feature: AutoStartupCallBackStubTest
56 * Function: OnAutoStartupOnInner
57 * SubFunction: AutoStartupCallBackStubTest
58 * FunctionPoints: AutoStartupCallbackStubTest OnAutoStartupOnInner
59 */
60 HWTEST_F(AutoStartupCallBackStubTest, OnAutoStartupOnInner_001, TestSize.Level1)
61 {
62 GTEST_LOG_(INFO) << "AutoStartupCallBackStubTest OnAutoStartupOnInner_001 start";
63 auto stub = new (std::nothrow) MockAutoStartupCallbackStub();
64 EXPECT_TRUE(stub);
65
66 AutoStartupInfo info;
67 info.bundleName = "bundleName";
68 MessageParcel data;
69 MessageParcel reply;
70 MessageOption option;
71 WriteInterfaceToken(data);
72 data.WriteParcelable(&info);
73
74 auto result = stub->OnRemoteRequest(
75 static_cast<uint32_t>(AAFwk::AbilityManagerInterfaceCode::ON_AUTO_STARTUP_ON), data, reply, option);
76 EXPECT_EQ(result, NO_ERROR);
77 GTEST_LOG_(INFO) << "AutoStartupCallBackStubTest OnAutoStartupOnInner_001 end";
78 }
79
80 /*
81 * Feature: AutoStartupCallBackStubTest
82 * Function: OnAutoStartupOffInner
83 * SubFunction: NA
84 * FunctionPoints: AutoStartupCallBackStubTest OnAutoStartupOffInner
85 */
86 HWTEST_F(AutoStartupCallBackStubTest, OnAutoStartupOffInner_001, TestSize.Level1)
87 {
88 GTEST_LOG_(INFO) << "AutoStartupCallBackStubTest OnAutoStartupOffInner_001 start";
89 auto stub = new (std::nothrow) MockAutoStartupCallbackStub();
90 EXPECT_TRUE(stub);
91
92 AutoStartupInfo info;
93 info.bundleName = "bundleName";
94 MessageParcel data;
95 MessageParcel reply;
96 MessageOption option;
97 WriteInterfaceToken(data);
98 data.WriteParcelable(&info);
99
100 auto result = stub->OnRemoteRequest(
101 static_cast<uint32_t>(AAFwk::AbilityManagerInterfaceCode::ON_AUTO_STARTUP_OFF), data, reply, option);
102 EXPECT_EQ(result, NO_ERROR);
103 GTEST_LOG_(INFO) << "AutoStartupCallBackStubTest OnAutoStartupOffInner_001 end";
104 }
105 } // namespace AbilityRuntime
106 } // namespace OHOS
107