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 #include <ipc_types.h>
18 #include <pointer_event.h>
19 #include "iremote_object_mocker.h"
20 #include "mock/mock_session_stub.h"
21 #include "session/host/include/zidl/session_stub.h"
22 #include "ability_start_setting.h"
23 #include "session/host/include/zidl/session_ipc_interface_code.h"
24 #include "want.h"
25 #include "ws_common.h"
26
27 using namespace testing;
28 using namespace testing::ext;
29
30 namespace OHOS {
31 namespace Rosen {
32
33 class SessionStubLifecycleTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39
40 private:
41 sptr <SessionStub> session_ = nullptr;
42 };
43
SetUpTestCase()44 void SessionStubLifecycleTest::SetUpTestCase()
45 {
46 }
47
TearDownTestCase()48 void SessionStubLifecycleTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void SessionStubLifecycleTest::SetUp()
53 {
54 session_ = new (std::nothrow) SessionStubMocker();
55 EXPECT_NE(nullptr, session_);
56 }
57
TearDown()58 void SessionStubLifecycleTest::TearDown()
59 {
60 session_ = nullptr;
61 }
62
63 namespace {
64
65 /**
66 * @tc.name: HandleShow009
67 * @tc.desc: sessionStub SessionStubLifecycleTest
68 * @tc.type: FUNC
69 * @tc.require: #I6JLSI
70 */
71 HWTEST_F(SessionStubLifecycleTest, HandleShow009, Function | SmallTest | Level2)
72 {
73 MessageParcel data;
74 MessageParcel reply;
75 data.WriteBool(false);
76 auto res = session_->HandleShow(data, reply);
77 ASSERT_EQ(0, res);
78 }
79
80 /**
81 * @tc.name: HandleHide010
82 * @tc.desc: sessionStub SessionStubLifecycleTest
83 * @tc.type: FUNC
84 * @tc.require: #I6JLSI
85 */
86 HWTEST_F(SessionStubLifecycleTest, HandleHide010, Function | SmallTest | Level2)
87 {
88 MessageParcel data;
89 MessageParcel reply;
90 data.WriteBool(true);
91 auto res = session_->HandleHide(data, reply);
92 ASSERT_EQ(0, res);
93 }
94
95 /**
96 * @tc.name: HandleDrawingCompleted
97 * @tc.desc: sessionStub SessionStubLifecycleTest
98 * @tc.type: FUNC
99 */
100 HWTEST_F(SessionStubLifecycleTest, HandleDrawingCompleted, Function | SmallTest | Level2)
101 {
102 MessageParcel data;
103 MessageParcel reply;
104 ASSERT_NE(session_, nullptr);
105 auto res = session_->HandleDrawingCompleted(data, reply);
106 ASSERT_EQ(0, res);
107 }
108
109 /**
110 * @tc.name: HandlePendingSessionActivation011
111 * @tc.desc: sessionStub SessionStubLifecycleTest
112 * @tc.type: FUNC
113 * @tc.require: #I6JLSI
114 */
115 HWTEST_F(SessionStubLifecycleTest, HandlePendingSessionActivation011, Function | SmallTest | Level2)
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 data.WriteBool(true);
120 AAFwk::Want options;
121 EXPECT_NE(data.WriteString("HandlePendingSessionActivation"), false);
122 EXPECT_NE(data.WriteParcelable(&options), false);
123 ASSERT_EQ(data.WriteUint32(1), true);
124 ASSERT_EQ(data.WriteUint64(2), true);
125 auto res = session_->HandlePendingSessionActivation(data, reply);
126 ASSERT_EQ(5, res);
127 }
128 }
129 }
130 }