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 #include "session_proxy.h" 16 17 #include <gtest/gtest.h> 18 #include "accessibility_event_info.h" 19 #include "iremote_object_mocker.h" 20 #include "mock_message_parcel.h" 21 #include "window_manager_hilog.h" 22 using namespace testing; 23 using namespace testing::ext; 24 namespace OHOS { 25 namespace Rosen { 26 namespace { 27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionProxyMockTest"}; 28 } 29 class SessionProxyMockTest : public testing::Test { 30 public: SessionProxyMockTest()31 SessionProxyMockTest() {} ~SessionProxyMockTest()32 ~SessionProxyMockTest() {} 33 }; 34 namespace { 35 /** 36 * @tc.name: TransferAccessibilityEvent01 37 * @tc.desc: normal function 38 * @tc.type: FUNC 39 */ 40 HWTEST_F(SessionProxyMockTest, TransferAccessibilityEvent01, Function | SmallTest | Level2) 41 { 42 WLOGI("TransferAccessibilityEvent01 begin"); 43 MockMessageParcel::ClearAllErrorFlag(); 44 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 45 SessionProxy* sProxy = new(std::nothrow) SessionProxy(iRemoteObjectMocker); 46 Accessibility::AccessibilityEventInfo info; 47 int64_t uiExtensionIdLevel = 0; 48 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); 49 WSError res = sProxy->TransferAccessibilityEvent(info, uiExtensionIdLevel); 50 ASSERT_EQ(res, WSError::WS_ERROR_IPC_FAILED); 51 MockMessageParcel::ClearAllErrorFlag(); 52 WLOGI("TransferAccessibilityEvent01 end"); 53 } 54 55 /** 56 * @tc.name: TransferAccessibilityEvent02 57 * @tc.desc: normal function 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(SessionProxyMockTest, TransferAccessibilityEvent02, Function | SmallTest | Level2) 61 { 62 WLOGI("TransferAccessibilityEvent02 begin"); 63 MockMessageParcel::ClearAllErrorFlag(); 64 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 65 SessionProxy* sProxy = new(std::nothrow) SessionProxy(iRemoteObjectMocker); 66 Accessibility::AccessibilityEventInfo info; 67 int64_t uiExtensionIdLevel = 0; 68 69 MockMessageParcel::SetWriteParcelableErrorFlag(true); 70 WSError res = sProxy->TransferAccessibilityEvent(info, uiExtensionIdLevel); 71 ASSERT_EQ(res, WSError::WS_ERROR_IPC_FAILED); 72 MockMessageParcel::ClearAllErrorFlag(); 73 WLOGI("TransferAccessibilityEvent02 end"); 74 } 75 76 /** 77 * @tc.name: TransferAccessibilityEvent02 78 * @tc.desc: normal function 79 * @tc.type: FUNC 80 */ 81 HWTEST_F(SessionProxyMockTest, TransferAccessibilityEvent03, Function | SmallTest | Level2) 82 { 83 WLOGI("TransferAccessibilityEvent03 begin"); 84 MockMessageParcel::ClearAllErrorFlag(); 85 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 86 SessionProxy* sProxy = new(std::nothrow) SessionProxy(iRemoteObjectMocker); 87 Accessibility::AccessibilityEventInfo info; 88 int64_t uiExtensionIdLevel = 0; 89 90 MockMessageParcel::SetWriteInt64ErrorFlag(true); 91 WSError res = sProxy->TransferAccessibilityEvent(info, uiExtensionIdLevel); 92 ASSERT_EQ(res, WSError::WS_ERROR_IPC_FAILED); 93 94 MockMessageParcel::ClearAllErrorFlag(); 95 WLOGI("TransferAccessibilityEvent03 end"); 96 } 97 } // namespace 98 } // namespace Rosen 99 } // namespace OHOS 100