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 "interoperable_data_controller.h" 18 #include "interoperable_server_manager.h" 19 #include "interoperable_device_observer.h" 20 #include "transmission_manager.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 using namespace testing::ext; 25 26 class InteroperableServerManagerTest : 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_InteroperableServerManager_001 36 * @tc.name test normal branch 37 * @tc.desc normal branch test 38 */ 39 HWTEST_F(InteroperableServerManagerTest, Telephony_InteroperableServerManager_001, Function | MediumTest | Level1) 40 { 41 std::string devId = "UnitTestDeviceId"; 42 std::string devName = "UnitTestDeviceName"; 43 uint16_t deviceType = 1; 44 auto deviceObserver = std::make_shared<InteroperableServerManager>(); 45 ASSERT_NO_THROW(deviceObserver->OnDeviceOnline(devId, devName, deviceType)); 46 ASSERT_NO_THROW(deviceObserver->OnDeviceOffline(devId, devName, deviceType)); 47 } 48 49 /** 50 * @tc.number Telephony_InteroperableServerManager_002 51 * @tc.name test recv message 52 * @tc.desc normal branch test 53 */ 54 HWTEST_F(InteroperableServerManagerTest, Telephony_InteroperableServerManager_002, Function | MediumTest | Level1) 55 { 56 int32_t msgType = 1; 57 cJSON *msg = nullptr; 58 auto deviceObserver = std::make_shared<InteroperableServerManager>(); 59 EXPECT_NO_THROW(deviceObserver->HandleSpecificMsg(msgType, msg)); 60 61 msg = cJSON_Parse("{ \"testData\": 101 }"); 62 msgType = static_cast<int32_t>(InteroperableMsgType::DATA_TYPE_QUERY_REQUISITES_DATA); 63 EXPECT_NO_THROW(deviceObserver->HandleSpecificMsg(msgType, msg)); 64 cJSON_Delete(msg); 65 } 66 67 /** 68 * @tc.number Telephony_InteroperableServerManager_003 69 * @tc.name test recv message 70 * @tc.desc normal branch test 71 */ 72 HWTEST_F(InteroperableServerManagerTest, Telephony_InteroperableServerManager_003, Function | MediumTest | Level1) 73 { 74 int32_t msgType = 1; 75 cJSON *msg = nullptr; 76 auto deviceObserver = std::make_shared<InteroperableServerManager>(); 77 EXPECT_NO_THROW(deviceObserver->HandleSpecificMsg(msgType, msg)); 78 79 msg = cJSON_Parse("{ \"testData\": 101 }"); 80 msgType = static_cast<int32_t>(InteroperableMsgType::DATA_TYPE_QUERY_REQUISITES_DATA); 81 EXPECT_NO_THROW(deviceObserver->HandleSpecificMsg(msgType, msg)); 82 cJSON_Delete(msg); 83 } 84 85 /** 86 * @tc.number Telephony_InteroperableServerManager_004 87 * @tc.name test recv query requisites data msg 88 * @tc.desc normal branch test 89 */ 90 HWTEST_F(InteroperableServerManagerTest, Telephony_InteroperableServerManager_004, Function | MediumTest | Level1) 91 { 92 cJSON *msg = cJSON_Parse("{ \"123\": \"123456\"}"); 93 auto deviceObserver = std::make_shared<InteroperableServerManager>(); 94 EXPECT_NO_THROW(deviceObserver->OnQueryRequisitesDataMsgReceived(msg)); 95 cJSON_Delete(msg); 96 97 msg = cJSON_Parse("{ \"phoneNumber\": \"123456\"}"); 98 EXPECT_NO_THROW(deviceObserver->OnQueryRequisitesDataMsgReceived(msg)); 99 cJSON_Delete(msg); 100 } 101 } // namespace Telephony 102 } // namespace OHOS