1 /* 2 * Copyright (C) 2025-2025 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 <cstring> 18 #include "cs_call.h" 19 #include "interoperable_communication_manager.h" 20 #include "singleton.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 using namespace testing::ext; 25 26 class InteroperableCommunicationManagerTest : public testing::Test { 27 public: SetUpTestCase()28 static void SetUpTestCase() {} TearDownTestCase()29 static void TearDownTestCase() {} SetUp()30 virtual void SetUp() {} TearDown()31 virtual void TearDown() {} 32 }; 33 34 /** 35 * @tc.number Telephony_InteroperableCommunicationManagerTest_001 36 * @tc.name test normal branch 37 * @tc.desc normal branch test 38 */ 39 HWTEST_F(InteroperableCommunicationManagerTest, 40 Telephony_InteroperableCommunicationManagerTest_001, Function | MediumTest | Level1) 41 { 42 DisconnectedDetails details; 43 sptr<CallBase> call1 = nullptr; 44 DialParaInfo mDialParaInfo; 45 sptr<CallBase> call2 = new CSCall(mDialParaInfo); 46 std::string devId = "UnitTestDeviceId"; 47 auto dcManager = DelayedSingleton<InteroperableCommunicationManager>::GetInstance(); 48 TelCallState pState = TelCallState::CALL_STATUS_UNKNOWN; 49 TelCallState nState1 = TelCallState::CALL_STATUS_INCOMING; 50 TelCallState nState2 = TelCallState::CALL_STATUS_DISCONNECTED; 51 TelCallState nState3 = TelCallState::CALL_STATUS_DISCONNECTING; 52 DistributedHardware::DmDeviceInfo deviceInfo; 53 deviceInfo.deviceTypeId = 0x6D; 54 55 ASSERT_NO_THROW(dcManager->CallStateUpdated(call1, pState, nState1)); 56 ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState1)); 57 ASSERT_NO_THROW(dcManager->SetMuted(true)); 58 ASSERT_NO_THROW(dcManager->MuteRinger()); 59 dcManager->OnDeviceOnline(deviceInfo); 60 ASSERT_NO_THROW(dcManager->CallStateUpdated(call1, pState, nState1)); 61 ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState1)); 62 ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState2)); 63 ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState3)); 64 ASSERT_NO_THROW(dcManager->SetMuted(true)); 65 ASSERT_NO_THROW(dcManager->MuteRinger()); 66 } 67 68 /** 69 * @tc.number Telephony_InteroperableCommunicationManagerTest_002 70 * @tc.name test device online and offline 71 * @tc.desc Function test 72 */ 73 HWTEST_F(InteroperableCommunicationManagerTest, 74 Telephony_InteroperableCommunicationManagerTest_002, Function | MediumTest | Level1) 75 { 76 DistributedHardware::DmDeviceInfo deviceInfo; 77 strncpy_s(deviceInfo.networkId, DM_MAX_DEVICE_ID_LEN + 1, "NetId", DM_MAX_DEVICE_ID_LEN + 1); 78 strncpy_s(deviceInfo.deviceName, DM_MAX_DEVICE_NAME_LEN + 1, "DevName", DM_MAX_DEVICE_NAME_LEN + 1); 79 deviceInfo.deviceTypeId = 1; 80 auto dcManager = DelayedSingleton<InteroperableCommunicationManager>::GetInstance(); 81 82 ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo)); 83 ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo)); 84 85 deviceInfo.deviceTypeId = 0x0E; 86 ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo)); 87 ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo)); 88 89 deviceInfo.deviceTypeId = 0x6D; 90 ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo)); 91 ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo)); 92 93 deviceInfo.deviceTypeId = 0x83; 94 ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo)); 95 ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo)); 96 } 97 } // namespace Telephony 98 } // namespace OHOS