• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ims_call.h"
20 #include "interoperable_communication_manager.h"
21 #include "interoperable_client_manager.h"
22 #include "singleton.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 using namespace testing::ext;
27 
28 class InteroperableCommunicationManagerTest : public testing::Test {
29 public:
SetUpTestCase()30     static void SetUpTestCase() {}
TearDownTestCase()31     static void TearDownTestCase() {}
SetUp()32     virtual void SetUp() {}
TearDown()33     virtual void TearDown() {}
34 };
35 
36 /**
37  * @tc.number   Telephony_InteroperableCommunicationManagerTest_001
38  * @tc.name     test normal branch
39  * @tc.desc     normal branch test
40  */
41 HWTEST_F(InteroperableCommunicationManagerTest,
42          Telephony_InteroperableCommunicationManagerTest_001, Function | MediumTest | Level1)
43 {
44     DisconnectedDetails details;
45     sptr<CallBase> call1 = nullptr;
46     DialParaInfo mDialParaInfo;
47     sptr<CallBase> call2 = new CSCall(mDialParaInfo);
48     std::string devId = "UnitTestDeviceId";
49     auto dcManager = DelayedSingleton<InteroperableCommunicationManager>::GetInstance();
50     TelCallState pState = TelCallState::CALL_STATUS_UNKNOWN;
51     TelCallState nState1 = TelCallState::CALL_STATUS_INCOMING;
52     TelCallState nState2 = TelCallState::CALL_STATUS_DISCONNECTED;
53     TelCallState nState3 = TelCallState::CALL_STATUS_DISCONNECTING;
54     DistributedHardware::DmDeviceInfo deviceInfo;
55     deviceInfo.deviceTypeId = 0x6D;
56 
57     ASSERT_NO_THROW(dcManager->CallStateUpdated(call1, pState, nState1));
58     ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState1));
59     ASSERT_NO_THROW(dcManager->SetMuted(true));
60     ASSERT_NO_THROW(dcManager->MuteRinger());
61     dcManager->OnDeviceOnline(deviceInfo);
62     ASSERT_NO_THROW(dcManager->CallStateUpdated(call1, pState, nState1));
63     ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState1));
64     ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState2));
65     ASSERT_NO_THROW(dcManager->CallStateUpdated(call2, pState, nState3));
66     ASSERT_NO_THROW(dcManager->SetMuted(true));
67     ASSERT_NO_THROW(dcManager->MuteRinger());
68 }
69 
70 /**
71  * @tc.number   Telephony_InteroperableCommunicationManagerTest_002
72  * @tc.name     test device online and offline
73  * @tc.desc     Function test
74  */
75 HWTEST_F(InteroperableCommunicationManagerTest,
76          Telephony_InteroperableCommunicationManagerTest_002, Function | MediumTest | Level1)
77 {
78     DistributedHardware::DmDeviceInfo deviceInfo;
79     strncpy_s(deviceInfo.networkId, DM_MAX_DEVICE_ID_LEN + 1, "NetId", DM_MAX_DEVICE_ID_LEN + 1);
80     strncpy_s(deviceInfo.deviceName, DM_MAX_DEVICE_NAME_LEN + 1, "DevName", DM_MAX_DEVICE_NAME_LEN + 1);
81     deviceInfo.deviceTypeId = 1;
82     auto dcManager = DelayedSingleton<InteroperableCommunicationManager>::GetInstance();
83 
84     ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo));
85     ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo));
86 
87     deviceInfo.deviceTypeId = 0x0E;
88     ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo));
89     ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo));
90 
91     deviceInfo.deviceTypeId = 0x6D;
92     ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo));
93     ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo));
94 
95     deviceInfo.deviceTypeId = 0x83;
96     ASSERT_NO_THROW(dcManager->OnDeviceOnline(deviceInfo));
97     ASSERT_NO_THROW(dcManager->OnDeviceOffline(deviceInfo));
98 }
99 
100 /**
101  * @tc.number   Telephony_InteroperableCommunicationManagerTest_003
102  * @tc.name     test new call created
103  * @tc.desc     Function test
104  */
105 HWTEST_F(InteroperableCommunicationManagerTest,
106          Telephony_InteroperableCommunicationManagerTest_003, Function | MediumTest | Level1)
107 {
108     auto dcManager = DelayedSingleton<InteroperableCommunicationManager>::GetInstance();
109     sptr<CallBase> call = nullptr;
110     dcManager->dataController_ = nullptr;
111     EXPECT_EQ(dcManager->dataController_, nullptr);
112     EXPECT_NO_THROW(dcManager->NewCallCreated(call)); // dataControl is nullptr
113 
114     dcManager->dataController_ = std::make_shared<InteroperableClientManager>();
115     dcManager->peerDevices_.push_back("test");
116     EXPECT_FALSE(dcManager->peerDevices_.empty());
117     EXPECT_NO_THROW(dcManager->NewCallCreated(call)); // call is nullptr
118 
119     DialParaInfo info;
120     call = new IMSCall(info);
121     EXPECT_NO_THROW(dcManager->NewCallCreated(call));
122     dcManager->peerDevices_.clear();
123 }
124 } // namespace Telephony
125 } // namespace OHOS