• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "iremote_object_mocker.h"
17 #include "mock_message_parcel.h"
18 #include "session_ipc_interface_code.h"
19 #include "session_proxy.h"
20 #include "ws_common.h"
21 #include <gtest/gtest.h>
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 class SessionProxyPropertyTest : public testing::Test {
29 public:
SessionProxyPropertyTest()30     SessionProxyPropertyTest() {}
~SessionProxyPropertyTest()31     ~SessionProxyPropertyTest() {}
32 };
33 
34 namespace {
35 
36 /**
37  * @tc.name: UpdateSessionPropertyByAction01
38  * @tc.desc: UpdateSessionPropertyByAction
39  * @tc.type: FUNC
40  */
41 HWTEST_F(SessionProxyPropertyTest, UpdateSessionPropertyByAction01, Function | SmallTest | Level2)
42 {
43     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction01 start";
44     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
45     ASSERT_NE(iRemoteObjectMocker, nullptr);
46     auto sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
47     ASSERT_NE(sProxy, nullptr);
48     WMError res = sProxy->UpdateSessionPropertyByAction(nullptr,
49         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
50     ASSERT_EQ(res, WMError::WM_OK);
51     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction01 end";
52 }
53 
54 /**
55  * @tc.name: UpdateSessionPropertyByAction02
56  * @tc.desc: UpdateSessionPropertyByAction
57  * @tc.type: FUNC
58  */
59 HWTEST_F(SessionProxyPropertyTest, UpdateSessionPropertyByAction02, Function | SmallTest | Level2)
60 {
61     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction02 start";
62     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
63     ASSERT_NE(iRemoteObjectMocker, nullptr);
64     auto sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
65     ASSERT_NE(sProxy, nullptr);
66     WMError res = sProxy->UpdateSessionPropertyByAction(nullptr,
67         WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
68     ASSERT_EQ(res, WMError::WM_OK);
69     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction02 end";
70 }
71 
72 /**
73  * @tc.name: UpdateSessionPropertyByAction
74  * @tc.desc: normal function
75  * @tc.type: FUNC
76  */
77 HWTEST_F(SessionProxyPropertyTest, UpdateSessionPropertyByAction, Function | SmallTest | Level2)
78 {
79     MockMessageParcel::ClearAllErrorFlag();
80     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
81     auto sessionProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
82     ASSERT_NE(sessionProxy, nullptr);
83     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
84     ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, sessionProxy->UpdateSessionPropertyByAction(nullptr,
85         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
86     MockMessageParcel::ClearAllErrorFlag();
87 
88     MockMessageParcel::SetWriteUint32ErrorFlag(true);
89     ASSERT_EQ(WMError::WM_OK, sessionProxy->UpdateSessionPropertyByAction(nullptr,
90         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
91     MockMessageParcel::ClearAllErrorFlag();
92 
93     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
94     ASSERT_NE(property, nullptr);
95     MockMessageParcel::SetWriteBoolErrorFlag(true);
96     ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, sessionProxy->UpdateSessionPropertyByAction(property,
97         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
98     MockMessageParcel::ClearAllErrorFlag();
99 
100     MockMessageParcel::SetWriteBoolErrorFlag(false);
101     ASSERT_EQ(WMError::WM_OK, sessionProxy->UpdateSessionPropertyByAction(property,
102         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
103     MockMessageParcel::ClearAllErrorFlag();
104 
105     MockMessageParcel::SetWriteBoolErrorFlag(true);
106     ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, sessionProxy->UpdateSessionPropertyByAction(nullptr,
107         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
108     MockMessageParcel::ClearAllErrorFlag();
109 
110     MockMessageParcel::SetWriteBoolErrorFlag(false);
111     ASSERT_EQ(WMError::WM_OK, sessionProxy->UpdateSessionPropertyByAction(nullptr,
112         WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
113     MockMessageParcel::ClearAllErrorFlag();
114 }
115 }
116 } // namespace Rosen
117 } // OHOS
118